Sign in to follow this  
jamesleighe

Waiting Till Next Frame (Spinning Issue)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this