http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rendering threads in DirectX games?



Hi Atul,

>	Thanks for the replies to my past emails.  Does anyone know if
>many commercial games use separate threads to render the image to the
>screen?  

I'm not 100% sure, but I think none. 

>E.G., a game logic thread could compute AI and take input from
>the user and when it has to blit, it could just tell the rendering thread
>to blit and immediately continue to do game logic, saving any time wasted

If I remember well from reading the SDK docs on the topic of lpDD->Blt(...)
it says something like: "The device tries to schedule a Blt, and if it is
unable to do so becouse it is busy it will return DDERR_WASSTILDRAWING".
Notice the "schedule" in this line, it implies that what you would want to
do with having a seperate thread is already implemented in hardware.

Microsoft even warns against using multiple treads for stuff like this
becouse apparently programmers seem to think that "mulithreaded" means
"more performance". However, to switch between threads costs you CPU cycles
too (and don't forget that in many cases one thread has to wait for
signaled events, mutexes and critical sections), and doing this too often
will have a negative effect on the applications performance.

So when should you use multiple threads ? To give you a general idea, here
are some cases where I would use multiple threads:

- Wherever an input buffer needs to be read like during sound recording
with DirectSound or recieving network messages with DirectPlay. Using a
second thread would prevent your input buffer from being overwritten.

- When you have a large amount of calculations to perform that would take a
few seconds or more to compute. Using a second thread in this case would
prevent your user interface from freezing up.

>saving any time wasted  from waiting for the surfaces to become unlocked ...

Having a second thread locking/unlocking surfaces will do nothing for you
at all becouse when a surface is locked, DDraw performs a win16 lock on
windows and nothing else will be executing other then the code between your
lock(...) - Unlock(...) calls.

Best regards,

Karel.

-------------------------====#### Class Logic ####====---------------------

                                 Software Development

                          Microsoft Certified Professional

		Karel Bagchus 
		mailto:karel@classlogic.com
		http://www.classlogic.com

		Transvaalstraat 15 / 3-hoog
		1092 HA Amsterdam
		the Netherlands

		Tel:		+31 (0)20 - 77 75 344
		Fax:	+31 (0)20 - 77 75 344
		GSM:	06 - 22 987 327


-------------------------====###################====---------------------

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html