castle-web-cli 0.4.229 → 0.4.231
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/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +860 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +126 -9
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +99 -14
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +406 -53
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +158 -8
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +149 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1035 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1518 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +117 -5
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +527 -5
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +187 -5
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Finding someone in a town (contract §5): a client asks where players are
|
|
2
|
+
// (`hub-where`) and is told each one's spot and the place's words for it --
|
|
3
|
+
// on a door's pad, near a door, what the place's `where` hook calls it --
|
|
4
|
+
// and Join puts a player beside another (`hub-goto`). A game answers neither,
|
|
5
|
+
// nothing crosses a block, and a held player stays put. `npm run check` runs
|
|
6
|
+
// it; it needs nothing installed.
|
|
7
|
+
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { register } from 'node:module';
|
|
10
|
+
|
|
11
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
12
|
+
register(
|
|
13
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
14
|
+
export async function resolve(specifier, context, next) {
|
|
15
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
|
|
16
|
+
return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
|
|
17
|
+
}
|
|
18
|
+
return next(specifier, context);
|
|
19
|
+
}
|
|
20
|
+
`)}`,
|
|
21
|
+
);
|
|
22
|
+
const { layer } = await import('../code/server/hub.js');
|
|
23
|
+
|
|
24
|
+
globalThis.__hubTestActors = [
|
|
25
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
26
|
+
{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
|
|
27
|
+
{ id: 'pad-race', components: { HubPad: { door: 'race', radius: 2 }, Transform: { x: -22, y: 0, z: 0 } } },
|
|
28
|
+
{ id: 'crate', components: { Solid: {}, Shape: { kind: 'box', width: 1, height: 2, depth: 1 }, Transform: { x: 11.6, y: 1, z: 10 } } },
|
|
29
|
+
];
|
|
30
|
+
const castleJson = {
|
|
31
|
+
server: { maxPlayers: 8 },
|
|
32
|
+
hub: {
|
|
33
|
+
contract: 1,
|
|
34
|
+
title: 'Town',
|
|
35
|
+
places: {
|
|
36
|
+
race: {
|
|
37
|
+
title: 'Foot Race',
|
|
38
|
+
scene: 'scenes/race.scene',
|
|
39
|
+
result: { outcomes: ['win', 'lose'], score: { unit: 'ms', better: 'lower', min: 0, max: 600000 } },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
45
|
+
const PLAYERS = [
|
|
46
|
+
{ playerId: 'p1', userId: '101', username: 'ada' },
|
|
47
|
+
{ playerId: 'p2', userId: '102', username: 'bo' },
|
|
48
|
+
{ playerId: 'p3', userId: '103', username: 'cy' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
function boot({ sessionId = 'dev:test', hooks = {}, hiddenPair = null } = {}) {
|
|
52
|
+
let ctx = null;
|
|
53
|
+
const h = layer(castleJson, { ...hooks, ready: (hub) => (ctx = hub) }, {}, sceneExists);
|
|
54
|
+
const sent = [];
|
|
55
|
+
const session = {
|
|
56
|
+
sessionId,
|
|
57
|
+
players: PLAYERS,
|
|
58
|
+
send: (playerId, msg) => sent.push([playerId, msg]),
|
|
59
|
+
broadcast() {},
|
|
60
|
+
...(hiddenPair
|
|
61
|
+
? {
|
|
62
|
+
hub: {
|
|
63
|
+
place: 'main',
|
|
64
|
+
arrival: () => null,
|
|
65
|
+
readResults: async () => ({ players: {}, boards: {} }),
|
|
66
|
+
updatePad: async () => ({ status: 'gathering', members: [] }),
|
|
67
|
+
reportResult: async () => ({ recorded: false }),
|
|
68
|
+
hiddenPair,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
};
|
|
73
|
+
h.sceneFor(session);
|
|
74
|
+
const players = new Map();
|
|
75
|
+
for (const { playerId } of PLAYERS) {
|
|
76
|
+
players.set(playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
77
|
+
}
|
|
78
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
79
|
+
h.ready(world);
|
|
80
|
+
for (const { playerId } of PLAYERS) {
|
|
81
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 0 });
|
|
82
|
+
}
|
|
83
|
+
// Everyone arrives once the group wait has passed.
|
|
84
|
+
const realNow = Date.now;
|
|
85
|
+
Date.now = () => realNow() + 5000;
|
|
86
|
+
h.place(world, []);
|
|
87
|
+
Date.now = realNow;
|
|
88
|
+
sent.length = 0;
|
|
89
|
+
return { h, session, world, sent, ctx: () => ctx };
|
|
90
|
+
}
|
|
91
|
+
const at = (b, playerId) => b.world.players.get(playerId).at;
|
|
92
|
+
const put = (b, playerId, x, z) => Object.assign(at(b, playerId), { x, z });
|
|
93
|
+
const whereOf = (b) => b.sent.filter(([, msg]) => msg.k === 'hub-where').at(-1);
|
|
94
|
+
|
|
95
|
+
let n = 0;
|
|
96
|
+
|
|
97
|
+
// Where: on a pad, the place's own words, near a door, or nothing.
|
|
98
|
+
{
|
|
99
|
+
const b = boot({ hooks: { where: (hub, spot) => (spot.x > 5 ? 'Lucky Lane' : null) } });
|
|
100
|
+
put(b, 'p2', -21, 0.5);
|
|
101
|
+
put(b, 'p3', 9, 9);
|
|
102
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2', 'p3', 'p1', 'nobody', 7] });
|
|
103
|
+
const [to, msg] = whereOf(b);
|
|
104
|
+
assert.equal(to, 'p1');
|
|
105
|
+
assert.deepEqual(msg.at, {
|
|
106
|
+
p2: { x: -21, z: 0.5, where: 'on the Foot Race pad', door: 'race', on: true },
|
|
107
|
+
p3: { x: 9, z: 9, where: 'Lucky Lane', door: null },
|
|
108
|
+
});
|
|
109
|
+
n += 1;
|
|
110
|
+
|
|
111
|
+
// Asked again at once: no second answer.
|
|
112
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2'] });
|
|
113
|
+
assert.equal(b.sent.filter(([, m]) => m.k === 'hub-where').length, 1);
|
|
114
|
+
n += 1;
|
|
115
|
+
|
|
116
|
+
// Near a door, and nowhere in particular.
|
|
117
|
+
put(b, 'p2', -24, 4);
|
|
118
|
+
put(b, 'p3', 0, 3);
|
|
119
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-where', ids: ['p3'] });
|
|
120
|
+
assert.deepEqual(whereOf(b)[1].at, { p3: { x: 0, z: 3, where: null, door: null } });
|
|
121
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-where', ids: ['p2'] });
|
|
122
|
+
assert.deepEqual(whereOf(b)[1].at, { p2: { x: -24, z: 4, where: 'near Foot Race', door: 'race' } });
|
|
123
|
+
n += 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Join never puts a player on a door's pad, nor at its edge (a pad takes
|
|
127
|
+
// whoever stands on it into its game), even beside a friend standing on one.
|
|
128
|
+
{
|
|
129
|
+
const b = boot();
|
|
130
|
+
put(b, 'p2', -25.5, 0);
|
|
131
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
132
|
+
// To p2's right (x + 1.6) is on the Foot Race pad: the other side.
|
|
133
|
+
assert.ok(Math.abs(at(b, 'p1').x - -27.1) < 1e-9, `off the pad: ${JSON.stringify(at(b, 'p1'))}`);
|
|
134
|
+
// Just off the pad's edge (x -24): they are not on it, so neither is the joiner.
|
|
135
|
+
const c = boot();
|
|
136
|
+
put(c, 'p2', -24.2, 0);
|
|
137
|
+
c.h.message(c.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
138
|
+
assert.ok(Math.abs(at(c, 'p1').x - -25.8) < 1e-9, `off the pad: ${JSON.stringify(at(c, 'p1'))}`);
|
|
139
|
+
put(b, 'p2', -22, 0);
|
|
140
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'p2' });
|
|
141
|
+
// On the pad themselves (v1.19): just off its edge, facing them, never on it.
|
|
142
|
+
assert.ok(Math.abs(at(b, 'p3').x - -18.8) < 1e-9 && Math.abs(at(b, 'p3').z) < 1e-9, `off their pad: ${JSON.stringify(at(b, 'p3'))}`);
|
|
143
|
+
assert.ok(Math.abs(b.world.players.get('p3').facing - -Math.PI / 2) < 1e-9, 'facing them');
|
|
144
|
+
n += 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
{
|
|
148
|
+
const b = boot();
|
|
149
|
+
put(b, 'p2', 10, 10);
|
|
150
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
151
|
+
const me = b.world.players.get('p1');
|
|
152
|
+
// The first spot (to p2's right, x + 1.6) is inside the crate: the next one.
|
|
153
|
+
assert.ok(Math.abs(me.at.x - 8.4) < 1e-9 && Math.abs(me.at.z - 10) < 1e-9, `beside: ${JSON.stringify(me.at)}`);
|
|
154
|
+
assert.ok(Math.abs(me.facing - Math.PI / 2) < 1e-9, 'faces them');
|
|
155
|
+
assert.equal(me.clamped, true);
|
|
156
|
+
assert.deepEqual(b.sent.at(-1), ['p1', { k: 'hub-jumped', facing: me.facing, to: 'p2' }]);
|
|
157
|
+
n += 1;
|
|
158
|
+
|
|
159
|
+
// A second jump within a second, a jump to oneself or to nobody: ignored.
|
|
160
|
+
put(b, 'p3', -10, -10);
|
|
161
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p3' });
|
|
162
|
+
assert.ok(Math.abs(me.at.x - 8.4) < 1e-9, 'still beside p2');
|
|
163
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'p3' });
|
|
164
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'ghost' });
|
|
165
|
+
assert.deepEqual([at(b, 'p3').x, at(b, 'p3').z], [-10, -10]);
|
|
166
|
+
n += 1;
|
|
167
|
+
|
|
168
|
+
// A held player stays where the place holds them.
|
|
169
|
+
b.ctx().hold('p3', { x: -10, y: 1, z: -10 });
|
|
170
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'p2' });
|
|
171
|
+
assert.deepEqual([at(b, 'p3').x, at(b, 'p3').z], [-10, -10]);
|
|
172
|
+
n += 1;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// A block hides both ways: no answer about, and no jump to, a hidden player.
|
|
176
|
+
{
|
|
177
|
+
const b = boot({ hiddenPair: (a, c) => [a, c].sort().join() === 'p1,p2' });
|
|
178
|
+
put(b, 'p2', 10, 10);
|
|
179
|
+
put(b, 'p3', 5, 5);
|
|
180
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2', 'p3'] });
|
|
181
|
+
assert.deepEqual(Object.keys(whereOf(b)[1].at), ['p3']);
|
|
182
|
+
put(b, 'p1', 0, 0);
|
|
183
|
+
// A held caller (a sitter is one) is not let go by a jump at a blocked
|
|
184
|
+
// player, any more than by one at nobody: the block shows nothing.
|
|
185
|
+
b.ctx().hold('p1', { x: 0, y: 1, z: 0 });
|
|
186
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
187
|
+
assert.deepEqual([at(b, 'p1').x, at(b, 'p1').z], [0, 0]);
|
|
188
|
+
n += 1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Whoever stays is told who went through which door.
|
|
192
|
+
{
|
|
193
|
+
const b = boot();
|
|
194
|
+
b.ctx().go('race', ['p1']);
|
|
195
|
+
const went = b.sent.filter(([, msg]) => msg.k === 'hub-went');
|
|
196
|
+
assert.deepEqual(went, [
|
|
197
|
+
['p2', { k: 'hub-went', players: ['p1'], door: 'race' }],
|
|
198
|
+
['p3', { k: 'hub-went', players: ['p1'], door: 'race' }],
|
|
199
|
+
]);
|
|
200
|
+
n += 1;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// A game answers neither.
|
|
204
|
+
{
|
|
205
|
+
const b = boot({ sessionId: 'dev:hub.race.abc123' });
|
|
206
|
+
put(b, 'p2', 10, 10);
|
|
207
|
+
put(b, 'p1', 0, 0);
|
|
208
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2'] });
|
|
209
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
210
|
+
assert.equal(whereOf(b), undefined);
|
|
211
|
+
assert.deepEqual([at(b, 'p1').x, at(b, 'p1').z], [0, 0]);
|
|
212
|
+
n += 1;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
console.log(`test-together: ${n} passed`);
|
|
@@ -7,26 +7,26 @@
|
|
|
7
7
|
"imports": {
|
|
8
8
|
"castle.real-time": {
|
|
9
9
|
"deckId": "xFVr-afOLuUQ",
|
|
10
|
-
"version": "2026-
|
|
10
|
+
"version": "2026-10-03T11:33:47.833Z"
|
|
11
11
|
},
|
|
12
12
|
"castle.physics-3d": {
|
|
13
13
|
"deckId": "JH0SclbPVP0y",
|
|
14
|
-
"version": "2026-
|
|
14
|
+
"version": "2026-10-03T09:17:32.572Z"
|
|
15
15
|
},
|
|
16
16
|
"castle.physics-2d": {
|
|
17
17
|
"deckId": "ckRZGFW4iPrx",
|
|
18
|
-
"version": "2026-
|
|
18
|
+
"version": "2026-10-03T04:25:18.207Z",
|
|
19
19
|
"via": "castle.physics-3d"
|
|
20
20
|
},
|
|
21
21
|
"castle.base": {
|
|
22
22
|
"deckId": "yRcmH4_aYllE",
|
|
23
|
-
"version": "2026-
|
|
23
|
+
"version": "2026-10-03T11:33:43.975Z"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"autoUpdateWhenImported": true,
|
|
27
27
|
"deckId": "ZwA_P_-VO-Qh",
|
|
28
28
|
"cardId": "bvRmCzyUpt_a",
|
|
29
|
-
"publishedVersion": "2026-
|
|
29
|
+
"publishedVersion": "2026-10-03T13:23:59.648Z",
|
|
30
30
|
"main": "main.jsx",
|
|
31
31
|
"server": {
|
|
32
32
|
"main": "code/server/index.js",
|
|
@@ -13,6 +13,13 @@ import { makeShapeMesh } from '@imports/castle.physics-3d/engine3d/materials.js'
|
|
|
13
13
|
// until it makes one.
|
|
14
14
|
const BLUEPRINT = 'blueprints/other-player.scene';
|
|
15
15
|
|
|
16
|
+
// How long a player the session starts or stops sending (a hub place's
|
|
17
|
+
// interest set) takes to grow in or shrink away, in seconds.
|
|
18
|
+
const FADE_SECONDS = 0.35;
|
|
19
|
+
// Where an entering actor waits for the frame its node is first drawn, so it
|
|
20
|
+
// is never drawn once at full size.
|
|
21
|
+
const SINK_Y = -1000;
|
|
22
|
+
|
|
16
23
|
function defaultBlueprint(scene) {
|
|
17
24
|
const files = scene.files ?? {};
|
|
18
25
|
if (files[BLUEPRINT]) {
|
|
@@ -28,9 +35,89 @@ export function makeAvatars() {
|
|
|
28
35
|
return {
|
|
29
36
|
actors: new Map(), // playerId -> actor id
|
|
30
37
|
tags: new Map(), // playerId, or 'self', -> name tag
|
|
38
|
+
// Players the session started or stopped sending (`enter`, `retire`):
|
|
39
|
+
// playerId -> how far grown, 0..1, and playerId -> { actorId, grown }
|
|
40
|
+
// for a shrinking actor no longer in `actors`.
|
|
41
|
+
entering: new Map(),
|
|
42
|
+
leaving: new Map(),
|
|
43
|
+
// Actor ids `animate` despawned after a `retire`: the client's own, not
|
|
44
|
+
// scene actors, so the frame that sees them gone does not report them.
|
|
45
|
+
retired: new Set(),
|
|
31
46
|
};
|
|
32
47
|
}
|
|
33
48
|
|
|
49
|
+
// The session started sending this player (a hub place's interest set): its
|
|
50
|
+
// actor grows in rather than appearing at full size. One still shrinking away
|
|
51
|
+
// turns around where it is.
|
|
52
|
+
export function enter(avatars, playerId) {
|
|
53
|
+
const leaving = avatars.leaving.get(playerId);
|
|
54
|
+
if (leaving) {
|
|
55
|
+
avatars.leaving.delete(playerId);
|
|
56
|
+
avatars.actors.set(playerId, leaving.actorId);
|
|
57
|
+
avatars.entering.set(playerId, leaving.grown);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
avatars.entering.set(playerId, 0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The session stopped sending this player: its label goes now and its actor
|
|
64
|
+
// shrinks away where it stands, then is despawned (`animate`).
|
|
65
|
+
export function retire(avatars, scene, playerId) {
|
|
66
|
+
const actorId = avatars.actors.get(playerId);
|
|
67
|
+
const earlier = avatars.leaving.get(playerId);
|
|
68
|
+
if (earlier && earlier.actorId !== actorId && scene.getActor(earlier.actorId)) {
|
|
69
|
+
avatars.retired.add(earlier.actorId);
|
|
70
|
+
scene.despawnActor(earlier.actorId);
|
|
71
|
+
}
|
|
72
|
+
dropTag(avatars, scene, playerId);
|
|
73
|
+
avatars.actors.delete(playerId);
|
|
74
|
+
const grown = avatars.entering.get(playerId) ?? 1;
|
|
75
|
+
avatars.entering.delete(playerId);
|
|
76
|
+
if (actorId && scene.getActor(actorId)) {
|
|
77
|
+
avatars.leaving.set(playerId, { actorId, grown });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Grow entering actors and shrink leaving ones by one frame. A deck that never
|
|
82
|
+
// calls `enter` or `retire` has nothing here.
|
|
83
|
+
export function animate(avatars, scene, dt) {
|
|
84
|
+
const step = dt / FADE_SECONDS;
|
|
85
|
+
for (const [playerId, grown] of avatars.entering) {
|
|
86
|
+
const actorId = avatars.actors.get(playerId);
|
|
87
|
+
const actor = actorId && scene.getActor(actorId);
|
|
88
|
+
if (!actor) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const node = scene.three?.nodes?.get(actorId)?.node;
|
|
92
|
+
if (!node) {
|
|
93
|
+
actor.components.Transform.y += SINK_Y;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const next = Math.min(1, grown + step);
|
|
97
|
+
node.scale.setScalar(Math.max(0.001, ease(next)));
|
|
98
|
+
if (next >= 1) {
|
|
99
|
+
avatars.entering.delete(playerId);
|
|
100
|
+
} else {
|
|
101
|
+
avatars.entering.set(playerId, next);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const [playerId, entry] of avatars.leaving) {
|
|
105
|
+
const node = scene.three?.nodes?.get(entry.actorId)?.node;
|
|
106
|
+
entry.grown -= step;
|
|
107
|
+
if (entry.grown <= 0 || !node || !scene.getActor(entry.actorId)) {
|
|
108
|
+
avatars.retired.add(entry.actorId);
|
|
109
|
+
scene.despawnActor(entry.actorId);
|
|
110
|
+
avatars.leaving.delete(playerId);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
node.scale.setScalar(Math.max(0.001, ease(entry.grown)));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function ease(t) {
|
|
118
|
+
return t * t * (3 - 2 * t);
|
|
119
|
+
}
|
|
120
|
+
|
|
34
121
|
// Create or update one other player and return its engine actor. A deck can
|
|
35
122
|
// modify the returned actor after the kit applies the network pose.
|
|
36
123
|
//
|
|
@@ -47,7 +134,8 @@ export function showPlayer(avatars, scene, playerId, username, pose, options = {
|
|
|
47
134
|
// The engine Transform is the client-visible pose for the other player's actor.
|
|
48
135
|
applyPose(actor.components.Transform, pose);
|
|
49
136
|
const transform = actor.components.Transform;
|
|
50
|
-
|
|
137
|
+
// A label appears once its actor has grown in.
|
|
138
|
+
if (username === null || avatars.entering.has(playerId)) {
|
|
51
139
|
dropTag(avatars, scene, playerId);
|
|
52
140
|
} else {
|
|
53
141
|
showTag(avatars, scene, playerId, username, transform, options.tagHeight);
|
|
@@ -77,6 +165,7 @@ export function dropMissing(avatars, scene, present) {
|
|
|
77
165
|
}
|
|
78
166
|
scene.despawnActor(avatars.actors.get(playerId));
|
|
79
167
|
avatars.actors.delete(playerId);
|
|
168
|
+
avatars.entering.delete(playerId);
|
|
80
169
|
dropTag(avatars, scene, playerId);
|
|
81
170
|
}
|
|
82
171
|
}
|
|
@@ -86,6 +175,17 @@ export function dropMissing(avatars, scene, present) {
|
|
|
86
175
|
// explicit disposal.
|
|
87
176
|
export function clearAvatars(avatars, scene) {
|
|
88
177
|
avatars.actors.clear();
|
|
178
|
+
avatars.entering.clear();
|
|
179
|
+
// A reset that is not a scene load (a closed connection, `switchSession`)
|
|
180
|
+
// leaves shrinking actors in the scene; nothing would despawn them later.
|
|
181
|
+
// The reset also forgets which actors were seen, so none is reported.
|
|
182
|
+
for (const { actorId } of avatars.leaving.values()) {
|
|
183
|
+
if (scene.getActor(actorId)) {
|
|
184
|
+
scene.despawnActor(actorId);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
avatars.leaving.clear();
|
|
188
|
+
avatars.retired.clear();
|
|
89
189
|
for (const key of [...avatars.tags.keys()]) {
|
|
90
190
|
dropTag(avatars, scene, key);
|
|
91
191
|
}
|
|
@@ -88,7 +88,10 @@ export function setPose(sim, playerId, message) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// Combine elapsed-time movement allowance with fixed delivery slack.
|
|
91
|
-
|
|
91
|
+
// A place may let one player move faster than the rest (the hub's
|
|
92
|
+
// `hub.tune`); everyone else keeps the deck's limit.
|
|
93
|
+
const maxSpeed = Number.isFinite(player.maxSpeed) ? player.maxSpeed : Limits.MAX_SPEED;
|
|
94
|
+
const reach = maxSpeed * earned(sim, player.movedAt) + Limits.MOVE_SLACK;
|
|
92
95
|
player.movedAt = sim.timeMs;
|
|
93
96
|
const step = {
|
|
94
97
|
x: asked.x - player.at.x,
|
|
@@ -6,8 +6,11 @@ import { componentDefaults } from '@imports/castle.real-time/code/server/gameHoo
|
|
|
6
6
|
|
|
7
7
|
// Root-anchored globs select files from the importing deck. Eager raw imports
|
|
8
8
|
// embed the text in the server bundle, whose runtime has no deck filesystem.
|
|
9
|
-
// Globbing also permits this kit's own package to omit a main scene.
|
|
10
|
-
|
|
9
|
+
// Globbing also permits this kit's own package to omit a main scene. Every
|
|
10
|
+
// scene is embedded, not only the main one, because a deck whose server takes
|
|
11
|
+
// its scene from the client (`sceneFromClient`) runs a different one in each
|
|
12
|
+
// session.
|
|
13
|
+
const sceneTexts = import.meta.glob('/scenes/*.scene', {
|
|
11
14
|
eager: true,
|
|
12
15
|
query: '?raw',
|
|
13
16
|
import: 'default',
|
|
@@ -40,10 +43,21 @@ const DEFAULTS = {
|
|
|
40
43
|
...componentDefaults,
|
|
41
44
|
};
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const MAIN_SCENE = 'scenes/main.scene';
|
|
47
|
+
|
|
48
|
+
// The deck scene a session should build: the one named, when the deck has it,
|
|
49
|
+
// else the main scene.
|
|
50
|
+
export function resolveScenePath(scenePath) {
|
|
51
|
+
return typeof scenePath === 'string' && sceneTexts[`/${scenePath}`] !== undefined
|
|
52
|
+
? scenePath
|
|
53
|
+
: MAIN_SCENE;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Parse one of the deck's scenes (the main one by default) and return actor ids
|
|
57
|
+
// with resolved components. `world.createSimulation` consumes this reduced
|
|
58
|
+
// representation at startup.
|
|
59
|
+
export function readScene(scenePath = MAIN_SCENE) {
|
|
60
|
+
const text = sceneTexts[`/${resolveScenePath(scenePath)}`];
|
|
47
61
|
|
|
48
62
|
// An empty actor list lets this kit bundle independently without a deck scene.
|
|
49
63
|
if (!text) {
|
|
@@ -59,6 +73,13 @@ export function readScene() {
|
|
|
59
73
|
}));
|
|
60
74
|
}
|
|
61
75
|
|
|
76
|
+
// The scene file's own `ground` setting (`{ none: true }` for a scene with no
|
|
77
|
+
// ground), or null.
|
|
78
|
+
export function sceneGround(scenePath = MAIN_SCENE) {
|
|
79
|
+
const text = sceneTexts[`/${resolveScenePath(scenePath)}`];
|
|
80
|
+
return text ? (JSON.parse(text).ground ?? null) : null;
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
// Shallow-merge each component in engine precedence order: defaults, blueprint,
|
|
63
84
|
// then scene instance values.
|
|
64
85
|
function resolveComponents(actor) {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
clamp,
|
|
11
11
|
number,
|
|
12
12
|
} from '@imports/castle.real-time/code/server/limits.js';
|
|
13
|
-
import { readScene } from './sceneBodies.js';
|
|
13
|
+
import { readScene, resolveScenePath, sceneGround } from './sceneBodies.js';
|
|
14
14
|
import * as Limits from './limits.js';
|
|
15
15
|
|
|
16
16
|
const DEG = Math.PI / 180;
|
|
@@ -26,6 +26,7 @@ const DEG = Math.PI / 180;
|
|
|
26
26
|
// staleReports how many owner reports were dropped for an old epoch
|
|
27
27
|
// doors [{ body, props, baseY, openT }]
|
|
28
28
|
// players playerId -> { body, at, facing, clamped, movedAt }
|
|
29
|
+
// scenePath the deck scene this session simulates
|
|
29
30
|
// spawn where players come in
|
|
30
31
|
// template the scene's own player actor, for its shape
|
|
31
32
|
// acc seconds not yet turned into whole physics steps
|
|
@@ -49,24 +50,32 @@ function emptySim() {
|
|
|
49
50
|
|
|
50
51
|
// Initialize Rapier and return the complete simulation consumed by server hooks.
|
|
51
52
|
// Scene bodies and the server-added ground exist before the promise resolves.
|
|
52
|
-
|
|
53
|
+
//
|
|
54
|
+
// `scenePath` picks one of the deck's scenes; anything the deck does not have
|
|
55
|
+
// builds its main scene.
|
|
56
|
+
export async function createSimulation(scenePath) {
|
|
53
57
|
await RAPIER.init();
|
|
54
58
|
const sim = emptySim();
|
|
59
|
+
sim.scenePath = resolveScenePath(scenePath);
|
|
55
60
|
buildGround(sim);
|
|
56
61
|
buildScene(sim);
|
|
57
62
|
return sim;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
// Add the server's 200 m square ground slab below the authored scene
|
|
65
|
+
// Add the server's 200 m square ground slab below the authored scene, unless
|
|
66
|
+
// the scene has none (`"ground": { "none": true }`, as the engine reads it).
|
|
61
67
|
// `Limits.FELL_OUT_Y` handles dynamic bodies that fall beyond its edge.
|
|
62
68
|
function buildGround(sim) {
|
|
69
|
+
if (sceneGround(sim.scenePath)?.none === true) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
63
72
|
const ground = sim.world.createRigidBody(RAPIER.RigidBodyDesc.fixed().setTranslation(0, -0.5, 0));
|
|
64
73
|
sim.world.createCollider(RAPIER.ColliderDesc.cuboid(100, 0.5, 100), ground);
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
// Create Rapier bodies and indexes from the reduced scene representation.
|
|
68
77
|
function buildScene(sim) {
|
|
69
|
-
for (const actor of readScene()) {
|
|
78
|
+
for (const actor of readScene(sim.scenePath)) {
|
|
70
79
|
const {
|
|
71
80
|
Transform: t,
|
|
72
81
|
Shape: shape,
|
|
@@ -258,11 +267,15 @@ function keepObjectsSane(sim) {
|
|
|
258
267
|
}
|
|
259
268
|
|
|
260
269
|
// Limit velocities imparted by server-side player capsules; the constant's
|
|
261
|
-
// declaration documents why the cap remains below walking speed.
|
|
270
|
+
// declaration documents why the cap remains below walking speed. A game
|
|
271
|
+
// may give one object its own cap for a while (`speedCap`: the hub kit's
|
|
272
|
+
// thrown objects fly at the place's throw speed), still enforced after
|
|
273
|
+
// every step.
|
|
262
274
|
const v = entry.body.linvel();
|
|
263
275
|
const speed = Math.hypot(v.x, v.y, v.z);
|
|
264
|
-
|
|
265
|
-
|
|
276
|
+
const cap = Number.isFinite(entry.speedCap) ? entry.speedCap : Limits.MAX_PUSHED_SPEED;
|
|
277
|
+
if (speed > cap) {
|
|
278
|
+
const scale = cap / speed;
|
|
266
279
|
entry.body.setLinvel({ x: v.x * scale, y: v.y * scale, z: v.z * scale }, true);
|
|
267
280
|
}
|
|
268
281
|
}
|