소스 검색

Fixed framerate now has sub-millisecond accuracy on Linux.

legacy
Sam Hocevar sam 15 년 전
부모
커밋
61524527a1
2개의 변경된 파일17개의 추가작업 그리고 8개의 파일을 삭제
  1. +1
    -1
      src/test-map.cpp
  2. +16
    -7
      src/timer.cpp

+ 1
- 1
src/test-map.cpp 파일 보기

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


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


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


+ 16
- 7
src/timer.cpp 파일 보기

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


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


// XXX
#include <SDL.h>

#include "timer.h" #include "timer.h"


/* /*
@@ -73,6 +72,18 @@ private:
return ret; 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__ #if defined __linux__
struct timeval tv0; struct timeval tv0;
#elif defined _WIN32 #elif defined _WIN32
@@ -105,9 +116,7 @@ float Timer::GetSeconds()
void Timer::WaitSeconds(float seconds) void Timer::WaitSeconds(float seconds)
{ {
float sleep = seconds - data->GetSeconds(false); 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);
} }



불러오는 중...
취소
저장