Expand description
Games that keep their own main loop (loop { update(); draw(); wait_frame(); })
instead of implementing Game. Same mechanism as the C SDK’s gasm_loop.h:
main_loop! exports the entry points and runs your function on the first frame;
main_loop::wait_frame suspends it until the next frame with Binaryen’s Asyncify,
inside the module. Build, then post-process the .wasm:
wasm-opt game.wasm --asyncify --pass-arg=asyncify-removelist@gasm_frame,gasm_loop_frame -O2 -o game.wasmⓘ
fn run() -> i32 {
loop {
if gasm::pad(0).held(gasm::Buttons::START) { return 0; }
draw();
gasm::main_loop::wait_frame();
}
}
gasm::main_loop!(run);main_loop!(run, on_exit) also exports gasm_exit (the player is quitting: flush
saves). wasm32 only: native builds of such a game run run straight through.
Functions§
- frames
- Frames waited so far.
- wait_
frame - Return to the runner; continues in the next frame (input and time are per frame).