Skip to main content

Module sim

Module sim 

Source
Expand description

Platform-agnostic simulation core.

Owns the Action / BuyQty types (the input router produces them; apply_action is the only thing that interprets them) and the per-tick state.tick() + ambient spawn helpers.

What lives outside this module:

  • the threaded sim loop on native (app.rs::sim_loop), which wraps sim_tick + apply_action with mpsc::recv_timeout, save scheduling via the Persistence impl, and the demo-recorder driver.
  • the requestAnimationFrame-driven loop on web (added when the wasm port lands), which calls the same sim_tick + apply_action single-threaded.

The split is: this module is cross-platform; threading + I/O scheduling around it isn’t. See tracking issue #13 for rationale.

Structs§

SimGeometry
Geometry the sim needs to interpret screen-space events. Updated on every render via Action::UpdateGeometry.

Enums§

Action
Commands the input router produces and the sim consumes. The sim is the sole authority on GameState mutation — input handling translates raw events (key/mouse/wheel) into these and feeds them through.
BuyQty
Buy quantity for a fingerer purchase action. Modifier-key meaning is translated to this in the input router; sim only consumes the resolved value so the modifier mapping can change without touching tick logic.

Functions§

apply_action
Apply one Action to the canonical GameState. Pure data: no I/O, no time, no threading. Called from both the native sim thread (on mpsc::recv_timeout returning Ok) and the web rAF loop.
sim_tick
Run the platform-agnostic body of one sim tick: state updates + ambient spawn helpers. Save scheduling and demo-driver autopilot are the caller’s concern (they live in app.rs::sim_loop on native).