Files

2.2 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, example, tested, tests, test_file_path, file_path, params, output
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports example tested tests test_file_path file_path params output
game_loop function cpp gamedev 0.1.0 impure loop_run(SDL_Window*, const LoopCfg&) -> void Game loop fixed-timestep estilo Glenn Fiedler ('Fix Your Timestep'). Desacopla simulacion (on_fixed_update con dt fijo) de renderizado (on_render con factor de interpolacion). Acumulador con cap anti spiral-of-death. Branch automatico desktop (while loop bloqueante) vs __EMSCRIPTEN__ (emscripten_set_main_loop). Issue 0072b.
gamedev
game-loop
sdl3
wasm
fixed-timestep
false error_go_core
struct State { bool quit = false; float t = 0; }; State st; fn::game::LoopCfg cfg; cfg.user = &st; cfg.on_fixed_update = [](void* u, float dt) { auto s = (State*)u; s->t += dt; }; cfg.on_render = [](void* u, float interp) { // render with interp factor between [0, 1) }; cfg.should_quit = [](void* u) { return ((State*)u)->quit; }; fn::game::loop_run(window, cfg); false
cpp/functions/gamedev/game_loop.cpp
name desc
window SDL_Window activo (no usado actualmente; reservado para futuras integraciones swap/vsync).
name desc
cfg LoopCfg con fixed_dt (default 1/60), max_steps_per_frame (cap), callbacks on_fixed_update/on_render/should_quit y user pointer.
Bloquea hasta should_quit==true (desktop). En WASM retorna inmediatamente y registra emscripten_set_main_loop.

game_loop

Loop canonico para apps gamedev del registry. Garantiza que la simulacion corra a fixed_dt constante (default 60 Hz) independientemente del framerate de render, y expone factor interp para que el renderer interpole posiciones entre estados de fisica.

Detalles:

  • frame_time se cap a fixed_dt * max_steps_per_frame para evitar la espiral de la muerte cuando el debugger pausa.
  • En __EMSCRIPTEN__ el estado del acumulador vive en variable static (g_rt) — solo un loop activo por modulo WASM.
  • should_quit se consulta antes de cada frame; en WASM dispara emscripten_cancel_main_loop.
  • loop_run retorna sin hacer nada si ambos callbacks son nulos.