feat(minigames): powerup name tags, centered loadout pips, prediction telemetry probe
- drawDrop now renders the powerup name on a semi-opaque plate pinned to the cell bottom (no bob, stays readable while the drop animates) - own loadout pip row centered above the play area - opt-in client telemetry behind localStorage.bompDebug='1': one row per reconciled snapshot (gap, envelope, correction branch, rttAvg, snapshot delivery cadence, remote-player snaps) plus transport kind changes, exposed as window.__bompDbg.stats()/.table()/.dump() to diagnose the reported WS jitter with data instead of guesses
This commit is contained in:
parent
8b7c698e96
commit
1883a1aabe
2 changed files with 135 additions and 2 deletions
|
|
@ -39,6 +39,65 @@ const POWERUP_COLORS: Record<string, string> = {
|
|||
kick: "#a3e635",
|
||||
};
|
||||
const POWERUP_GLYPH: Record<string, string> = { bomb: "●", range: "✸", speed: "»", kick: "⇥" };
|
||||
const POWERUP_NAME: Record<string, string> = { bomb: "BOMB", range: "RANGE", speed: "SPEED", kick: "KICK" };
|
||||
|
||||
/* ---- opt-in prediction telemetry (localStorage.bompDebug = "1") -------------
|
||||
* Records one row per reconciled snapshot so a playtest can answer, with data,
|
||||
* whether visible jitter comes from correction trims (b=1/2), round resets
|
||||
* (b=3), remote-player snaps (rs), bursty snapshot delivery (s), or a jumpy
|
||||
* RTT estimate (r). Dump with __bompDbg.stats() / .table() in devtools. */
|
||||
const BOMP_DEBUG =
|
||||
typeof window !== "undefined" &&
|
||||
(() => {
|
||||
try {
|
||||
return window.localStorage.getItem("bompDebug") === "1";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
interface DbgRow {
|
||||
/** ms since page epoch (performance.now at record). */
|
||||
t: number;
|
||||
v: number;
|
||||
/** |pred - est| at reconcile, cells (-1 when no estimate was possible). */
|
||||
g: number;
|
||||
/** correction envelope for that snapshot, cells. */
|
||||
e: number;
|
||||
/** 0 none, 1 envelope trim, 2 capped ease (>2.5 cells), 3 ack-backwards reset. */
|
||||
b: number;
|
||||
/** rttAvg feeding the envelope, ms. */
|
||||
r: number;
|
||||
/** ms since the previously reconciled snapshot version (delivery cadence). */
|
||||
s: number;
|
||||
/** remote-player >1.5-cell snaps since the previous row. */
|
||||
rs: number;
|
||||
}
|
||||
|
||||
function dbgRecord(
|
||||
st: { ring: DbgRow[]; lastAt: number; remoteSnaps: number; lastRs: number } | null,
|
||||
now: number,
|
||||
v: number,
|
||||
g: number,
|
||||
e: number,
|
||||
b: number,
|
||||
r: number,
|
||||
): void {
|
||||
if (!st) return;
|
||||
st.ring.push({
|
||||
t: Math.round(now),
|
||||
v,
|
||||
g: Math.round(g * 100) / 100,
|
||||
e: Math.round(e * 100) / 100,
|
||||
b,
|
||||
r: Math.round(r),
|
||||
s: Math.round(now - st.lastAt),
|
||||
rs: st.remoteSnaps - st.lastRs,
|
||||
});
|
||||
st.lastAt = now;
|
||||
st.lastRs = st.remoteSnaps;
|
||||
if (st.ring.length > 4000) st.ring.splice(0, 1000);
|
||||
}
|
||||
|
||||
interface RenderPos {
|
||||
x: number;
|
||||
|
|
@ -254,6 +313,20 @@ function drawDrop(ctx: CanvasRenderingContext2D, x: number, y: number, kind: str
|
|||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillText(POWERUP_GLYPH[kind] ?? "?", cxp, cyp + 1);
|
||||
// Name tag: small text on a semi-opaque plate pinned to the cell bottom
|
||||
// (no bob, so it stays readable while the drop itself animates).
|
||||
const name = POWERUP_NAME[kind];
|
||||
if (name) {
|
||||
const ly = y * CELL + CELL - 6;
|
||||
ctx.font = `700 8px ui-monospace, monospace`;
|
||||
const w = Math.min(CELL - 2, ctx.measureText(name).width + 6);
|
||||
ctx.fillStyle = "rgba(2, 6, 23, 0.68)";
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(cxp - w / 2, ly - 5, w, 10, 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = POWERUP_COLORS[kind] ?? "#e2e8f0";
|
||||
ctx.fillText(name, cxp, ly + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
function drawBomb(ctx: CanvasRenderingContext2D, x: number, y: number, fuseTicks: number, t: number) {
|
||||
|
|
@ -382,6 +455,47 @@ export function BomperatorGame({
|
|||
const lastAckedDirRef = useRef<Dir | null>(null);
|
||||
const lastVersionSeenRef = useRef(-1);
|
||||
const rttAvgRef = useRef(100);
|
||||
const dbgRef = useRef<{ ring: DbgRow[]; lastAt: number; remoteSnaps: number; lastRs: number } | null>(
|
||||
null,
|
||||
);
|
||||
if (BOMP_DEBUG && dbgRef.current === null) {
|
||||
const st: { ring: DbgRow[]; lastAt: number; remoteSnaps: number; lastRs: number } = {
|
||||
ring: [],
|
||||
lastAt: 0,
|
||||
remoteSnaps: 0,
|
||||
lastRs: 0,
|
||||
};
|
||||
dbgRef.current = st;
|
||||
const pct = (xs: number[], p: number) => {
|
||||
if (xs.length === 0) return 0;
|
||||
const s = [...xs].sort((a, b) => a - b);
|
||||
return Math.round(s[Math.min(s.length - 1, Math.floor(p * s.length))] * 100) / 100;
|
||||
};
|
||||
(window as unknown as Record<string, unknown>).__bompDbg = {
|
||||
rows: st.ring,
|
||||
table: () => console.table(st.ring.slice(-250)),
|
||||
dump: () => JSON.stringify(st.ring),
|
||||
stats: () => {
|
||||
const r = st.ring;
|
||||
const out = {
|
||||
n: r.length,
|
||||
trims: r.filter((x) => x.b === 1).length,
|
||||
eases: r.filter((x) => x.b === 2).length,
|
||||
resets: r.filter((x) => x.b === 3).length,
|
||||
remoteSnaps: st.remoteSnaps,
|
||||
gapP50: pct(r.map((x) => x.g), 0.5),
|
||||
gapP95: pct(r.map((x) => x.g), 0.95),
|
||||
gapMax: r.length ? Math.max(...r.map((x) => x.g)) : 0,
|
||||
snapDtP50: pct(r.map((x) => x.s), 0.5),
|
||||
snapDtP95: pct(r.map((x) => x.s), 0.95),
|
||||
rttMin: r.length ? Math.min(...r.map((x) => x.r)) : 0,
|
||||
rttMax: r.length ? Math.max(...r.map((x) => x.r)) : 0,
|
||||
};
|
||||
console.table(out);
|
||||
return out;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
matchRef.current = match;
|
||||
|
|
@ -445,6 +559,12 @@ export function BomperatorGame({
|
|||
[transport],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!BOMP_DEBUG) return undefined;
|
||||
const off = transport.onKindChange?.((k) => console.info(`[bompDbg] transport kind -> ${k}`));
|
||||
return () => off?.();
|
||||
}, [transport]);
|
||||
|
||||
/**
|
||||
* Fire a direction change immediately with a monotonic seq. The server drops
|
||||
* anything at or below the last applied seq, so there is no reason to queue
|
||||
|
|
@ -645,6 +765,7 @@ export function BomperatorGame({
|
|||
predRef.current = me.alive ? { x: me.x, y: me.y } : null;
|
||||
facingRef.current = me.dir;
|
||||
lastAckedDirRef.current = null;
|
||||
if (BOMP_DEBUG) dbgRecord(dbgRef.current, now, view.version, -1, 0, 3, rttAvgRef.current);
|
||||
} else {
|
||||
// Drop acknowledged inputs; the newest one is the dir the server is
|
||||
// now applying. Note a release (null) counts as a real direction.
|
||||
|
|
@ -721,6 +842,17 @@ export function BomperatorGame({
|
|||
pred.x += (est.x - pred.x) * k;
|
||||
pred.y += (est.y - pred.y) * k;
|
||||
}
|
||||
if (BOMP_DEBUG) {
|
||||
dbgRecord(
|
||||
dbgRef.current,
|
||||
now,
|
||||
view.version,
|
||||
gap,
|
||||
envelope,
|
||||
gap > 2.5 ? 2 : gap > envelope ? 1 : 0,
|
||||
rttAvgRef.current,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
lastAckRef.current = ack;
|
||||
|
|
@ -768,6 +900,7 @@ export function BomperatorGame({
|
|||
if (Math.hypot(target.x - current.x, target.y - current.y) > 1.5) {
|
||||
current.x = target.x;
|
||||
current.y = target.y;
|
||||
if (BOMP_DEBUG && dbgRef.current) dbgRef.current.remoteSnaps += 1;
|
||||
} else {
|
||||
current.x += (target.x - current.x) * ease;
|
||||
current.y += (target.y - current.y) * ease;
|
||||
|
|
|
|||
|
|
@ -89,9 +89,9 @@ export function BomperatorHud({
|
|||
))}
|
||||
</div>
|
||||
|
||||
{/* Own loadout pips */}
|
||||
{/* Own loadout pips, centered over the play area */}
|
||||
{me && me.alive && (
|
||||
<div className="flex flex-wrap items-center gap-1.5 text-xs">
|
||||
<div className="flex flex-wrap items-center justify-center gap-1.5 text-xs">
|
||||
<Pip label="Charges" value={String(me.bombsMax)} />
|
||||
<Pip label="Range" value={String(me.range)} accent={me.range > 1} />
|
||||
<Pip label="Speed" value={speedBoost > 0 ? `+${speedBoost}` : "base"} accent={speedBoost > 0} />
|
||||
|
|
|
|||
Loading…
Reference in a new issue