Files
CydandClaude Fable 5 afc3fd839e Vendor dpl3-revive: the Division/DPL3 renderer, now ours
Bring the graphics-dev collaborator's dpl3-revive into the repo as first-class
project code (they've handed it off; it's ours now). This is the proven
Division renderer that our in-process rt_draw has been trying to be.

What's here:
- parser/  B2Z/V2Z/SVT/SCN/SPL/BGF/BMF/BSL decoders (pure Python).
- spec/    reverse-engineered format + the definitive VelociRender wire
           protocol (from the original DIVISION source, matches our live
           VPX node/action tables exactly).
- source-ref/  read-only copies of the original DIVISION C (BIZREAD.C,
           DPLTYPES.H, DPL.H) that define the formats.
- patha/   the "virtual VelociRender board": vrboard.py (24-action protocol
           server), vrview.py (numpy software rasterizer, the reference),
           vrview_gl.py (moderngl GPU backend, 832x512@60Hz), plus the
           run/replay/regress tooling and evidence renders. Drives FLYK/BLADE/
           Star Trek demos AND our btl4opt/rpl4opt game binaries.
- viewer/  WebGL archive generators (.py); prebuilt HTML/data regeneratable.
- samples/ small test models/textures.
- bt*.raw.bin  real BTL4OPT arena wire captures (kept for offline renderer
           testing/regression against OUR game).

.gitignore keeps the multi-hundred-MB demo capture dumps + debug logs +
regeneratable viewer bundles out of history (they stay on disk).

Phase 0 of the integration is validated: their board decodes our bt8 capture
with zero errors (3748 nodes, 507 instances, 4 mechs) and renders our arena
(terrain/dome/sky, correct Division DAC gamma). Plan + status in memory;
integration continues in emulator/RENDERER-COLLAB.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 22:06:25 -05:00

171 lines
6.5 KiB
Python

