From 39066900773e7857faf2d02e7ed51b71d219d97d Mon Sep 17 00:00:00 2001 From: godosa Date: Tue, 6 Oct 2026 23:39:36 +0200 Subject: godosa-engine: initial public history --- src/Godosa.Core/Runs/FrameClock.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Godosa.Core/Runs/FrameClock.cs (limited to 'src/Godosa.Core/Runs/FrameClock.cs') 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; + +/// Game time per frame: deterministic → a fixed whatever the wall clock; otherwise the wall dt +/// clamped to [0, maxDt]. (e.g. a map still loading) → no game time and no frame counted. +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; } + + /// The game dt of this frame (0 when held); counts the frame unless held. + public double Next(double wallDt) + { + if (Held) + return 0; + var dt = Deterministic ? Step : Math.Clamp(wallDt, 0, maxDt); + Frame++; + Seconds += dt; + return dt; + } +} -- cgit