PROCITY/web/js/citizens/keepers.js
m3ultra 293a82c5e8 R42 THE LOOK: five lane-runs — the pub is dressed, the decks read, and the town is cast
John looked at R41's proof shots and named three faults. All three are fixed, at zero draw
cost, and every lane corrected somebody's numbers on the way — including its own.

E-LOOK (§42.1+§42.2a) — THE PREMISE WAS WRONG. "The pub props have no texture" (my brief,
quoting E's own R41 note) is false: all 37 carry COLOR_0 and three.js renders it. The colour
was BLEACHED — jukebox at saturation 0.02, 15 assets under 0.05; what the source library
called colour was baked AO. So the fix was a palette imposed on colour already present, in
place: 46 assets, draw delta +0 and tri delta +0 on every one, proved the honest way — the
concatenated POSITION/NORMAL/TEXCOORD/index bytes are sha1-identical to R41, so footprints
and origins provably did not move. (A first-pass bbox check ignored node rotations and
"found" 3 phantom violations; thrown out for the byte comparison.) The banquette was 1990s
office teal and went burgundy; the beer umbrella was white and went brewery green.
THE DECK, diagnosed before being touched: 7 greys, chassis 0.05 luminance on a 0.033 bench =
1.21:1, and the one high-contrast feature was INSIDE-OUT (white ring around a dark disc; a
turntable is a dark record on a light platter). Now Technics silver at 6.74:1, black vinyl,
red start/stop. Node contract re-read from the shipped GLB: 4/4 + 1/1 PASS. Filed to R43,
not fixed: deck_1200_rigged has NO PLINTH (bottom 43mm of 119mm lost to R41 join damage).

E-CAST (§42.3) — 19 of 24 ship. Rejected: comical_luchador_01 (Mixamo Ch43, purple mask
reading EL CHUPACABRA, identified from the file's own material name), a 3-heads-tall cartoon
child, a robed wuxia elder, a WW2 infantryman — and dj_phrtt_01, AN UNCLOTHED BODY whose only
texture is a bare-skin atlas, which was in the DEFAULT crowd and live on the depot. It is the
R41 deny-list's failure class through a different door: an innocent name from another
pipeline. Only rendering all 24 and LOOKING found it.
Ruling 2 (prefer CC0) was REFUSED ON MEASUREMENT: Quaternius is 25 nodes / 23 joints and ZERO
of 64 canonical tracks bind — it would have loaded silently and never animated. Replacements
came from Mixamo's Ch## pool, filtered to the contract-clean 65-bone family (candidates ran
65..99 bones; named characters carry facial/hair bones).
THE LICENCE GAP WAS UNREAD, NOT MISSING: every source FBX carries ApplicationVendor "Mixamo,
Inc." internally. Adobe royalty-free, no attribution owed. B's amber rows are now real.

B (§42.5) — MY ASSIGNED FIX WAS USELESS AND B PROVED IT. document.fonts.ready shipped, then
measured: the atlas canvases are already byte-identical across boots, the game ships NO
webfonts (document.fonts.size === 0), and ready fires 50ms BEFORE the first fillText. The
real cause of unreproducible bookmarks is the wall-clock CROWD — 983 changed px of 921,600,
ALL in the pedestrian band; 0 px with the crowd out. New DBG.freeze() takes stable bookmarks
2/5 -> 5/5. Also found: ?pop=0 boots 140 citizens (0 is falsy against the default).
THE BENCH: D's filing correct on both counts. Front-vs-road 90.0deg -> 0.0deg, min=med=max
over 60/60 instances; the streetlight arm now reaches 1.05m over the road where it reached
0.00. Both used a base yaw that pointed +Z down the street while their own comments claimed
otherwise — the side term was already right, which is why it survived 41 rounds of reading.
Also: on any box with CDN access 9 of 60 benches are the depot GLB, 90deg out from the house
law — normalised at the geometry, once, at load. benchStops(plan) exported as one truth.

C (§42.2b) — 122 vs 123 WAS THE CAMERA ASPECT, and nobody was wrong. Draw counts are
post-frustum-cull and the sweep camera inherits the window aspect: 1.25->116, 1.60->122 (C's
harness), 1.778->123 (F's), 2.37->124. Pinned MEASURE_ASPECT=16/9 with a 1.25 control.
E's "keep the bench dark" advice was measured and declined with reason (deck-vs-bench was
already 4.73:1, over threshold). "Reads as a black box" is a claim about pixels, so C measured
pixels: near-black in the booth crop 57.5% -> 26.7%, distinct colours 228 -> 389. Bench
rebuilt 3->7 boxes with an open record bay; headphones on the mixer; faceDoor aims booths at
the player's entry — alignment within 45deg went 49% -> 92%. Two bugs found by looking: a
fitting could be planted INSIDE A WALL (0.77m of a 0.86m half-depth in plaster), and every
booth part sat 25mm sunk into its own worktop.

D (§42.4) — five swaps IN PLACE at the same index (pickRig indexes these arrays and pedIndex
is in the identity signature and the impostor atlas; removal would renumber the town).
Identity signature pre- vs post-swap: 0 differing lines of 150 — who each citizen is did not
move, only which body they wear. dj_phrtt_01 verified gone AT THE WIRE, not from source: a
fresh default boot fetches 32 ped GLBs, none retired.
THE CONTROL ARM FOUND A 41-ROUND-OLD BUG: the ped being RETIRED, comical_boy_01, binds only
3,132 of 3,460 tracks — six thumb bones lack the mixamorig prefix. It had been silently
dropping six tracks per clip since it shipped. Testing the thing being thrown away found it.
Imported B's benchStops mid-round: sitters now 0.0deg to the road, signatures byte-identical
across the rewire. Corrected F's filing: the browse smoke was flaky-by-construction (a 16-25s
race against a live sim), not deterministically red.

