자동 시점 · 점수판 보완: 궁극기 점수는 공수 교대(선수 시작 자리가 40m 넘게 옮겨 간 라운드) 초기화를 사용으로 보지 않음 (한 명만 점수가 있어도) · 전략 보기 카메라 거리를 시야각 · 화면비 · 기울기로 계산해 모든 선수가 화면 안 (fitDistance) · 라운드가 끝난 뒤 점수판 팀 점수는 그 라운드까지 (최종 점수) · 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-08 22:54:41 +09:00
parent c36db3ef9a
commit a5a1c8406a
5 changed files with 133 additions and 16 deletions

View File

@@ -15,7 +15,7 @@ import CrosshairPanel from './CrosshairPanel';
import { buildAnimIndex, rigInput } from '../lib/replayAnim';
import { abilityLook, type AbilityLook } from '../lib/abilities';
import { loadVfxDb, vfxCoverage, VfxObject, type Place, type VfxDb } from '../lib/vfx';
import { buildDirector, shotIndexAt, SHOT_LABEL } from '../lib/director';
import { buildDirector, fitDistance, shotIndexAt, SHOT_LABEL } from '../lib/director';
import { boardIndex } from '../lib/scoreboard';
import ReplayScoreboard from './ReplayScoreboard';
@@ -50,6 +50,11 @@ type View = Exclude<CamMode, 'auto'>;
const CAM_LABEL: Record<CamMode, string> = { auto: '자동', top: '위에서', fp: '1인칭', free: '자유시점' };
/** 자동 · 위에서 볼 때 카메라가 따라가는 빠르기 (1초에 남은 거리의 이만큼) */
const AUTO_EASE = 2.2;
/** 자동 · 위에서: 보는 곳에서 카메라 쪽 방향 (위로 많이 · 앞으로 조금, 단위 벡터) */
const AUTO_DIR: [number, number, number] = (() => {
const l = Math.hypot(0.92, 0.42);
return [0, 0.92 / l, 0.42 / l];
})();
type MapState = { state: 'none' | 'loading' | 'ready' | 'error'; progress?: number };
/** 천장 자르기: 자동 · 끔 · 직접(가장 낮은 층에서 cm) */
@@ -1044,6 +1049,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
} else if (auto) {
// 전략 보기: 살아 있는 선수(없으면 모두)가 다 들어오게 내려다본다
let n = 0;
let aliveN = 0;
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity, ySum = 0;
for (const pass of [0, 1]) {
for (const v of views) {
@@ -1053,15 +1059,23 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
ySum += q.y;
n++;
}
if (pass === 0) aliveN = n;
if (n) break;
}
if (n) {
autoGoal.set((x0 + x1) / 2, ySum / n, (z0 + z1) / 2);
autoDist = Math.max(36, Math.min(125, Math.max(x1 - x0, (z1 - z0) * camera.aspect * 0.8) * 0.95 + 26));
// 시야각 · 화면비 · 기울기로 모두가 들어오는 거리 (선수 몸 · 이름표 높이만큼 위아래로 넉넉히)
const pts: [number, number, number][] = [];
for (const v of views) {
if (!v.group.visible || (aliveN > 0 && isDead(replay, v.idx, t))) continue;
const q = v.group.position;
pts.push([q.x, q.y, q.z], [q.x, q.y + 6, q.z]);
}
autoDist = Math.max(36, Math.min(400, fitDistance(pts, [autoGoal.x, autoGoal.y, autoGoal.z], AUTO_DIR, camera.fov, camera.aspect)));
}
const k = 1 - Math.exp(-dt * AUTO_EASE);
autoTarget.lerp(autoGoal, k);
tmp.set(autoTarget.x, autoTarget.y + autoDist * 0.92, autoTarget.z + autoDist * 0.42);
tmp.set(autoTarget.x + AUTO_DIR[0] * autoDist, autoTarget.y + AUTO_DIR[1] * autoDist, autoTarget.z + AUTO_DIR[2] * autoDist);
camera.position.lerp(tmp, k);
camera.lookAt(autoTarget);
} else controls.update();

View File

