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 | 30x 30x 30x 14x 13x 14x 14x 24x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 6x 6x 29x 4x 4x 35x 35x 35x 35x 35x 35x 35x 35x 2x 2x 2x 35x 4x 35x 2x 2x 2x 2x 2x 2x 2x 35x 3x 35x 2x 2x 2x 2x 2x 35x 2x 2x 2x 2x 2x 35x 2x 2x 2x 35x 3x 3x 35x 35x 35x 35x 30x 12x 1x 1x 8x 7x 7x 7x 7x 7x 7x 3x 3x 3x 2x 2x 1x 1x 4x 1x 4x 4x 4x 1x 1x 30x | /**
* LR2's mania drawing options (the hidden panel of `LR2f.cpp` L1054-L1470): how they move, size and shake what the
* playfield draws. They change only the drawing; note times, lanes and judgment are untouched. The formulas are LR2's
* (`DrawNotes`, `LR2f.cpp` L2155-L2331) and run in LR2's 640x480 pixels, scaled to the stage by `unit`.
*/
import type { PlayOptions } from '@be-music/player-scene-model';
/** LR2's screen height, the unit its mania drawing options are written in. */
export const LR2_SCREEN_HEIGHT = 480;
const TAU = Math.PI * 2;
const HALF_PI = Math.PI / 2;
/** The mania drawing options that are on. */
export interface LR2ManiaVisual {
readonly acceleration: PlayOptions['lr2Acceleration'];
readonly earthquake: number;
readonly tornado: number;
readonly superLoop: number;
readonly char: number;
readonly heartbeat: number;
readonly nabeatsu: number;
readonly sinCurve: number;
readonly wave: number;
readonly spiral: number;
readonly sideJump: number;
}
/** The mania drawing options of `options`, or `undefined` when none is on (the playfield then skips the pass). */
export function resolveLR2ManiaVisual(options: Partial<PlayOptions> | undefined): LR2ManiaVisual | undefined {
if (options === undefined) return undefined;
const visual: LR2ManiaVisual = {
acceleration: options.lr2Acceleration ?? 'OFF',
earthquake: options.lr2Earthquake ?? 0,
tornado: options.lr2Tornado ?? 0,
superLoop: options.lr2SuperLoop ?? 0,
char: options.lr2Char ?? 0,
heartbeat: options.lr2Heartbeat ?? 0,
nabeatsu: options.lr2Nabeatsu ?? 0,
sinCurve: options.lr2SinCurve ?? 0,
wave: options.lr2Wave ?? 0,
spiral: options.lr2SpiralEffect ?? 0,
sideJump: options.lr2SideJump ?? 0,
};
const on =
visual.acceleration !== 'OFF' ||
visual.earthquake > 0 ||
visual.tornado > 0 ||
visual.superLoop > 0 ||
visual.char > 0 ||
visual.heartbeat > 0 ||
visual.nabeatsu > 0 ||
visual.sinCurve > 0 ||
visual.wave > 0 ||
visual.spiral > 0 ||
visual.sideJump > 0 ||
false;
return on ? visual : undefined;
}
/** One note (or mine) as the playfield is about to draw it. Lengths are stage pixels. */
export interface LR2ManiaNoteInput {
/** How far above the judge line the note's own time puts it (0 on the line). */
readonly distance: number;
/** The same for a long note's end. */
readonly tailDistance?: number;
/** The judge line's distance from the top of the stage: LR2 measures a note's place along the lane against it. */
readonly lineY: number;
/** LR2's lane number: 0 / 10 the scratches, 1–9 / 11–19 the keys. */
readonly lane: number;
/** The note's index among its lane's notes and mines, in time order. */
readonly index: number;
/** The play clock, in milliseconds. */
readonly nowMs: number;
/** Stage pixels per LR2 pixel (the stage's height over 480). */
readonly unit: number;
/** NABEATSU's sway this frame, which the caller has already moved the note layer by. */
readonly sway?: LR2ManiaShake;
}
/** Where and how large the options draw the note. Lengths are stage pixels. */
export interface LR2ManiaNotePlacement {
/** The note's distance above the judge line; negative below it. */
readonly distance: number;
/** A long note's end, likewise. */
readonly tailDistance: number | undefined;
/** The sideways shift from the note's lane. */
readonly xOffset: number;
/** Added to the note's width and height, about its centre. */
readonly widthDelta: number;
readonly heightDelta: number;
}
/** A sine over one `periodMs` of the play clock, at `phaseMs` into it. */
function wave(phaseMs: number, periodMs: number): number {
return ((((phaseMs % periodMs) + periodMs) % periodMs) / periodMs) * TAU;
}
/** Places one note under the mania options, in LR2's order of application. */
export function placeLR2ManiaNote(visual: LR2ManiaVisual, input: LR2ManiaNoteInput): LR2ManiaNotePlacement {
const unit = input.unit > 0 ? input.unit : 1;
const lineY = input.lineY / unit;
const now = Math.floor(input.nowMs);
const { lane, index } = input;
// LR2 keeps a note's offset from the line as a negative `note_y`; `pos` is its place along the lane, 0 on the line
// and 1 at the top of the screen.
let y = -input.distance / unit;
let tailY = input.tailDistance === undefined ? y : -input.tailDistance / unit;
const pos = lineY !== 0 ? -y / lineY : 0;
const tailPos = lineY !== 0 ? -tailY / lineY : 0;
let x = 0;
let widthDelta = 0;
let heightDelta = 0;
const eased =
visual.acceleration === 'RANDOM'
? (index + lane) % 2 === 0
? 'ACCELERATION'
: 'DECELERATION'
: visual.acceleration;
if (eased === 'ACCELERATION') {
y = Math.sin(pos * HALF_PI) * -lineY;
tailY = Math.sin(tailPos * HALF_PI) * -lineY;
} else if (eased === 'DECELERATION') {
y = (1 - Math.cos(pos * HALF_PI)) * -lineY;
tailY = (1 - Math.cos(tailPos * HALF_PI)) * -lineY;
}
// A note past the line stays on it before the effects below move it.
y = Math.min(0, y);
tailY = Math.min(0, tailY);
// NABEATSU's sway joins the note here, before the effects below turn or stretch it, as in LR2. The note layer is
// already moved by it, so it is taken back out at the end.
const swayX = (input.sway?.x ?? 0) / unit;
const swayY = (input.sway?.y ?? 0) / unit;
x = swayX;
y += swayY;
tailY += swayY;
if (visual.heartbeat > 0) {
const beat = Math.sin(wave((index + lane * 2) * 50 + now, 500));
widthDelta += beat * visual.heartbeat * 2;
heightDelta += beat * visual.heartbeat;
}
if (visual.tornado > 0) {
x = (visual.tornado * y * -0.5 * Math.sin((lane / 10 + (now % 1000) / 1000) * TAU)) / 100;
}
if (visual.superLoop > 0) {
const period = (120 - visual.superLoop) * 50;
const angle = wave(now, period);
const turnedX = x * Math.cos(angle) - y * Math.sin(angle);
const turnedY = x * Math.sin(angle) + y * Math.cos(angle);
tailY = turnedY + tailY - y;
y = turnedY;
x = turnedX;
}
if (visual.sinCurve > 0) {
x += Math.sin(Math.trunc(visual.sinCurve / 10) * Math.PI * pos) * visual.sinCurve;
}
if (visual.spiral > 0) {
const reach = (index % 2 === 0 ? 1 : -1) * pos * visual.spiral;
const angle = wave(now + (index * 7 + lane) * 30, 300);
x += Math.sin(angle) * reach;
y += Math.cos(angle) * reach;
tailY += Math.cos(angle) * reach;
}
if (visual.sideJump > 0) {
const reach = (index % 2 === 0 ? 1 : -1) * pos * visual.sideJump;
const angle = wave(lane * 50 + index * 77 + now, 500);
x += Math.sin(angle) * reach;
y -= Math.abs(Math.cos(angle) * reach);
tailY -= Math.abs(Math.cos(angle) * reach);
}
if (visual.wave > 0) {
const swing = Math.sin(wave(lane * 100 + now, 1000));
y += visual.wave * pos * pos * swing;
tailY += visual.wave * tailPos * tailPos * swing;
}
if (visual.char > 0 && (lane + index) % (Math.trunc(((100 - visual.char) * 2) / 10) + 2) === 0) {
y *= 3;
tailY *= 3;
}
x -= swayX;
y -= swayY;
tailY -= swayY;
return {
distance: -y * unit,
tailDistance: input.tailDistance === undefined ? undefined : -tailY * unit,
xOffset: x * unit,
widthDelta: widthDelta * unit,
heightDelta: heightDelta * unit,
};
}
/** A shake of the drawing, in stage pixels. */
export interface LR2ManiaShake {
readonly x: number;
readonly y: number;
}
const STILL: LR2ManiaShake = { x: 0, y: 0 };
/** EARTHQUAKE: the offset of the whole play screen at `nowMs` of the play clock. */
export function resolveLR2Earthquake(visual: LR2ManiaVisual | undefined, nowMs: number, unit: number): LR2ManiaShake {
if (visual === undefined || visual.earthquake <= 0) return STILL;
const now = Math.floor(nowMs);
return {
x: Math.sin(wave(now, 1000)) * visual.earthquake * unit,
y: Math.sin(wave(now, 1234)) * visual.earthquake * 0.75 * unit,
};
}
/**
* NABEATSU: the offset of the notes and bar lines at `nowMs` of the play clock. They sway only while the clock's
* second (within the minute) is a multiple of 3; from 50 up, also during seconds 30–39 and seconds ending in 3. The
* first second of the play never sways.
*/
export function resolveLR2Nabeatsu(visual: LR2ManiaVisual | undefined, nowMs: number, unit: number): LR2ManiaShake {
if (visual === undefined || visual.nabeatsu <= 0) return STILL;
const now = Math.floor(nowMs);
const seconds = Math.trunc(now / 1000);
const second = seconds % 60;
let sways = second % 3 === 0;
if (visual.nabeatsu >= 50 && ((second >= 30 && second < 40) || second % 10 === 3)) sways = true;
if (seconds === 0 || !sways) return STILL;
const periodX = Math.trunc(Math.sin(wave(now, 12345)) * 200 + 1000);
const periodY = Math.trunc(Math.sin(wave(now, 10000)) * 300 + 1234);
return {
x: Math.sin(wave(now, periodX)) * visual.nabeatsu * unit,
y: Math.sin(wave(now, periodY)) * visual.nabeatsu * 0.75 * unit,
};
}
/**
* Each note's and mine's index within its lane, in time order: LR2 keeps one array per lane, mines included, and its
* effects alternate by that index. Kept per notes array, so a chart is walked once.
*/
export function resolveLR2ManiaNoteIndexes(
notes: readonly { readonly channel: string; readonly seconds: number }[],
mines: readonly { readonly channel: string; readonly seconds: number }[],
): WeakMap<object, number> {
const cached = indexCache.get(notes);
if (cached !== undefined && cached.mines === mines) return cached.indexes;
const indexes = new WeakMap<object, number>();
const counts = new Map<string, number>();
const all = [...notes, ...mines].sort((left, right) => left.seconds - right.seconds);
for (const object of all) {
const count = counts.get(object.channel) ?? 0;
indexes.set(object, count);
counts.set(object.channel, count + 1);
}
indexCache.set(notes, { mines, indexes });
return indexes;
}
const indexCache = new WeakMap<object, { mines: unknown; indexes: WeakMap<object, number> }>();
|