Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | 185x 185x 185x 185x 185x 5473x 5473x 5473x 5473x 5473x 5473x 694x 211x 844x 4114x 4114x 211x 128x 420x 420x 420x 420x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 288x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 204x 204x 204x 89x 89x 89x 204x 19x 204x 6x 210x 210x 210x 1990x 1987x 6x 6x | import { resolveBmsonBGAEventInput, type BmsonBGAEventInput } from './bmson-bga.ts';
import { resolveChartTextInput, type ChartTextInput } from './chart-text.ts';
import { formatSeconds } from '../utils.ts';
import { writeRuntimeEventLog } from './engine-trace.ts';
import type { PreparedPlaybackChartData } from './bootstrap.ts';
import type { JudgeCoreEffectSink } from './judge-core-types.ts';
import type { PlaySession } from './play-session.ts';
import type { PlayJudge } from './play-strategy.ts';
import type { PlayerUIFrameSummary, PlayerUISeekJudgment } from './ui-signal-bus.ts';
/**
* Seeking: a command to the running play, handled by the play loop between two ticks (ADR 0016). The play is never
* started again: its audio, its chart time and its judge move to the second sought, and the host is told through a
* `seek` UI command and a frame of the next generation.
*/
/** A judge-core effect sink that keeps, of a judge rebuilt from the start, only the judgments it makes. */
export interface SeekRebuildSink {
readonly emit: JudgeCoreEffectSink;
readonly judgments: PlayerUISeekJudgment[];
readonly bmsonBGAInputs: BmsonBGAEventInput[];
readonly chartTextInputs: ChartTextInput[];
}
/**
* The sink a judge is re-simulated into when it seeks: nothing is heard, shown or traced, and every judgment is kept
* with the chart second it was made at and the gauge and EX score of `summary` right after it.
*/
export function createSeekRebuildSink(summary: Readonly<PlayerUIFrameSummary>): SeekRebuildSink {
const judgments: PlayerUISeekJudgment[] = [];
const bmsonBGAInputs: BmsonBGAEventInput[] = [];
const chartTextInputs: ChartTextInput[] = [];
let seconds = 0;
return {
judgments,
bmsonBGAInputs,
chartTextInputs,
emit: (effect) => {
const bgaInput = resolveBmsonBGAEventInput(effect);
if (bgaInput) bmsonBGAInputs.push(bgaInput);
const textInput = resolveChartTextInput(effect);
if (textInput) chartTextInputs.push(textInput);
if ('seconds' in effect && effect.seconds !== undefined) seconds = effect.seconds;
if (effect.kind !== 'judge-combo') return;
judgments.push({
judge: effect.judge,
combo: effect.combo,
...(effect.channel !== undefined ? { channel: effect.channel } : {}),
...(effect.signedDeltaMs !== undefined ? { deltaMs: effect.signedDeltaMs } : {}),
seconds,
...(summary.gauge !== undefined ? { gauge: summary.gauge.current } : {}),
exScore: summary.exScore,
});
},
};
}
/** Clears what the judge marked on the play's notes (judged, the long-note visibility), so it can judge them again. */
export function resetPlayNotes(chart: PreparedPlaybackChartData): void {
for (const notes of [chart.notes, chart.renderNotes, chart.scorableNotes, chart.invisibleNotes]) {
for (const note of notes) {
note.judged = false;
note.visibleUntilBeat = undefined;
}
}
for (const mine of chart.landmineNotes) mine.judged = false;
}
/**
* How far before `judgeFromSeconds` a seek rebuilds its judge and realtime audio to ({@link applySeek}): past the
* realtime audio's trigger slack, so a note or sound right on it is still to come.
*/
const SEEK_JUDGE_FROM_EPSILON_SECONDS = 1e-4;
/** The seek target within the chart or an aborted replay's recorded end; a non-finite value goes to the start. */
export function clampSeekSeconds(session: PlaySession, seconds: number): number {
Iif (!Number.isFinite(seconds)) return 0;
const replayEnd = session.replay ? session.options.replayAbortedAtUs : undefined;
const endSeconds =
replayEnd !== undefined && Number.isFinite(replayEnd)
? Math.min(session.totalSeconds, Math.max(0, replayEnd / 1_000_000))
: session.totalSeconds;
return Math.max(0, Math.min(seconds, endSeconds));
}
/**
* Applies a seek to chart second `seconds` at play-clock time `nowMs`, when the judge can seek; returns the second it
* went to, or `undefined` when it could not. The audio session stops what plays and resets its gains (`seek`), the
* volume changes before the target apply again and the sounds still ringing there start partway; chart time re-bases on
* the play clock at the tempo in force (a paused play stays paused); the judge rebuilds its state from the start; the
* UI buses drop what they still hold of the old position and get the `seek` command, the long notes held across the
* target and a cleared POOR image; and a frame at the target goes out. A play that seeks records no replay.
*
* `judgeFromSeconds` (at most `seconds`) is where the judge and the realtime audio go to instead: the notes and sounds
* from it on are still to come, judged and played on the next tick, while the clock goes on from `seconds`. A seamless
* PRACTICE loop goes back to its range's start this way, carrying the time it overshot, without skipping the notes on
* the range's first beat. The judge rebuilds to just before it, so a note on it is judged live: AUTO play plays it.
*/
export function applySeek(
session: PlaySession,
judge: PlayJudge,
seconds: number,
nowMs: number,
judgeFromSeconds?: number,
): number | undefined {
Iif (judge.seek === undefined) return undefined;
const { audioSession, uiEnabled, uiSignals, summary } = session;
const target = clampSeekSeconds(session, seconds);
const from = judgeFromSeconds === undefined ? target : Math.min(target, clampSeekSeconds(session, judgeFromSeconds));
session.replayRecorder?.discard();
session.seekGeneration += 1;
session.keyBoundBGA?.reset();
const generation = session.seekGeneration;
audioSession?.seek?.(target);
// Up to `from` the sounds still ringing start partway; those from it on fire as the next tick reaches them.
const soundsFrom = from < target ? Math.max(0, from - SEEK_JUDGE_FROM_EPSILON_SECONDS) : target;
session.volumeChanges.seek(soundsFrom);
session.backgroundAudio.seek(soundsFrom, (sound, offsetSeconds) =>
audioSession?.triggerEventAt?.(sound.event, offsetSeconds),
);
// Chain notes queued before the seek are dropped. A replay's rebuild queues its presses' chain notes again, starting
// the ones already due partway; a live play has no presses before the seek to sound.
session.chainSounds.clear();
session.tempoClock.rebase(nowMs, target);
session.resetScore();
resetPlayNotes(session.playbackChart);
const rebuilt = judge.seek(from < target ? Math.max(0, from - SEEK_JUDGE_FROM_EPSILON_SECONDS) : target);
session.bmsonBGA?.reset(rebuilt.bmsonBGAInputs);
session.chartText?.reset(rebuilt.chartTextInputs);
// What the buses still hold belongs to the old position.
uiSignals.drainCommands();
session.activeStateSignals?.drainPendingJudgeCombos();
if (uiEnabled) {
const { gauge, course, ...counts } = summary;
uiSignals.pushCommand({
kind: 'seek',
generation,
seconds: target,
snapshot: {
summary: {
...counts,
...(gauge !== undefined ? { gauge: { ...gauge } } : {}),
...(course !== undefined ? { course: { ...course } } : {}),
},
combo: session.score.scoreTracker.combo,
maxCombo: session.score.scoreTracker.maxCombo,
judgments: rebuilt.judgments,
},
});
for (const held of rebuilt.heldLongNotes) {
Eif (held.endBeat !== undefined) {
uiSignals.pushCommand({ kind: 'hold-lane-until-beat', channel: held.channel, beat: held.endBeat });
}
uiSignals.pushCommand({ kind: 'long-note-start', channel: held.channel, beat: held.beat, mode: held.mode });
}
for (const passing of rebuilt.hellChargeNotes ?? []) {
uiSignals.pushCommand({
kind: 'hell-charge',
channel: passing.channel,
beat: passing.beat,
state: passing.state,
});
}
uiSignals.pushCommand({ kind: 'clear-poor-bga' });
} else {
writeRuntimeEventLog(session.writeOutput, 'seek', [
['time', formatSeconds(target)],
['generation', generation],
]);
}
session.tracer.flushUntil(target);
session.publishUIFrame(target, session.beatAtSeconds(target));
return target;
}
/** What the play loop knows on a tick when it asks whether a looping PRACTICE play goes back to its start. */
export interface PracticeLoopTick {
/** The chart second of the tick. */
nowSec: number;
/** The play's end: a practice play's is the head of the bar after its range (`PreparedPlaybackChartData.totalSeconds`). */
totalSeconds: number;
/** Nothing is left to judge ({@link PlayJudge.isSettled}). */
settled: boolean;
/** Judging closed on an emptied survival gauge ({@link PlayJudge.isClosed}). */
closed: boolean;
/** The play clock passed the play's horizon (its end, the widest BAD reach and a second of grace). */
pastHorizon: boolean;
/** The loop is seamless (no rest after the range): it goes back at the end without waiting for the last judgments. */
seamless?: boolean;
}
/**
* Whether a looping PRACTICE play (`PlayPractice.loop`, #949) goes back to its start on this tick: when its gauge
* emptied, or once the play's end is reached with every note judged — or at the horizon at the latest, where a play
* that did not loop would end.
*/
export function isPracticeLoopDue(tick: Readonly<PracticeLoopTick>): boolean {
if (tick.closed || tick.pastHorizon) return true;
return (tick.settled || tick.seamless === true) && tick.nowSec >= tick.totalSeconds;
}
/**
* PRACTICE's loop (#949): moves the play back to where it loops from (`PlaySession.practiceLoopStartSeconds`, the head
* of the rest bars before the range, or the range itself), `overshootSeconds` on for a seamless loop that went past the
* range's end (the notes and sounds from the loop's start on still come, `applySeek`'s `judgeFromSeconds`), at
* play-clock time `nowMs`, as a seek there does (`applySeek`): the audio stops what still rings, the judge,
* the score, the combo and the gauge go back to the practice settings, the notes are judged again, and the host gets a
* `seek` UI command and a frame of the next generation, keeping the samples, the BGA and the skin it loaded. Returns
* the second it went to, or `undefined` when the judge cannot seek.
*/
export function restartPractice(
session: PlaySession,
judge: PlayJudge,
nowMs: number,
overshootSeconds = 0,
): number | undefined {
const loopStart = session.practiceLoopStartSeconds;
return applySeek(session, judge, loopStart + Math.max(0, overshootSeconds), nowMs, loopStart);
}
|