Changeset 118


Ignore:
Timestamp:
Aug 15, 2010, 4:29:13 PM (10 years ago)
Author:
sam
Message:

Fixed framerate now has sub-millisecond accuracy on Linux.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/test-map.cpp

    r116 r118  
    1919#include "video.h"
    2020
    21 static int const FPS = 30.0f;
     21static float const FPS = 30.0f;
    2222
    2323int main(int argc, char **argv)
  • trunk/src/timer.cpp

    r116 r118  
    1414#if defined __linux__
    1515#   include <sys/time.h>
     16#   include <unistd.h>
    1617#elif defined _WIN32
    1718#   define WIN32_LEAN_AND_MEAN
    1819#   include <windows.h>
     20#   include <SDL.h> // FIXME: this should not be needed
    1921#else
    2022#   include <SDL.h>
    2123#endif
    22 
    23 // XXX
    24 #include <SDL.h>
    2524
    2625#include "timer.h"
     
    7473    }
    7574
     75    void WaitSeconds(float seconds)
     76    {
     77#if defined __linux__
     78        usleep((int)(seconds * 1000000.0f));
     79#elif defined _WIN32
     80        /* FIXME: use native Win32 stuff */
     81        SDL_Delay((int)(seconds * 1000.0f + 0.5f));
     82#else
     83        SDL_Delay((int)(seconds * 1000.0f + 0.5f));
     84#endif
     85    }
     86
    7687#if defined __linux__
    7788    struct timeval tv0;
     
    106117{
    107118    float sleep = seconds - data->GetSeconds(false);
    108     if (sleep <= 1e-4f)
    109         return;
    110 
    111     SDL_Delay((int)(sleep * 1000.0f + 0.5f));
     119    if (sleep > 1e-4f)
     120        data->WaitSeconds(sleep);
    112121}
    113122
Note: See TracChangeset for help on using the changeset viewer.