How does XNA sync work?

How does XNA support consistent and accurate 60 FPS frame rates? Furthermore, how does it maintain such an accurate time without 100% processor binding?

+5
source share
4 answers

I don’t know exactly how XNA does this, but when you played with OpenGL a few years ago, I did the same thing using very simple code.

At the heart of this, I assume that XNA has some kind of rendering cycle, it may or may not be integrated with the standard even processing cycle, but, for the sake of example, suppose this is not so. in this case you could write something like this.

TimeSpan FrameInterval =  TimeSpan.FromMillis(1000.0/60.0);
DateTime PrevFrameTime = DateTime.MinValue;
while(true)
{
    DateTime CurrentFrameTime = DateTime.Now;
    TimeSpan diff = DateTime.Now - PrevFrameTime;
    if(diff < FrameInterval)
    {
        DrawScene();
        PrevFrameTime = CurrentFrameTime;
    }
    else
    {
        Thread.Sleep(FrameInterval - diff);
    }
}

, , - Environment.Ticks DateTimes ( ), , . drawScene 60 , , .

+2

lukes , :

XNA FX, , Windows Game.Update , , , (, 16 ). , XNA FX Reflector :)

: XNA GameStudio 1.0 Alpha/Beta " WinForms", ...

+4

60 , , . .

, - , 1000 .

, XNA , 60 , , , . , - , fps - - , , . , , , .

, XNA- , - , , , , , , . , , FPS, , .

0

You can read all about how the XNA timer was implemented here . Game time in XNA Game Studio , but basically it would try wiat 1/60 seconds before continuing the cycle again, also note that the update can be called several times before rendering if XNA needs to "catch up."

0
source

All Articles