Game Timing issues
http://www.gamedev.net/community/forums/topic.asp?topic_id=339608&whichpage=1�
Has a few examples of getting your game updated at a certain freq.
The problem I'm encountering is calling performance counter or timegettime every loop, when there is no msg pending, results in nearly 100% cpu usage. Placing a well calculated Sleep in the loop solves the problem of the cpu usage, limiting the gameupdate + drawing. I'm just wondering if this is the right way to go.
thx in advance :)
Why are you so bothered about 100% cpu usage? It's how games work, they are always updating themselfs as fast as they can.
You could place a sleep(0) somewhere to lower the cpu usage, but that's about it.
Toolmaker
You could place a sleep(0) somewhere to lower the cpu usage, but that's about it.
Toolmaker
When your application has focus, it's a good idea to run at full cpu usage, because the user expects results from your application, and not from others.
When it does not have focus, the user doesn't really care about what you do, so you should regularly sleep to allow other processes to run.
When it does not have focus, the user doesn't really care about what you do, so you should regularly sleep to allow other processes to run.
Funny how people are concerned when their game runs at 99% CPU, but don't care at all when the process named "System Idle Process" runs at 99% CPU.
I would actually suggest. That you take whatever idle time your loop takes up and give that to the sleep method based on either an average or a remaining time.
For instance, you find it is time for you to do your game update which is at a fixed frequency, and your rendering is running at a capped fps you could allow your program to sleep for the remaining time till the next game update or frame rendering. However, a sleep will probably hinder your key capturing and other input event checking if they run from the same thread. So you should definitely make sure that they are running in other threads and call interrupts via function pointers or the observer pattern using a thread safe/concurrent programming model. But neglecting other processes while your game is running is not only bad programming practice it can cause undo frustration on your customers and potential fans as well as increase the amount crashes that your program will experience mostly from the users getting bored of waiting a million years for the system to actually do its tasks because your game takes up as much CPU time as it possibly can.
For instance, you find it is time for you to do your game update which is at a fixed frequency, and your rendering is running at a capped fps you could allow your program to sleep for the remaining time till the next game update or frame rendering. However, a sleep will probably hinder your key capturing and other input event checking if they run from the same thread. So you should definitely make sure that they are running in other threads and call interrupts via function pointers or the observer pattern using a thread safe/concurrent programming model. But neglecting other processes while your game is running is not only bad programming practice it can cause undo frustration on your customers and potential fans as well as increase the amount crashes that your program will experience mostly from the users getting bored of waiting a million years for the system to actually do its tasks because your game takes up as much CPU time as it possibly can.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement