UK
games/alis / tools / run.php · commit 9c722cf
<?php// Headless runner of the ALIS port (debugging): boots a game, runs N VM frames, saves screenshots.//   bin/jumphp php games/alis tools/run.php data/robinson 300 [every] [keys]// keys: "frame:SDLKEY,frame:SDLKEY" (SDL key codes, held 4 frames), e.g. "100:13" = Return at frame 100.use App\Alis\Alis;use App\Alis\Machine;use App\Alis\SysVars;require __DIR__ . '/../vendor/autoload.php';// --audio (anywhere) = ALIS_AUDIO=1 (the env does not reach the Docker php of bin/jumphp)$audioArg = in_array('--audio', $argv, true);// --source: the source edition (the scripts compiled from <dir>/src/*.als, docs/language.md)$sourceArg = in_array('--source', $argv, true);// --hd: the HD edition's text capture (fn/hd.php): glyphs-NNNNN.json beside each saved frame$hdArg = in_array('--hd', $argv, true);// --hd-capture=<dir>: every bitmap the game draws, as a PNG in its palette (App\Alis\HdSprites, tools/hd/)foreach ($argv as $a) {    if (str_starts_with($a, '--hd-capture=')) {        \App\Alis\HdSprites::$capture = substr($a, 13);        \App\Alis\HdSprites::$on = true;        @mkdir(\App\Alis\HdSprites::$capture, 0777, true);    }}$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--hd-capture=')));// --hd-sprites: the sprite pack of the HD edition (<data>/hd/), how much of each frame it covers (hd-sprites.txt)$hdSpritesArg = in_array('--hd-sprites', $argv, true);$argv = array_values(array_filter($argv, fn ($a) => $a !== '--hd-sprites'));// --skip-intro: the "Skip intro" button pressed whenever it is offered (App\Alis\IntroSkip)$skip = in_array('--skip-intro', $argv, true) ? new \App\Alis\IntroSkip() : null;$argv = array_values(array_filter($argv, fn ($a) => $a !== '--skip-intro'));// --watch=0x184c: print that byte of the main script's variables (mb[0x184c]) when it changes$watch = null;foreach ($argv as $a) { if (str_starts_with($a, '--watch=')) $watch = intval(substr($a, 8), 0); }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--watch=')));// --hd3d: the HD edition's land (fn/hd3d.php): land-NNNNN.bmp beside each saved frame$hd3dArg = in_array('--hd3d', $argv, true);$hd3dCompare = in_array('--hd3d-compare', $argv, true);$panelArg = in_array('--panel', $argv, true);// --memcrc: a checksum of the whole VM memory and registers at each new picture, in var/<out>/memcrc.txt (compare runs)$memcrcArg = in_array('--memcrc', $argv, true);$argv = array_values(array_filter($argv, fn ($a) => $a !== '--memcrc'));$memcrc = [];// --compiled: the scripts compiled to PHP (App\Alis\Compiled\Compiler); --compiled-dump: their PHP kept in var/<out>/compiled/\App\Alis\Compiled\Compiler::$on = in_array('--compiled', $argv, true) || in_array('--compiled-dump', $argv, true);$compiledDump = in_array('--compiled-dump', $argv, true);$argv = array_values(array_filter($argv, fn ($a) => $a !== '--compiled' && $a !== '--compiled-dump'));// --compiled-only=Flow,Expressions: only these template groups (src/Alis/Compiled/Templates/<Group>.php)foreach ($argv as $a) { if (str_starts_with($a, '--compiled-only=')) { \App\Alis\Compiled\Templates::$only = explode(',', substr($a, 16)); \App\Alis\Compiled\Compiler::$on = true; } }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--compiled-only=')));// --compiled-from=<dir>: the scripts in PHP of that folder (tools/compiled/readable.php, edited or not) run the gameforeach ($argv as $a) { if (str_starts_with($a, '--compiled-from=')) { $d = substr($a, 16); \App\Alis\Compiled\Compiler::$fromDir = str_starts_with($d, '/') ? $d : __DIR__ . '/../' . $d; \App\Alis\Compiled\Compiler::$on = true; } }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--compiled-from=')));foreach ($argv as $a) { if (str_starts_with($a, '--film-dump=')) $filmDumpAt = (int) substr($a, 12); }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--film-dump=')));// --lazy-delay=0.1,20: the files loaded on demand come 0.1 s + size / 20 MB/s after they are asked (like the browser)foreach ($argv as $a) { if (str_starts_with($a, '--lazy-delay=')) { $dp = explode(',', substr($a, 13)) + [1 => 20, 2 => '.']; SysVars::$lazyDelay = [(float) $dp[0], max(0.01, (float) $dp[1]), $dp[2]]; } }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--lazy-delay=')));$argv = array_values(array_filter($argv, fn ($a) => $a !== '--panel'));$panelLog = [];\App\Alis\Hd3d::$allSprites = in_array('--hd3d-all-sprites', $argv, true);$argv = array_values(array_filter($argv, fn ($a) => $a !== '--hd3d-all-sprites'));$skipSeen = 0;// --hd3d-budget=0.01: the share of the time the HD passes may take (App\Alis\Hd3d::$budget; tiny = a slow computer)foreach ($argv as $a) { if (str_starts_with($a, '--hd3d-budget=')) \App\Alis\Hd3d::$budget = (float) substr($a, 14); }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--hd3d-budget=')));$argv = array_values(array_filter($argv, fn ($a) => $a !== '--hd3d-compare'));$argv = array_values(array_filter($argv, fn ($a) => $a !== '--hd3d'));\App\Alis\Hd3d::$on = $hd3dArg;\App\Alis\Hd3d::$debug = in_array('--hd3d-debug', $argv, true);foreach ($argv as $a) { if (str_starts_with($a, '--hd3d-scale=')) \App\Alis\Hd3d::$passScale = (int) substr($a, 13); }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--hd3d-scale=')));$argv = array_values(array_filter($argv, fn ($a) => $a !== '--hd3d-debug'));$argv = array_values(array_filter($argv, fn ($a) => $a !== '--hd'));// --profile=N: every N frames, print the time per VM cycle and the memory$profileEvery = 0;foreach ($argv as $a) { if (str_starts_with($a, '--profile=')) $profileEvery = (int) substr($a, 10); }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--profile=')));$argv = array_values(array_filter($argv, fn ($a) => $a !== '--audio' && $a !== '--source'));// --replay=var/trace/<time>: replays a session recorded by App\Alis\Trace (var/trace.on): its steps, inputs and audio;// its own trace goes to var/trace/ too (var/trace.on is not needed)$replay = null;foreach ($argv as $a) { if (str_starts_with($a, '--replay=')) $replay = array_map(fn ($l) => json_decode($l, true), file(__DIR__ . '/../' . substr($a, 9), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); }$argv = array_values(array_filter($argv, fn ($a) => !str_starts_with($a, '--replay=')));$dir = $argv[1] ?? 'data/robinson';$frames = (int) ($argv[2] ?? 200);$every = (int) ($argv[3] ?? 50);$keys = [];$clicks = [];$holdFor = [];foreach (array_filter(explode(',', $argv[4] ?? '')) as $k) {    $p = explode(':', $k);    if (($p[1] ?? '') === 'h') {       // "frame:h:SYM:N" = hold key SYM for N frames        $keys[(int) $p[0]] = (int) $p[2];        $holdFor[(int) $p[0]] = (int) $p[3];    } elseif (($p[1] ?? '') === 'm') {       // "frame:m:x:y" = left click at x,y (game pixels)        $clicks[(int) $p[0]] = [(int) $p[2], (int) $p[3]];    } else {        $keys[(int) $p[0]] = (int) $p[1];    }}$out = __DIR__ . '/../var/' . ($argv[6] ?? 'run');if ($compiledDump) { \App\Alis\Compiled\Compiler::$dumpDir = "$out/compiled"; }   // 6th argument: output folder in var/ (several runs at once)@mkdir($out, 0777, true);array_map('unlink', glob("$out/*.bmp") ?: []);$m = new Machine();// files loaded on demand (catalog/<game>.json): taken from the developer's full copy (.alis-data/<game>)$gameId = basename($dir);SysVars::$lazy = (\App\Alis\GameLibrary::catalog(__DIR__ . '/../catalog', $gameId))['lazy'] ?? [];// 7th argument "http404": no developer copy, downloads answered 404 after 10 frames (the browser without the films)if (($argv[7] ?? '') === 'http404') {    SysVars::$http = new class (new \JumPHP\Bridge\JsBridge()) extends \JumPHP\Http\Http {        public array $queue = [];        public function request(string $method, string $url, string|array|null $body = null, array $headers = [], ?float $timeout = null): \JumPHP\Async\Task        {            return $this->queue[] = new \JumPHP\Async\Task();        }    };}SysVars::$lazyDev = ($argv[7] ?? '') === 'http404' ? '' : '';if (($argv[7] ?? '') !== 'http404') SysVars::$lazyDev = is_dir(__DIR__ . "/../../../.alis-data/$gameId") ? realpath(__DIR__ . "/../../../.alis-data/$gameId") : '';if ($hdSpritesArg) {    \App\Alis\HdSprites::$on = true;    \App\Alis\HdSprites::$dir = $dir ?? '';    \App\Alis\HdSprites::loadPack();    fprintf(STDERR, "hd sprites: %d in the pack\n", count(\App\Alis\HdSprites::$pack ?? []));}$hdSpritesLog = [];if ($sourceArg) {    SysVars::$sourceDir = __DIR__ . '/../' . $dir . '/src';}SysVars::$hdText = $hdArg;$t0 = microtime(true);if (!$m->boot(__DIR__ . '/../' . $dir)) {    fwrite(STDERR, "boot failed: {$m->error}\n");    exit(1);}printf("booted %s (version %d, platform %d, %dx%d) in %.0f ms\n", $m->gameName, Alis::$platform->version, Alis::$platform->kind,    Alis::$platform->width, Alis::$platform->height, (microtime(true) - $t0) * 1000);// ALIS_AUDIO=1: mix the audio (22050 Hz stereo, 441 frames per VM frame) into var/run/audio.wav$audio = $audioArg || (bool) getenv('ALIS_AUDIO');$pcm = '';$audioTime = 0.0;if ($audio) {    \App\Alis\audio_output_init(22050, 2);}// ALIS_TRACE=N: log the opcodes of the first N VM cycles to var/run/trace.txt$traceCycles = (int) ($argv[5] ?? getenv('ALIS_TRACE'));if ($traceCycles > 0) {    $log = fopen("$out/trace.txt", 'w');    foreach (['tab_opcodes' => 'opcodes', 'tab_codesc1' => 'codesc1names'] as $tab => $names) {        foreach (\App\Alis\Tables::$$tab as $code => $fn) {            if ($fn === null) continue;            $name = \App\Alis\Tables::$names[$names][$code] ?? "?$code";            \App\Alis\Tables::$$tab[$code] = function () use ($fn, $name, $log, $m, $traceCycles) {                if ($m->cycles < $traceCycles) {                    $sc = Alis::$script;                    $at = Alis::$opcode_pc - $sc->data->data_org;                    $fn();                    // name, offset in the script, where the VM went after it (tools/lang/check.php)                    fprintf($log, "%d %s %06x %s %x %x\n", $m->cycles, $sc->name, Alis::$opcode_pc, $name, $at, $sc->pc - $sc->data->data_org);                    return;                }                $fn();            };        }    }}if ($replay !== null) {    @touch(__DIR__ . '/../var/trace.on');    \App\Alis\Trace::start(__DIR__ . '/../var');    \App\Alis\audio_output_init(22050, 2);    $frames = count($replay);}$release = [];$t0 = microtime(true);$ops = 0;$maxFrame = 0.0;$tailTime = 0.0;$tailCycles = 0;for ($i = 1; $i <= $frames && $m->running; $i++) {    if (isset($keys[$i])) {        SysVars::$held[$keys[$i]] = true;        if (!\App\Alis\sys_is_modifier($keys[$i])) {            SysVars::$button = $keys[$i];        }        $release[$i + ($holdFor[$i] ?? 4)] = $keys[$i];    }    if (isset($clicks[$i])) {        SysVars::$mouse->x = $clicks[$i][0];        SysVars::$mouse->y = $clicks[$i][1];        SysVars::$mouse->lb = 1;        SysVars::$mouse->lb_clicked = 1;    }    if (isset($clicks[$i - 4])) {        SysVars::$mouse->lb = 0;    }    // the arrows held = the joystick (like PlayScene), Shift with them = its fire button (run)    $pad = 0;    foreach ([\SDLK_UP => 1, \SDLK_DOWN => 2, \SDLK_LEFT => 4, \SDLK_RIGHT => 8] as $sym => $bit) {        $pad |= isset(SysVars::$held[$sym]) ? $bit : 0;    }    if ($pad && (isset(SysVars::$held[\SDLK_LSHIFT]) || isset(SysVars::$held[\SDLK_RSHIFT]))) {        $pad |= 0x80;    }    SysVars::$pad = $pad;    if (isset($release[$i])) {        unset(SysVars::$held[$release[$i]]);    }    if (SysVars::$http !== null && $i % 10 === 0) {        foreach (SysVars::$http->queue as $task) {            $task->settle(new \JumPHP\Http\HttpResponse(404, ''));        }        SysVars::$http->queue = [];    }    if ($skip !== null) {        static $skipPhase = '';        if ($skip->offered()) {            $skip->skipping = true;        }        $skip->update(0.02);        if ($skip->phase() !== $skipPhase) {            printf("frame %d: intro phase %s\n", $i, $skipPhase = $skip->phase());        }    }    $stepDt = 0.02;    $stepMs = $i * 20;    if ($replay !== null) {        $in = $replay[$i - 1];        SysVars::$held = array_fill_keys($in['held'], true);        SysVars::$button = $in['btn'];        $mo = SysVars::$mouse;        [$mo->x, $mo->y, $mo->lb, $mo->rb, $mo->lb_clicked, $mo->rb_clicked] = [$in['mx'], $in['my'], $in['lb'], $in['rb'], $in['lbc'], $in['rbc']];        SysVars::$pad = $in['pad'];        [$stepDt, $stepMs] = [$in['dt'], $in['ms']];        \App\Alis\Trace::input($in);    }    $tf = microtime(true);    $m->advance($stepDt, $stepMs);    if ($replay !== null && $replay[$i - 1]['au'] > 0) {        \App\Alis\audio_mix($replay[$i - 1]['au']);    }    $tf = microtime(true) - $tf;    if ($audio) {        $ta = microtime(true);        $pcm .= \App\Alis\audio_mix(441);        $audioTime += microtime(true) - $ta;    }    if ($tf > $maxFrame) { $maxFrame = $tf; }    if ($i > $frames - 300) { $tailTime += $tf; $tailCycles += $m->lastOpcodes > 0 ? 1 : 0; }    $ops += $m->lastOpcodes;    if ($watch !== null && Alis::$basemain) {        static $wLast = null;        $wv = \App\Alis\xread8(Alis::$basemain + $watch);        if ($wv !== $wLast) { printf("frame %d: mb[0x%x] = %d\n", $i, $watch, $wv); $wLast = $wv; }    }    // ALIS_PROFILE=N: every N frames, the time per VM cycle and the memory (does the game slow down over time?)    if (($pe = $profileEvery) > 0) {        static $pT = 0.0, $pC = 0, $pO = 0;        $pT += $tf; $pC += $m->lastOpcodes > 0 ? 1 : 0; $pO += $m->lastOpcodes;        if ($i % $pe === 0) {            printf("frame %6d: %5.2f ms/cycle %6d ops/cycle %6.1f us/kop mem %.1f MB\n", $i, $pT * 1000 / max(1, $pC), $pO / max(1, $pC), $pT * 1e6 / max(1, $pO / 1000), memory_get_usage() / 1048576);            $pT = 0.0; $pC = 0; $pO = 0;        }    }    if ($hdArg) {        static $hdLast = '';        $txt = implode('', array_map(fn ($g) => chr($g['char']), SysVars::$hdShown));        if ($txt !== $hdLast) {            printf("frame %d: %d glyphs [%s]\n", $i, count(SysVars::$hdShown), substr($txt, 0, 100));            if ($txt !== '' && !file_exists(sprintf('%s/text-%05d.bmp', $out, $i))) {                file_put_contents(sprintf('%s/text-%05d.bmp', $out, $i), SysVars::$frameBmp);                file_put_contents(sprintf('%s/text-%05d.json', $out, $i), json_encode(SysVars::$hdShown));            }            $hdLast = $txt;        }    }    // a sprite the HD pass left out (or drew, --hd3d-all-sprites): the HD land of that frame, in var/<out>/skip/    if (\App\Alis\Hd3d::$skipped !== $skipSeen && \App\Alis\Hd3d::$land !== null) {        $skipSeen = \App\Alis\Hd3d::$skipped;        @mkdir("$out/skip", 0777, true);        $L = \App\Alis\Hd3d::$land;        $pal = substr(SysVars::$frameBmp, 54, 1024);        file_put_contents(sprintf('%s/skip/%05d-hd.bmp', $out, SysVars::$frameCount), \App\Alis\sys_bmp_header($L['w'] * 2, $L['h'] * 2, 8, strlen($L['hd'])) . $pal . $L['hd']);        file_put_contents(sprintf('%s/skip/%05d-low.bmp', $out, SysVars::$frameCount), \App\Alis\sys_bmp_header($L['w'], $L['h'], 8, strlen($L['low'])) . $pal . $L['low']);    }    // --panel: the brightness of the interface (below the land) of each new picture (does it come and go?)    if ($panelArg && SysVars::$frameBmp !== '' && SysVars::$frameCount !== ($panelLast ?? -1)) {        $panelLast = SysVars::$frameCount;        $px = substr(SysVars::$frameBmp, 54 + 1024);        $sum = 0;        $n = 0;        for ($y = 140; $y < 200; $y += 2) {            for ($x = 0; $x < 320; $x += 4) {                $sum += ord($px[$y * 320 + $x]) !== 0 ? 1 : 0;                $n++;            }        }        $panelLog[] = sprintf('%d:%d', SysVars::$frameCount, (int) round($sum * 100 / $n));    }    // --film-dump=N: the film's own frame (its buffer, its palette) at update N, in var/<out>/film-N.bmp    if (isset($filmDumpAt) && $i === $filmDumpAt && \App\Alis\FilmVars::$pvgalogic !== null) {        $bf = \App\Alis\FilmVars::$bfilm;        $fw = max(1, $bf->width); $fh = max(1, $bf->height);        $px = substr(\App\Alis\FilmVars::$pvgalogic, \App\Alis\FilmVars::$vgalogic, $fw * $fh);        $pal = substr(SysVars::$frameBmp, 54, 1024);        file_put_contents(sprintf('%s/film-%05d.bmp', $out, $i), \App\Alis\sys_bmp_header($fw, $fh, 8, strlen($px)) . $pal . $px);        printf("film %dx%d frame %d window %d,%d %dx%d\n", $fw, $fh, $bf->frame, \App\Alis\read16le($bf->basemain + 0xe), \App\Alis\read16le($bf->basemain + 0x10), \App\Alis\read16le($bf->basemain + 0x12) + 1, \App\Alis\read16le($bf->basemain + 0x14) + 1);    }    if ($hdSpritesArg && SysVars::$frameCount !== ($hdSpritesLast ?? -1)) {        $hdSpritesLast = SysVars::$frameCount;        $px = 0;        foreach (\App\Alis\HdSprites::$shown as $sh) {            foreach ($sh['tiles'] as [$x1, $y1, $x2, $y2]) {                $px += ($x2 - $x1) * ($y2 - $y1);            }        }        $hdSpritesLog[] = SysVars::$frameCount . ' ' . count(\App\Alis\HdSprites::$shown) . ' ' . $px;    }    if ($memcrcArg && SysVars::$frameCount !== ($memcrcLast ?? -1)) {        $memcrcLast = SysVars::$frameCount;        $memcrc[] = sprintf('%d %08x %d %d %08x', SysVars::$frameCount, crc32(Alis::$mem), Alis::$varD7, Alis::$varD6, crc32(Alis::$sd7 . "\0" . Alis::$sd6 . "\0" . Alis::$oldsd7));    }    // --hd3d-compare: each new HD land, halved, against the game's own land (a sprite drawn by one only)    if ($hd3dCompare && \App\Alis\Hd3d::$land !== null && \App\Alis\Hd3d::$land !== ($cmpLast ?? null)) {        $cmpLast = $L = \App\Alis\Hd3d::$land;        $bad = 0; $rows = [];        for ($y = 0; $y < $L['h']; $y++) {            $n = 0;            for ($x = 0; $x < $L['w']; $x++) {                $hp = $L['hd'][($y * 2) * $L['w'] * 2 + $x * 2];                if ($hp !== $L['low'][$y * $L['w'] + $x]) { $n++; }            }            if ($n > $L['w'] / 4) { $rows[] = $y; }            $bad += $n;        }        // above the first row where the land differs a lot (the terrain), the HD sky must be the game's        $sky = [];        $heavy = $rows[0] ?? $L['h'];        for ($y = 0; $y < $heavy; $y++) {            $n = 0;            for ($x = 0; $x < $L['w']; $x++) {                if ($L['hd'][($y * 2) * $L['w'] * 2 + $x * 2] !== $L['low'][$y * $L['w'] + $x]) { $n++; }            }            if ($n >= 2) { $sky[] = "$y:$n"; }        }        if ($sky !== []) {            printf("frame %d (vm %d): HD only, above the land: rows %s\n", $i, SysVars::$frameCount, implode(' ', array_slice($sky, 0, 12)));        }        if ($rows !== [] && $sky !== []) {            @mkdir("$out/cmp", 0777, true);            $pal = substr(SysVars::$frameBmp, 54, 1024);            file_put_contents(sprintf('%s/cmp/%05d-low.bmp', $out, SysVars::$frameCount), \App\Alis\sys_bmp_header($L['w'], $L['h'], 8, strlen($L['low'])) . $pal . $L['low']);            file_put_contents(sprintf('%s/cmp/%05d-hd.bmp', $out, SysVars::$frameCount), \App\Alis\sys_bmp_header($L['w'] * 2, $L['h'] * 2, 8, strlen($L['hd'])) . $pal . $L['hd']);        }    }    if ($every > 0 && $i % $every === 0 && SysVars::$frameBmp !== '') {        file_put_contents(sprintf('%s/frame-%05d.bmp', $out, $i), SysVars::$frameBmp);        if ($hd3dArg && SysVars::$hdLand !== null) {            file_put_contents(sprintf('%s/land-%05d.bmp', $out, $i), SysVars::$hdLand['bmp']);            file_put_contents(sprintf('%s/land-%05d.json', $out, $i), json_encode(array_diff_key(SysVars::$hdLand, ['bmp' => 1])));        }        if ($hdArg) {            file_put_contents(sprintf('%s/glyphs-%05d.json', $out, $i), json_encode(SysVars::$hdShown));        }    }}$dt = microtime(true) - $t0;if (\App\Alis\Compiled\Compiler::$on) {    $n = $k = 0; $c = 0;    foreach (\App\Alis\Compiled\Compiler::$cache as $cs) { if ($cs) { $c++; $n += $cs->native; $k += $cs->interpreted; } }    printf("compiled scripts: %d (%d instructions in PHP, %d run by the VM)%s\n", $c, $n, $k, \App\Alis\Compiled\Compiler::$fromFiles ? sprintf(", %d from %s", \App\Alis\Compiled\Compiler::$fromFiles, \App\Alis\Compiled\Compiler::$fromDir) : "");}if ($hdSpritesLog !== []) {    @mkdir($out, 0777, true);    file_put_contents("$out/hd-sprites.txt", implode("\n", $hdSpritesLog) . "\n");}if ($memcrc !== []) {    file_put_contents("$out/memcrc.txt", implode("\n", $memcrc) . "\n");}if ($panelLog !== []) {    file_put_contents("$out/panel.txt", implode("\n", $panelLog) . "\n");}if (\App\Alis\Hd3d::$passes > 0) {    printf("HD passes: %d, %.2f ms each, %d sprites left out\n", \App\Alis\Hd3d::$passes, \App\Alis\Hd3d::$passSeconds * 1000 / \App\Alis\Hd3d::$passes, \App\Alis\Hd3d::$skipped);}printf("memory peak %.1f MB, now %.1f MB, mem string %.1f MB\n", memory_get_peak_usage() / 1048576, memory_get_usage() / 1048576, strlen(Alis::$mem) / 1048576);printf("slowest frame: %.1f ms; last 300 frames: %d VM cycles, %.1f ms per VM cycle\n", $maxFrame * 1000, $tailCycles, $tailTime * 1000 / max(1, $tailCycles));printf("%d frames, %d VM cycles, %d opcodes in %.2f s (%.1f ms/frame)\n", $i - 1, $m->cycles, $ops, $dt, $dt * 1000 / max(1, $i - 1));if ($audio) {    $n = strlen($pcm);    file_put_contents("$out/audio.wav", 'RIFF' . pack('V', 36 + $n) . 'WAVEfmt ' . pack('VvvVVvv', 16, 1, 2, 22050, 22050 * 4, 4, 16) . 'data' . pack('V', $n) . $pcm);    printf("audio: %.1f s mixed in %.2f s (%.1f us per frame), var/run/audio.wav\n", $n / 4 / 22050, $audioTime, $audioTime * 1e6 / max(1, $n / 4));}file_put_contents("$out/opened.txt", implode("\n", array_unique(SysVars::$opened)) . "\n");if (SysVars::$frameBmp !== '') {    file_put_contents("$out/last.bmp", SysVars::$frameBmp);}if ($m->error !== null) {    fwrite(STDERR, "ERROR: {$m->error}\n");    exit(2);}