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

Started by
6 comments, last by Shannon Barber 18 years ago
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.
Advertisement
I would say doing that would make things needlessly complex.
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
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.
Sounds good.

Kuphryn
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.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
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.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement