Skip to content

GameSpeed

namespace Griff.Scenes;
public sealed class GameSpeed : Component

The game’s speed, with no code: a sim’s speed buttons (pause, 1x, 2x, 4x, 16x) set it with their Do action (“Set Speed” with 4, or Faster and Slower), and so can a Trigger on a key’s message or a script. While it’s Exact (the default) the game goes faster by taking more steps of the usual length, so it plays out the same at any speed: a worker walking a grid crosses as many cells in a game second at 16x as at 1x. One is enough, on any entity of the scene.

It sets the game’s Time.FastForward and Time.Scale as the scene starts and whenever its Speed or Exact changes, so a script setting those itself isn’t undone. Fast-forward does nothing in a network game, whose steps are kept in step between the players.

This is a component: its saved properties are on its component page.

public bool Exact { get; set; }

Faster speeds take more steps of the usual length each frame (Time.FastForward), so everything goes as it does at normal speed, only sooner. Untick it to make each step longer instead (Time.Scale): it costs the machine less, but what goes a step at a time is coarser at high speeds. Speeds below 1 always make steps shorter.

public float Speed { get; set; }

How fast the game runs: 1 normal speed, 4 four times as fast, 0.5 half speed, 0 paused (up to 64). The Set Speed, Faster and Slower actions change it, and so can scripts.

public IReadOnlyList<string> Speeds { get; set; }

The speeds Faster and Slower go through, one a row, e.g. 1, 2, 4 and 16.

public void Faster()

Goes to the next of its Speeds above the speed now (from paused, the slowest).

public void SetSpeed(float speed = 1f)

Runs the game at speed: 1 normal, 4 four times as fast, 0 paused.

public void Slower()

Goes to the next of its Speeds below the speed now; at the slowest, it stays.

public static ValueTuple<float, float> TimeFor(float speed, bool exact)

The scale of each step (Time.Scale) and how many steps it takes for one (Time.FastForward) that speed runs the game at, exact or not.

public const float MostSpeed

The fastest it goes.