@@ -270,3 +270,32 @@ export const SHOT_LABEL: Record<ShotKind, string> = {
overview: '전략 보기',
post: '라운드 끝',
};
type V3 = [number, number, number];
const dot = (a: V3, b: V3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
const cross = (a: V3, b: V3): V3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
const unit = (a: V3): V3 => {
const l = Math.hypot(...a) || 1;
return [a[0] / l, a[1] / l, a[2] / l];
};
/**
* 전략 보기 카메라 거리: 카메라를 target + dir × 거리 에 두고 target 을 볼 때 모든 점이 화면(가장자리 margin 남김) 안에 들어오는 가장 짧은 거리.
* 카메라 공간에서 점의 깊이 = dot(q, f) + 거리 (f = -dir), 가로 · 세로 = dot(q, 오른쪽) · dot(q, 위). |가로| ≤ tan(가로 시야/2) × 깊이 를 거리로 푼다.
* dir 은 위쪽(y) 성분이 있어야 한다 (내려다보기)
*/
export function fitDistance(points: V3[], target: V3, dir: V3, fovDeg: number, aspect: number, margin = 0.85): number {
const d = unit(dir);
const f: V3 = [-d[0], -d[1], -d[2]];
const right = unit(cross(f, [0, 1, 0]));
const up = cross(right, f);
const tv = Math.tan(((fovDeg / 2) * Math.PI) / 180) * margin;
const th = tv * aspect;
let need = 0;
for (const p of points) {
const q: V3 = [p[0] - target[0], p[1] - target[1], p[2] - target[2]];
const z = dot(q, f);
need = Math.max(need, Math.abs(dot(q, right)) / th - z, Math.abs(dot(q, up)) / tv - z);
}
return need;
}

View File

@@ -1,4 +1,4 @@
import { indexAt, isDead, roundAt, type ReplayFile } from './replay';
import { indexAt, isDead, roundAt, samplePlayer, type ReplayFile } from './replay';
/**
* 리플레이 점수판 (게임에서 Tab 을 누른 화면): 크레딧 · 궁극기 점수 · 킬/데스/어시 · 전투 점수.
@@ -40,8 +40,27 @@ export function boardIndex(r: ReplayFile): BoardIndex {
return { rows, times, ultMax: ultCosts(r, rows), has: rows.some((a) => a.length > 0) };
}
/** 공수 교대로 시작한 라운드 번호 (rounds 의 순번): 선수들 시작 자리가 크게 바뀐 라운드 (같은 편이면 13m 안, 교대하면 90m 넘게, 13.08 어비스 실측) */
const SWAP_CM = 4000;
export function sideSwaps(r: ReplayFile): Set<number> {
const out = new Set<number>();
const spawn = (p: number, k: number) => samplePlayer(r.players[p].track, r.rounds[k].buy + 1500, r.sampleMs * 30);
for (let k = 1; k < r.rounds.length; k++) {
const d: number[] = [];
for (let p = 0; p < r.players.length; p++) {
const a = spawn(p, k - 1);
const b = spawn(p, k);
if (a && b) d.push(Math.hypot(a.x - b.x, a.y - b.y));
}
d.sort((x, y) => x - y);
if (d.length && d[Math.floor(d.length / 2)] > SWAP_CM) out.add(k);
}
return out;
}
/**
* 궁극기 점수: 궁을 쓴 순간(점수가 0 으로 떨어짐) 바로 앞 점수. 모두가 같은 때 0 이 되는 것(공수 교대 초기화)은 쓴 것이 아니다.
* 궁극기 점수: 궁을 쓴 순간(점수가 0 으로 떨어짐) 바로 앞 점수.
* 공수 교대 초기화(교대 직전 라운드가 끝난 뒤 ~ 교대 라운드 구매 시작 3초 뒤 사이에 0 이 된 것)는 쓴 것이 아니다. 한 명만 점수가 있어도 같다.
* 쓴 기록이 없으면 요원 표 값과 경기에서 모은 가장 큰 점수 중 큰 것
*/
export function ultCosts(r: ReplayFile, rows: number[][][]): number[] {
@@ -57,10 +76,13 @@ export function ultCosts(r: ReplayFile, rows: number[][][]): number[] {
last = v;
}
});
const resets = [...sideSwaps(r)].map((k) => {
const prev = r.rounds[k - 1];
return [prev.end >= 0 ? prev.end : prev.combat >= 0 ? prev.combat : prev.buy, r.rounds[k].buy + 3000];
});
const used: number[][] = rows.map(() => []);
for (const d of drops) {
const same = drops.filter((x) => Math.abs(x.t - d.t) <= 3000).length;
if (same >= Math.max(3, Math.ceil(r.players.length / 2))) continue; // 초기화
if (resets.some(([a, b]) => d.t >= a && d.t <= b)) continue; // 공수 교대 초기화
used[d.p].push(d.from);
}
return r.players.map((pl, p) => {
@@ -132,11 +154,13 @@ export function loadoutAt(r: ReplayFile, p: number, t: number): string | null {
return primary ?? side;
}
/** 라운드 · 팀 점수: t 가 속한 라운드 번호와 그 라운드 전까지 이긴 수 */
/** 라운드 · 팀 점수: t 가 속한 라운드 번호와 그 라운드 전까지 이긴 수 (라운드가 끝난 뒤면 그 라운드까지) */
export function teamScoreAt(r: ReplayFile, rounds: { num: number; score: { ally: number; enemy: number } }[] | undefined, t: number) {
const rd = roundAt(r, t);
const num = rd?.num ?? 1;
const before = rounds?.filter((x) => x.num < num).sort((a, b) => b.num - a.num)[0];
// 라운드가 끝났으면(승패 확정) 그 라운드까지 (마지막 라운드가 끝난 뒤 최종 점수)
const done = !!rd && rd.end >= 0 && t >= rd.end;
const before = rounds?.filter((x) => (done ? x.num <= num : x.num < num)).sort((a, b) => b.num - a.num)[0];
return { round: num, ally: before?.score.ally ?? 0, enemy: before?.score.enemy ?? 0 };
}