Files

23 lines
674 B
C++

#pragma once
// game_loop — fixed-timestep game loop (Glenn Fiedler) for SDL3 + WASM.
// Issue 0072b. Decouples physics/sim (fixed dt) from rendering (interp).
#include <SDL3/SDL.h>
namespace fn::game {
struct LoopCfg {
float fixed_dt = 1.0f / 60.0f;
int max_steps_per_frame = 5;
void (*on_fixed_update)(void* user, float dt) = nullptr;
void (*on_render)(void* user, float interp) = nullptr;
bool (*should_quit)(void* user) = nullptr; // optional poll
void* user = nullptr;
};
// Blocking on desktop. On WASM uses emscripten_set_main_loop and returns immediately.
void loop_run(SDL_Window* win, const LoopCfg& cfg);
} // namespace fn::game