aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/src/Godosa.Core/Runs/FrameClock.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Godosa.Core/Runs/FrameClock.cs')
-rw-r--r--src/Godosa.Core/Runs/FrameClock.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Godosa.Core/Runs/FrameClock.cs b/src/Godosa.Core/Runs/FrameClock.cs
new file mode 100644
index 0000000..eedb78d
--- /dev/null
+++ b/src/Godosa.Core/Runs/FrameClock.cs
@@ -0,0 +1,23 @@
+namespace Godosa.Core.Runs;
+
+/// <summary>Game time per frame: deterministic → a fixed <see cref="Step"/> whatever the wall clock; otherwise the wall dt
+/// clamped to [0, maxDt]. <see cref="Held"/> (e.g. a map still loading) → no game time and no frame counted.</summary>
+public sealed class FrameClock(bool deterministic, double step = 1.0 / 60, double maxDt = 0.1)
+{
+ public bool Deterministic { get; } = deterministic;
+ public double Step { get; } = step;
+ public long Frame { get; private set; }
+ public double Seconds { get; private set; }
+ public bool Held { get; set; }
+
+ /// <summary>The game dt of this frame (0 when held); counts the frame unless held.</summary>
+ public double Next(double wallDt)
+ {
+ if (Held)
+ return 0;
+ var dt = Deterministic ? Step : Math.Clamp(wallDt, 0, maxDt);
+ Frame++;
+ Seconds += dt;
+ return dt;
+ }
+}