|
From: Philip B. <phi...@pb...> - 2007-11-13 01:16:22
|
Hello everyone, This will be a rather long message. I have a question regarding multi threading and syncrhonization for a = game that I'm working on. The game will have hundreds of objects = (enemies, bullets and so on), and I am trying to think of an efficient = way to implement this using multiple threads. I will have input and player actions in one thread since they are tied = together, window message processing in the main thread which will be = idle for the most part, and then a thread which handles the enemies. I = will give them different priority levels so that they don't all move at = full speed all the time. I have two ideas for how to do this: 1. Give each enemy its own critical section object so that it is free = whenever it is not being read or written to. Then whenever the player = thread or another enemy in the same thread wants to access it either for = reading or writing, it'll enter the critical section. I figure that this = could potencially cause delays, for example what if an enemy decides to = move while the player is firing at it and thus modifying its data from a = different thread? 2. Have a critical section for all the enemies, which I guess would not = be very practical but it is one idea that I had. Can anyone perhaps suggest a good way of handling this? I want to be = able to read and write the enemy information from any thread as fast as = possible, though most of the work will occur in one and the same thread = (the enemy thread). Thanks in advance for any help. Regards Philip Bennefall |