From 75856b60dfc98a68676599809ecc4121b577ff87 Mon Sep 17 00:00:00 2001 From: "prompt.ac/@jeffrey" Date: Wed, 5 Aug 2026 14:28:31 -0700 Subject: [PATCH] Keep both OSKIEWAR fighters on camera --- xbox/live/hello.js | 109 +++++++++++++++++++++++++++++++++ xbox/live/tests/hello.test.mjs | 41 ++++++++++++- 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/xbox/live/hello.js b/xbox/live/hello.js index 006a3b3939..84468d2863 100644 --- a/xbox/live/hello.js +++ b/xbox/live/hello.js @@ -2100,6 +2100,114 @@ function runnerBounds(player, t) { return { left, right, top, bottom }; } +function runnerScreenBounds(player, t) { + const world = player.replayGeometry || player.frozenGeometry || + runnerWorldGeometry(player, t); + const geometry = projectRunnerWorldGeometry(world); + let left = geometry.head.x - geometry.head.radius; + let right = geometry.head.x + geometry.head.radius; + let top = geometry.head.y - geometry.head.radius; + let bottom = geometry.head.y + geometry.head.radius; + for (const segment of geometry.segments) { + const radius = segment.width / 2; + left = Math.min(left, segment.x1 - radius, segment.x2 - radius); + right = Math.max(right, segment.x1 + radius, segment.x2 + radius); + top = Math.min(top, segment.y1 - radius, segment.y2 - radius); + bottom = Math.max(bottom, segment.y1 + radius, segment.y2 + radius); + } + return { left, right, top, bottom }; +} + +// Final render invariant: both complete animated fighter geometries must fit +// inside the action-safe viewport. Camera modes may orbit or focus, but this +// aspect-aware correction recenters their shared frame and moves the dolly +// back far enough for landscape, portrait, live, and replay projection alike. +function containFighters(t) { + const worlds = players.map((player) => player.replayGeometry || + player.frozenGeometry || runnerWorldGeometry(player, t)); + if (!worlds.length) return; + const points = []; + for (const world of worlds) { + const { head } = world; + points.push( + { x: head.x - head.radius, y: head.y, z: head.z }, + { x: head.x + head.radius, y: head.y, z: head.z }, + { x: head.x, y: head.y - head.radius, z: head.z }, + { x: head.x, y: head.y + head.radius, z: head.z }, + ); + for (const segment of world.segments) { + const radius = segment.width / 2; + for (const endpoint of [ + { x: segment.x1, y: segment.y1, z: segment.z1 }, + { x: segment.x2, y: segment.y2, z: segment.z2 }, + ]) { + points.push( + { x: endpoint.x - radius, y: endpoint.y, z: endpoint.z }, + { x: endpoint.x + radius, y: endpoint.y, z: endpoint.z }, + { x: endpoint.x, y: endpoint.y - radius, z: endpoint.z }, + { x: endpoint.x, y: endpoint.y + radius, z: endpoint.z }, + ); + } + } + } + const minX = Math.min(...points.map((point) => point.x)); + const maxX = Math.max(...points.map((point) => point.x)); + const minY = Math.min(...points.map((point) => point.y)); + const maxY = Math.max(...points.map((point) => point.y)); + const minZ = Math.min(...points.map((point) => point.z)); + const maxZ = Math.max(...points.map((point) => point.z)); + const target = { x: (minX + maxX) / 2, y: (minY + maxY) / 2, + z: (minZ + maxZ) / 2 }; + for (const axis of ["x", "y", "z"]) + cameraDoll.position[axis] += target[axis] - cameraDoll.target[axis]; + cameraDoll.target = target; + + const marginX = compactLayout() ? 34 : 64; + const marginY = 26; + const safeWidth = Math.max(1, stageRight - stageLeft - marginX * 2); + const safeHeight = Math.max(1, stageBottom - stageTop - marginY * 2); + const requiredWidth = Math.max( + (maxX - minX) * (stageRight - stageLeft) / safeWidth, + (maxY - minY) * cameraAspect * + (stageBottom - stageTop) / safeHeight, + compactLayout() ? 720 : 900, + ); + if (requiredWidth > cameraDoll.width) { + const amount = requiredWidth / Math.max(1, cameraDoll.width) * 1.04; + for (const axis of ["x", "y", "z"]) + cameraDoll.position[axis] = target[axis] + + (cameraDoll.position[axis] - target[axis]) * amount; + cameraDoll.width *= amount; + } + + // Perspective and z-depth can make the world-space estimate asymmetric. + // Iteratively measure the actual projection and expand along the existing + // camera ray until every point satisfies the screen-space safe rectangle. + const centerX = viewCenterX(); + const centerY = (stageTop + stageBottom) / 2; + for (let pass = 0; pass < 4; pass++) { + cameraDoll.dirty = true; + cameraDoll.prepare(); + const projected = points.map((point) => cameraDoll.project(point)); + const left = Math.min(...projected.map((point) => point.x)); + const right = Math.max(...projected.map((point) => point.x)); + const top = Math.min(...projected.map((point) => point.y)); + const bottom = Math.max(...projected.map((point) => point.y)); + const factor = Math.max(1, + (centerX - left) / (safeWidth / 2), + (right - centerX) / (safeWidth / 2), + (centerY - top) / (safeHeight / 2), + (bottom - centerY) / (safeHeight / 2)); + if (factor <= 1.001) break; + const amount = factor * 1.025; + for (const axis of ["x", "y", "z"]) + cameraDoll.position[axis] = target[axis] + + (cameraDoll.position[axis] - target[axis]) * amount; + cameraDoll.width *= amount; + } + cameraDoll.dirty = true; +} + function resolveRunnerBounds(player, t) { // Walls use a stable fighting-game pushbox. Animated hands and feet remain // the actual hit geometry, but cannot shove the root back and forth at an @@ -2794,6 +2902,7 @@ function paint() { drawSelectionScreen(t, titleInk, titlePanel); return; } + containFighters(t); cameraDoll.prepare(); const worldInk = mixColor([72, 90, 125], [45, 63, 92], visualTheme.light); const edgeWidth = Math.max(2, wallThickness * cameraScale() * .14); diff --git a/xbox/live/tests/hello.test.mjs b/xbox/live/tests/hello.test.mjs index 3c264d03ae..f6afbd3630 100644 --- a/xbox/live/tests/hello.test.mjs +++ b/xbox/live/tests/hello.test.mjs @@ -21,7 +21,7 @@ function createFight(startImmediately = true, enterGame = true, }; const fight = new Function( "runtime", "gamepad", "capabilities", "telemetry", "gameSignal", "saveReplay", "publishLive", "drum", "wipe", "box", "line", "triangle", "write", "systemWrite", "gameView", - `${source}\nreturn { boot, sim, paint, controlLocale, players, ball, balls, bullets, grenades, gunPickups, grenadePickups, runnerWorldGeometry, runnerDistanceToPoint, disableBall: () => { ballEnabled = false; for (const item of balls) item.active = false; }, enableBall: (index = 0) => { ballEnabled = true; const item = balls[index]; item.active = true; item.serveAt = 0; item.safeUntil = 0; item.safePlayers = 0; }, setWind: (value) => { windAcceleration = value; }, windState: () => ({ direction: windDirection, mph: windMph }), nextRound: () => resetRound(runtime().monotonicUs, false), knockOut: () => killPlayer(players[1], 0, runtime().monotonicUs, "KO"), wackBall: () => { players[0].attackKind = "KICK"; returnBall(ball, players[0], runtime().monotonicUs, false); }, shieldBall: () => returnBall(ball, players[0], runtime().monotonicUs, true), crossWackBall: (contact = 1) => crossWackBall(ball, players.map((player) => ({ player, contact })), runtime().monotonicUs), enterGame: () => enterShellMode("GAME", runtime().monotonicUs), shellState: () => ({ mode: shellMode, choice: shellChoice, lab: labPlayers.map((player) => ({ ...player })) }), startFight: () => { shellMode = "GAME"; selecting = false; startReplay(runtime().monotonicUs); resetRound(runtime().monotonicUs, true); }, selectionState: () => ({ selecting, ready: selectionReady.slice() }), cameraState: () => ({ cameraWidth, cameraCenter, cameraCenterY, cameraAspect, stageRight, viewHeight }), roundState: () => ({ roundResult, roundElapsedUs, matchOver }), viewerState: () => ({ active: Boolean(roundViewer), mode: roundViewerMode, status: roundViewerStatus, name: matchName }), instantReplayState: () => instantReplay ? { active: true, paused: instantReplay.paused, cursor: instantReplay.cursor, frames: instantReplay.frames.length } : { active: false }, replayFrameCount: () => roundReplayFrames.length };` + `${source}\nreturn { boot, sim, paint, controlLocale, players, ball, balls, bullets, grenades, gunPickups, grenadePickups, runnerWorldGeometry, runnerDistanceToPoint, disableBall: () => { ballEnabled = false; for (const item of balls) item.active = false; }, enableBall: (index = 0) => { ballEnabled = true; const item = balls[index]; item.active = true; item.serveAt = 0; item.safeUntil = 0; item.safePlayers = 0; }, setWind: (value) => { windAcceleration = value; }, windState: () => ({ direction: windDirection, mph: windMph }), nextRound: () => resetRound(runtime().monotonicUs, false), knockOut: () => killPlayer(players[1], 0, runtime().monotonicUs, "KO"), wackBall: () => { players[0].attackKind = "KICK"; returnBall(ball, players[0], runtime().monotonicUs, false); }, shieldBall: () => returnBall(ball, players[0], runtime().monotonicUs, true), crossWackBall: (contact = 1) => crossWackBall(ball, players.map((player) => ({ player, contact })), runtime().monotonicUs), enterGame: () => enterShellMode("GAME", runtime().monotonicUs), shellState: () => ({ mode: shellMode, choice: shellChoice, lab: labPlayers.map((player) => ({ ...player })) }), startFight: () => { shellMode = "GAME"; selecting = false; startReplay(runtime().monotonicUs); resetRound(runtime().monotonicUs, true); }, selectionState: () => ({ selecting, ready: selectionReady.slice() }), cameraState: () => ({ cameraWidth, cameraCenter, cameraCenterY, cameraAspect, stageRight, viewHeight }), screenBounds: () => players.map((player) => runnerScreenBounds(player, runtime().monotonicUs / 1e6)), actionSafeRect: () => ({ left: compactLayout() ? 34 : 64, right: stageRight - (compactLayout() ? 34 : 64), top: stageTop + 26, bottom: stageBottom - 26 }), roundState: () => ({ roundResult, roundElapsedUs, matchOver }), viewerState: () => ({ active: Boolean(roundViewer), mode: roundViewerMode, status: roundViewerStatus, name: matchName }), instantReplayState: () => instantReplay ? { active: true, paused: instantReplay.paused, cursor: instantReplay.cursor, frames: instantReplay.frames.length } : { active: false }, replayFrameCount: () => roundReplayFrames.length };` )( () => ({ monotonicUs: now, unixMs: 1785870000000 + Math.floor(now / 1000) }), (index = 0) => ({ ...pads[index], down: pads[index].down.slice() }), @@ -81,6 +81,45 @@ test("web camera follows landscape, 16:9, and portrait viewports", () => { } }); +test("camera contains both complete fighters at every supported aspect", () => { + for (const viewport of [ + { width: 2560, height: 1080 }, + { width: 1920, height: 1080 }, + { width: 608, height: 1080 }, + ]) { + const { fight, tick } = createFight(false, false, "web", null, viewport); + const assertContained = () => { + fight.paint(); + const safe = fight.actionSafeRect(); + for (const bounds of fight.screenBounds()) { + const label = `${viewport.width}x${viewport.height}`; + assert.ok(bounds.left >= safe.left - .5, + `${label}: ${bounds.left} crossed left edge ${safe.left}`); + assert.ok(bounds.right <= safe.right + .5, + `${label}: ${bounds.right} crossed right edge ${safe.right}`); + assert.ok(bounds.top >= safe.top - .5, + `${label}: ${bounds.top} crossed top edge ${safe.top}`); + assert.ok(bounds.bottom <= safe.bottom + .5, + `${label}: ${bounds.bottom} crossed bottom edge ${safe.bottom}`); + } + }; + + fight.startFight(); + fight.players[0].x = 800; + fight.players[0].y = 11800; + fight.players[0].z = -560; + fight.players[1].x = 11200; + fight.players[1].y = 1300; + fight.players[1].z = 560; + tick(); + assertContained(); + + fight.knockOut(); + tick(); + assertContained(); + } +}); + test("spectator QR uses the raw Meet-style round URL", () => { assert.match(source, /https:\/\/oskiewar\.com\/" \+ matchName/); assert.doesNotMatch(source, /https:\/\/oskiewar\.com\/watch\//); -- knotmirror 0.0.1