DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Hosted Sites > TripleBuffer
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 07-01-2004, 05:10 PM   #1
shadwdrak
New Member
 
Join Date: Jul 2004
Posts: 1
Default

I noticed that the CPU usage was spiking to 100% when the app was not active. Normally this is if its a windowed app, or if you alt-tabbed out of a full screen app.

I fixed this by having the framework sleep 5 seconds in the main loop if it wasn't active.

look at the code below, I added an else, and the Sleep inside it.

Code:
void Core::Loop() { ... if( mbActive ) { ... } // active else { Sleep(5); //if we are not the active app, then be nice and free up the cpu. } ... }
shadwdrak is offline   Reply With Quote
Old 07-01-2004, 09:20 PM   #2
bladder
DevMaster Staff
 
bladder's Avatar
 
Join Date: Sep 2003
Location: Hell
Posts: 1,109
Default

yeah, that should have been done before. Always good to let the CPU have some time to itself when inactive.
___________________________________________
- TripleBuffer
- Me blog
bladder is offline   Reply With Quote
Old 01-27-2005, 12:04 PM   #3
Bored_Now
New Member
 
Join Date: Jan 2005
Posts: 1
Default

Quote:
Originally Posted by shadwdrak
I noticed that the CPU usage was spiking to 100% when the app was not active. Normally this is if its a windowed app, or if you alt-tabbed out of a full screen app.

I fixed this by having the framework sleep 5 seconds in the main loop if it wasn't active.

look at the code below, I added an else, and the Sleep inside it.

Code:
void Core::Loop() { ... if( mbActive ) { ... } // active else { Sleep(5); //if we are not the active app, then be nice and free up the cpu. } ... }
[snapback]8547[/snapback]

I've had a think about this and would like to suggest an alternative. The active status should only change when a windows message is received. Ideally the game should respond as soon as this is received. A way to do this is to replace the Sleep call with a GetMessage() / TranslateMessage() / DispatchMessage() set of calls. The GetMessage() call will block until a message is received and so free the CPU until the game needs it again.
Bored_Now is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 09:02 PM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.