Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/282606961466429440
Added 'windows' tag, since this is a question specific to the Windows API.
Link
Trevor Powell
  • 21.5k
  • 1
  • 63
  • 96
Source Link
German
  • 181
  • 1
  • 6

Could the delta frame time be negative?

I'm following a tutorial about the time management and, the tutorial shows this function:

double GetFrameTime()
{
    LARGE_INTEGER currentTime;
    __int64 tickCount;
    QueryPerformanceCounter(&currentTime);

    tickCount = currentTime.QuadPart-frameTimeOld;
    frameTimeOld = currentTime.QuadPart;

    if(tickCount < 0.0f)
        tickCount = 0.0f;

    return float(tickCount)/countsPerSecond;
}

The tutorial explains that, this function basically gets the time that one frame takes, but, I don't understand how the variable tickCount can be negative, if the currentTime is increasing all the time (calling this function every frame, obviously), so, is that if really necessary?