From 9724663602b4b1eb755bf334c475dc2c80e4b386 Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Sun, 20 Sep 2026 15:14:23 +0800 Subject: feat(m6a): add save speed and day-night controls --- src/LivingVillage.Kernel/SimulationControl.fs | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/LivingVillage.Kernel/SimulationControl.fs (limited to 'src/LivingVillage.Kernel/SimulationControl.fs') diff --git a/src/LivingVillage.Kernel/SimulationControl.fs b/src/LivingVillage.Kernel/SimulationControl.fs new file mode 100644 index 0000000..83e5f36 --- /dev/null +++ b/src/LivingVillage.Kernel/SimulationControl.fs @@ -0,0 +1,54 @@ +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 -- cgit v1.2.3