aorecomp

Anarchy Online classic in the browser

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


commit c100f682a5746b6c5284f47c355da2958f48fb0d
parent 42e5cf94f29101c7ce1f5ea77aa42064d6f78b0f
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 18:38:15 +0000

Use observed arrivals for native walking final approaches

Diffstat:
MDEVELOPERS.md | 15++++++++++++++-
MTODO.md | 17++++++++++-------
Aserver/browser_walk_approach_test.go | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools/client/game_test.mjs | 10++++------
Atools/client/test_walk_approach.mjs | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 191 insertions(+), 14 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -503,7 +503,8 @@ Short key/click helpers release on the fresh consumed SDL event, then read the next full snapshot. Reading a large snapshot while holding a skill button can trigger native autorepeat and buy more points than intended. `GameTest.walk(x, z)` follows observed position and heading with bounded native -steering/final-approach pulses. It rejects stalled routes and waits for actor +steering pulses and forward input held until arrival or a steering change. +It rejects stalled routes and waits for actor readiness when travel changes playfields, including a walk started while the local actor is absent during zoning. Use it for ordinary ground routes. @@ -528,6 +529,18 @@ The Chromium harness saves runtime exception details with each error, preserving stack frames even for primitive throws such as `unwind`. Verify that diagnostic path without loading the game with `node --test tools/client/test_game_errors.mjs`. +For focused final-approach verification: + +```sh +AO_GAME_TEST=1 go test ./server -run '^TestBrowserWalkingFinalApproach$' -count=1 -timeout=5m -v +``` + +The controlled fixtures use valid training caps and test walking and running +through five integer/fractional waypoints, a real wall refusal, released-input recovery and +cold pose retention. Native arrivals stay within 0.35m; server comparisons allow +the original compact movement packet's 1/8-metre X/Z encoding. Evidence is saved +under `local/walk-final-approach/`. + `TestBrowserStarterEquipment` creates two Atrox Enforcers through Options with their normal Omni starter loadouts and the production training-ground population. It checks issued-bat equip/remove/re-wear, normal skill purchases, the issued diff --git a/TODO.md b/TODO.md @@ -4523,13 +4523,16 @@ and server restarts. Turn every reproduced bug into a focused regression test. and cold restart. This advances the connected gate without completing its repeatable fresh-character, death/reclaim and next-level coverage. See [earned creature upgrades](docs/earned-creature-upgrade.md). -- [ ] [P2] Fix low-speed fractional final approaches in `GameTest.walk`. - A controlled Run Speed5 mission route stalls at Z13.99 when targeting14.5; - continuous native W crosses the same boundary. Short final-approach pulses - also stall at30.99 for31.5. Check fractional/integer destinations at low and - ordinary speeds without bypassing collision or losing wall-stall detection. - Evidence: `local/mission-generation/native-candidate-ticked.log`, - `native-held-route.log` and their retained traces. +- [x] [P2] Fix low-speed fractional final approaches in `GameTest.walk`. + Timed forward pulses reproduced a stall at Z30.99 for31.5. Hold forward input + until observed arrival or steering change, retaining bounded steering and the + existing stall check. Controlled, healthy Run Speed5 walking/100 running now + reach ten integer/fractional waypoints, refuse the real wall, release input, + recover and retain their cold poses. Native arrivals stay within0.35m; server + comparisons account for the original compact1/8-metre pose encoding. Both + cases pass in74.90s, and the zoning/objective/exit regression passes in60.91s. + All19 traces are clean. Evidence: `local/walk-final-approach/verification.json` + and `zoning-verification.json`; see [browser testing](DEVELOPERS.md#browser-game-testing). - [ ] [P2] Audit native input across focus transitions and rapid target changes. Cover leaving/returning to the tab, opening/closing options or chat, held keys/modifiers, repeats, reconnect and slow frames. Compare the first input diff --git a/server/browser_walk_approach_test.go b/server/browser_walk_approach_test.go @@ -0,0 +1,104 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "math" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + "time" +) + +func TestBrowserWalkingFinalApproach(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for native walking final approaches") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/walk-final-approach", time.Now().Format("20060102-150405")) + for _, speed := range []uint16{5, 100} { + t.Run(fmt.Sprint(speed), func(t *testing.T) { + world, _ := newMissionEntranceWorld(t) + if err := world.handleMovement(world.clients[1], playerMovementRequest(world.characters[1], 1)); err != nil { + t.Fatal(err) + } + player := world.characters[1] + if speed == 100 { + player.level = 100 + player.stats.Abilities = characterAbilitiesStats{60, 60, 60, 60, 60, 60} + player.running = true + } + player.stats.Speed.RunSpeed = speed + player.health = player.maximumHealth() + if uint32(speed) > player.trainingMaximum(156) { + t.Fatal("walking fixture exceeds the native skill cap") + } + player.position, player.rotation, player.movement = [3]float32{15.01, .011, 30.5}, [4]float32{0, 0, 0, 1}, playerMovement{} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("walk-approach"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.savePosition_locked(player); err != nil { + t.Fatal(err) + } + if err := world.db.Close(); err != nil { + t.Fatal(err) + } + world = newServerForTest(t) + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + json.NewEncoder(w).Encode(map[string]any{"position": world.characters[1].position, + "inventory": world.characters[1].inventory, "speed": world.characters[1].stats.Speed.RunSpeed, "running": world.characters[1].running}) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + stopped := make(chan struct{}) + go func() { + defer close(stopped) + ticker := time.NewTicker(time.Second / 60) + defer ticker.Stop() + for { + select { + case now := <-ticker.C: + world.advancePlayerMovement(now) + case <-ctx.Done(): + return + } + } + }() + defer func() { cancel(); <-stopped }() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_walk_approach.mjs"), host.URL, filepath.Join(output, fmt.Sprint(speed))) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + if err := command.Run(); err != nil { + t.Fatal(err) + } + cancel() + <-stopped + if err := world.flushPositions(time.Now().Add(20 * time.Second)); err != nil { + t.Fatal(err) + } + cold := reloadMissionEntranceWorld(t) + + position := cold.characters[1].position + // Preserve native arrival tolerance plus compact-pose quantization. + if math.Hypot(float64(position[0]-15), float64(position[2]-43)) >= .55 { + t.Fatal("walking completion did not survive cold loading", position) + } + t.Logf("Browser artifacts: %s", output) + }) + } +} diff --git a/tools/client/game_test.mjs b/tools/client/game_test.mjs @@ -261,8 +261,8 @@ export class GameTest { const angle = difference(yaw, 2 * Math.atan2(actor.rotation[1], actor.rotation[3])); const key = Math.abs(angle) > 0.06 ? (angle > 0 ? 'KeyD' : 'KeyA') : 'KeyW'; - // Hold straight travel until steering or the final approach needs another pulse. - if (key === 'KeyW' && distance > 3) { + // Keep forward input held until arrival or an observed steering change. + if (key === 'KeyW') { await this.hold('KeyW', `walk toward ${x},${z}`, state => { const actor = this.local(state); if (!actor || actor.playfield !== field) return true; @@ -270,14 +270,12 @@ export class GameTest { if (distance < best - 0.05) { best = distance; progressAt = Date.now(); } assert(Date.now() - progressAt < 8000, 'Route is not approaching its destination'); const yaw = Math.atan2(x - actor.position[0], z - actor.position[2]); - return distance < 2 || Math.abs(difference(yaw, 2 * Math.atan2(actor.rotation[1], actor.rotation[3]))) > 0.06; + return distance < 0.35 || Math.abs(difference(yaw, 2 * Math.atan2(actor.rotation[1], actor.rotation[3]))) > 0.06; }, 120000); continue; } - const delay = key === 'KeyW' - ? Math.min(500, Math.max(40, (distance - 0.1) / 4.025 * 1000)) - : Math.min(200, Math.max(20, Math.abs(angle) / 3.5 * 1000)); + const delay = Math.min(200, Math.max(20, Math.abs(angle) / 3.5 * 1000)); this.record({kind: 'action', action: 'walk-pulse', key, delay, x, z}); const sequence = this.sequence; await this.page.keyboard.press(key, {delay}); diff --git a/tools/client/test_walk_approach.mjs b/tools/client/test_walk_approach.mjs @@ -0,0 +1,59 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output] = process.argv.slice(2); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +let game; +const evidence = {waypoints: []}; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'walk-approach', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + const server = async () => (await page.request.get(url + '/test-state')).json(); + await page.goto(url); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + evidence.initial = await server(); + + // Approach both fractional coordinates and integers, including a lateral turn. + for (const [x, z] of [[15, 31.5], [15, 33], [15, 34.5], [16.5, 33.5], [15, 33]]) { + await game.walk(x, z); + const position = game.local().position; + assert(Math.hypot(position[0] - x, position[2] - z) < .35); + // Compact movement positions use 1/8-metre X/Z coordinates. + let state; + const deadline = Date.now() + 3000; + do { + await game.snapshot(); + state = await server(); + evidence.currentWaypoint = {target: [x, z], native: game.local().position, server: state.position}; + assert(Date.now() < deadline, 'Server did not retain the reached waypoint'); + } while (Math.hypot(state.position[0] - position[0], state.position[2] - position[2]) >= .2); + evidence.waypoints.push({target: [x, z], native: position, server: state.position}); + delete evidence.currentWaypoint; + await game.save(output + '/waypoint-' + evidence.waypoints.length); + } + + // A blocked route must still fail, release forward input and allow recovery. + await assert.rejects(game.walk(15, 49), /Route is not approaching its destination/); + evidence.blocked = await server(); + assert(evidence.blocked.position[2] < 48.5); + await game.save(output + '/blocked'); + await game.walk(15, 43); + evidence.final = await server(); + assert.deepEqual(evidence.final.inventory, evidence.initial.inventory); + assert.deepEqual(game.errors, []); + console.log('PASS: fractional/integer approaches, real wall refusal and recovery at Run Speed ' + evidence.initial.speed); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + if (game) await game.save(output + '/final'); + } finally { await browser.close(); } +}