diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/main.c b/src/main.c index d15877e..aebc6aa 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,4 @@ #include "pong.h" -#include <SDL2/SDL_atomic.h> -#include <SDL2/SDL_thread.h> -#include <SDL2/SDL_timer.h> #include <raylib.h> int Difficulty = 1; @@ -52,19 +49,25 @@ void set_screen_mode() { } static int internal_clock() { - SDL_SetThreadPriority(SDL_THREAD_PRIORITY_TIME_CRITICAL); - double NewTime = 0; - double OldTime = 0; - double Milliseconds = (1000.0/60)/1000.0; - double DeltaTime = 0; + const struct timespec Delay = { + 0, 9999 + }; + struct timespec Remaining = { + 0, 0 + }; + double OldTime = GetTime(); while(GameGoing == true) { - NewTime = SDL_GetTicks()/1000.0f; - DeltaTime += (NewTime-OldTime)/Milliseconds; - OldTime = NewTime; - while(DeltaTime >= 1.0) { + //nanosleep(&Delay, &Remaining); + double NewTime = GetTime(); + while((NewTime-OldTime) < (1.0/60.0f)) { + NewTime = GetTime(); + } + if((NewTime-OldTime) >= (1.0/60.0f)) { SDL_AtomicAdd(&Ticks, 1); - DeltaTime--; + OldTime = GetTime(); } + + printf("%lf,%lf,%d\n", GetTime(),(NewTime-OldTime), SDL_AtomicGet(&Ticks)); } return(0); } |