Skip to main content

Module app

Module app 

Source
Expand description

Native runner. Two threads:

  • main thread: owns the terminal, renders snapshots of the game state, captures crossterm events, normalizes them into crate::input::InputEvents, and feeds them to the platform-agnostic input router (which produces Actions + mutates UiState). Never blocks the sim — a slow render (SSH lag, terminal resize, stuck flush) is invisible to game logic.
  • sim thread: owns the canonical GameState, runs the 20Hz tick loop via crate::sim::sim_tick, drains Actions, saves to disk through the Persistence impl, and publishes snapshots via ArcSwap. Tick cadence is driven by mpsc::recv_timeout(until_next_tick), so it wakes exactly on tick deadlines or incoming actions — no busy spin, no lost ticks under arbitrary render delay.

The cross-platform half (input router, apply_action, sim_tick) is in src/input.rs and src/sim.rs. This file owns native-specific glue: crossterm event translation, threading, save scheduling, and the demo-recorder autopilot.

Structs§

App

Functions§

build_demo_state
Rich starting state for --demo-for-recording. Tuned so a viewer sees numbers moving fast (high FPS → counter spins visibly) and many rings of hands around the biscuit (heavy owned counts). Starting cuques is intentionally modest relative to FPS so the HUD counter grows by a visible fraction every frame instead of looking frozen.