decoupled timers from interpreter tick rate
This commit is contained in:
18
CountdownTimerSDL.cpp
Normal file
18
CountdownTimerSDL.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "CountdownTimerSDL.hpp"
|
||||
|
||||
CountdownTimerSDL::CountdownTimerSDL(unsigned frequency):
|
||||
mDesiredFrequency{frequency},
|
||||
mSDLFrequency{SDL_GetPerformanceFrequency()},
|
||||
mStartTime{0},
|
||||
mStartValue{0} {}
|
||||
|
||||
void CountdownTimerSDL::set(unsigned value) {
|
||||
mStartTime = SDL_GetPerformanceCounter();
|
||||
mStartValue = value;
|
||||
}
|
||||
|
||||
unsigned CountdownTimerSDL::get() const {
|
||||
Uint64 elapsedTime = SDL_GetPerformanceCounter() - mStartTime;
|
||||
Uint64 elapsedTicks = (elapsedTime * mDesiredFrequency) / mSDLFrequency;
|
||||
return elapsedTicks >= mStartValue ? 0 : mStartValue - elapsedTicks;
|
||||
}
|
||||
Reference in New Issue
Block a user