Files
aee/source/core/jail/jgame.cpp
Sergio Valor fe41919e1e clang-format
mogudes coses de config.yaml a debug.yaml
2026-04-16 16:46:18 +02:00

58 lines
1.2 KiB
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;
}
// No toca update — retornem false sense més. Des de Phase B.2 ja no
// hi ha fibers: cap caller fa spin-waits (`while (!JG_ShouldUpdate())`)
// i el Director pren el control del main loop frame a frame.
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;
}