aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 9b477498bd02a63470ab16183215a45a634b1e99
parent ecefa6ebb75fe9d65a8c5a2ca886cad94b0be804
Author: anon <anon@example.com>
Date:   Fri, 16 Oct 2026 23:50:56 +0000

Add isolated native playfield coverage sweep and missing arrivals

Diffstat:
Adocs/playfield-validation.md | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/playfields.go | 4++++
Atools/client/sweep_capture.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/sweep_playfields.py | 217+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 349 insertions(+), 0 deletions(-)

diff --git a/docs/playfield-validation.md b/docs/playfield-validation.md @@ -0,0 +1,50 @@ +# Playfield coverage + +The native sweep uses an isolated character and server, exercises the real +teleport/reconnect protocol, and then repeats each scene with a fresh client. +It retains logs, screenshots, frame counts, loading times and resident memory. +A transition failure is also retried immediately on a fresh client to separate +arrival failures from state retained across zones. + +Build the native client and unpack the runtime assets first (running the Go +server once does the latter). From the repository root, with an active X11 +display and its normal `DISPLAY`/`XAUTHORITY` environment: + +```sh +make -C src -f Makefile.linux -j8 +python3 tools/client/sweep_playfields.py +``` + +The sweep needs Go, a C compiler, SDL2/OpenGL development libraries, Python 3.11 +or newer with Pillow, `gnome-session-inhibit`, and `xset`. It reserves ports +7520, 7521 and 8082. It does not use the user's server or `data/users.yaml`. +Preferences and diagnostics are private to the run; large immutable assets +are shared. Results remain under `local/playfield-sweep/playfield-sweep-*`. +Ctrl-C stops the owned processes and keeps completed results. + +`catalog.json` reconciles server entries with actual 14.9.1 database definitions. +There are 370 definitions: 363 scenes in the sweep, six dependency/developer +entries, and one empty bunker definition (1673). The server catalog also lists +25 names without definitions in this release; these are excluded explicitly. +The four added arrivals (124, 641, 706 and 4704) use district centres from the +release database, consistent with other provisional catalog arrivals. + +`results.jsonl` is appended after each scene. `ready-and-rendering` requires a +server acknowledgement followed by at least ten seconds and 30 rendered frames. +It establishes loading/presentation liveness, not visual or gameplay correctness. +Screenshots need review, and the FPS values at these catalog arrivals are not +comparable to the fixed Bronto Burger/Lush Fields performance cameras. A build +running concurrently also makes these unsuitable as performance benchmarks. +`build.json` records the source revision, working diff and executable digest. + +The first run found a common indoor failure in vertex-buffer `Optimize`, followed +by unsupported diffuse/specular material-source states. These shared adapter +paths have regression tests for state, buffer contents and rendered pixels. +After the fixes, Camelot, Condemned Subway, Temple of Three Winds, Fixer Grid and +the regular Grid loaded and rendered in sequence on native Linux. + +Full native coverage is still in progress. Browser coverage must be run separately: +paged memory, WebGL, asset fetching and asynchronous WebSocket cleanup can fail +independently. A single arrival also does not cover the whole playfield. Follow-up +coverage should turn the camera, move through authored districts, exercise +inventory/map and audio, and repeat a bounded zoning loop to detect resource growth. diff --git a/server/playfields.go b/server/playfields.go @@ -385,8 +385,11 @@ var playfields = map[uint32]playfield{ // 14.9.1 population resources supply these district centres; arrivals need collision validation. 120: {name: "Camelot", spawn: [3]float32{218, 30.3445263, 254}}, + 124: {name: "Tir Assembly Hall", spawn: [3]float32{216, 14.000001, 162}}, 125: {name: "Smuggler's Rearranged", spawn: [3]float32{158, 39.2397766, 206}}, 127: {name: "Condemned Subway", spawn: [3]float32{150, 107.603256, 274}}, + 641: {name: "Tir Arena", spawn: [3]float32{340, 6.80000019, 380}}, + 706: {name: "Omni Entertainment Arena", spawn: [3]float32{220, 16.3999996, 180}}, 1833: {name: "Dng: Cyborg Barracks", spawn: [3]float32{104, 10.6003942, 172}}, 1840: {name: "Rompa Bar", spawn: [3]float32{234, 5, 152}}, 1913: {name: "Reet Retreat (dng)", spawn: [3]float32{136, 9.00000191, 108}}, @@ -398,5 +401,6 @@ var playfields = map[uint32]playfield{ 4107: {name: "Fixer Grid (dng)", spawn: [3]float32{306, 1.01377094, 66}}, 4121: {name: "Will To Fight", spawn: [3]float32{994, 195.001389, 296}}, 4604: {name: "Arrival_hall", spawn: [3]float32{196, 1.01377845, 208}}, + 4704: {name: "Booster Shop (dungeon)", spawn: [3]float32{178, 5.00021553, 144}}, 4805: {name: "Home Crypt", spawn: [3]float32{202, 61.7459335, 150}}, } diff --git a/tools/client/sweep_capture.c b/tools/client/sweep_capture.c @@ -0,0 +1,78 @@ +#define _GNU_SOURCE +#include <assert.h> +#include <dlfcn.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_opengl.h> + +static unsigned long frames, draws, frame_draws, most_draws; +static double reported; + +void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) +{ + static void (*draw)(GLenum, GLsizei, GLenum, const void *); + if (!draw) draw = dlsym(RTLD_NEXT, "glDrawElements"); + ++draws; + ++frame_draws; + draw(mode, count, type, indices); +} + +void SDL_GL_SwapWindow(SDL_Window *window) +{ + static void (*swap)(SDL_Window *); + if (!swap) swap = dlsym(RTLD_NEXT, "SDL_GL_SwapWindow"); + const char *directory = getenv("AO_SWEEP_DIRECTORY"); + char path[1024], temporary[1024]; + + /* Capture on the rendering thread before presenting its back buffer. */ + snprintf(path, sizeof(path), "%s/capture.request", directory); + if (!access(path, F_OK)) { + assert(!unlink(path)); + int width, height; + SDL_GL_GetDrawableSize(window, &width, &height); + unsigned char *pixels = malloc((size_t)width * height * 3); + assert(pixels); + GLint read_buffer, pack_alignment; + glGetIntegerv(GL_READ_BUFFER, &read_buffer); + glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); + glReadBuffer(GL_BACK); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + glReadBuffer(read_buffer); + glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); + snprintf(temporary, sizeof(temporary), "%s/capture.tmp", directory); + FILE *file = fopen(temporary, "wb"); + assert(file); + fprintf(file, "P6\n%d %d\n255\n", width, height); + for (int y = height - 1; y >= 0; --y) + assert(fwrite(pixels + (size_t)y * width * 3, 3, width, file) == (size_t)width); + assert(!fclose(file)); + free(pixels); + snprintf(path, sizeof(path), "%s/capture.ppm", directory); + assert(!rename(temporary, path)); + } + swap(window); + ++frames; + if (frame_draws > most_draws) most_draws = frame_draws; + frame_draws = 0; + + /* Publish complete telemetry once a second without partial JSON reads. */ + struct timespec timestamp; + assert(!clock_gettime(CLOCK_MONOTONIC, &timestamp)); + double seconds = timestamp.tv_sec + timestamp.tv_nsec / 1e9; + if (seconds - reported >= 1) { + snprintf(temporary, sizeof(temporary), "%s/frame.tmp", directory); + FILE *file = fopen(temporary, "w"); + assert(file); + fprintf(file, "{\"time\":%.6f,\"frames\":%lu,\"draws\":%lu,\"max_draws\":%lu}\n", + seconds, frames, draws, most_draws); + assert(!fclose(file)); + snprintf(path, sizeof(path), "%s/frame.json", directory); + assert(!rename(temporary, path)); + reported = seconds; + most_draws = 0; + } +} diff --git a/tools/client/sweep_playfields.py b/tools/client/sweep_playfields.py @@ -0,0 +1,217 @@ +"""Exercise every available 14.9.1 playfield in an isolated native client/server.""" +import hashlib +import json +import os +import pathlib +import re +import shutil +import socket +import subprocess +import sys +import time +import urllib.parse +import urllib.request + +import PIL.Image + +root = pathlib.Path(__file__).resolve().parents[2] +sys.path.insert(0, str(root)) +import tools.data.ao_database + +work = root / 'local/playfield-sweep' +work.mkdir(parents=True, exist_ok=True) +output = work / ('playfield-sweep-' + time.strftime('%Y%m%d-%H%M%S')) +output.mkdir() + +# Build only the small test adapter and server; use the existing native game. +subprocess.run(['cc', '-shared', '-fPIC', '-O2', str(root / 'tools/client/sweep_capture.c'), + '-o', str(work / 'sweep-capture.so'), '-lSDL2', '-lGL', '-ldl'], check=True) +subprocess.run(['go', 'build', '-o', str(work / 'server'), './server'], cwd=root, check=True) + +# Share immutable assets while isolating preferences and diagnostic output. +assets = output / 'assets' +assets.mkdir() +for source in (root / 'anarchy-assets-14.9.1').iterdir(): + if source.name in ['cd_image', 'fonts']: + (assets / source.name).symlink_to(source) + elif source.is_dir(): + shutil.copytree(source, assets / source.name) + else: + shutil.copy2(source, assets / source.name) +active = output / 'active' +active.mkdir() +fixture = output / 'server' +(fixture / 'data').mkdir(parents=True) +for name in ['terrain.bin', 'zone_links.yaml', 'npc_spawns.yaml', 'maps']: + (fixture / 'data' / name).symlink_to(root / 'data' / name) +for name in ['runtime', 'client']: + (fixture / name).symlink_to(root / name) +(fixture / 'anarchy-assets-14.9.1').symlink_to(assets) +(fixture / '.runtime-bundle').write_text(hashlib.sha256((root / 'runtime/manifest.json').read_bytes()).hexdigest() + '\n') +(fixture / 'data/users.yaml').write_text('- id: 73\n name: Playfield Sweep\n playfield: 705\n position: [960, 16.5, 510]\n rotation: [0, 0, 0, 1]\n appearance: 789\n monster_data: 0\n level: 1\n') +for port in [7520, 7521, 8082]: + with socket.socket() as connection: + assert connection.connect_ex(('127.0.0.1', port)) != 0, port + +# Reconcile the server catalog with actual release definitions, including exclusions. +database = tools.data.ao_database.Database(assets) +catalog = [] +for line in (root / 'server/playfields.go').read_text().splitlines(): + match = re.match(r'\s+(\d+):\s+\{name: ("(?:[^"\\]|\\.)*")(.*)', line) + if not match: + continue + identity = int(match[1]) + row = {'id': identity, 'name': json.loads(match[2])} + if (1000001, identity) not in database.records: + row['skip'] = 'no playfield definition in 14.9.1' + elif 'unavailable: true' in match[3]: + row['skip'] = 'dependency-only entry in server catalog' + catalog.append(row) +known = {row['id'] for row in catalog} +for kind, identity in database.records: + if kind == 1000001 and identity not in known: + row = {'id': identity, 'name': database.read(kind, identity)[8:40].split(b'\0')[0].decode('ascii').strip()} + if identity in [101, 105]: + row['skip'] = 'door-link dependency or developer graphics test area' + elif identity == 1673: + row['skip'] = 'empty definition: zero zones, zero districts, no outdoor ground' + else: + row['skip'] = 'not in server catalog; investigate arrival' + catalog.append(row) +database.close() +(output / 'catalog.json').write_text(json.dumps(catalog, indent=2) + '\n') +priority = [120, 127, 1931, 4107, 152, 124, 641, 706, 4704, 705, 695] +zones = sorted([row for row in catalog if 'skip' not in row], key=lambda row: (priority.index(row['id']) if row['id'] in priority else len(priority), row['id'])) +with (root / 'src/build/linux/game').open('rb') as executable: + executable_hash = hashlib.file_digest(executable, 'sha256').hexdigest() +metadata = { + 'source_commit': subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip(), + 'working_diff': subprocess.check_output(['git', 'diff', 'HEAD'], cwd=root, text=True), + 'executable_sha256': executable_hash, + 'started': time.time(), + 'client': 'native Linux', + 'coverage': 'arrival loading and rendered frames; screenshots require visual review', +} +(output / 'build.json').write_text(json.dumps(metadata, indent=2) + '\n') +print(output, flush=True) +client = None +client_log = None +process_number = 0 + + +def request(path, fields=None): + data = urllib.parse.urlencode(fields).encode() if fields is not None else None + return urllib.request.urlopen('http://127.0.0.1:8082' + path, data, timeout=10).read() + + +def stop_client(): + global client, client_log + if client is not None: + if client.poll() is None: + client.kill() + client.wait(timeout=10) + client_log.close() + client = client_log = None + + +def run_zone(zone, phase): + global client, client_log, process_number + # Changing the isolated character invokes the server's real teleport/reconnect path. + if phase == 'cold': + stop_client() + previous_pid = client.pid if client is not None else None + if client is None: + deadline = time.monotonic() + 10 + while json.loads(request('/map-players'))['players'][0]['connected']: + assert time.monotonic() < deadline, 'server did not observe client disconnect' + time.sleep(.1) + request('/teleport/73', {'playfield': zone['id']}) + request('/time', {'hour': 13, 'minute': 30}) + started = time.monotonic() + result = {'phase': phase, 'id': zone['id'], 'name': zone['name'], 'started': time.time(), 'status': 'timeout', 'previous_pid': previous_pid} + if client is None: + process_number += 1 + client_log = (output / f'client-{process_number}.log').open('w') + for name in ['frame.json', 'capture.request', 'capture.ppm']: + (active / name).unlink(missing_ok=True) + env = os.environ.copy() + env.update(SDL_VIDEODRIVER='x11', ANARCHY_CD='cd_image', ANARCHY_SETUP='Setupf', ANARCHY='.', LD_PRELOAD=str(work / 'sweep-capture.so'), AO_SWEEP_DIRECTORY=str(active)) + client = subprocess.Popen([str(root / 'src/build/linux/game'), 'localtest', 'localtest', '73', '2130706433', '7521', '0', '0'], cwd=assets, env=env, stdout=client_log, stderr=subprocess.STDOUT) + result['pid'] = client.pid + result['log'] = f'client-{process_number}.log' + result['log_start'] = (output / result['log']).stat().st_size + ready = None + first_frame = None + last_frame = None + # A ready packet alone is insufficient: require ten seconds and 30 subsequent frames. + while time.monotonic() - started < 120: + if client.poll() is not None: + result.update(status='client-exit', exit_code=client.returncode) + break + player = json.loads(request('/map-players'))['players'][0] + if player['playfield'] == zone['id'] and player['connected'] and ready is None: + ready = time.monotonic() + result['ready_seconds'] = ready - started + result['position'] = player['position'] + if (active / 'frame.json').exists(): + frame = json.loads((active / 'frame.json').read_text()) + if ready is not None and frame['time'] >= ready: + if first_frame is None: + first_frame = frame + last_frame = frame + if frame['time'] - first_frame['time'] >= 10 and frame['frames'] - first_frame['frames'] >= 30: + result['status'] = 'ready-and-rendering' + result['frames'] = frame['frames'] - first_frame['frames'] + result['fps'] = result['frames'] / (frame['time'] - first_frame['time']) + result['draws_per_frame'] = (frame['draws'] - first_frame['draws']) / result['frames'] + break + time.sleep(.25) + result['elapsed_seconds'] = time.monotonic() - started + result['log_end'] = (output / result['log']).stat().st_size + result['last_frame'] = last_frame + # Save a screenshot only when a live rendering thread can service the request. + if client.poll() is None and last_frame is not None: + (active / 'capture.ppm').unlink(missing_ok=True) + (active / 'capture.request').touch() + deadline = time.monotonic() + 5 + while time.monotonic() < deadline and not (active / 'capture.ppm').exists() and client.poll() is None: + time.sleep(.1) + if (active / 'capture.ppm').exists(): + result['screenshot'] = f'{phase}-{zone["id"]}.png' + PIL.Image.open(active / 'capture.ppm').save(output / result['screenshot']) + (active / 'capture.ppm').unlink() + memory = pathlib.Path(f'/proc/{client.pid}/status') + if memory.exists(): + result['memory'] = [line for line in memory.read_text().splitlines() if line.startswith(('VmRSS:', 'VmHWM:'))] + with (output / 'results.jsonl').open('a') as results: + results.write(json.dumps(result) + '\n') + print(json.dumps(result), flush=True) + if result['status'] != 'ready-and-rendering': + stop_client() + return result + + +# Own all test processes, character data and logs; preserve the user's server state. +with (output / 'server.log').open('w') as server_log: + inhibitor = subprocess.Popen(['gnome-session-inhibit', '--reason', 'AO playfield coverage', '--inhibit-only'], stdout=server_log, stderr=server_log) + server = subprocess.Popen([str(work / 'server'), '-login-port', '7520', '-world-port', '7521', '-http-port', '8082'], cwd=fixture, stdout=server_log, stderr=server_log) + try: + subprocess.run(['xset', 'dpms', 'force', 'on'], check=True) + for attempt in range(60): + assert server.poll() is None + with socket.socket() as connection: + if connection.connect_ex(('127.0.0.1', 8082)) == 0: + break + time.sleep(1) + for phase in ['transition', 'cold']: + for zone in zones: + result = run_zone(zone, phase) + if phase == 'transition' and result['status'] != 'ready-and-rendering': + run_zone(zone, 'cold-repro') + finally: + stop_client() + server.terminate() + server.wait(timeout=10) + inhibitor.terminate() + inhibitor.wait(timeout=10) + print('Sweep processes stopped; results retained in', output, flush=True)