Files

61 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Check the parametric animation models in re/notes/anim_battle.md against the Mesen captures.
usage: anim_validate.py [CAPROOT] (default re/runs/anim)
bomb: W1 circle centre (184,64), r = 16 + 8*floor((rel-146)/3) on the frames the table is complete;
fixed colour R = 1 + floor((rel-145)/3) (cap 21), G = min(5, ...)
ready: READY letter x positions at rel 1600 (KO capture: rel 1528 = start of state 03)"""
import math, os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from anim_analyze import load, ppu_states # noqa: E402
CH = 3 + 224 * 4
HFR = 8 * CH
root = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(__file__), '..', 'runs', 'anim')
def w1_lines(hd, f):
for ch in range(8):
c = hd[f][ch * CH:(ch + 1) * CH]
if c[0] and c[1] == 0x26:
return [(c[3 + 4 * l], c[4 + 4 * l]) for l in range(224)]
return None
def circle(cx, cy, r):
out = []
for y in range(224):
dy = y - cy
if abs(dy) >= r:
out.append((255, 0))
else:
hw = math.sqrt(r * r - dy * dy)
out.append((max(0, round(cx - hw)), min(255, round(cx + hw))))
return out
frames, hd, ev, st = load(f'{root}/p03')
ppu = ppu_states(ev, len(frames))
ok = tot = 0
worst = 0
for f in range(146, 168):
r = 16 + 8 * ((f - 146) // 3)
got = w1_lines(hd, f)
if got is None:
continue
pred = circle(184, 64, r)
rows = [(a, b) for a, b in zip(got, pred) if a[0] <= a[1] or b[0] <= b[1]]
err = max(max(abs(a[0] - b[0]), abs(a[1] - b[1])) for a, b in rows)
tot += 1
ok += err <= 2
worst = max(worst, err) if err <= 2 else worst
if err > 2:
print(f'bomb f{f}: r{r} max line error {err} (table being rebuilt this frame)')
print(f'bomb circle: {ok}/{tot} frames within 2 px (worst passing {worst})')
bad = 0
for f in range(146, 210):
fx = ppu[f][1]
pr = min(21, 1 + (f - 145) // 3)
if fx[0] != pr:
bad += 1
print(f'bomb tint R ramp: {64 - bad}/64 frames match R = min(21, 1 + (rel-145)//3)')