#!/usr/bin/env python3
"""
regress.py -- cross-scene regression: replay every scene capture through the
board + renderer, save a PNG each, report errors/timing. Also self-tests
sect_vector picking against the SHARKS scene.
python regress.py
"""
import os, sys, struct, time, traceback
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('SDL_VIDEODRIVER', 'dummy')
import numpy as np
from vrboard import VirtualBoard, Assembler, A, pack_vr
from decode_anim import find_framed_start
SCENES = [
('SHARKS', 'cap8.raw.bin', 2000),
('SDEMO', 'sdemo2.raw.bin', 800),
('KLNGVID', 'klng.raw.bin', 900),
('BLADE', 'blade2.raw.bin', 300),
('FXTEST', 'fxtest.raw.bin', 400),
]
def replay(path, upto):
data = open(path, 'rb').read()
board = VirtualBoard()
asm = Assembler(); asm.feed(data[find_framed_start(data):])
errs = 0
for m in asm:
try:
board.handle(m)
except Exception:
errs += 1
if board.frames >= upto:
break
return board, errs
def main():
from vrview import Renderer
r = Renderer()
ok = True
soft_frames = {}
for name, path, upto in SCENES:
if not os.path.exists(path):
print(f'{name:8} SKIP (no capture {path})')
continue
try:
board, herrs = replay(path, upto)
board._view = r
r.cache = type(r.cache)() # fresh SceneCache per scene
t0 = time.perf_counter()
r.frame = 0; r.skip = 1
r.draw(board)
ms = (time.perf_counter() - t0) * 1000
r.pygame.image.save(r.screen, f'regress_{name.lower()}.png')
soft_frames[name] = r.last_frame.copy()
print(f'{name:8} OK frame={ms:6.0f}ms instances={len(r.cache.instances):4} '
f'lights={len(r.cache.dirlights)}+amb handler-errors={herrs}')
except Exception:
ok = False
print(f'{name:8} FAIL')
traceback.print_exc()
# ---- GPU backend pass (moderngl, headless standalone context) ----------
# Same scenes through vrview_gl.GLRenderer: PNG each, sustained-frame
# timing (VBOs cached after frame 1), and a mean-abs-diff sanity check
# against the software reference at the same resolution.
try:
from vrview_gl import GLRenderer
g = GLRenderer() # native 832x512 target res
print(f'-- GL backend: {g.ctx.info["GL_RENDERER"]} {g.w}x{g.h} --')
for name, path, upto in SCENES:
if not os.path.exists(path):
continue
try:
board, _ = replay(path, upto)
board._view = g
g.cache = type(g.cache)()
g.frame = 0; g.skip = 1
g.draw(board) # frame 1: VBO/texture upload
t0 = time.perf_counter(); N = 20
for _i in range(N): # sustained: uniforms only
g.skip = 1
g.draw(board)
ms = (time.perf_counter() - t0) * 1000 / N
arr = g.last_frame
pgs = g.pygame.image.frombuffer(arr.tobytes(), (g.w, g.h), 'RGB')
g.pygame.image.save(pgs, f'regress_gl_{name.lower()}.png')
diff = ''
sf = soft_frames.get(name)
if sf is not None:
import pygame as _pg
small = _pg.transform.smoothscale(pgs, (sf.shape[1], sf.shape[0]))
sa = np.transpose(_pg.surfarray.array3d(small), (1, 0, 2))
diff = (f' diff-vs-soft='
f'{np.abs(sf.astype(int) - sa.astype(int)).mean():.1f}/255')
print(f'{name:8} GL frame={ms:6.1f}ms ({1000/max(ms,1e-3):5.0f}fps)'
f'{diff}')
except Exception:
ok = False
print(f'{name:8} GL FAIL')
traceback.print_exc()
except Exception as e:
print(f'-- GL backend unavailable ({e}) -- skipped --')
# sect_vector self-test on SHARKS: ray from the camera into the fish cluster
board, _ = replay('cap8.raw.bin', 2000)
board._view = r
r.cache = type(r.cache)()
reply = board.handle_sect_test = None
p = struct.pack('<4f6f', 0, 0, 0, 0, 0, 5, 5, -460, 380, -430)
rep = board.do_sect_vector(p)
act, = struct.unpack_from('<I', rep, 4),
h = struct.unpack_from('<I', rep, 8)[0]
print(f'sect_vector(camera -> fish cluster): instance handle {h:#x} '
f'({"HIT" if h else "miss"})')
p2 = struct.pack('<4f6f', 0, 0, 0, 0, 0, 5, 5, 0, 5000, 5)
h2 = struct.unpack_from('<I', board.do_sect_vector(p2), 8)[0]
print(f'sect_vector(straight up): {h2:#x} '
f'(hit = ocean surface overhead, correct underwater)')
# sect_pixel through the crosshair
p3 = struct.pack('<4f2f', 0, 0, 0, 0, 416.0, 256.0) # board-pixel center
h3 = struct.unpack_from('<I', board.do_sect_pixel(p3), 8)[0]
print(f'sect_pixel(center 416,256): {h3:#x}')
# statistics
rep = board.do_statistics(b'')
act, val = struct.unpack_from('<II', rep, 4)
print(f'statistics reply: action={act} value={val} '
f'({"OK" if act == 15 and val == 1 else "BAD"})')
# get_geom_vertices (0x18): read back the ocean quad and verify bytes
gh = next(iter(board.uploads))
req = struct.pack('<10I', gh, 0, 0, 0, 0, 0, 0, 0, 0, 0)
rep = board.do_get_geom_vertices(req)
got = bytearray()
off = 0
while off < len(rep):
lw, act2 = struct.unpack_from('<II', rep, off)
n = lw & 0xffff
got += rep[off + 8: off + 4 + n]
off += 4 + n
orig = bytes(board.uploads[gh][-1]['data'])
print(f'get_geom_vertices({gh:#x}): {len(got)}B read back, '
f'matches upload = {bytes(got[:len(orig)]) == orig}')
# readpixels self-test (needs a rendered frame)
board2, _ = replay('cap8.raw.bin', 100)
board2._view = r
r.cache = type(r.cache)()
r.frame = 0; r.skip = 1
r.draw(board2)
rep = board2.do_readpixels(struct.pack('<3I', 10, 10, 100))
board2._view = None
frags = 0; off = 0; total = 0
while off < len(rep):
lw, act3 = struct.unpack_from('<II', rep, off)
n = lw & 0xffff
frags += 1; total += n - 4
off += 4 + n
print(f'readpixels(10,10,100): {frags} fragment(s), {total}B pixel data '
f'({"OK" if total == 400 else "BAD"})')
print('regression', 'PASSED' if ok else 'FAILED')
if __name__ == '__main__':
main()