Jump to content
  • Advertisement
Sign in to follow this  
jamesleighe

Waiting Till Next Frame (Spinning Issue)

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

So, my server does a number of 'frames' a second and sends the updates to the clients but when it's not time for the next frame it simply spins...

This is kinda weak because it uses more processing power than is needed most of the time.
Is there any way to 'sleep' the process for a reliable amount of time? I hear Sleep is not reliable at all but I could be wrong.

Share this post


Link to post
Share on other sites
Advertisement
On Windows, for accurate real-time systems like games, there isn't really a solution for this.

The most accurate thing you can do is to make a spin-loop that keeps calling [font="'Courier New"]Sleep(0)[/font] and/or [font="'Courier New"]YieldProcessor[/font], etc... Unfortunately, it's really a trade-off between accuracy and power efficiency :/

Share this post


Link to post
Share on other sites
Sleep is abysmal. Stay away from it like from the plague.

The most reliable and accurate thing you can use under Windows is[font="Courier New"] CreateWaitableTimer [/font]and [font="Courier New"]SetWaitableTimer[/font][font="Arial"]. Be sure to use[/font] [font="Courier New"]timeBeginPeriod [/font]to have 1ms resolution[font="Arial"].
[/font][font="Arial"]This allows you to create a timer that fires regularly and use any of the wait functions on that handle to block at 1ms accuracy. This is much better than anything you could possibly get from Sleep.
[/font]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!