Core · class
TickTrace
Explained in The loop.
class TickTrace implements TickTraceLikeimport { TickTrace } from '@driftengine/core';Constructor
new
constructor(channels: number, capacity?: number)| Parameter | Type | Description |
|---|---|---|
channels | number | |
capacity? | number |
Properties
| Name | Type | Description |
|---|---|---|
channelsreadonly | number |
Accessors
| Name | Type | Description |
|---|---|---|
lengthget | number |
Methods
push
push(values: ArrayLike<number>, flags?: number): void| Parameter | Type | Description |
|---|---|---|
values | ArrayLike<number> | |
flags? | number |
sample
sample(tick: number, out: Float32Array): voidThe state at a tick, clamped to the range that exists.
| Parameter | Type | Description |
|---|---|---|
tick | number | |
out | Float32Array |
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| Parameter | Type | Description |
|---|---|---|
tick | number | |
channel | number |
flagsAt
flagsAt(tick: number): number| Parameter | Type | Description |
|---|---|---|
tick | number |
tickAtOrBefore
tickAtOrBefore(channel: number, value: number): numberThe last tick at which a non-decreasing channel was at or below value.
| Parameter | Type | Description |
|---|---|---|
channel | number | |
value | number |
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.