Sign in to follow this  
johnnyBravo

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

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this