• Advertisement
Sign in to follow this  

Is it an ok idea to run game loop in different thread from window(c++)?

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement