• Advertisement
Sign in to follow this  

How to make windowed games share the CPU

This topic is 4798 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

hey, i have a windowed top down shooter but when i switch to another window, i think my game is still eating up too much CPU time, does anyone have any ideas of how to fix this?

Share this post


Link to post
Share on other sites
Advertisement
Catch the WM_ACTIVATE message in your window proc and pause the game loop, e.g. by using GetMessage() instead of PeekMessage() if the pause-flag is set.

Share this post


Link to post
Share on other sites
There are probably many ways to do this, but one way is to listen for the WM_ACTIVATE event to determine when your window becomes inactive. When it does, call whatever code you need to pause your game, and then set a flag. That flag should trigger your main loop to call WaitMessage() instead of calling your game logic. WaitMessage will cause your program to stop running until your window recieves a message. When you get another WM_ACTIVATE message that indicates your window is active, unpause the game and reset the flag.

Share this post


Link to post
Share on other sites
So are you saying i recieve a WM_ACTIVATE message everytime the window is activated OR inactivated, or do i recieve a WM_INACTIVATE message when I go to another window and a WM_ACTIVATE when it is activated?

if possible, i dont want to pause this window myself, i notice windows does a nice job of pausing while i move or resize the window. It pauses the window clock and as far as i can see basically does nothing untill you are done your moving or resizing. I was wondering if there was some way i could tell windows to pause it like that when it isnt being used. This allows me to have even less unnecesary cpu time used and it makes it easier for me to code :D

thanks.

Share this post


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

  • Advertisement