F (§42.6) — qa.sh --strict 24 passed / 0 failed / 0 warn / 0 skipped. New Gate 11: period law
(0/5 banned; CONTROL: R41's roster trips all five) and roster licence (24/24, 0 unverified;
CONTROL: an amber row turns 20 red). r41_shots.py promoted warn -> strict.
R41'S BYTE-HASH BAN IS REVERSED AND ITS STATED REASON WITHDRAWN AS WRONG. A gate may pin a
hash under five in-run assertions (classic+flags boot, freeze().stillLive all-false, a second
freeze removing 0 draws, settle until DBG.info() stops changing, hash with the dbg panel
hidden): 5/5 bookmarks now pin to one sha256 over 3 fresh boots. Two findings got it there —
the chunk streamer (a fixed settle is a bet on load) and the fps readout, which with
everything else frozen was the last thing moving at 53-62 px.
?pop=0 fixed (Number.isFinite) — a no-op for 35 rounds. Three red flags_check gates fixed.

Street: noon 282 · NIGHT 291/300 — the nine-draw margin INTACT, every R41 row reproducing to
the digit. Interior at pinned 16:9: 123 @ dept/auto, margin 227. selfcheck 157,647/157,647,
0x5f76e76 unmoved. No tag — John's playtest rules the epoch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 23:49:49 +10:00

132 lines
7.8 KiB
JavaScript

