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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | 132x 132x | import type { ResolvedChainSound } from '@be-music/chart-model';
import type { BeMusicEvent, BeMusicSourceFormat } from '@be-music/chart-source';
import type { TimedLandmineNote, TimedPlayableNote } from '../playable-notes.ts';
import type { ReplayInputEvent } from '../replay/format.ts';
import type { RulesetConfig } from '../ruleset/definitions.ts';
import type { GaugeJudgeIndex } from '../ruleset/gauge.ts';
import type { HCNTickCounter } from '../ruleset/long-note.ts';
import type { GrooveGaugeJudgmentKind } from './groove-gauge.ts';
import type { AnyKeyRoutes } from './any-key.ts';
import type { LaneHoldHistory } from './lane-hold.ts';
import type { ScratchSpin } from './scratch-spin.ts';
import type { PlugoutLaneSoundState } from './plugout-lane-sound.ts';
import type { InputSource } from './input-source.ts';
import { type PendingAutoLongNoteState, type TimedManualJudge } from './judge-rules.ts';
import { type ScoreSummary, type ScoreTracker } from './scoring.ts';
import type { PlayerGaugeSummary, PlayerUICommand } from './ui-signal-bus.ts';
/**
* The judge core's state, inputs, effects and tuning constants (see `judge-core.ts`).
*/
/** Slack added to "has chart time reached X" checks so float noise never holds an event back by one step. */
export const JUDGE_TIME_EPSILON_SECONDS = 1e-6;
/** `#WAV00` — the sample a mine explosion plays, when the chart defines one. */
export const LANDMINE_EXPLOSION_SAMPLE_KEY = '00';
/** Everything about the play that stays fixed while it runs. */
export interface JudgeCoreConfig {
ruleset: RulesetConfig;
/** Judged notes, sorted by time. The core marks them `judged` (and sets `visibleUntilBeat` on long notes). */
scorableNotes: TimedPlayableNote[];
landmineNotes: TimedLandmineNote[];
invisibleNotes: TimedPlayableNote[];
/** Notes whose keysound a note-less press plays (LR2 lane-sound hold). */
laneSoundNotes: readonly TimedPlayableNote[];
/** Scratch lanes (`16` / `26` and their mapped equivalents) — they read the scratch window tables. */
scratchChannels: ReadonlySet<string>;
/** AUTO SCRATCH: the core plays the scratch lanes itself and ignores input on them. */
autoScratch: boolean;
/** The assisted subset of scratchChannels; absent means the legacy combined switch. */
autoScratchChannels?: ReadonlySet<string>;
/**
* ANY KEY (#751): a press takes the nearest unjudged note in reach on any lane and holds that lane until its key comes
* up (`any-key.ts`). Inputs keep naming the keys' own lanes; the core routes them.
*/
anyKey?: boolean;
/**
* Scale of the millisecond domain (`nowMs`, release-margin deadlines, lane press / release stamps) per chart second.
* Live play runs it on the playback clock (`1000 / speed`, wall-clock milliseconds); a replay runs it on chart time
* (`1000`).
*/
judgeMsPerChartSecond: number;
/**
* Skip building `trace` effects. Live play with a UI discards them (only the terminal log writes them), so it sets
* this to keep their objects off the judge path. Absent means they are emitted.
*/
omitTraceEffects?: boolean;
/** `#WAVxx` table, for the mine explosion sample. */
wavResources: Readonly<Record<string, string>>;
/**
* The explosion slot by chart time in place of `#WAV00` (`PlayerPlayRuntime.landmineSampleKeys`), in time order: a
* mine uses the last cue at or before its own time; a cue without `sampleKey` is silent.
*/
landmineSampleKeys?: ReadonlyArray<{ seconds: number; sampleKey?: string }>;
/** Object-id radix, for reading mine damage values. */
idBase: 36 | 62;
sourceFormat: BeMusicSourceFormat;
/**
* Authored time of the negative BPM that freezes chart events, autoplay, mines and miss sweeps.
*/
reversalSeconds?: number;
/** Observed activation tick used to mirror input times. A legacy replay mirrors at the authored time. */
reversalAnchor?: { readonly seconds: number };
/**
* The play ends the moment a survival gauge empties (`PlayerOptions.endOnFailure`): from the judgment that emptied
* it on, nothing is scored (see `isJudgingClosed`).
*/
endOnFailure: boolean;
/** Practice starts here: earlier note heads (including their tails) are consumed without scoring. */
practiceFromSeconds?: number;
}
/** The play's running result — the same shape as the engine's public `PlayerSummary`. */
export interface JudgeCoreSummary extends ScoreSummary {
fast: number;
slow: number;
gauge?: PlayerGaugeSummary;
}
/** The score side of the state: the summary the host shows, and the gauge it is updated through. */
export interface JudgeCoreScore {
summary: JudgeCoreSummary;
scoreTracker: ScoreTracker;
applyGaugeJudge: (judge: GrooveGaugeJudgmentKind) => void;
applyGaugeDelta: (delta: number) => void;
/** One Hell Charge tick: a judge-table entry at a rate (beatoraja's `gauge.update(judge, rate)`). */
applyGaugeTick: (judge: GaugeJudgeIndex, rate: number) => void;
/** Empties the gauge for good (LR2's `HP = 0` when a reversed play ends with notes outstanding). */
drainGaugeToZero: () => void;
}
/** A Hell Charge note passing the judge line: its gauge ticks run from its judged head until its tail passes. */
export interface HCNPassingState {
note: TimedPlayableNote;
/** The tail's microsecond: the counter stops there. */
endUs: number;
counter: HCNTickCounter;
/** The tail was released at GOOD or better: the lane gains until the tail passes, held or not. */
tailGood: boolean;
/** The gaining state last sent to the UI (`hell-charge` command), so only a switch is sent. */
reported?: 'gaining' | 'draining';
/** The lane's next Hell Charge note, judged before this one has passed: it ticks once this one's tail passes. */
next?: HCNPassingState;
}
/** A long note whose head was hit and whose tail is not resolved yet. */
export interface ActiveLongNoteState {
endSeconds: number;
note: TimedPlayableNote;
mode: 1 | 2 | 3;
headJudge: TimedManualJudge;
audioStopped: boolean;
/**
* True when `headJudge` has ALREADY been applied to the score (charge modes judge the head on the press). The
* tail then stands alone; LN mode instead defers, and resolves head and tail into one combined judgment.
*/
headScored: boolean;
/**
* A back-spin scratch (`isBackSpinScratch`): its tail is judged on a press from another source than
* {@link headSource} (`endsBackSpinScratch`), and a release settles it only as the ruleset says.
*/
backSpinScratch?: true;
/**
* The source of the press that hit the head of a scratch long note (beatoraja's `sckey`): a back-spin scratch's, or
* an LN's on a scratch lane under a ruleset that keys scratch holds by source. `undefined` when the input named none.
*/
headSource?: InputSource;
}
/** The judge state of one manual play. Owned by the core: drivers read it, only {@link runJudgeCoreStep} writes it. */
export interface JudgeCoreState {
readonly config: JudgeCoreConfig;
readonly summary: JudgeCoreScore['summary'];
readonly scoreTracker: ScoreTracker;
readonly applyGaugeJudge: (judge: GrooveGaugeJudgmentKind) => void;
readonly applyGaugeDelta: (delta: number) => void;
readonly applyGaugeTick: (judge: GaugeJudgeIndex, rate: number) => void;
readonly drainGaugeToZero: () => void;
combo: number;
/**
* Lanes whose key is down: between a `hold` and a `release`. The core takes key-state input only — a driver whose
* input reports no releases infers them first (`play-key-inference.ts`) — so a press never holds a lane by itself.
*/
readonly heldChannels: Set<string>;
readonly activeLongNotes: Map<string, ActiveLongNoteState>;
/**
* Millisecond each let-go long note settles at: at once (`-Infinity`), or once the ruleset's release margin has run
* out (beatoraja's `longnoteMargin`), until when pressing the lane again resumes the hold.
*/
readonly longNoteSettleMs: Map<string, number>;
/** Chart second each held long note was released at — its tail is judged against the release, not the tick. */
readonly longHoldReleaseSeconds: Map<string, number>;
/** Each lane's press and release instants, for asking whether it was down when a mine crossed the line. */
readonly laneHolds: Map<string, LaneHoldHistory>;
/** ANY KEY: the lane each pressed key was routed to (empty without {@link JudgeCoreConfig.anyKey}). */
readonly anyKeyRoutes: AnyKeyRoutes;
/** The latest instant (true clock, seconds) the timed judgments were advanced to — an ESC abort stops there. */
advancedThroughSeconds: number;
readonly pendingAutoScratchLongNotes: PendingAutoLongNoteState[];
readonly autoScratchNotes: readonly TimedPlayableNote[];
/** Per-lane sorted note times — the reference notes a phantom press is measured against for an empty POOR. */
readonly scorableNoteSecondsByChannel: ReadonlyMap<string, number[]>;
autoScratchCursor: number;
scorableMissCursor: number;
landmineExpireCursor: number;
/**
* How far each unsettled mine has been checked: 1 once its LR2 PGREAT-window entry, 2 once its crossing of the judge
* line. A mine is settled (judged) after its last check.
*/
readonly landminePhases: Map<TimedLandmineNote, number>;
/** The Hell Charge note passing each lane, while its gauge ticks run. */
readonly hcnPassing: Map<string, HCNPassingState>;
invisibleExpireCursor: number;
remainingScorableNotes: number;
remainingLandmineNotes: number;
remainingInvisibleNotes: number;
/** Each lane's sound cursor under a ruleset that picks lane sounds as plugout does (`RulesetConfig.laneSound`). */
readonly plugoutLaneSounds?: PlugoutLaneSoundState;
}
/** One thing that happens to the judge state, stamped with chart seconds (and the millisecond domain). */
export type JudgeCoreInput =
/** Time passes: long-note holds and tails, HCN ticks, auto-scratch, misses, mines and invisible notes resolve. */
| { kind: 'advance'; nowSec: number; nowMs: number }
/**
* A lane press on `channels` (already mapped from key tokens). `source` is the physical input it came from: a scratch
* hold remembers it, lane holds and ANY KEY routes are keyed by it (by `tokens` when it is absent), and the replay
* records it. `spin` is the way a scratch press turned the turntable, for display only.
*/
| {
kind: 'press';
channels: ReadonlySet<string>;
tokens: readonly string[];
nowSec: number;
nowMs: number;
source?: InputSource;
spin?: ScratchSpin;
/** The physical input, only recorded (`ReplayInputEvent.code`). */
code?: string;
}
/**
* Keys went down and stay down (key-state input): the lanes count as held until released. `inferred`: the driver
* inferred it from input without releases, so no lane cue shows it. `tokens` name the keys, which ANY KEY routes by.
*/
| {
kind: 'hold';
channels: ReadonlySet<string>;
tokens?: readonly string[];
inferred?: boolean;
/** The physical input holding the lanes (see `press`). */
source?: InputSource;
}
/**
* Keys came up. `recordSec` is the instant the replay records for the release. `inferred`: the driver inferred it
* from input without releases (the replay marks it), so no lane cue shows it.
*/
| {
kind: 'release';
channels: ReadonlySet<string>;
tokens: readonly string[];
nowSec: number;
nowMs: number;
recordSec: number;
inferred?: boolean;
/** The physical input that came up (see `press`). */
source?: InputSource;
/** The physical input, only recorded (`ReplayInputEvent.code`). */
code?: string;
}
/**
* The play ended: anything still unjudged is charged as POOR at `totalSeconds` — except, past an LR2 negative-BPM
* reversal, the notes the frozen pump never reached, which empty the gauge instead.
*/
| { kind: 'finish'; totalSeconds: number };
/** A `name value` field of a no-TUI trace line (the time field is added from the effect's `seconds`). */
export type JudgeTraceField = readonly [key: string, value: string | number | boolean | undefined];
/** Where a keysound the core triggered came from. */
export type JudgeSoundSource = 'auto-scratch' | 'manual-note' | 'lane-fallback' | 'mine-hit' | 'long-note-end';
/** What a step produced, in order. Drivers map these onto audio, the UI buses, the replay and the no-TUI trace. */
export type JudgeCoreEffect =
/**
* Record a raw input in the replay (before it is judged). `channels` is only valid during dispatch. `inferred`
* marks a release the driver inferred from input without releases.
*/
| {
kind: 'record-input';
action: ReplayInputEvent['action'];
seconds: number;
/** The physical input (`ReplayInputEvent.source`); `undefined` when the input named none. */
source: InputSource | undefined;
channels: ReadonlySet<string>;
inferred?: boolean;
/** The scratch spin of a press (`ReplayInputEvent.spin`). */
spin?: ScratchSpin;
/** The physical input (`ReplayInputEvent.code`). */
code?: string;
}
/** Count an empty POOR in the replay's native result. */
| { kind: 'record-empty-poor' }
/** An input is about to be judged at `seconds` (replay): flush time-scheduled trace output up to it first. */
| { kind: 'input-time'; seconds: number }
/** Play a keysound / explosion sample. */
| { kind: 'sound'; source: JudgeSoundSource; event: BeMusicEvent; seconds: number; channel: string }
/** A press sounded a note that LRX chain notes follow: play them, each its delay after `seconds`. */
| { kind: 'chain-sounds'; sounds: readonly ResolvedChainSound[]; seconds: number; channel: string }
/** Cut a lane's sounding keysound (a long note released or broken). */
| {
kind: 'stop-sound';
channel: string;
seconds: number;
reason: 'long-note-release' | 'long-note-break';
event: BeMusicEvent;
}
/** The gauge moved (`judge` absent for raw deltas). `delta` is the applied change, after clamping. */
| { kind: 'gauge'; seconds: number; reason: string; judge?: GrooveGaugeJudgmentKind; delta?: number }
/** The combo was set to `value`. */
| { kind: 'combo'; seconds: number; value: number; reason: string; judge?: string; channel?: string }
/** A long note changed state. */
| {
kind: 'long-note';
seconds: number;
channel: string;
state: 'start' | 'release' | 'break' | 'complete';
mode: 1 | 2 | 3;
event: BeMusicEvent;
endSeconds: number;
}
/** A presentation cue for the gameplay UI (lane flashes, holds, long-note bars). */
| { kind: 'ui'; command: PlayerUICommand }
/** The POOR BGA was triggered / cleared — delivered to every host, UI or not. */
| { kind: 'poor-bga'; action: 'trigger' | 'clear'; seconds: number }
/** The no-TUI trace's POOR BGA marker at this point of the output. */
| { kind: 'poor-trace'; action: 'trigger' | 'clear'; seconds: number }
/**
* The judge readout: what the UI's judge / combo display shows. `longNote` marks a judgment of a long note (its head
* in a charge mode, or the whole note), which LR2's automatic judge timing does not sample.
*/
| {
kind: 'judge-combo';
seconds?: number;
judge: string;
combo: number;
channel?: string;
signedDeltaMs?: number;
longNote?: boolean;
/**
* A POOR that takes no note: an empty POOR (a press near a note that does not consume it), or the one that sums
* up the notes a stopped play left. Absent for a POOR on a note.
*/
poor?: 'empty' | 'remaining';
}
/** A no-TUI trace line. */
| { kind: 'trace'; name: string; seconds: number; fields: readonly JudgeTraceField[] }
/** The play state changed outside a frame tick: republish the frame (at `beat`, or the beat of `seconds`). */
| { kind: 'frame'; seconds: number; beat?: number };
export type JudgeCoreEffectSink = (effect: JudgeCoreEffect) => void;
|