Core · class

TickTrace

Explained in The loop.

class TickTrace implements TickTraceLike
import { TickTrace } from '@driftengine/core';

Constructor

new

constructor(channels: number, capacity?: number)
ParameterTypeDescription
channelsnumber
capacity?number

Properties

NameTypeDescription
channelsreadonlynumber

Accessors

NameTypeDescription
lengthgetnumber

Methods

push

push(values: ArrayLike<number>, flags?: number): void
ParameterTypeDescription
valuesArrayLike<number>
flags?number

sample

sample(tick: number, out: Float32Array): void

The state at a tick, clamped to the range that exists.

ParameterTypeDescription
ticknumber
outFloat32Array
More

Clamped rather than refused because both ends are ordinary rather than exceptional: a caller one tick past the end is a character who has finished, and holding their last state is exactly what they should look like.

channelAt

channelAt(tick: number, channel: number): number
ParameterTypeDescription
ticknumber
channelnumber

flagsAt

flagsAt(tick: number): number
ParameterTypeDescription
ticknumber

tickAtOrBefore

tickAtOrBefore(channel: number, value: number): number

The last tick at which a non-decreasing channel was at or below value.

ParameterTypeDescription
channelnumber
valuenumber
More

This is how two runs of the same course are compared at the same point on the course rather than at the same moment in time. Comparing by time drifts the instant one character takes a wider line; comparing by distance does not, which is what makes the difference a split rather than a guess.

The last tick of a run of equal values, not the first, and that matters wherever the channel can stall: a character who stopped for half a second has a plateau, and answering its first tick would report them ahead by the whole length of the stall.

The channel must be non-decreasing. Binary search over anything else returns an answer that is merely arbitrary rather than obviously wrong, so a caller whose channel can go backwards must clamp it on the way in.

-1 on an empty trace: there is no tick to name, and 0 would be a lie about a tick that does not exist.