Search code examples
c++uwpdirectx-11frame-rategame-loop

60 FPS Game Loop on Universal Windows Platform Direct3D C++ App


pretty new on the C++ side of windows - special non-Win32 such as UWP -

I am trying to cap FPSs at a steady 60 FPS by simply ticking (Update/Render) every 1000/60 milliseconds. I am facing a strange situation though. If I am using Present(0,0), the swap chain will lock and v-sync automatically, all good. If I use Present1(0,DXGI_PRESENT_DO_NOT_WAIT, &params) ... I hit 600 FPSs...

NOW, while letting FPSs free (600), I want to implement my own ticker. So far I have:

bool Ticker::Tick() {

    long currentTick = GetTickCount64();
    long deltaTicks = (currentTick - gLastTick);
    bool tick = false;

    // determine whether it is tick time
    if (deltaTicks >= gUpdateTime) {
        gLastTick = currentTick;
        gTicksCount++;
        char buf[256];
        sprintf_s(buf, "Current delta: %30d\n", deltaTicks);
        OutputDebugStringA(buf);
        tick = true;
    }

    // this metric must happen regardless of actual true Ticks
    if (currentTick - gSecondTime >= 1000) {
        gCurrentFrameRate = gTicksCount;
        gSecondTime = currentTick;
        OutputDebugStringW(L"Second is up\n");
        gTicksCount = 0;
    }

    return tick;
}

Needless to say this is not working... I am hitting 20/21 FPSs when my target is refresh very 1000/60.

I believe I am committing a rather silly mistake but I can't see where.

Thank you.


Solution

  • From the doc:

    The resolution of the GetTickCount64 function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.

    So as 1000/60 ~ 15ms, the counter resolution is inadequate.