Skip to content

Calibration

namespace Griff.Scenes;
public sealed class Calibration : Component, IDrawable, IActionReady

Measures how late this player hears the game’s sound (speakers with a delay of their own, like Bluetooth headphones) or sees its screen, and offers to set their offset to it: it plays clicks (or, measuring Visual, flashes its light in silence) on a steady beat, the player taps along with its TapAction, a click or a touch for a few bars, and it works out how long after each beat the taps came, leaves out the odd ones and offers their average as the Result, which its Apply action makes the player’s Game.AudioOffset (or VisualOffset), kept in their save data. Beat clocks allow for the offset from then on.

It starts as it’s shown (a panel with it opens; see StartOnShow), playing its clicks in place of the music (which comes back when it’s done), and hides the buttons inside it while the player taps, showing them again when it’s done: Entity > Audio > Create Calibration Screen makes a panel with one, its prompt, and Apply, Again and Back buttons, for an options menu’s button to open. It draws its light and a dot for each beat to tap, lit as each tap lands. Its Start, Stop and Apply actions are there for buttons and scripts, its Prompt for a text to say what to do, and its Result, Taps and Current outputs for anything else. It runs in real time, under a pause menu too, and each machine keeps its own in a network game: it measures and sets its own player’s offset, which no other player’s game ever sees.

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

public bool Applied { get; }

True once its result has been applied, until it starts again.

public int Beats { get; set; }

Beats to tap along to. Half of them need steady taps for a result.

public bool Clicks { get; set; }

A click of the left mouse button, or a touch, taps too.

public Color Color { get; set; }

The color of its light and of the dots for the beats.

public int CountIn { get; set; }

Beats to listen to (or watch) before the taps count.

public float Current { get; }

The player’s offset it measures, as it’s set now, in milliseconds (Game.AudioOffset or VisualOffset).

public bool IsRunning { get; }

True while the clicks or flashes are going.

public CalibrationKind Measures { get; set; }

What it measures: Audio taps along to clicks, Visual to a light flashing in silence.

public int Order { get; set; }

Higher draws on top, like Order (an entity’s sprite says for it).

public string Prompt { get; }

What to tell the player now, for a Text to show (its Output): how to tap, how many taps so far, what it measured and whether to apply it. It names the tap action in braces, so the text shows its key or button.

public float Result { get; }

What it measured, in milliseconds: how long after the beats the steady taps came, on average. Below 0 when they came before. 0 until it’s measured.

public float Size { get; set; }

How big its light is, in world units (the dots go under it); 0 draws nothing.

public float Spread { get; }

How far the steady taps were from their average, in milliseconds: how much to trust the result.

public bool StartOnShow { get; set; }

Starts as soon as it’s shown (as its panel opens, or the scene starts); off, it waits for its Start action.

public CalibrationState State { get; }

Where it has got to.

public string? TapAction { get; set; }

An input action that taps: Jump is Space and the gamepad’s A. Empty leaves just clicks and touches. Like a menu’s controls, it listens while it’s on the top panel (or no panel is open).

public int Taps { get; }

The taps counted so far, on the beats to tap along to.

public float Tempo { get; set; }

Beats a minute of the clicks or flashes: slow enough that a late tap isn’t taken for the next beat’s.

public string Title { get; }

What it sets, for a heading: “Audio Offset” or “Visual Offset”.

public float Volume { get; set; }

How loud the clicks are, 0 to 1, on top of the player’s sound volume.

public void Start()

Starts it (again): the clicks or flashes begin, and earlier taps are forgotten.

public void Stop()

Stops it without a result, bringing the music back.

public event Action<Calibration>? Finished

Raised when it’s done measuring, with a result or without.