55 lines
965 B
C++
55 lines
965 B
C++
#include "core/jail/jgame.hpp"
|
|
|
|
namespace {
|
|
|
|
bool quitting = false;
|
|
Uint32 update_ticks = 0;
|
|
Uint32 update_time = 0;
|
|
Uint32 cycle_counter = 0;
|
|
Uint32 last_delta_time = 0;
|
|
|
|
} // namespace
|
|
|
|
void JG_Init() {
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
|
update_time = SDL_GetTicks();
|
|
last_delta_time = update_time;
|
|
}
|
|
|
|
void JG_Finalize() {
|
|
SDL_Quit();
|
|
}
|
|
|
|
void JG_QuitSignal() {
|
|
quitting = true;
|
|
}
|
|
|
|
bool JG_Quitting() {
|
|
return quitting;
|
|
}
|
|
|
|
void JG_SetUpdateTicks(Uint32 milliseconds) {
|
|
update_ticks = milliseconds;
|
|
}
|
|
|
|
bool JG_ShouldUpdate() {
|
|
const Uint32 now = SDL_GetTicks();
|
|
if (now - update_time > update_ticks) {
|
|
update_time = now;
|
|
cycle_counter++;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Uint32 JG_GetCycleCounter() {
|
|
return cycle_counter;
|
|
}
|
|
|
|
Uint32 JG_GetDeltaMs() {
|
|
const Uint32 now = SDL_GetTicks();
|
|
const Uint32 delta = now - last_delta_time;
|
|
last_delta_time = now;
|
|
return delta;
|
|
}
|