Skip to content

KernelAPI reference

Class FrameClock

Namespace: MicroEngine.Kernel
Assembly: MicroEngine.Kernel.dll
Guide: Modules and the frame schedule

The loop’s clock: turns the time each frame stands for into fixed steps, following TimeSettings. The platform only supplies a monotonic clock; how much simulated time a frame adds, how many steps it runs, how far a slow frame catches up and the interpolation blend are decided here, the same way on every backend.

C#
public sealed class FrameClock

Inheritance

object ← FrameClock

Remarks

One frame is: BeginFrame with the frame’s elapsed time, TryStep until it returns false (or until the caller stops early), then EndSteps.

C#
clock.BeginFrame(clock.ClampElapsed(now - last));
while (clock.TryStep(out var step)) schedule.Run(FramePhase.FixedUpdate, step);
clock.EndSteps();

Constructors

FrameClock(TimeSettings)

A clock following settings.

C#
public FrameClock(TimeSettings settings)

Parameters

settings TimeSettings

Exceptions

ArgumentNullException

settings is null.

ArgumentOutOfRangeException

A setting is out of range (Validate).

Properties

Blend

The current frame’s interpolation blend, set by EndSteps (Blend).

C#
public float Blend { get; }

Property Value

float

Context

The frame’s context for the phases that run once per frame.

C#
public FrameContext Context { get; }

Property Value

FrameContext

Delta

Seconds the current frame stands for (Delta).

C#
public double Delta { get; }

Property Value

double

FixedDelta

Seconds of one fixed step.

C#
public double FixedDelta { get; }

Property Value

double

FixedStep

Fixed steps completed so far.

C#
public long FixedStep { get; }

Property Value

long

Frame

Frames begun so far; the current frame’s number while one runs.

C#
public long Frame { get; }

Property Value

long

Mode

Whether time follows the wall clock or advances one step per frame.

C#
public TimeMode Mode { get; }

Property Value

TimeMode

Pending

Time added but not simulated yet, in seconds.

C#
public double Pending { get; }

Property Value

double

Settings

The policy this clock follows.

C#
public TimeSettings Settings { get; }

Property Value

TimeSettings

StepsThisFrame

Steps run in the current frame.

C#
public int StepsThisFrame { get; }

Property Value

int

Methods

BeginFrame(double)

Starts a frame. In real time, elapsed seconds are added to the pending time (pass a value already limited by ClampElapsed; negative values count as 0); in deterministic time exactly one step is added and elapsed is ignored.

C#
public void BeginFrame(double elapsed)

Parameters

elapsed double

ClampElapsed(double)

The time a real-time frame may stand for: elapsed limited to 0..MaxFrameDelta. The loop applies it to the time it measured before pacing that time to the display.

C#
public double ClampElapsed(double elapsed)

Parameters

elapsed double

Returns

double

DiscardPending()

Forgets the pending time, so time spent away (a suspended app) is not simulated when it comes back.

C#
public void DiscardPending()

EndSteps()

Ends the frame’s steps. A frame that ran MaxStepsPerFrame steps keeps at most one step pending (the rest is dropped: the game slows down rather than falling further behind). Then sets Blend: the pending fraction of a step in real time, 1 in deterministic time.

C#
public void EndSteps()

TryStep(out FrameContext)

Takes the next fixed step if one is due and the frame has not run MaxStepsPerFrame yet. The caller runs the fixed phases with step when it returns true.

C#
public bool TryStep(out FrameContext step)

Parameters

step FrameContext

The step’s context: FixedStep is the index of this step, Blend is 0.

Returns

bool