namespace LivingVillage.Kernel type SimulationSpeed = | OneX | TwoX | FiveX type SimulationControl = { Paused: bool Speed: SimulationSpeed } module SimulationControl = let initial : SimulationControl = { Paused = false Speed = OneX } let setSpeed (speed: SimulationSpeed) (control: SimulationControl) : SimulationControl = { control with Speed = speed } let togglePause (control: SimulationControl) : SimulationControl = { control with Paused = not control.Paused } let initialForConfiguredSteps (configuredSteps: int) : SimulationControl * int option = let steps = if configuredSteps > 0 then configuredSteps else 1 let control = match steps with | 2 -> setSpeed TwoX initial | 5 -> setSpeed FiveX initial | _ -> initial let legacySteps = match steps with | 1 | 2 | 5 -> None | value -> Some value control, legacySteps let stepsPerFrame (control: SimulationControl) : int = if control.Paused then 0 else match control.Speed with | OneX -> 1 | TwoX -> 2 | FiveX -> 5 let stepsPerFrameWithLegacy (legacySteps: int option) (control: SimulationControl) : int = if control.Paused then 0 else match legacySteps with | Some steps when steps > 0 -> steps | _ -> stepsPerFrame control