18 lines
615 B
C#
18 lines
615 B
C#
namespace GamePort.Game;
|
|
|
|
/// <summary>Explicit port policy: 60 simulation calls/second, independent of presentation.</summary>
|
|
public sealed class FixedStepClock
|
|
{
|
|
public const float Step = 1f / 60;
|
|
private double accumulated;
|
|
public int Advance(double elapsed)
|
|
{
|
|
if (!double.IsFinite(elapsed) || elapsed < 0) throw new ArgumentOutOfRangeException(nameof(elapsed));
|
|
accumulated += Math.Min(elapsed, 0.25);
|
|
var steps = (int)Math.Floor((accumulated + 1e-10) * 60);
|
|
accumulated -= steps / 60.0;
|
|
return steps;
|
|
}
|
|
public void Reset() => accumulated = 0;
|
|
}
|