castle-web-cli 0.4.240 → 0.4.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +2 -0
- package/dist/platformDoc.js +1 -1
- package/dist/roomLogs.d.ts +1 -0
- package/dist/roomLogs.js +30 -6
- package/kits/hub-game/code/client/chrome.js +8 -4
- package/kits/hub-game/code/client/padCues.js +11 -7
- package/kits/hub-game/code/client/padReadability.js +3 -3
- package/kits/hub-game/code/server/hub.js +141 -28
- package/kits/hub-game/code/server/players.js +6 -1
- package/kits/hub-game/code/server/standing.js +7 -3
- package/kits/hub-game/code/systems/hub.js +2 -1
- package/kits/hub-game/docs/contract.md +14 -2
- package/kits/hub-game/scripts/test-ballot.mjs +1 -1
- package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +259 -6
- package/kits/hub-game/scripts/test-rehello.mjs +5 -3
- package/kits/hub-game/scripts/test-standing.mjs +135 -2
- package/kits/hub-game/scripts/test-stuck.mjs +5 -1
- package/kits/multiplayer-3d/castle.json +1 -1
- package/kits/multiplayer-3d/code/client/resumeGate.js +18 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +41 -7
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +226 -0
- package/kits/physics-3d/castle.json +1 -1
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
- package/kits/physics-3d/systems/physics3d.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Two players on exactly one spot (hub-game v1.218, Nov 17 Market check).
|
|
2
|
+
// Real Player + Physics3DSystem + the kit's vendored Rapier WASM, as
|
|
3
|
+
// test-wall-slide.mjs runs them: the local player (the hub player blueprint)
|
|
4
|
+
// and another player's avatar (a kinematic Solid capsule, as multiplayer-3d
|
|
5
|
+
// draws one) standing exactly where the local body stands.
|
|
6
|
+
//
|
|
7
|
+
// 1. Informational: while they stay coaxial the local body is wedged into
|
|
8
|
+
// the ground and cannot walk (the bug the server's step-off now
|
|
9
|
+
// prevents). Logged, not asserted: a physics change that frees a coaxial
|
|
10
|
+
// body is no failure.
|
|
11
|
+
// 2. The gap before the step-off reaches the joiner's client: its body sits
|
|
12
|
+
// under the other avatar for N frames, then the session's placement
|
|
13
|
+
// arrives, either in one step (multiplayer-3d `placedTo`) or as clamped
|
|
14
|
+
// rows eased a quarter of the way each (`clampedTo` under CLAMP_SNAP).
|
|
15
|
+
// After it the body walks at full pace.
|
|
16
|
+
// 3. The other side of the same gap: the first player stands still while
|
|
17
|
+
// the joiner's avatar is drawn on them, then slides to the stepped-off
|
|
18
|
+
// spot. The first player walks at full pace once it has gone.
|
|
19
|
+
//
|
|
20
|
+
// Run from any directory: node kits/physics-3d/scripts/test-coaxial-escape.mjs
|
|
21
|
+
import assert from 'node:assert/strict';
|
|
22
|
+
import { register } from 'node:module';
|
|
23
|
+
|
|
24
|
+
register('data:text/javascript,' + encodeURIComponent(`
|
|
25
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
export async function resolve(specifier, context, next) {
|
|
28
|
+
const parent = context.parentURL ?? '';
|
|
29
|
+
if (specifier.startsWith('@imports/castle.physics-2d/')) {
|
|
30
|
+
specifier = parent.replace(/\\/kits\\/.*/, '/kits/physics-2d/') + specifier.slice(27);
|
|
31
|
+
}
|
|
32
|
+
if ((specifier.startsWith('.') || specifier.startsWith('file:')) && parent.includes('/kits/') && !/\\.(m?js|jsx|json)$/.test(specifier)) {
|
|
33
|
+
const base = new URL(specifier, parent).href;
|
|
34
|
+
for (const ext of ['.js', '.jsx']) if (existsSync(fileURLToPath(base + ext))) return next(base + ext, context);
|
|
35
|
+
}
|
|
36
|
+
return next(specifier, context);
|
|
37
|
+
}
|
|
38
|
+
export async function load(url, context, next) {
|
|
39
|
+
if (url.endsWith('.jsx')) {
|
|
40
|
+
return { format: 'module', source: readFileSync(fileURLToPath(url), 'utf8'), shortCircuit: true };
|
|
41
|
+
}
|
|
42
|
+
return next(url, context);
|
|
43
|
+
}
|
|
44
|
+
`));
|
|
45
|
+
const { Player } = await import('../behaviors/Player.jsx');
|
|
46
|
+
const { Physics3DSystem } = await import('../systems/physics3d.js');
|
|
47
|
+
|
|
48
|
+
const DT = 1 / 60;
|
|
49
|
+
const SPAWN = { x: 0, z: 9 };
|
|
50
|
+
// The hub arrival row's step-off for the Town (face 180, spread 1.5).
|
|
51
|
+
const PLACED = { x: -1.5, z: 9 };
|
|
52
|
+
// One clamped row every other frame (a 30 Hz session), eased a quarter.
|
|
53
|
+
const ROW_FRAMES = 2;
|
|
54
|
+
const CLAMP_EASE = 0.25;
|
|
55
|
+
const SPEED = Player.defaultProps.speed;
|
|
56
|
+
const props = { ...Player.defaultProps };
|
|
57
|
+
const tf = (x, y, z) => ({ x, y, z, rotationX: 0, rotationY: 180, rotationZ: 0, scaleX: 1, scaleY: 1, scaleZ: 1 });
|
|
58
|
+
const flat = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
|
|
59
|
+
|
|
60
|
+
async function makeWorld() {
|
|
61
|
+
const me = { id: 'player', runtime: {}, components: {
|
|
62
|
+
Transform: tf(SPAWN.x, 1, SPAWN.z), Shape: { kind: 'capsule', radius: 0.35, height: 1.4 },
|
|
63
|
+
Body: { type: 'dynamic', lockRotations: true, friction: 0, restitution: 0, gravityScale: 2 }, Solid: {}, Player: { ...props },
|
|
64
|
+
} };
|
|
65
|
+
const system = new Physics3DSystem();
|
|
66
|
+
const scene = {
|
|
67
|
+
time: 0, keys: new Set(), persistent: { camAngle: Math.PI / 4 },
|
|
68
|
+
data: { ground: {}, engine: {} }, actors: [me], maxFps: 0, three: null, cameraControl: 'orbit',
|
|
69
|
+
getActors: () => scene.actors, getActor: (id) => scene.actors.find((a) => a.id === id),
|
|
70
|
+
actorsWith: () => [], forEachBehavior: () => {},
|
|
71
|
+
};
|
|
72
|
+
system.attach(scene);
|
|
73
|
+
const api = scene.physics3d;
|
|
74
|
+
for (let i = 0; i < 200 && !api.ready(); i += 1) {
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
76
|
+
system.afterBehaviors(scene, DT);
|
|
77
|
+
}
|
|
78
|
+
assert.ok(api.ready(), 'real Rapier initialized');
|
|
79
|
+
const body = () => system.bodies.get(me.id).body;
|
|
80
|
+
const frame = (walking) => {
|
|
81
|
+
scene.time += DT;
|
|
82
|
+
scene.keys = new Set(walking ? ['KeyW'] : []);
|
|
83
|
+
new Player(props).update(me, scene, DT);
|
|
84
|
+
system.afterBehaviors(scene, DT);
|
|
85
|
+
return { ...body().translation() };
|
|
86
|
+
};
|
|
87
|
+
let standing;
|
|
88
|
+
for (let i = 0; i < 180; i += 1) standing = frame(false);
|
|
89
|
+
// Body.defaultProps filled in, as the engine does for a blueprint's Body.
|
|
90
|
+
const avatar = { id: 'avatar', runtime: {}, components: {
|
|
91
|
+
Transform: tf(SPAWN.x, standing.y, SPAWN.z), Shape: { kind: 'capsule', radius: 0.35, height: 1.4 },
|
|
92
|
+
Body: { type: 'kinematic', friction: 0.6, restitution: 0, gravityScale: 0, lockRotations: true }, Solid: {},
|
|
93
|
+
} };
|
|
94
|
+
scene.actors.push(avatar);
|
|
95
|
+
// multiplayer-3d acceptClamp: a placement in one step, or an eased row.
|
|
96
|
+
const put = (to) => {
|
|
97
|
+
body().setTranslation(to, true);
|
|
98
|
+
Object.assign(me.components.Transform, to);
|
|
99
|
+
};
|
|
100
|
+
const place = (to) => { put(to); body().setLinvel({ x: 0, y: 0, z: 0 }, true); };
|
|
101
|
+
const ease = (to) => {
|
|
102
|
+
const at = body().translation();
|
|
103
|
+
put({ x: at.x + (to.x - at.x) * CLAMP_EASE, y: at.y + (to.y - at.y) * CLAMP_EASE, z: at.z + (to.z - at.z) * CLAMP_EASE });
|
|
104
|
+
};
|
|
105
|
+
return { me, avatar, standing, frame, place, ease, body, close: () => system.dispose(scene) };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Walk for a second; the distance covered over its last half.
|
|
109
|
+
function walkPace(w) {
|
|
110
|
+
let mid;
|
|
111
|
+
for (let i = 0; i < 60; i += 1) {
|
|
112
|
+
const p = w.frame(true);
|
|
113
|
+
if (i === 29) mid = p;
|
|
114
|
+
}
|
|
115
|
+
return flat(w.body().translation(), mid) / 0.5;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 1. Coaxial and staying so: wedged.
|
|
119
|
+
{
|
|
120
|
+
const w = await makeWorld();
|
|
121
|
+
for (let i = 0; i < 30; i += 1) w.frame(false);
|
|
122
|
+
const from = w.body().translation();
|
|
123
|
+
for (let i = 0; i < 120; i += 1) w.frame(true);
|
|
124
|
+
const moved = flat(w.body().translation(), from);
|
|
125
|
+
const sunk = w.standing.y - w.body().translation().y;
|
|
126
|
+
w.close();
|
|
127
|
+
console.log(`coaxial (informational): walked ${moved.toFixed(3)} m in 2 s, sunk ${sunk.toFixed(3)} m into the ground`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 2. The joiner: N frames under the avatar (walking or not), then the step-off.
|
|
131
|
+
const rows = [];
|
|
132
|
+
for (const how of ['place', 'ease']) {
|
|
133
|
+
for (const frames of [1, 6, 30, 120]) {
|
|
134
|
+
for (const walking of [false, true]) {
|
|
135
|
+
const w = await makeWorld();
|
|
136
|
+
for (let i = 0; i < frames; i += 1) w.frame(walking);
|
|
137
|
+
const target = { x: PLACED.x, y: w.standing.y, z: PLACED.z };
|
|
138
|
+
if (how === 'place') {
|
|
139
|
+
w.place(target);
|
|
140
|
+
w.frame(false);
|
|
141
|
+
} else {
|
|
142
|
+
// Rows keep coming until the body is near the spot (the server's
|
|
143
|
+
// settle ends at 0.25 m); the walk is held off meanwhile.
|
|
144
|
+
for (let i = 0; i < 120 && flat(w.body().translation(), target) > 0.25; i += 1) {
|
|
145
|
+
if (i % ROW_FRAMES === 0) w.ease(target);
|
|
146
|
+
w.frame(false);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const off = flat(w.body().translation(), target);
|
|
150
|
+
const y = w.body().translation().y;
|
|
151
|
+
const pace = walkPace(w);
|
|
152
|
+
w.close();
|
|
153
|
+
rows.push({ how, frames, walking, off: +off.toFixed(3), y: +y.toFixed(3), pace: +pace.toFixed(2) });
|
|
154
|
+
assert.ok(pace > SPEED * 0.9, `${how} after ${frames} frames (walking ${walking}): walks at ${pace} m/s`);
|
|
155
|
+
assert.ok(Math.abs(y - w.standing.y) < 0.05, `${how} after ${frames} frames: standing height ${y}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const row of rows) console.log(JSON.stringify(row));
|
|
160
|
+
|
|
161
|
+
// 3. The first player: the joiner's avatar drawn on them, then sliding away.
|
|
162
|
+
for (const frames of [6, 60]) {
|
|
163
|
+
const w = await makeWorld();
|
|
164
|
+
for (let i = 0; i < frames; i += 1) w.frame(false);
|
|
165
|
+
const t = w.avatar.components.Transform;
|
|
166
|
+
for (let i = 0; i < 20; i += 1) {
|
|
167
|
+
t.x += (PLACED.x - t.x) * 0.25;
|
|
168
|
+
w.frame(false);
|
|
169
|
+
}
|
|
170
|
+
const pace = walkPace(w);
|
|
171
|
+
const y = w.body().translation().y;
|
|
172
|
+
w.close();
|
|
173
|
+
console.log(`first player: avatar on them ${frames} frames then slid off; walks ${pace.toFixed(2)} m/s, y ${y.toFixed(3)}`);
|
|
174
|
+
assert.ok(pace > SPEED * 0.9, `first player walks once the avatar slid off (${pace} m/s)`);
|
|
175
|
+
}
|
|
176
|
+
console.log('test-coaxial-escape: free at full pace once the step-off or the avatar arrives');
|
|
@@ -838,6 +838,14 @@ function makeApi(system, runtime) {
|
|
|
838
838
|
}
|
|
839
839
|
return bodyOf(actor);
|
|
840
840
|
},
|
|
841
|
+
// After directly correcting a body's position, discard its pre-correction
|
|
842
|
+
// interpolation pose. Frames without a fixed step then draw the body
|
|
843
|
+
// where it was put; the next fixed step starts fresh history there.
|
|
844
|
+
resetInterpolation: (actor) => {
|
|
845
|
+
runtime.touch?.(actor);
|
|
846
|
+
const entry = system.bodies.get(idOf(actor));
|
|
847
|
+
if (entry) entry.prev = null;
|
|
848
|
+
},
|
|
841
849
|
mass: (actor) => bodyOf(actor)?.mass() ?? 0,
|
|
842
850
|
getVelocity: (actor) => {
|
|
843
851
|
const v = bodyOf(actor)?.linvel();
|