acdream/src/AcDream.Runtime/GameRuntimeClock.cs
Erik 854d9e9cd1 feat(runtime): define borrowed views commands and ordered events
Establish the J1 presentation-independent contract with instance-scoped clocks and generations, immutable borrowed views, typed generation-gated commands, normalized ordered diagnostics, and teardown acknowledgements. Route graphical startup plus press-time selection, movement, and combat through focused App adapters over the exact existing owners without adding a queue or mirrored world.

Validated by the Release solution build, 13 Runtime tests, 3,838 App tests with three existing skips, and the complete 8,424-test Release suite with five existing skips.

Co-authored-by: Codex <codex@openai.com>
2026-07-25 19:08:42 +02:00

45 lines
1.3 KiB
C#

namespace AcDream.Runtime;
public readonly record struct RuntimeFrameTime(
ulong FrameNumber,
double DeltaSeconds,
double SimulationTimeSeconds);
public interface IGameRuntimeClock
{
ulong FrameNumber { get; }
double SimulationTimeSeconds { get; }
}
/// <summary>
/// Instance-scoped simulation clock shared by graphical and future headless
/// hosts. It owns no wall-clock/global state.
/// </summary>
public sealed class GameRuntimeClock : IGameRuntimeClock
{
public ulong FrameNumber { get; private set; }
public double SimulationTimeSeconds { get; private set; }
public RuntimeFrameTime Advance(
double hostDeltaSeconds,
bool advanceSimulationTime = true)
{
double deltaSeconds = NormalizeDeltaSeconds(hostDeltaSeconds);
FrameNumber = checked(FrameNumber + 1UL);
if (advanceSimulationTime)
SimulationTimeSeconds += deltaSeconds;
return new RuntimeFrameTime(
FrameNumber,
deltaSeconds,
SimulationTimeSeconds);
}
public static double NormalizeDeltaSeconds(double deltaSeconds) =>
double.IsFinite(deltaSeconds)
&& deltaSeconds > 0.0
&& deltaSeconds <= float.MaxValue
? deltaSeconds
: 0.0;
}