Do you use multithreading in your games ?

Started by
7 comments, last by Frozen 20 years, 3 months ago
Well, I''m new to windows programming, so I have a question: Do you use multithreading in your games ? If yes, which is the optimal number of threads?
Advertisement
Neh... it takes too much extra work. I think they probably to do in some professional games, but it takes way more error handleing especially if you are new to threading cause things don''t always happen in the right order and stuff. That is just my opinion, some here probably do use it but it is easier to not.




It''s Maxd Gaming, put in an underscore and I will beat you with a rubber ducky!
{ Check out my Forum } { My First Space Art (Ever) }{ My .Net Information }{ A upcoming space RTS codenamed Gruntacktica . }{ . }

Not following the new trend:
Looky here mommy! No cow pic!


The Untitled RPG - |||||||||| 40%Free Music for your gamesOriginal post by capn_midnight 23yrold, is your ass burning from all the kissing it is recieving?
For some things like networking, multithreading is sometimes required. But from personal experience, I''ve only experimented with multithreading for input, and even though I was only writing in the input thread and reading in the main thread, it felt too complex for me, so I scrapped it.
Threads can be used for far more things. Actually, they can be used for quite practical things.

Imagine a scenario where you want to read a giant chunk of data from a file without interrupting but you want to display an animation during the time it takes to load it. Simple, you use a thread that displays an animation and halts when the main application reports that the file has been fully loaded.

It''s quite simple, in all situations where you know you have to, without any doubt, do two things at the same time seperately, threads are the way to go.
-----------------------------Final Frontier Trader
Yes, for AI, netcode, and other small stuff.
Depends on the type of game and scale of course. My engine can detect if you have a dual processor system, or Hyper-Threading, and it will then spawn more threads, because your system can handle them so well.

Threads arent a huge no-no in games, but you DO have to pace yourself when using them. You dont want to over do it...

Some places i use/might use threads:
- Window control code. A blocking thread receives the window''s messages and handles them, then blocks.
- Real time map streaming. A thread reads the level file from the hard disk to memory, in small quantities, to not slow gameplay down. It "sleeps" once a large portion of the world has been "uploaded" to memory...
- Blocking netcode. A thread waits for incoming data from another player''s pc. It blocks if there isnt any.
- AI. If the AI isnt very processor intensive, it can sit on another thread.

[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD][Yann L.][Enginuity]
The most irrefutable evidence that there is intelligent life in the Universe is that they haven''t contacted us!

How can you detect if I have a dual processor system, or Hyper-Threading? Or is it secret ?

On Windows, there is an API function to get system information.
quote:On Windows, there is an API function to get system information.


Clicky is a nice little tutorial covering Hyper-threading. It includes source code to check the system for hyper-threading.

quote:Original post by biovenger
Threads can be used for far more things. Actually, they can be used for quite practical things.

Imagine a scenario where you want to read a giant chunk of data from a file without interrupting but you want to display an animation during the time it takes to load it. Simple, you use a thread that displays an animation and halts when the main application reports that the file has been fully loaded.

It's quite simple, in all situations where you know you have to, without any doubt, do two things at the same time seperately, threads are the way to go.



Or, alternately, you could use a thread to load the next level when the game senses the game is almost over(i.e. one monster left).




Being that I am human, I am prone to (MANY)mistakes.
Check everything I post with Google, etc.

-- Chronic sufferer of OCD

[edited by - Luke Thompson on January 18, 2004 2:10:19 AM]

[edited by - Luke Thompson on January 18, 2004 2:10:47 AM]
Threads are good for emulating missing OS features such as overlapped (asynchronous) I/O, which is available on Windows NT, but not Windows/DOS and not standard on most UNIX-es.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement