#!/usr/bin/env python3 """ run_demo.py -- one-command launcher: pick a scene, run the virtual board with the live window, and start FLYK in the custom DOSBox-X against it. python run_demo.py # SHARKS.SCN (default) python run_demo.py SDEMO # any HPDAVE scene by basename python run_demo.py TMPRIGS --prefix rig1 python run_demo.py SDEMO --dir HPDAVE --exe flyk Writes C:\\RUNSCN.BAT in the staged tree (see stage_assets.py), spawns dosbox-x-vrlink with VRLINK=1 after the board socket is up, then runs the vrrun board loop inline (window opens on first draw_scene). Ctrl-C / close window to stop; the DOSBox process is killed on exit. """ import os, sys, subprocess, threading, atexit HERE = os.path.dirname(os.path.abspath(__file__)) STAGE = r"c:\temp\flykc" DOSBOX = r"G:\DOSBox-X\dosbox-x-vrlink.exe" CONF = os.path.join(HERE, "flyk_vr.conf") def main(): args = [a for a in sys.argv[1:] if not a.startswith("--")] scene = (args[0] if args else "SHARKS").upper() if not scene.endswith(".SCN"): scene += ".SCN" proddir = "HPDAVE" exe = "flyk" prefix = "live" for i, a in enumerate(sys.argv): if a == "--dir" and i + 1 < len(sys.argv): proddir = sys.argv[i + 1] if a == "--exe" and i + 1 < len(sys.argv): exe = sys.argv[i + 1] if a == "--prefix" and i + 1 < len(sys.argv): prefix = sys.argv[i + 1] scn_path = os.path.join(STAGE, proddir, scene) if not os.path.exists(scn_path): raise SystemExit(f"{scn_path} not staged -- run stage_assets.py first") # joystick flight: rewrite the scene's TRACKER line to the game-port path # (DOSBox maps the physical stick; FLYK's KEYBOARD tracker is inert under # DOSBox, THRUSTMASTER is what moved the camera -- verified live on BLADE). # Disable with --no-joystick. import re s = open(scn_path, encoding='latin1').read() if "--no-joystick" not in sys.argv: s2 = re.sub(r'(?m)^\s*TRACKER\s+\S+\s+[\d.]+\s+[\d.]+', 'TRACKER THRUSTMASTER 4.0 0.3', s) if s2 != s: open(scn_path, 'w', encoding='latin1').write(s2) print("scene TRACKER -> THRUSTMASTER (joystick flight)") s = s2 # RETRACE n = the scene's frame-rate divider (60/n Hz on the real board) mr = re.search(r'(?m)^\s*RETRACE\s+(\d+)', s) if mr: os.environ['VRVIEW_FPS'] = str(max(1, 60 // max(1, int(mr.group(1))))) print(f"RETRACE {mr.group(1)} -> pacing {os.environ['VRVIEW_FPS']} Hz") # ambient SPECIALFX sim is opt-in (--sfx): most scenes' defs are event-only if "--sfx" in sys.argv: os.environ['VRVIEW_SFX'] = '1' print("ambient SPECIALFX sim enabled") with open(os.path.join(STAGE, "RUNSCN.BAT"), "w") as fp: fp.write(f"cd \\{proddir}\r\ncall SETSVGA.BAT\r\n{exe} .\\{scene}\r\n") print(f"scene: {proddir}\\{scene} (capture prefix: {prefix})") proc = [] def launch_dosbox(): env = dict(os.environ, VRLINK='1') p = subprocess.Popen([DOSBOX, "-conf", CONF], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) proc.append(p) print(f"dosbox launched (pid {p.pid})") threading.Timer(2.0, launch_dosbox).start() atexit.register(lambda: [p.kill() for p in proc if p.poll() is None]) # --soft = software rasterizer (reference); default is the moderngl backend sys.argv = ["vrrun.py", prefix, "--view"] + ( ["--soft"] if "--soft" in sys.argv else []) import vrrun try: vrrun.main() except KeyboardInterrupt: pass if __name__ == "__main__": main()