The SolutionTo solve this, I developed a fairly simple multithreading model, that frees the game's programmer from the message pump and its undesirable finite state programming model. Fortunately, Windows supports multithreading. This means that our application runs several simultaneous execution threads. The idea is very simple: put the message pump in one thread, put the game in another thread. The message pump will remain in the initial thread (being the initial thread does not imply that it has more priviledges or importance). We can thus remove the UpdateWorld() function from the Message Pump and return it to its simplest form. Now, we just need to add the code necessary to initiate the game thread to the DoInit() function.
And MainThread() is defined by:
Now, here we are. MainThread() will invoke our RunGame() function, and when it is finished, we just post a WM_CLOSE message to tell the other thread to finish execution. |
|||||||||||