#include "core/jail/jgame.hpp" #include "core/system/fiber.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; } // Encara no toca update: cedim el control al Director per a que puga // processar events, animar l'overlay i mantindre l'àudio viu. Sense // aquest yield, els spin-waits típics de les cinemàtiques // (`while (!JG_ShouldUpdate()) { JI_Update(); ... }`) congelarien // tot el main loop — el fiber no cediria mai. GameFiber::yield(); 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; }