Skip to content

Time

namespace Griff.Runtime;
public sealed class Time : IKeepsState

Game time. The game moves in steps of FixedDelta (a sixtieth of a second unless StepRate says otherwise), whatever the screen’s frame rate, so the same input gives the same game on any machine; the screen is drawn between the last two steps (see Blend). Delta is a step’s game time: multiply speeds by it.

public float Blend { get; }

How far the screen being drawn is between the game’s last two steps, from 0 (the one before) to 1 (the last): what’s drawn is placed that far from where it was to where it is, so it moves smoothly on any screen. 1 when the game is stepped by hand or held still.

public float Delta { get; }

Game seconds this step covers, after Scale: FixedDelta at normal speed.

public long DrawnFrames { get; }

Frames the screen has shown (one each Advance or Tick), where Frame counts steps.

public float FastForward { get; set; }

Fast-forward that stays exact: 4 runs the game four times as fast by taking four steps of the usual length for each one it would take, where Scale 4 takes steps four times as long. Everything goes as it does at normal speed, only sooner: a walker crosses as many cells in a game second, a body falls the same arc, a timer fires on the same step, so a sim plays out the same at any speed. It multiplies Scale (Scale 0 still pauses). Real time stays real: the camera’s pan keys, fades and menus (what goes by UnscaledDelta) move at their usual speed. A machine that can’t take that many steps slows down rather than skipping any. From 1 (normal speed) to 64; it does nothing in a network game, whose steps are kept in step between the players.

public float FixedDelta { get; }

Real seconds each step covers: 1 / StepRate.

public long Frame { get; }

How many steps the game has taken since it started.

public bool IsFrozen { get; }

True during a HitStop: Delta is 0 whatever Scale is.

public bool IsPaused { get; }

True while a Panel that pauses the game is open (a pause menu): Delta is 0 whatever Scale is, and scripts outside open panels don’t update. Set by the game.

public double RealTotal { get; }

Real seconds since the game started, counted frame by frame as the screen shows them, stalls included.

public float Scale { get; set; }

1 is normal speed, 0.5 is slow motion, 0 pauses gameplay. It makes each step cover more or less game time: above 1, what goes a step at a time (a grid mover’s cells, physics) is coarser. FastForward speeds a game up with steps of the usual length instead.

public float SlowMotionScale { get; }

How much SlowMotion is slowing the game right now: 1 at normal speed. It multiplies Scale, so a game paused with Scale 0 stays paused.

public int StepRate { get; set; }

How many steps the game takes a second: the project’s Step Rate (Game > Step Rate in the editor, 60 unless it’s changed), and a script can change it as the game runs (say, 120 for a level whose fast bodies need finer steps). Each step is FixedDelta long. From 10 to 240.

public double Total { get; }

Scaled seconds since the game started.

public float UnscaledDelta { get; }

Real seconds this step covers, ignoring Scale: FixedDelta as the game runs, and a fraction of it while it’s fast-forwarded (see FastForward).

public const int DefaultStepRate

How many steps a second a game takes unless its project or a script says otherwise.

public const float MaxDelta

The most real time a single frame may cover, so a stall (breakpoint, window drag) doesn’t teleport things: a frame takes at most this much in steps (6 at 60 a second), and the game slows down rather than falling further behind.

public const float MaxFastForward

The fastest FastForward goes.

public const int MaxStepRate

The most steps a second StepRate takes.

public const int MinStepRate

The fewest steps a second StepRate takes.