// PROCITY Lane D — shopkeepers. One keeper per open shop, standing at the counter slot, playing a
// shared idle clip, turning to greet the player when they come near. Keepers are spawned when an
// interior builds and disposed with it (they don't share the street's rig pool — a handful at a time,
// each owns its actor).
//
// Coordination (Lane F wiring): Lane C exposes the counter position + facing in its interior `places`;
// pass it to spawn(). Until Lane C lands, the test page mocks a counter. Deterministic per shop:
// rng(citySeed,'keeper',shopId) picks the ped type + height so a shop's keeper is stable across visits.
import * as THREE from 'three';
import { rng } from '../core/prng.js';
import { pickRig, spawnRig } from './rigs.js';
import { makePlaceholder } from './placeholder.js';
import { browsePostureFor, keeperPostureFor, GROUP_OF } from './postures.js';
const GREET_RANGE = 6.0; // m — start turning to the player inside this
const GREET_CLAMP = 0.62; // rad — max turn off the counter-facing base (~35°)
const GREET_EASE = 3.5; // turn responsiveness
export class KeeperManager {
constructor({ camera = null, citySeed = 20261990, fleet = null } = {}) {
this.camera = camera;
this.citySeed = citySeed >>> 0;
this.fleet = fleet;
this.keepers = [];
this._p = new THREE.Vector3();
}
// spawn(target, { x, z, ry, shopId, type, browse, pedIndex, seedKey }) → keeper handle.
// ry = the counter's outward facing (keeper) / the browse point's shelf-facing yaw (browser).
// browse = R9 interior-presence: a browser rig at a C browse point — faces the goods, no greet.
// pedIndex = pick this exact fleet ped (so a browser IS the ped who ducked in off the street).
// seedKey = per-instance seeding key (e.g. `${shopId}#${slot}`) so browsers at one shop differ.
spawn(target, { x = 0, z = 0, ry = 0, shopId = 'shop', type = 'shop', browse = false, pedIndex = null, seedKey = null, slot = null } = {}) {
const r = rng(this.citySeed, browse ? 'browser' : 'keeper', seedKey || shopId);
const height = 1.58 + r() * 0.34;
// [R41 §41.3] A REAL BROWSE STATE. Until now a "browser" was a rig standing at Lane C's browse
// point playing the shopkeeper's idle. It now plays a browse clip — hold / carry / open the
// cabinet / pick the record up — seeded per (shopId, slot), NOT per visit, so the same shop reads
// the same way every time you walk back in. F already passes `seedKey = "<shopId>#<i>"`; the slot
// index is taken from it when the caller doesn't pass one, so no shell edit is needed.
// The keeper gets a seeded idle variant instead, or a trade flavour (the publican pours, the
// record-shop keeper wears the cans) — see postures.KEEPER_TYPE_CLIP.
const bank = this.fleet && this.fleet.bank;
const slotIdx = slot != null ? slot : (seedKey && /#(\d+)$/.test(seedKey) ? +/#(\d+)$/.exec(seedKey)[1] : 0);
const wantId = browse ? browsePostureFor(this.citySeed, shopId, slotIdx)
: keeperPostureFor(this.citySeed, shopId, type);
if (bank && wantId) bank.ensureGroup(GROUP_OF[wantId]); // first interior fetches browse.glb; a
// pub/record counter fetches venue.glb
let actor, kind, phase = 0;
// [R42 §42.4] which BODY this figure is wearing, published on the handle. Purely informational —
// it draws no randoms and changes no behaviour — but without it there is no way to audit a room's
// cast at runtime, which is exactly what the recast round needed to prove (band.js already
// publishes `pedIndex` on every crew member; keepers were the gap).
let pedIdx = null;
if (this.fleet && this.fleet.ready) {
// NB the `r()` draw order below is R9's, unchanged and deliberately so: height, then pickRig
// (only when the caller did NOT pin a pedIndex), then phase (only when a rig resolved). The
// R41 posture is drawn from its OWN stream above, so no keeper's ped type or height moves.
const idx = (pedIndex != null && this.fleet.all[pedIndex]) ? pedIndex : (pickRig(this.fleet, r()) || {}).index;
const rig = idx != null && this.fleet.all[idx];
const want = bank ? bank.get(wantId) : null; // resident already? use it at spawn
const spawned = rig && spawnRig(rig, { ry, height, clip: want || this.fleet.idleClip, phase: (phase = r()) });
if (spawned && want) spawned.setClip(want, { phase }); // re-plant off the posed skeleton
if (spawned) { actor = spawned; kind = 'rig'; pedIdx = idx; }
}
if (!actor) { // asset-free fallback
const ph = makePlaceholder(rng(this.citySeed, browse ? 'browser-body' : 'keeper-body', seedKey || shopId), { height });
ph.fig.rotation.y = ry;
actor = ph; kind = 'placeholder';
}
actor.fig.position.set(x, 0, z);
target.add(actor.fig);
// `want` is kept ONLY while the assigned clip is still unresolved — update() upgrades in place the
// frame its group lands and then clears it. That is what makes lazy loading safe here: the clip a
// browse point plays is decided by (citySeed, shopId, slot) at spawn, and the fetch only decides
// when it starts, never which. A boot with no bank leaves `want` null and nothing ever runs.
// Gated on `fleet.clipsRequested` (boot-stable), NOT on `bank` — a spawn that happens before the
// dynamic import resolves would otherwise silently lose its posture forever. update() kicks the
// group itself in that case, so the only thing timing decides is when the upgrade shows.
const wantsIt = kind === 'rig' && wantId && this.fleet && this.fleet.clipsRequested && !(bank && bank.has(wantId));
const k = { actor, kind, baseRy: ry, curTurn: 0, target, shopId, type, browse,
pedIndex: pedIdx, want: wantsIt ? wantId : null, phase };
this.keepers.push(k);
return k;
}
remove(k) {
if (!k) return;
const i = this.keepers.indexOf(k);
if (i >= 0) this.keepers.splice(i, 1);
k.target.remove(k.actor.fig);
k.actor.dispose?.();
}
disposeAll() { [...this.keepers].forEach(k => this.remove(k)); }
// update(dt, playerPos?) — tick idle animation + the greet head/body turn. playerPos defaults to
// the camera position (the player IS the camera in interior mode).
update(dt, playerPos = null) {
const pp = playerPos || (this.camera && this.camera.position) || null;
const bank = this.fleet && this.fleet.bank;
for (const k of this.keepers) {
const a = k.actor;
// [R41 §41.3] self-heal: the assigned clip's group finished fetching → install it now, once.
if (k.want && bank && a.setClip) {
const c = bank.get(k.want);
if (c) { a.setClip(c, { phase: k.phase }); k.want = null; }
else bank.ensureGroup(GROUP_OF[k.want]); // spawned before the bank existed → kick it now
}
if (a.mixer) a.mixer.update(dt); // rig idle
else a.tick?.(dt, false); // placeholder idle
if (k.browse) continue; // browsers face the goods (ry) — no greet turn
if (pp) {
const dx = pp.x - a.fig.position.x, dz = pp.z - a.fig.position.z;
const dist = Math.hypot(dx, dz);
let want = 0;
if (dist < GREET_RANGE) {
// desired absolute facing toward the player, expressed relative to the counter base
const toPlayer = Math.atan2(-dx, -dz); // rig-front convention (local -Z)
let rel = toPlayer - k.baseRy;
rel = Math.atan2(Math.sin(rel), Math.cos(rel)); // wrap to -π..π
want = Math.max(-GREET_CLAMP, Math.min(GREET_CLAMP, rel));
}
k.curTurn += (want - k.curTurn) * Math.min(1, dt * GREET_EASE);
a.fig.rotation.y = k.baseRy + k.curTurn;
}
}
}
}