42c14fae59
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2.2 KiB
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. |
|
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 |
|
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_timese cap afixed_dt * max_steps_per_framepara 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_quitse consulta antes de cada frame; en WASM disparaemscripten_cancel_main_loop.loop_runretorna sin hacer nada si ambos callbacks son nulos.