Skip to content

Commit

Permalink
Fix timing issues by using the performance counter
Browse files Browse the repository at this point in the history
When porting to Linux, I switched to using SDL_GetTicks, but its resolution is not high enough, leading to frame rate hitches. Now using SDL_GetPerformanceCounter.
  • Loading branch information
amaiorano committed Apr 19, 2016
1 parent e3a71d5 commit 392123e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/System.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "System.h"
#include "IO.h"
#include <SDL.h>
#include <chrono>

namespace System
{
Expand Down Expand Up @@ -40,7 +41,8 @@ namespace System

float64 GetTimeSec()
{
return SDL_GetTicks() / 1000.0;
static Uint64 start = SDL_GetPerformanceCounter();
return static_cast<float64>(SDL_GetPerformanceCounter() - start) / SDL_GetPerformanceFrequency();
}
}

Expand Down

0 comments on commit 392123e

Please sign in to comment.