All pastes #204221 Raw Edit

Mine

public text v1 · immutable
#204221 ·published 2006-10-15 19:19 UTC
rendered paste body
int FPS()
{
    // ==== VARIABLES
    static int curFrames = 0;       // number of frames for this second
    static int last = 0;            // last time we completed a full second
    static int fps = 0;             // fps for last second
    
    // ==== CALCULATIONS

    int current = SDL_GetTicks();   // current time
    curFrames++;                    // increase frame for this second

    if( current - last > 1000 )     // if a second has elapsed
    {
        last = current;             // we completed a new full second
        fps = curFrames;            // we have a new frames for last second
        curFrames = 0;              // reset counter
    }

    // ==== RETURN
    return fps;
}