Browse Source

Fixed framerate now has sub-millisecond accuracy on Linux.

legacy
Sam Hocevar sam 14 years ago
parent
commit
61524527a1
2 changed files with 17 additions and 8 deletions
  1. +1
    -1
      src/test-map.cpp
  2. +16
    -7
      src/timer.cpp

+ 1
- 1
src/test-map.cpp View File

@@ -18,7 +18,7 @@
#include "ticker.h"
#include "video.h"

static int const FPS = 30.0f;
static float const FPS = 30.0f;

int main(int argc, char **argv)
{


+ 16
- 7
src/timer.cpp View File

@@ -13,16 +13,15 @@

#if defined __linux__
# include <sys/time.h>
# include <unistd.h>
#elif defined _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <SDL.h> // FIXME: this should not be needed
#else
# include <SDL.h>
#endif

// XXX
#include <SDL.h>

#include "timer.h"

/*
@@ -73,6 +72,18 @@ private:
return ret;
}

void WaitSeconds(float seconds)
{
#if defined __linux__
usleep((int)(seconds * 1000000.0f));
#elif defined _WIN32
/* FIXME: use native Win32 stuff */
SDL_Delay((int)(seconds * 1000.0f + 0.5f));
#else
SDL_Delay((int)(seconds * 1000.0f + 0.5f));
#endif
}

#if defined __linux__
struct timeval tv0;
#elif defined _WIN32
@@ -105,9 +116,7 @@ float Timer::GetSeconds()
void Timer::WaitSeconds(float seconds)
{
float sleep = seconds - data->GetSeconds(false);
if (sleep <= 1e-4f)
return;

SDL_Delay((int)(sleep * 1000.0f + 0.5f));
if (sleep > 1e-4f)
data->WaitSeconds(sleep);
}


Loading…
Cancel
Save