natiny_backend_loop

C
void natiny_backend_loop(natiny_loop_fn fn, void* userdata);

Starts the main application loop. The callback is called once per frame.

natiny_loop_fn is declared in natiny.h as

C
typedef void (*natiny_loop_fn)(float dt, void* userdata);

Parameters

Name Type Description
fn natiny_loop_fn Function called every frame with delta time in seconds
userdata void* User pointer passed to the callback

Example

C
void frame(float dt, void* ud) {
    update_scene(dt, ud);
}

natiny_backend_loop(frame, &app_state);

Notes

  • On desktop this runs a standard game loop.
  • On web this uses requestAnimationFrame.
  • The loop returns when the last window closes. With more than one open, closing one - by its close button or with natiny_window_destroy - leaves the others running, in whatever order they go. The same on every backend.
  • A window destroyed from inside the callback is released at the next frame boundary, so the frame that asked for it finishes first.