Is it an ok idea to run game loop in different thread from window(c++)?
Hi, while using threads to load game data as not to freeze the window, I was wondering if its an idea to put the entire game loop into a different thread from the window's message pump loop eg the PeekMessage, while(msq != WM_QUIT etc.
So if the game is starting to freeze up for whatever reason the window will still respond fine, eg minimize, quit etc.
So what do you think?
Thanks
edit: also doing this would allow the game loop to keeping flowing if the window is being dragged or something.
I'm using something simillar. I preserve starting thread, however I alow work to happen only in other threads. Starting thread is for cleanup purposes.
Yes it will allow you to continue updating and rendering even while the user clicks on the status-bar. Most annoying, and quite complicated to work around this issue.
I've done that. No problem at all. Also the game thread can be easily paused if needed (minimizing th window for example). But consider to use WaitMessage in the message loop...
Yes it's a good idea to run the game loop in a separate thread. When you call WaitMessage when the program is minimized, be sure to call SuspendThread on the game loop thread immediately before the WaitMessage call, and ResumeThread immediately after. That way your game won't be busy using the CPU when it's not supposed to be.
It may be better to use a monitor to put the rendering thread to sleep at an appropriate syncronization point. Suspend/ResumeThread are down & dirty routines and using them this like could result in bad mojo.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement