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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | 458918x 458918x 969798x 969798x 1564428x 1549080x 90289x 90289x 12520x 12520x 346815x 598x 1195725x 1195725x 8112166x 1195127x 271504x 102155x 102155x 102155x 102155x 707x 707x 707x 707x 43x 664x 6255x 2694x 3561x 3561x 6255x 6255x 6255x 903x 2658x 96933x 96933x 45139x 16654x 8260x 8394x 8394x 124704x 124704x 124704x 124704x 5143x 5143x 5143x 5143x 334x 334x 334x 334x 42699x 357095x 82931x 29810x 53121x 53121x 53121x 53121x 53121x 45139x 45139x 45139x 45139x 42393x 45139x 45139x 45139x 7982x 6666x 6666x 6480x 6666x 6666x 1316x 1316x 1316x 1316x 1172x 1316x 610x 6x 604x 604x | import type { TimedLandmineNote, TimedPlayableNote } from '../playable-notes.ts';
import type { JudgeWindowSetUs, RulesetConfig, RulesetWindowTables } from '../ruleset/definitions.ts';
import { judgeWindowEarlyReachUs, judgeWindowLateReachUs, selectJudgeWindowSet } from '../ruleset/judge.ts';
import { longNoteOwesTailMiss, noteLateReachUs } from '../ruleset/long-note.ts';
import type { GaugeJudgeIndex } from '../ruleset/gauge.ts';
import type { GrooveGaugeJudgmentKind } from './groove-gauge.ts';
import { isLongPlayableNote, resolveRulesetLongNoteMode, type TimedManualJudge } from './judge-rules.ts';
import { applyJudgeToSummary, type JudgmentKind } from './scoring.ts';
import {
JUDGE_TIME_EPSILON_SECONDS,
type JudgeCoreConfig,
type JudgeCoreEffectSink,
type JudgeCoreState,
type JudgeCoreSummary,
} from './judge-core-types.ts';
/**
* Judge-core scoring: the ruleset windows a judgment reads, and how a judgment moves the
* score, gauge and combo.
*/
// ---- LR2 negative-BPM reversal --------------------------------------------------------------------------------
/**
* The clock a press, a release or a long-note hold is judged on. Past an LR2 negative-BPM reversal R it is the
* mirrored `t' = 2R - now` (OpenLR2 `LR2f.cpp:12624,12931`, LR2body.exe 0x42c25b / 0x42c788): notes around the
* reversal stay hittable just after it, empty POORs keep firing while the lane's next note is within reach of t', and
* a long note spanning the reversal BADs on release. t' never passes R, so nothing past it is ever reached. Pure in
* the true chart time, so replays reproduce it.
*/
export function toJudgeClock(
config: Pick<JudgeCoreConfig, 'reversalSeconds' | 'reversalAnchor'>,
seconds: number,
): number {
const reversal = config.reversalAnchor?.seconds ?? config.reversalSeconds;
return reversal !== undefined && seconds > reversal ? 2 * reversal - seconds : seconds;
}
/**
* Clamps a forward pump reference (misses, auto-scratch) strictly BELOW the reversal. The sweeps are inclusive at
* their reference (some add {@link JUDGE_TIME_EPSILON_SECONDS} on top), while LR2 orders lane notes (op 10+) AFTER the
* negative BPM (op 8) on the reversal tick, so a note exactly AT the reversal is frozen with the pump.
*/
export function clampToReversal(config: Pick<JudgeCoreConfig, 'reversalSeconds'>, seconds: number): number {
const reversal = config.reversalSeconds;
return reversal === undefined ? seconds : Math.min(seconds, reversal - 2 * JUDGE_TIME_EPSILON_SECONDS);
}
// ---- windows --------------------------------------------------------------------------------------------------
/**
* Signed judge windows in force at a given chart time. The ruleset owns the whole table set — key vs scratch, note
* vs long-note end, and (LR2 only) the `#EXRANKxx` timeline — so the core never derives a window itself.
*/
export function windowTablesAt(config: JudgeCoreConfig, seconds: number): RulesetWindowTables {
return config.ruleset.windowsAt(Math.round(seconds * 1e6));
}
export function judgeWindowsFor(
config: JudgeCoreConfig,
channel: string,
seconds: number,
longNoteEnd = false,
): JudgeWindowSetUs {
return selectJudgeWindowSet(windowTablesAt(config, seconds), {
scratch: config.scratchChannels.has(channel),
longNoteEnd,
});
}
/**
* Widest reach (seconds) any lane can have at `seconds`, used as the candidate search radius. Only a coarse bound:
* the asymmetric legs are settled against each note's own window set.
*/
export function maxJudgeReachSeconds(config: Pick<JudgeCoreConfig, 'ruleset'>, seconds: number): number {
const tables = config.ruleset.windowsAt(Math.round(seconds * 1e6));
// Unrolled: a fresh array of the four sets on every press showed up in allocation profiles.
return (
Math.max(
judgeWindowLateReachUs(tables.note),
judgeWindowEarlyReachUs(tables.note),
judgeWindowLateReachUs(tables.scratch),
judgeWindowEarlyReachUs(tables.scratch),
judgeWindowLateReachUs(tables.longNoteEnd),
judgeWindowEarlyReachUs(tables.longNoteEnd),
judgeWindowLateReachUs(tables.longScratchEnd),
judgeWindowEarlyReachUs(tables.longScratchEnd),
0,
) / 1e6
);
}
/** How far ahead of a note its judgable window opens — when the lane's fallback keysound becomes that note's. */
export function maxJudgeEarlyReachSeconds(config: JudgeCoreConfig, seconds: number): number {
const tables = windowTablesAt(config, seconds);
return Math.max(judgeWindowEarlyReachUs(tables.note), judgeWindowEarlyReachUs(tables.scratch), 0) / 1e6;
}
/** The BAD gate of the opening key windows, in seconds — the horizon invisible notes are retired after. */
export function badWindowSeconds(config: JudgeCoreConfig): number {
// Two divisions on purpose: the engine always derived it through the millisecond readout, and the expiry compare
// must not move by a rounding step.
return judgeWindowLateReachUs(config.ruleset.windows.note) / 1000 / 1000;
}
/**
* How long past its own time a note stays reachable, in seconds. Resolved from the window set active at THAT NOTE's
* time and on THAT NOTE's lane: a mid-chart `#EXRANKxx` must not retroactively move the deadline of notes that had
* already scrolled past under the old rank. The replay simulator freezes the same per-note deadline.
*/
export function resolveMissDeadlineSeconds(config: JudgeCoreConfig, note: TimedPlayableNote): number {
return resolveNoteLateReachUs(config, note) / 1e6;
}
function resolveNoteLateReachUs(config: JudgeCoreConfig, note: TimedPlayableNote): number {
const { ruleset } = config;
return noteLateReachUs(
ruleset,
judgeWindowsFor(config, note.channel, note.seconds),
resolveRulesetLongNoteMode(ruleset.longNoteStyle, note),
);
}
/**
* A chart instant in whole microseconds, the replay's clock. Timed judgments (tails, misses, auto notes, mines) are
* scheduled on it, so the engine and the replay simulator see the same instants and the same ties.
*/
export function toJudgeUs(seconds: number): number {
return Math.round(seconds * 1e6);
}
/** The microsecond past which a note can no longer be pressed: it is missed once time has moved beyond it. */
export function resolveMissDeadlineUs(config: JudgeCoreConfig, note: TimedPlayableNote): number {
return toJudgeUs(note.seconds) + resolveNoteLateReachUs(config, note);
}
/** Channel order, the tie-break for timed judgments that fall on the same microsecond. */
export function compareJudgeChannels(left: string, right: string): number {
return left < right ? -1 : left > right ? 1 : 0;
}
// ---- score ----------------------------------------------------------------------------------------------------
export function applyGaugeJudge(
state: JudgeCoreState,
seconds: number,
judge: GrooveGaugeJudgmentKind,
emit: JudgeCoreEffectSink,
reason = 'judge',
): void {
const previousGauge = state.summary.gauge?.current;
state.applyGaugeJudge(judge);
const nextGauge = state.summary.gauge?.current;
emit({
kind: 'gauge',
seconds,
reason,
judge,
delta: previousGauge !== undefined && nextGauge !== undefined ? nextGauge - previousGauge : undefined,
});
}
export function applyGaugeDelta(
state: JudgeCoreState,
seconds: number,
delta: number,
reason: string,
emit: JudgeCoreEffectSink,
): void {
const previousGauge = state.summary.gauge?.current;
state.applyGaugeDelta(delta);
const nextGauge = state.summary.gauge?.current;
if (previousGauge === nextGauge) {
return;
}
emit({
kind: 'gauge',
seconds,
reason,
delta: previousGauge !== undefined && nextGauge !== undefined ? nextGauge - previousGauge : undefined,
});
}
/**
* One Hell Charge tick on the gauge (see `HCNTickCounter`): the ruleset's held tick while the lane gains, its released
* tick while it loses (beatoraja: GREAT ×0.5 and BAD ×0.5 of the judge table).
*/
export function applyHCNGaugeTick(
state: JudgeCoreState,
seconds: number,
gain: boolean,
emit: JudgeCoreEffectSink,
): void {
if (isJudgingClosed(state)) {
return;
}
const tick = state.config.ruleset.hcnTick;
const previousGauge = state.summary.gauge?.current;
state.applyGaugeTick(
(gain ? tick.heldJudge : tick.releasedJudge) as GaugeJudgeIndex,
gain ? tick.heldRate : tick.releasedRate,
);
const nextGauge = state.summary.gauge?.current;
if (previousGauge === nextGauge) {
return;
}
emit({
kind: 'gauge',
seconds,
reason: gain ? 'hold-gain' : 'hold-drain',
delta: previousGauge !== undefined && nextGauge !== undefined ? nextGauge - previousGauge : undefined,
});
}
export function setCombo(
state: JudgeCoreState,
seconds: number,
value: number,
reason: string,
emit: JudgeCoreEffectSink,
judge?: string,
channel?: string,
): void {
emit({ kind: 'combo', seconds, value, reason, judge, channel });
state.combo = value;
}
function applyFastSlow(summary: JudgeCoreSummary, judge: JudgmentKind, signedDeltaMs: number): void {
if (judge === 'GREAT' || judge === 'GOOD') {
if (signedDeltaMs < 0) {
summary.fast += 1;
} else Eif (signedDeltaMs > 0) {
summary.slow += 1;
}
}
}
export function markScorableJudged(state: JudgeCoreState, note: TimedPlayableNote): boolean {
Iif (note.judged) {
return false;
}
note.judged = true;
state.remainingScorableNotes -= 1;
return true;
}
export function markLandmineJudged(state: JudgeCoreState, note: TimedLandmineNote): boolean {
Iif (note.judged) {
return false;
}
note.judged = true;
state.remainingLandmineNotes -= 1;
return true;
}
export function markInvisibleJudged(state: JudgeCoreState, note: TimedPlayableNote): boolean {
Iif (note.judged) {
return false;
}
note.judged = true;
state.remainingInvisibleNotes -= 1;
return true;
}
/**
* True when a long note the player never held contributes a SECOND miss for its tail. Charge modes score head and
* tail separately, so a note missed at the head owes two POORs — except under That-Which-Must-Not-Be-Named, where a broken head cancels the
* tail outright (`headBadSkipsTail`).
*/
export function noteOwesTailMiss(ruleset: RulesetConfig, note: TimedPlayableNote): boolean {
return longNoteOwesTailMiss(
ruleset,
isLongPlayableNote(note) ? resolveRulesetLongNoteMode(ruleset.longNoteStyle, note) : undefined,
);
}
/**
* True once judging has stopped: the survival gauge emptied in a play that ends on failure
* (`JudgeCoreConfig.endOnFailure`). Nothing after the judgment that emptied it counts — no tally, combo, gauge or
* fast / slow — as in the replay simulator, which checks the same at the same points.
*/
export function isJudgingClosed(state: JudgeCoreState): boolean {
return state.config.endOnFailure && state.summary.gauge?.failedMidPlay === true;
}
export function applyResolvedManualJudge(
state: JudgeCoreState,
channel: string,
judge: TimedManualJudge,
atSeconds: number,
emit: JudgeCoreEffectSink,
longNote = false,
): void {
if (isJudgingClosed(state)) {
return;
}
const { summary } = state;
const deltaMs = Math.abs(judge.signedDeltaMs);
applyJudgeToSummary(summary, judge.kind, state.scoreTracker);
applyGaugeJudge(state, atSeconds, judge.kind, emit);
if (judge.kind === 'PERFECT' || judge.kind === 'GREAT' || judge.kind === 'GOOD') {
applyFastSlow(summary, judge.kind, judge.signedDeltaMs);
emit({ kind: 'poor-bga', action: 'clear', seconds: atSeconds });
setCombo(state, atSeconds, state.combo + 1, 'judge', emit, judge.kind, channel);
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'judge',
seconds: atSeconds,
fields: [
['result', judge.kind],
['channel', channel],
['deltaMs', Math.round(deltaMs)],
],
});
}
emit({
kind: 'judge-combo',
seconds: atSeconds,
judge: judge.kind,
combo: state.combo,
channel,
signedDeltaMs: judge.signedDeltaMs,
...(longNote ? { longNote } : {}),
});
emit({ kind: 'poor-trace', action: 'clear', seconds: atSeconds });
return;
}
if (judge.kind === 'BAD') {
setCombo(state, atSeconds, 0, 'judge', emit, 'BAD', channel);
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'judge',
seconds: atSeconds,
fields: [
['result', 'BAD'],
['channel', channel],
['deltaMs', Math.round(deltaMs)],
],
});
}
emit({
kind: 'judge-combo',
seconds: atSeconds,
judge: 'BAD',
combo: state.combo,
channel,
signedDeltaMs: judge.signedDeltaMs,
...(longNote ? { longNote } : {}),
});
return;
}
emit({ kind: 'poor-bga', action: 'trigger', seconds: atSeconds });
emit({ kind: 'poor-trace', action: 'trigger', seconds: atSeconds });
setCombo(state, atSeconds, 0, 'judge', emit, 'POOR', channel);
if (!state.config.omitTraceEffects) {
emit({
kind: 'trace',
name: 'judge',
seconds: atSeconds,
fields: [
['result', 'POOR'],
['channel', channel],
['deltaMs', Math.round(deltaMs)],
],
});
}
emit({
kind: 'judge-combo',
judge: 'POOR',
combo: state.combo,
channel,
signedDeltaMs: judge.signedDeltaMs,
...(longNote ? { longNote } : {}),
});
}
/** Charges a POOR (gauge + tally) with no other cue — the second judgment a missed charge note owes. */
export function applyTailMissPoor(state: JudgeCoreState, seconds: number, emit: JudgeCoreEffectSink): void {
if (isJudgingClosed(state)) {
return;
}
applyJudgeToSummary(state.summary, 'POOR', state.scoreTracker);
applyGaugeJudge(state, seconds, 'POOR', emit, 'miss');
}
|