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 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 2x 2x 2x 2x 3x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 3x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 2x 1x 1x 1x 1x 1x | import { resolveConstantVisibility, resolveConstantAlpha } from '@be-music/player-scene-model';
import { drawLabel } from '../../../stage/draw-label.ts';
/**
* The measure lines of the shared playfield: the chart's bar lines from the playhead, drawn with the skin's lines, by the
* Be-Music Skin, or as a thin bar across each run of adjacent lanes.
*/
import { resolveChart } from '@be-music/chart-model';
import { findFirstIndexNumberAtOrAfter } from '@be-music/shared-utils/core';
import {
isDrawnAtTime,
resolveDrawBottom,
resolveDrawY,
type NoteDrawWindow,
} from '../../../chart/note-draw-window.ts';
import type { PlayfieldContext } from './context.ts';
import { resolveSideLaneRuns, type SideLaneRun } from './measure-line-runs.ts';
function resolveMeasureBeats(ctx: PlayfieldContext): number[] {
const chartEntry = ctx.play.chart;
Iif (!chartEntry) {
return [];
}
Eif (ctx.measureBeatCache.chartId === chartEntry.id) {
return ctx.measureBeatCache.beats;
}
// The resolved chart's bar lines: one per measure start up to the last measure, using the chosen `#RANDOM` branch's
// `#xxx02` lengths, and none when a bmson chart opts out with `lines: []`.
const beats = [...(ctx.play.resolvedPlayChart ?? resolveChart(chartEntry.chart)).barLines];
ctx.measureBeatCache = { chartId: chartEntry.id, beats };
return beats;
}
/**
* Draws horizontal measure lines on the playfield at every `#MEASURE` boundary. A skin may give its own lines
* (`PlayfieldSkin.measureLines`; the LR2 family's `#SRC_LINE` / `#DST_LINE`), each repeated at every boundary; otherwise
* we fall back to a thin bar across each run of adjacent lanes, so double play's banks get one each and the gap between
* them stays clear.
*/
export function renderMeasureLines(ctx: PlayfieldContext, drawWindow: NoteDrawWindow, pixelsPerBeat: number): void {
const { currentBeat } = drawWindow;
const beats = resolveMeasureBeats(ctx);
Iif (beats.length === 0 || ctx.play.laneChannels.length === 0) {
return;
}
const firstChannel = ctx.play.laneChannels[0]!;
const lastChannel = ctx.play.laneChannels[ctx.play.laneChannels.length - 1]!;
const left = ctx.play.laneX.get(firstChannel);
const right = ctx.play.laneX.get(lastChannel);
Iif (!left || !right) {
return;
}
const top = left.top;
const bottom = left.bottom;
let firstBeatIndex: number;
Iif (drawWindow.rules === 'beatoraja') {
// A bar line is a timeline like any other: gone once its time has come (a STOP on it included).
firstBeatIndex = findFirstIndexNumberAtOrAfter(beats, currentBeat);
const timing = ctx.play.timingResolver;
while (
timing &&
firstBeatIndex < beats.length &&
!isDrawnAtTime(drawWindow, timing.beatToSeconds(beats[firstBeatIndex]!))
) {
firstBeatIndex += 1;
}
} else {
// LR2 drops a bar line once the playhead has passed it (`DrawNotes` 0x40703d-0x40705b), so one under a STOP that
// began on it stays on the judgement line for the STOP. A pixel of slack keeps the line just crossed for a frame,
// as LR2 draws it once more on the line before dropping it.
// Past an LR2 negative-BPM reversal a bar line the playhead passed before it stays gone as the scroll runs back.
firstBeatIndex = findFirstIndexNumberAtOrAfter(
beats,
drawWindow.reachedBeat - 1 / Math.max(Number.EPSILON, pixelsPerBeat),
);
}
// beatoraja's rules end the walk where the notes' walk ends (bar lines are timelines like any other).
const maxBeat =
drawWindow.rules === 'beatoraja'
? drawWindow.lastBeat
: currentBeat + ((left.baseBottom ?? bottom) - top + 1) / Math.max(Number.EPSILON, pixelsPerBeat);
const beatDistance = ctx.play.scrollMapper
? (toBeat: number): number => ctx.play.scrollMapper!.distanceBetween(currentBeat, toBeat)
: (toBeat: number): number => toBeat - currentBeat;
const drawBottom = resolveDrawBottom(drawWindow, bottom);
const lineY = (beat: number): number => resolveDrawY(drawWindow, bottom - beatDistance(beat) * pixelsPerBeat, bottom);
const constant = resolveConstantVisibility({
enabled: ctx.options?.visualConstant,
durationMs: ctx.options?.noteDurationMs,
fadeMs: ctx.options?.constantFadeMs,
noSpeed: ctx.play.playState.view.hiSpeed.locked,
});
const alphaAt = (beat: number) =>
constant.enabled && ctx.play.timingResolver
? resolveConstantAlpha(ctx.play.timingResolver.beatToSeconds(beat), drawWindow.nowSeconds, constant)
: 1;
const skinLines = ctx.playfieldSkin.measureLines();
if (skinLines !== undefined) {
// Each of the skin's lines (one per side under double play) at every boundary, in the skin's order.
for (let lineIndex = 0; lineIndex < skinLines.length; lineIndex += 1) {
const line = skinLines[lineIndex]!;
const texture = line.cell.texture;
Iif (texture === undefined) continue;
for (let beatIndex = firstBeatIndex; beatIndex < beats.length; beatIndex += 1) {
const beat = beats[beatIndex]!;
Iif (beat > maxBeat) {
break;
}
const y = lineY(beat);
Iif (y < top - 1 || y > drawBottom + 1) {
continue;
}
const alpha = alphaAt(beat);
Iif (alpha <= 0) continue;
const sprite = ctx.noteLayerPool.acquireSprite();
sprite.texture = texture;
sprite.label = drawLabel(ctx, 'measure-line', lineIndex, beat);
sprite.position.set(line.x, Math.round(y + (line.yOffset ?? 0)));
sprite.width = line.width;
sprite.height = line.height;
line.applyToSprite?.(sprite);
Iif (alpha !== 1) sprite.alpha *= alpha;
}
}
return;
}
const binding = ctx.skinBinding;
Eif (binding?.drawsMeasureLines) {
// The skin draws them: hand it one line per lane run, so double play's gap stays clear.
const runs = resolveMeasureLineRuns(ctx).map((run) => ({
...run,
lane: [...ctx.play.laneX.values()].find((lane) => lane.x === run.x) ?? left,
}));
for (let beatIndex = firstBeatIndex; beatIndex < beats.length; beatIndex += 1) {
const beat = beats[beatIndex]!;
Iif (beat > maxBeat) {
break;
}
for (const run of runs) {
const lane = run.lane;
const y = resolveDrawY(
drawWindow,
lane.bottom - beatDistance(beat) * pixelsPerBeat * (lane.scrollScale ?? 1),
lane.bottom,
);
Iif (y < lane.top - 1 || y > resolveDrawBottom(drawWindow, lane.bottom) + 1) continue;
const alpha = alphaAt(beat);
Eif (alpha > 0)
binding.addMeasureLine({ side: run.side, x: run.x, w: run.w, y, ...(alpha !== 1 ? { alpha } : {}) });
}
}
return;
}
// Fallback: simple white strip when the theme draws none, one per run of adjacent lanes so double play's gap stays
// clear. One pooled `Graphics` carries every line — the accumulated rect-fill commands form one batched draw, no
// per-line allocation.
const runs = resolveMeasureLineRuns(ctx).map((run) => ({
...run,
lane: [...ctx.play.laneX.values()].find((lane) => lane.x === run.x) ?? left,
}));
const graphic = ctx.noteLayerPool.acquireGraphics();
for (let beatIndex = firstBeatIndex; beatIndex < beats.length; beatIndex += 1) {
const beat = beats[beatIndex]!;
if (beat > maxBeat) {
break;
}
for (const run of runs) {
const lane = run.lane;
const y = resolveDrawY(
drawWindow,
lane.bottom - beatDistance(beat) * pixelsPerBeat * (lane.scrollScale ?? 1),
lane.bottom,
);
if (y < lane.top - 1 || y > resolveDrawBottom(drawWindow, lane.bottom) + 1) continue;
graphic.rect(run.x, Math.round(y), run.w, 1).fill({ color: 0x9a8fd0, alpha: 0.28 * alphaAt(beat) });
}
}
}
/** The lane runs of this frame's lanes, recomputed only when their geometry changes. */
function resolveMeasureLineRuns(ctx: PlayfieldContext): readonly SideLaneRun[] {
let signature = ctx.play.laneX.size;
for (const lane of ctx.play.laneX.values()) {
signature = (signature * 31 + lane.x * 7 + lane.w) % 1_000_000_007;
}
const cached = ctx.measureLineRuns;
Iif (cached && cached.signature === signature) return cached.runs;
const runs = resolveSideLaneRuns(ctx.play.laneX);
ctx.measureLineRuns = { signature, runs };
return runs;
}
|