Jump to content
  • Advertisement
Sign in to follow this  
ScorpII

Unity Game Timing issues

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

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!