summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Kernel/SimulationControl.fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Kernel/SimulationControl.fs')
-rw-r--r--src/LivingVillage.Kernel/SimulationControl.fs54
1 files changed, 54 insertions, 0 deletions
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