Arcade.Physics.Sim
Types
Simulated time and the number of steps taken to reach it.
A point on a recorded path, at a moment of simulated time.
What one step left: go on, stop here (as a loop's break does, so the caller's stop function closes the run), or done with a result.
Functions
fn record_every(n : Int, step : Int, x : a, xs : List(a)) : List(a) needs () do if records(step, n) do Cons(x, xs) else xs end end
fn tick(c : SimClock, dt : Float) : SimClock needs () do { t: c.t +. dt, step: c.step + 1 } end
Step s0 with step while time_of says it is before max_t. A step that goes on is stepped again; one that stops, or a state already out of time, is closed by stop; one that is done is the result. cx is passed to every call, so the hooks can be named top-level functions. Tail-recursive.