3D 리플레이 1단계: .vrf 변환기(tools/replay-extract) · 사이트 3D 재생기 · 대화 동기화
- tools/replay-extract: ValorantReplayParser(MIT, 고정 커밋) → gvr-replay JSON v1 (선수 이동 10Hz · 라운드 · 킬 · 사격 · 스킬/설치물 · 녹화 시작 시각) - 사이트: 경기 화면 '3D 리플레이' 칸 (three.js 지연 로드). 미니맵 바닥 + 실제 높이, 회전 · 확대 · 선수 선택 · 따라가기 · 킬피드 · 자막 · 말하는 사람 표시 - 동기화: 같은 킬의 경기 기록 시각과 리플레이 시각 차이 중앙값 (못 맞추면 라운드 시작) 현장 모드 시계에 묶어 재생 · 멈춤 · 이동 · 배속이 대화와 같이 움직임 - 목 서버 데모(GVR_MOCK_REPLAY), 동기화 테스트 4개 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import type {
|
||||
} from '@gvr/shared';
|
||||
|
||||
import { reportClient } from './report';
|
||||
import type { ReplayFile } from './replay';
|
||||
|
||||
/** 전역 신호: 401 → 로그인 화면, 503 device_offline → 잠금 화면 */
|
||||
type Signal = 'unauthorized' | 'not_member' | 'device_offline';
|
||||
@@ -135,6 +136,8 @@ export const api = {
|
||||
),
|
||||
matches: (o: { game?: GameType; limit?: number; before?: number } = {}) => request<MatchSummary[]>(`/api/matches${qs(o)}`),
|
||||
match: (id: string) => request<MatchDetail>(`/api/matches/${encodeURIComponent(id)}`),
|
||||
/** 발로란트 리플레이(.vrf)에서 뽑은 재생 데이터. 없으면 404 replay_not_found */
|
||||
replay: (id: string) => request<ReplayFile>(`/api/matches/${encodeURIComponent(id)}/replay`),
|
||||
culpritMatches: (o: { game?: GameType; limit?: number } = {}) => request<CulpritMatchItem[]>(`/api/culprit/matches${qs(o)}`),
|
||||
culpritMatch: (id: string) => request<CulpritMatchInfo>(`/api/culprit/matches/${encodeURIComponent(id)}`),
|
||||
culpritBudget: () => request<CulpritBudget>('/api/culprit/budget'),
|
||||
|
||||
141
site/web/src/lib/replay.ts
Normal file
141
site/web/src/lib/replay.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
import type { KillData, MatchDetail } from '@gvr/shared';
|
||||
|
||||
/** tools/replay-extract (gvr-replay v1) 출력. t 는 리플레이 시작부터 ms, 좌표는 게임 월드 단위 */
|
||||
export interface ReplayFile {
|
||||
format: 'gvr-replay';
|
||||
v: 1;
|
||||
matchId: string | null;
|
||||
map: string | null;
|
||||
build: string | null;
|
||||
/** 리플레이 녹화 시작 (서버 시계, 유닉스 ms) */
|
||||
recordedAt: number;
|
||||
durationMs: number;
|
||||
sampleMs: number;
|
||||
players: { puuid: string | null; character: string | null; track: { t: number[]; x: number[]; y: number[]; z: number[]; yaw: number[]; pitch: number[] } }[];
|
||||
rounds: { num: number; buy: number; combat: number; end: number }[];
|
||||
phases: [number, number][];
|
||||
/** [t, killer, victim] */
|
||||
kills: [number, number, number][];
|
||||
/** [t, player, x, y, z, yaw, pitch] */
|
||||
shots: [number, number, number, number, number, number, number][];
|
||||
/** [t0, t1, kind, x, y, z, owner] */
|
||||
objects: [number, number, number, number, number, number, number][];
|
||||
objectKinds: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 리플레이 시간(t) ↔ 기록 시각(ts, 게임 PC 시계) 맞추기.
|
||||
* 기본: ts = recordedAt + t + offset. offset 은 같은 킬(죽인 사람 · 죽은 사람이 같은 것)이
|
||||
* 경기 기록(match-details → 킬 이벤트 ts)과 리플레이에서 각각 언제인지 비교한 차이의 중앙값.
|
||||
* 킬을 못 맞추면 라운드 교전 시작으로 맞춘다 (정확도 낮음).
|
||||
*/
|
||||
export interface ReplaySync {
|
||||
offset: number;
|
||||
/** 맞춘 킬 수 */
|
||||
matched: number;
|
||||
/** 킬별 차이가 중앙값에서 벗어난 정도 (절대값 최대, ms). 이게 작아야 동기화가 정확하다 */
|
||||
spreadMs: number | null;
|
||||
/** 킬별 차이 (ms, 중앙값 기준) */
|
||||
residuals: number[];
|
||||
}
|
||||
|
||||
export function computeSync(m: MatchDetail, r: ReplayFile): ReplaySync {
|
||||
const kills = m.events.filter((e) => e.type === 'kill');
|
||||
const used = new Set<string>();
|
||||
const diffs: number[] = [];
|
||||
for (const [t, ki, vi] of r.kills) {
|
||||
const killer = r.players[ki]?.puuid;
|
||||
const victim = r.players[vi]?.puuid;
|
||||
if (!victim) continue;
|
||||
const at = r.recordedAt + t;
|
||||
let best: { id: string; d: number } | null = null;
|
||||
for (const e of kills) {
|
||||
if (used.has(e.id)) continue;
|
||||
const d = e.data as KillData;
|
||||
if (d.victim?.puuid !== victim) continue;
|
||||
if (killer && d.killer?.puuid && d.killer.puuid !== killer) continue;
|
||||
const diff = e.ts - at;
|
||||
// 1분 넘게 차이 나면 다른 라운드의 킬
|
||||
if (Math.abs(diff - (diffs.length ? median(diffs) : diff)) > 60000) continue;
|
||||
if (!best || Math.abs(diff) < Math.abs(best.d)) best = { id: e.id, d: diff };
|
||||
}
|
||||
if (best) {
|
||||
used.add(best.id);
|
||||
diffs.push(best.d);
|
||||
}
|
||||
}
|
||||
if (diffs.length >= 3) {
|
||||
const off = median(diffs);
|
||||
const residuals = diffs.map((d) => d - off);
|
||||
return { offset: off, matched: diffs.length, spreadMs: Math.max(...residuals.map(Math.abs)), residuals };
|
||||
}
|
||||
// 킬로 못 맞추면 라운드 교전 시작으로 맞춘다. 앱은 라운드 시작을 "교전 시작 - 30초" 로 저장한다 (valorant.ts BUY_MS)
|
||||
const rd: number[] = [];
|
||||
for (const mr of m.rounds ?? []) {
|
||||
const rr = r.rounds.find((x) => x.num === mr.num);
|
||||
if (rr && rr.combat >= 0) rd.push(mr.startedAt + 30000 - (r.recordedAt + rr.combat));
|
||||
}
|
||||
if (rd.length) return { offset: median(rd), matched: 0, spreadMs: null, residuals: [] };
|
||||
return { offset: 0, matched: 0, spreadMs: null, residuals: [] };
|
||||
}
|
||||
|
||||
function median(a: number[]): number {
|
||||
const s = [...a].sort((x, y) => x - y);
|
||||
const n = s.length;
|
||||
return n % 2 ? s[(n - 1) / 2] : (s[n / 2 - 1] + s[n / 2]) / 2;
|
||||
}
|
||||
|
||||
/** 이동 기록에서 t 시점 위치 (앞뒤 표본 사이 직선 보간). 표본이 sampleMs*5 넘게 끊겼으면 그 사이는 없음 */
|
||||
export function samplePlayer(tr: ReplayFile['players'][number]['track'], t: number, gapMs: number) {
|
||||
const T = tr.t;
|
||||
if (!T.length || t < T[0] - gapMs) return null;
|
||||
let lo = 0;
|
||||
let hi = T.length - 1;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi + 1) >> 1;
|
||||
if (T[mid] <= t) lo = mid;
|
||||
else hi = mid - 1;
|
||||
}
|
||||
const i = lo;
|
||||
const j = Math.min(i + 1, T.length - 1);
|
||||
if (t - T[i] > gapMs) return { x: tr.x[i], y: tr.y[i], z: tr.z[i], yaw: tr.yaw[i], pitch: tr.pitch[i], stale: true };
|
||||
const span = T[j] - T[i];
|
||||
const k = j === i || span > gapMs || span <= 0 ? 0 : Math.min(1, Math.max(0, (t - T[i]) / span));
|
||||
let dy = tr.yaw[j] - tr.yaw[i];
|
||||
if (dy > 180) dy -= 360;
|
||||
if (dy < -180) dy += 360;
|
||||
return {
|
||||
x: tr.x[i] + (tr.x[j] - tr.x[i]) * k,
|
||||
y: tr.y[i] + (tr.y[j] - tr.y[i]) * k,
|
||||
z: tr.z[i] + (tr.z[j] - tr.z[i]) * k,
|
||||
yaw: tr.yaw[i] + dy * k,
|
||||
pitch: tr.pitch[i] + (tr.pitch[j] - tr.pitch[i]) * k,
|
||||
stale: false,
|
||||
};
|
||||
}
|
||||
|
||||
/** t 가 속한 라운드 (구매 단계 시작 기준) */
|
||||
export function roundAt(r: ReplayFile, t: number) {
|
||||
let cur = r.rounds[0] ?? null;
|
||||
for (const rd of r.rounds) if (rd.buy <= t) cur = rd;
|
||||
return cur;
|
||||
}
|
||||
|
||||
/** 이 라운드에서 t 전에 죽었는지 (다시 움직인 기록이 있으면 부활로 본다) */
|
||||
export function isDead(r: ReplayFile, player: number, t: number) {
|
||||
const rd = roundAt(r, t);
|
||||
if (!rd) return false;
|
||||
let death = -1;
|
||||
for (const [kt, , v] of r.kills) if (v === player && kt >= rd.buy && kt <= t) death = kt;
|
||||
if (death < 0) return false;
|
||||
const T = r.players[player]?.track.t ?? [];
|
||||
// 죽은 뒤 2초 넘어 움직인 표본이 t 전에 있으면 살아난 것
|
||||
let lo = 0;
|
||||
let hi = T.length;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi) >> 1;
|
||||
if (T[mid] <= death + 2000) lo = mid + 1;
|
||||
else hi = mid;
|
||||
}
|
||||
return !(lo < T.length && T[lo] <= t);
|
||||
}
|
||||
Reference in New Issue
Block a user