perf: adaptive performance mode for mobile

Auto-detect low-end devices (< 4 cores or touch) and reduce visual
complexity: 60% fewer particles, 6 vs 16 speed lines, 15 vs 40 stars,
halved datacenter buildings/racks, skip LED blinking animations,
fewer GPU graveyard chips, reduced afterimages and exhaust particles.

Toggle in fight viewer (LO/HI button), persisted in localStorage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 00:00:48 +00:00
co-authored by Claude Opus 4.6
parent 78f83a7520
commit 5af5ee1cba
4 changed files with 97 additions and 31 deletions
+32
View File
@@ -2,6 +2,38 @@
// Gameplay constants — all tunable magic numbers in one place
// ═══════════════════════════════════════════════════════════════
// --- Performance mode ---
const PERF_KEY = 'bf_perf_mode'
function detectLowEnd(): boolean {
if (typeof navigator === 'undefined') return false
const cores = navigator.hardwareConcurrency || 4
const mobile = navigator.maxTouchPoints > 0
return cores < 4 || mobile
}
function loadPerfPref(): boolean | null {
try {
const v = localStorage.getItem(PERF_KEY)
if (v === '1') return true
if (v === '0') return false
} catch {}
return null
}
let _perfMode = loadPerfPref() ?? detectLowEnd()
export function isPerfMode(): boolean { return _perfMode }
export function setPerfMode(on: boolean): void {
_perfMode = on
try { localStorage.setItem(PERF_KEY, on ? '1' : '0') } catch {}
}
/** Scale a particle count down in performance mode (40%) */
export function perfParticles(count: number): number {
return _perfMode ? Math.max(1, Math.round(count * 0.4)) : count
}
// --- Choreography selection probabilities ---
export const CREATOR_ULTIMATE_CHANCE = 0.5 // Creator ultimate chance (non-crit); 1.0 on crits
export const CREATOR_THEMED_MOVE_RATIO = 0.6 // Creator uses creator-themed moves 60% of the time