castle-web-cli 0.4.237 → 0.4.238
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/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +78 -9
- package/dist/castleJson.d.ts +2 -0
- package/dist/castleJson.js +1 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +5 -0
- package/dist/init.js +2 -1
- package/dist/save-deck.js +4 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +47 -0
- package/kits/base/sdk/castle.d.ts +3 -1
- package/kits/base/sdk/castle.js +1 -0
- package/kits/base/sdk/commands.d.ts +25 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +4 -1
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +207 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +154 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +3 -2
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +56 -6
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/hub.js +258 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +272 -84
- package/kits/hub-game/docs/analytics.md +11 -2
- package/kits/hub-game/docs/contract.md +352 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +99 -5
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +183 -0
- package/kits/hub-game/scripts/test-role-client.mjs +421 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// Checks a HubSceneManifest v1 (to v1.7) and the files it names. The format's spec lives with the
|
|
2
|
+
// native hub engine that loads it (castle-client, nativetown/hubscene/SPEC.md); this is the same
|
|
3
|
+
// validator, kept in step with it.
|
|
4
|
+
// node validate-manifest.mjs <root>/<hubId>/manifest.json [--no-hash]
|
|
5
|
+
// Exits 1 with one line per fault.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import crypto from 'node:crypto';
|
|
9
|
+
import { HATS } from '../../code/client/hats.js';
|
|
10
|
+
import { ROLE_TOPS, ROLE_TOOLS } from '../../code/client/role.js';
|
|
11
|
+
import { EARNED_SHAPES, EARNED_SHAPE_CLASS, SQUARE_SHAPES } from '../../code/client/earned.js';
|
|
12
|
+
|
|
13
|
+
export function validateManifest(m, dir, { hash = true } = {}) {
|
|
14
|
+
const faults = [];
|
|
15
|
+
const fault = (s) => faults.push(s);
|
|
16
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
17
|
+
const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
18
|
+
const vec = (v, n) => Array.isArray(v) && v.length === n && v.every(isNum);
|
|
19
|
+
const color = (v) => typeof v === 'string' && /^#[0-9a-fA-F]{6}$/.test(v);
|
|
20
|
+
if (!isObj(m)) return ['manifest is not an object'];
|
|
21
|
+
if (m.format !== 'castle.hubScene') fault(`format ${JSON.stringify(m.format)}`);
|
|
22
|
+
if (m.version !== 1) fault(`version ${m.version}`);
|
|
23
|
+
if (typeof m.hubId !== 'string' || !m.hubId) fault('no hubId');
|
|
24
|
+
if (typeof m.title !== 'string') fault('no title');
|
|
25
|
+
if (!isObj(m.source)) fault('no source');
|
|
26
|
+
|
|
27
|
+
const assets = isObj(m.assets) ? m.assets : (fault('no assets'), {});
|
|
28
|
+
const audioTypes = ['mp3', 'ogg', 'wav', 'm4a'];
|
|
29
|
+
const checkAsset = (id, a) => {
|
|
30
|
+
if (!isObj(a) || !['glb', 'png', 'webp', ...audioTypes].includes(a.type)) { fault(`asset ${id}: type ${a?.type}`); return; }
|
|
31
|
+
if (typeof a.sha256 !== 'string' || !/^[0-9a-f]{64}$/.test(a.sha256)) fault(`asset ${id}: sha256`);
|
|
32
|
+
if (typeof a.uri !== 'string') { fault(`asset ${id}: uri`); return; }
|
|
33
|
+
const file = path.resolve(dir, a.uri);
|
|
34
|
+
if (!fs.existsSync(file)) { fault(`asset ${id}: ${a.uri} missing`); return; }
|
|
35
|
+
if (!fs.statSync(file).isFile()) { fault(`asset ${id}: not a file`); return; }
|
|
36
|
+
const buf = fs.readFileSync(file);
|
|
37
|
+
if (a.bytes !== undefined && a.bytes !== buf.length) fault(`asset ${id}: bytes ${a.bytes} != ${buf.length}`);
|
|
38
|
+
if (hash && crypto.createHash('sha256').update(buf).digest('hex') !== a.sha256) fault(`asset ${id}: sha256 mismatch`);
|
|
39
|
+
if (a.type === 'glb' && (buf.length < 4 || buf.readUInt32LE(0) !== 0x46546c67)) fault(`asset ${id}: not a glb`);
|
|
40
|
+
};
|
|
41
|
+
for (const [id, a] of Object.entries(assets)) checkAsset(id, a);
|
|
42
|
+
|
|
43
|
+
// Additive v1.7: old manifests have none; if any block is present, all three are required.
|
|
44
|
+
if (['avatarFits', 'wearModels', 'wearPieces'].some((key) => Object.hasOwn(m, key))) {
|
|
45
|
+
const styles = ['toon', 'blocky', 'bean', 'pixel'];
|
|
46
|
+
if (!isObj(m.avatarFits)) fault('avatarFits is not an object');
|
|
47
|
+
else {
|
|
48
|
+
for (const style of Object.keys(m.avatarFits)) if (!styles.includes(style)) fault(`avatarFits: unknown style ${style}`);
|
|
49
|
+
for (const style of styles) {
|
|
50
|
+
const fits = m.avatarFits[style];
|
|
51
|
+
if (!Array.isArray(fits) || fits.length !== 16) { fault(`avatarFits.${style}: expected 16 entries`); continue; }
|
|
52
|
+
for (const [i, fit] of fits.entries()) {
|
|
53
|
+
const where = `avatarFits.${style}[${i}]`;
|
|
54
|
+
if (!isObj(fit)) { fault(`${where}: not an object`); continue; }
|
|
55
|
+
if (!styles.includes(fit.drawnFrom)) fault(`${where}: drawnFrom`);
|
|
56
|
+
if (!(vec(fit.chest, 4) || vec(fit.chest, 5))) fault(`${where}: chest`);
|
|
57
|
+
for (const [key, n] of [['waist', 3], ['sash', 4], ['hand', 3], ['hat', 3]]) if (!vec(fit[key], n)) fault(`${where}: ${key}`);
|
|
58
|
+
if (fit.square !== undefined && fit.square !== true) fault(`${where}: square`);
|
|
59
|
+
if (!isNum(fit.top) || fit.top <= 0) fault(`${where}: top`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const requiredModels = [
|
|
64
|
+
...HATS.map((id) => `hat/${id}`), ...EARNED_SHAPES.map((id) => `earned/${id}`),
|
|
65
|
+
...SQUARE_SHAPES.map((id) => `earned/square/${id}`),
|
|
66
|
+
...ROLE_TOPS.flatMap((id) => [`role/top-${id}`, `role/square/top-${id}`]),
|
|
67
|
+
...ROLE_TOOLS.map((id) => `role/tool-${id}`),
|
|
68
|
+
];
|
|
69
|
+
if (!isObj(m.wearModels)) fault('wearModels is not an object');
|
|
70
|
+
else {
|
|
71
|
+
for (const id of requiredModels) if (!Object.hasOwn(m.wearModels, id)) fault(`wearModels: missing ${id}`);
|
|
72
|
+
for (const [id, asset] of Object.entries(m.wearModels)) {
|
|
73
|
+
if (!/^(hat|earned|role)\/(square\/)?[a-z0-9-]+$/.test(id)) fault(`wearModels ${id}: id`);
|
|
74
|
+
if (asset?.type !== 'glb') fault(`wearModels ${id}: not a glb asset`);
|
|
75
|
+
if (asset?.uri !== `../shared/${asset?.sha256}.glb`) fault(`wearModels ${id}: uri`);
|
|
76
|
+
checkAsset(`wearModels ${id}`, asset);
|
|
77
|
+
if (!isObj(assets[id]) || ['uri', 'sha256', 'type', 'bytes'].some((key) => assets[id][key] !== asset?.[key])) fault(`wearModels ${id}: not registered in assets`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const anchors = Object.fromEntries([
|
|
81
|
+
...ROLE_TOPS.map((id) => [`role/top-${id}`, 'waist']), ...ROLE_TOOLS.map((id) => [`role/tool-${id}`, 'hand']),
|
|
82
|
+
...EARNED_SHAPES.map((shape) => {
|
|
83
|
+
const cls = EARNED_SHAPE_CLASS[shape];
|
|
84
|
+
return [`earned/${shape}`, cls === 'badge' || cls === 'pin' ? 'chest' : cls === 'belt' ? 'waist' : cls === 'held' ? 'hand' : 'sash'];
|
|
85
|
+
}),
|
|
86
|
+
]);
|
|
87
|
+
if (!isObj(m.wearPieces)) fault('wearPieces is not an object');
|
|
88
|
+
else {
|
|
89
|
+
for (const id of Object.keys(anchors)) if (!Object.hasOwn(m.wearPieces, id)) fault(`wearPieces: missing ${id}`);
|
|
90
|
+
for (const [id, piece] of Object.entries(m.wearPieces)) {
|
|
91
|
+
if (!isObj(piece)) { fault(`wearPieces ${id}: not an object`); continue; }
|
|
92
|
+
if (!anchors[id] || piece.anchor !== anchors[id]) fault(`wearPieces ${id}: anchor`);
|
|
93
|
+
if (!color(piece.tint)) fault(`wearPieces ${id}: tint`);
|
|
94
|
+
if (typeof piece.placement !== 'string' || !piece.placement.trim()) fault(`wearPieces ${id}: placement`);
|
|
95
|
+
if ((piece.scale !== undefined || !id.startsWith('role/top-')) && (!isNum(piece.scale) || piece.scale <= 0)) fault(`wearPieces ${id}: scale`);
|
|
96
|
+
if (!isObj(m.wearModels) || !Object.hasOwn(m.wearModels, id)) fault(`wearPieces ${id}: no model`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const assetOf = (id, type, where) => {
|
|
101
|
+
if (id === null || id === undefined) return;
|
|
102
|
+
if (!assets[id]) fault(`${where}: unknown asset ${id}`);
|
|
103
|
+
else if (type && assets[id].type !== type && !(type === 'image' && ['png', 'webp'].includes(assets[id].type))) fault(`${where}: asset ${id} is ${assets[id].type}, not ${type}`);
|
|
104
|
+
};
|
|
105
|
+
// v1.6, optional: castle.json-relative sound path -> its audio asset.
|
|
106
|
+
if (m.audio !== undefined) {
|
|
107
|
+
if (!isObj(m.audio)) fault('audio is not an object');
|
|
108
|
+
else for (const [file, id] of Object.entries(m.audio)) {
|
|
109
|
+
if (!file.trim()) fault('audio: empty path');
|
|
110
|
+
if (typeof id !== 'string' || !id || !Object.hasOwn(assets, id)) fault(`audio ${file}: unknown asset ${String(id)}`);
|
|
111
|
+
else if (!audioTypes.includes(assets[id]?.type)) fault(`audio ${file}: asset ${id} is not audio`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const tierNames = new Set(Object.keys(m.tiers?.profiles ?? {}));
|
|
116
|
+
if (!isObj(m.tiers) || !tierNames.size) fault('no tiers.profiles');
|
|
117
|
+
else if (!tierNames.has(m.tiers.default)) fault(`tiers.default ${m.tiers.default} is not a profile`);
|
|
118
|
+
const tierList = (t, where) => { if (t !== null && t !== undefined && !(Array.isArray(t) && t.every((x) => tierNames.has(x)))) fault(`${where}: tiers ${JSON.stringify(t)}`); };
|
|
119
|
+
|
|
120
|
+
if (!Array.isArray(m.layers) || !m.layers.length) fault('no layers');
|
|
121
|
+
for (const [i, l] of (m.layers ?? []).entries()) {
|
|
122
|
+
const w = `layers[${i}]`;
|
|
123
|
+
assetOf(l.asset, 'glb', w);
|
|
124
|
+
tierList(l.tiers, w);
|
|
125
|
+
if (l.role === 'prop') {
|
|
126
|
+
if (!Array.isArray(l.instances) || !l.instances.length) fault(`${w}: prop without instances`);
|
|
127
|
+
for (const inst of l.instances ?? []) if (!vec(inst.transform, 16)) fault(`${w}: instance transform`);
|
|
128
|
+
} else if (l.role !== 'scene') fault(`${w}: role ${l.role}`);
|
|
129
|
+
else if (l.transform !== null && l.transform !== undefined && !vec(l.transform, 16)) fault(`${w}: transform`);
|
|
130
|
+
}
|
|
131
|
+
if (m.avatar) {
|
|
132
|
+
assetOf(m.avatar.asset, 'glb', 'avatar');
|
|
133
|
+
if (!isNum(m.avatar.rootAboveFloor)) fault('avatar.rootAboveFloor');
|
|
134
|
+
}
|
|
135
|
+
if (!isObj(m.render) || !color(m.render.clearColor)) fault('render.clearColor');
|
|
136
|
+
if (!isObj(m.lights)) fault('no lights');
|
|
137
|
+
else {
|
|
138
|
+
const { hemisphere: h, ambient: a, sun: s } = m.lights;
|
|
139
|
+
if (h && !(color(h.sky) && color(h.ground) && isNum(h.intensity))) fault('lights.hemisphere');
|
|
140
|
+
if (a && !(color(a.color) && isNum(a.intensity))) fault('lights.ambient');
|
|
141
|
+
if (s && !(color(s.color) && isNum(s.intensity) && vec(s.direction, 3))) fault('lights.sun');
|
|
142
|
+
}
|
|
143
|
+
if (m.sky) {
|
|
144
|
+
assetOf(m.sky.dome, 'glb', 'sky.dome');
|
|
145
|
+
tierList(m.sky.tiers, 'sky');
|
|
146
|
+
const zones = m.sky.zones ?? [];
|
|
147
|
+
if (!zones.length || zones.length > 16) fault(`sky: ${zones.length} zones`);
|
|
148
|
+
if (zones.filter((z) => !z.box).length !== 1) fault('sky: not exactly one zone without a box');
|
|
149
|
+
const ids = new Set();
|
|
150
|
+
for (const z of zones) {
|
|
151
|
+
if (ids.has(z.id)) fault(`sky: two zones ${z.id}`);
|
|
152
|
+
ids.add(z.id);
|
|
153
|
+
if (!color(z.color)) fault(`sky zone ${z.id}: color`);
|
|
154
|
+
assetOf(z.image, 'image', `sky zone ${z.id}`);
|
|
155
|
+
if (z.box && !(vec(z.box, 4) && z.box[0] < z.box[2] && z.box[1] < z.box[3])) fault(`sky zone ${z.id}: box`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (m.fog) {
|
|
159
|
+
if (!color(m.fog.color)) fault('fog.color');
|
|
160
|
+
if (m.fog.type === 'linear' ? !(isNum(m.fog.near) && isNum(m.fog.far)) : m.fog.type === 'exp2' ? !isNum(m.fog.density) : true) fault(`fog ${m.fog.type}`);
|
|
161
|
+
}
|
|
162
|
+
if (!isObj(m.camera) || !isNum(m.camera.fovDeg) || !isNum(m.camera.near) || !isNum(m.camera.far)) fault('camera');
|
|
163
|
+
|
|
164
|
+
const spawns = Array.isArray(m.spawns) ? m.spawns : (fault('no spawns'), []);
|
|
165
|
+
if (spawns.filter((s) => s.default).length !== 1) fault('spawns: not exactly one default');
|
|
166
|
+
for (const s of spawns) {
|
|
167
|
+
if (!['arrival', 'start', 'doorExit'].includes(s.kind)) fault(`spawn ${s.id}: kind ${s.kind}`);
|
|
168
|
+
if (!vec(s.position, 3)) fault(`spawn ${s.id}: position`);
|
|
169
|
+
}
|
|
170
|
+
const colliders = Array.isArray(m.colliders) ? m.colliders : (fault('no colliders'), []);
|
|
171
|
+
const SIZE = { box: 3, sphere: 1, capsule: 2, cylinder: 2, cone: 2 };
|
|
172
|
+
for (const [i, c] of [...colliders.entries(), ...(m.ground ? [['ground', m.ground]] : [])]) {
|
|
173
|
+
if (!(c.shape in SIZE)) { fault(`collider ${i}: shape ${c.shape}`); continue; }
|
|
174
|
+
if (!vec(c.size, SIZE[c.shape])) fault(`collider ${i} (${c.actorId}): size`);
|
|
175
|
+
if (!vec(c.center, 3) || !vec(c.rotation, 4)) fault(`collider ${i} (${c.actorId}): center/rotation`);
|
|
176
|
+
if (!['fixed', 'kinematic', 'dynamic'].includes(c.body)) fault(`collider ${i}: body ${c.body}`);
|
|
177
|
+
if (c.gravityScale !== undefined && !isNum(c.gravityScale)) fault(`collider ${i}: gravityScale`);
|
|
178
|
+
if (c.lockRotations !== undefined && typeof c.lockRotations !== 'boolean') fault(`collider ${i}: lockRotations`);
|
|
179
|
+
if (c.eulerDeg !== undefined && !vec(c.eulerDeg, 3)) fault(`collider ${i}: eulerDeg`);
|
|
180
|
+
}
|
|
181
|
+
for (const d of Array.isArray(m.doors) ? m.doors : (fault('no doors'), [])) {
|
|
182
|
+
if (!['hub', 'deck', 'classic', 'unresolved'].includes(d.target?.type)) fault(`door ${d.id}: target.type ${d.target?.type}`);
|
|
183
|
+
if (d.target?.type === 'unresolved' && d.target.resolveAt !== 'load') fault(`door ${d.id}: unresolved target not resolved at load`);
|
|
184
|
+
if (!vec(d.position, 3)) fault(`door ${d.id}: position`);
|
|
185
|
+
if (d.trigger && !(vec(d.trigger.center, 3) && isNum(d.trigger.radius))) fault(`door ${d.id}: trigger`);
|
|
186
|
+
if (d.leafColliderIndex !== null && d.leafColliderIndex !== undefined && !colliders[d.leafColliderIndex]) fault(`door ${d.id}: leafColliderIndex`);
|
|
187
|
+
}
|
|
188
|
+
for (const c of Array.isArray(m.characters) ? m.characters : (fault('no characters'), [])) {
|
|
189
|
+
if (!vec(c.position, 3)) fault(`character ${c.id}: position`);
|
|
190
|
+
}
|
|
191
|
+
// v1.4, both optional: an older manifest has neither.
|
|
192
|
+
if (m.deck !== null && m.deck !== undefined && !isObj(m.deck)) fault('deck is not an object');
|
|
193
|
+
if (isObj(m.deck) && Object.hasOwn(m.deck, 'soundscape')) validateSoundscape(m.deck.soundscape, fault);
|
|
194
|
+
if (m.interactables !== undefined) {
|
|
195
|
+
if (!Array.isArray(m.interactables)) fault('interactables is not a list');
|
|
196
|
+
else {
|
|
197
|
+
const ids = new Set();
|
|
198
|
+
for (const a of m.interactables) {
|
|
199
|
+
const c = a?.components;
|
|
200
|
+
if (typeof a?.id !== 'string' || !a.id || ids.has(a.id)) { fault(`interactable ${a?.id}: id`); continue; }
|
|
201
|
+
ids.add(a.id);
|
|
202
|
+
// The chat moderation opt-in is a component-only entry: exactly { HubChatModeration: { v: 1 } }.
|
|
203
|
+
if (a.id === 'hub-chat-moderation') {
|
|
204
|
+
const mk = isObj(c) ? c.HubChatModeration : null;
|
|
205
|
+
if (Object.keys(c ?? {}).length !== 1 || !isObj(mk) || mk.v !== 1 || Object.keys(mk).length !== 1) fault(`interactable ${a.id}: not { HubChatModeration: { v: 1 } }`);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
// v1.6: the soundscape's components (deck.soundscape zones, steps.paths, ambience.spots)
|
|
209
|
+
// and the Town jukebox (by actor id, its Shape and Lookable) are interactables too.
|
|
210
|
+
const sc = m.deck?.soundscape;
|
|
211
|
+
const components = ['HubNpc', 'HubAct', 'HubSeat', sc?.zones, sc?.steps?.paths, ...Object.keys(isObj(sc?.ambience?.spots) ? sc.ambience.spots : {})].filter((k) => typeof k === 'string');
|
|
212
|
+
const emitter = a.id === 'jukebox' && isObj(c) && (isObj(c.Shape) || isObj(c.Lookable));
|
|
213
|
+
if (!isObj(c) || !(emitter || components.some((k) => Object.hasOwn(c, k)))) fault(`interactable ${a.id}: no interaction or sound component`);
|
|
214
|
+
else if (!isObj(c.Transform) || !['x', 'y', 'z', 'rotationY'].every((k) => isNum(c.Transform[k]))) fault(`interactable ${a.id}: Transform`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
for (const l of Array.isArray(m.labels) ? m.labels : (fault('no labels'), [])) {
|
|
219
|
+
if (typeof l.text !== 'string' || !vec(l.anchor, 3)) fault(`label ${l.actorId}`);
|
|
220
|
+
}
|
|
221
|
+
if (!isObj(m.actors)) fault('no actors');
|
|
222
|
+
else for (const [id, a] of Object.entries(m.actors)) {
|
|
223
|
+
if (!['npc', 'game', 'decor', 'static', 'player'].includes(a.kind)) fault(`actor ${id}: kind ${a.kind}`);
|
|
224
|
+
if (a.bounds !== null && a.bounds !== undefined && !vec(a.bounds, 6)) fault(`actor ${id}: bounds`);
|
|
225
|
+
}
|
|
226
|
+
if (m.merged !== null && m.merged !== undefined) {
|
|
227
|
+
if (!isObj(m.merged)) fault('merged is not an object');
|
|
228
|
+
else {
|
|
229
|
+
const seen = new Set();
|
|
230
|
+
for (const [chunk, ids] of Object.entries(m.merged)) {
|
|
231
|
+
if (!m.actors?.[chunk]) fault(`merged ${chunk}: not in actors`);
|
|
232
|
+
if (!Array.isArray(ids) || !ids.length || !ids.every((id) => typeof id === 'string')) { fault(`merged ${chunk}: ids`); continue; }
|
|
233
|
+
for (const id of ids) {
|
|
234
|
+
if (seen.has(id)) fault(`merged ${chunk}: ${id} in two chunks`);
|
|
235
|
+
if (m.actors?.[id]) fault(`merged ${chunk}: ${id} is also in actors`);
|
|
236
|
+
seen.add(id);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return faults;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// castle.json hub.soundscape is a boolean or an object. Validate its shape without filling
|
|
245
|
+
// defaults or rewriting the authored values (the kit chooses the actual synthesis presets).
|
|
246
|
+
function validateSoundscape(sc, fault) {
|
|
247
|
+
const obj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
248
|
+
const name = (v) => typeof v === 'string' && Boolean(v.trim());
|
|
249
|
+
const component = (v) => typeof v === 'string' && /^[A-Za-z][A-Za-z0-9_]*$/.test(v);
|
|
250
|
+
const check = (ok, key) => { if (!ok) fault(`deck.soundscape${key}`); };
|
|
251
|
+
const fields = (v, keys, where) => { for (const k of Object.keys(v)) check(keys.includes(k), `${where}.${k}: unknown key`); };
|
|
252
|
+
const map = (v, where, components = false) => {
|
|
253
|
+
if (!obj(v)) { check(false, where); return; }
|
|
254
|
+
for (const [k, val] of Object.entries(v)) check((components ? component(k) : name(k)) && name(val), `${where}.${k}`);
|
|
255
|
+
};
|
|
256
|
+
if (typeof sc === 'boolean') return;
|
|
257
|
+
if (!obj(sc)) { check(false, ' must be a boolean or object'); return; }
|
|
258
|
+
fields(sc, ['babble', 'steps', 'zones', 'ambience', 'ui', 'cues'], '');
|
|
259
|
+
for (const k of ['babble', 'ui', 'cues']) if (Object.hasOwn(sc, k)) check(typeof sc[k] === 'boolean', `.${k}`);
|
|
260
|
+
if (Object.hasOwn(sc, 'zones')) check(component(sc.zones), '.zones');
|
|
261
|
+
if (Object.hasOwn(sc, 'steps') && typeof sc.steps !== 'boolean') {
|
|
262
|
+
if (!obj(sc.steps)) check(false, '.steps');
|
|
263
|
+
else {
|
|
264
|
+
fields(sc.steps, ['default', 'zones', 'paths'], '.steps');
|
|
265
|
+
if (Object.hasOwn(sc.steps, 'default')) check(name(sc.steps.default), '.steps.default');
|
|
266
|
+
if (Object.hasOwn(sc.steps, 'paths')) check(component(sc.steps.paths), '.steps.paths');
|
|
267
|
+
if (Object.hasOwn(sc.steps, 'zones')) { map(sc.steps.zones, '.steps.zones'); check(component(sc.zones), '.steps.zones needs zones'); }
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (Object.hasOwn(sc, 'ambience')) {
|
|
271
|
+
if (!obj(sc.ambience)) check(false, '.ambience');
|
|
272
|
+
else {
|
|
273
|
+
const a = sc.ambience;
|
|
274
|
+
fields(a, ['default', 'beds', 'spots', 'music'], '.ambience');
|
|
275
|
+
if (Object.hasOwn(a, 'default')) check(name(a.default), '.ambience.default');
|
|
276
|
+
if (Object.hasOwn(a, 'music')) check(typeof a.music === 'boolean', '.ambience.music');
|
|
277
|
+
if (Object.hasOwn(a, 'spots')) map(a.spots, '.ambience.spots', true);
|
|
278
|
+
if (Object.hasOwn(a, 'beds')) { map(a.beds, '.ambience.beds'); check(component(sc.zones), '.ambience.beds needs zones'); }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
284
|
+
const file = process.argv[2];
|
|
285
|
+
if (!file) { console.error('usage: node validate-manifest.mjs <manifest.json> [--no-hash]'); process.exit(2); }
|
|
286
|
+
const m = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
287
|
+
const faults = validateManifest(m, path.dirname(path.resolve(file)), { hash: !process.argv.includes('--no-hash') });
|
|
288
|
+
for (const f of faults) console.log(f);
|
|
289
|
+
console.log(faults.length ? `${faults.length} fault(s)` : `ok: ${m.hubId} (${Object.keys(m.assets).length} assets, ${m.layers.length} layers, ${m.spawns.length} spawns, ${m.doors.length} doors, ${m.characters.length} characters, ${m.colliders.length} colliders)`);
|
|
290
|
+
process.exit(faults.length ? 1 : 0);
|
|
291
|
+
}
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
"imports": {
|
|
8
8
|
"castle.real-time": {
|
|
9
9
|
"deckId": "xFVr-afOLuUQ",
|
|
10
|
-
"version": "2026-10-
|
|
10
|
+
"version": "2026-10-21T18:37:16.504Z"
|
|
11
11
|
},
|
|
12
12
|
"castle.physics-3d": {
|
|
13
13
|
"deckId": "JH0SclbPVP0y",
|
|
14
|
-
"version": "2026-10-
|
|
14
|
+
"version": "2026-10-21T18:38:09.393Z"
|
|
15
15
|
},
|
|
16
16
|
"castle.physics-2d": {
|
|
17
17
|
"deckId": "ckRZGFW4iPrx",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"castle.base": {
|
|
22
22
|
"deckId": "yRcmH4_aYllE",
|
|
23
|
-
"version": "2026-10-
|
|
23
|
+
"version": "2026-10-21T18:36:51.857Z"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"autoUpdateWhenImported": true,
|
|
27
27
|
"deckId": "ZwA_P_-VO-Qh",
|
|
28
28
|
"cardId": "bvRmCzyUpt_a",
|
|
29
|
-
"publishedVersion": "2026-10-
|
|
29
|
+
"publishedVersion": "2026-10-21T18:38:54.798Z",
|
|
30
30
|
"main": "main.jsx",
|
|
31
31
|
"server": {
|
|
32
32
|
"main": "code/server/index.js",
|
|
@@ -47,13 +47,24 @@ const LAG_SHARE = 0.1;
|
|
|
47
47
|
const STATE = 's';
|
|
48
48
|
const WORLD = 'w';
|
|
49
49
|
|
|
50
|
+
// A connection that never dropped can still have missed broadcasts: a host
|
|
51
|
+
// throws away the frames of a client that stops reading (a phone app in the
|
|
52
|
+
// background), and keeps the socket if it drains in time. Those frames carried
|
|
53
|
+
// changes no later broadcast repeats, so an NPC that walked off and stopped
|
|
54
|
+
// stays where this client last saw it. A session that offers a resync (`rs` on
|
|
55
|
+
// its WORLD) is asked for one after an away at least this long, and only that
|
|
56
|
+
// WORLD then counts as current. A shorter away (a frame hitch) keeps the
|
|
57
|
+
// ordinary release, as does a session that offers none.
|
|
58
|
+
export const RESYNC_AWAY_MS = 5000;
|
|
59
|
+
|
|
50
60
|
// An unarmed gate. `since` is the page time the room was last current,
|
|
51
61
|
// `serverAt` the simulation time then (null with no clock yet), `shownAt` the
|
|
52
62
|
// first page time the page was visible again while armed, `dropped` whether
|
|
53
63
|
// the connection left `connected` during the away, `lostAt` the last page time
|
|
54
|
-
// it was seen not connected,
|
|
64
|
+
// it was seen not connected, `backAt` when it came back after that, and
|
|
65
|
+
// `asked` whether a resync was asked for (`ask`).
|
|
55
66
|
export function makeGate() {
|
|
56
|
-
return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null };
|
|
67
|
+
return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false };
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
// Arm the gate for an away that began at page time `since`, when the server's
|
|
@@ -70,6 +81,7 @@ export function arm(gate, since, serverAt) {
|
|
|
70
81
|
gate.dropped = false;
|
|
71
82
|
gate.lostAt = null;
|
|
72
83
|
gate.backAt = null;
|
|
84
|
+
gate.asked = false;
|
|
73
85
|
return true;
|
|
74
86
|
}
|
|
75
87
|
|
|
@@ -80,6 +92,18 @@ export function clear(gate) {
|
|
|
80
92
|
gate.dropped = false;
|
|
81
93
|
gate.lostAt = null;
|
|
82
94
|
gate.backAt = null;
|
|
95
|
+
gate.asked = false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Whether to ask for a resync now, at page time `now`: once per away, an away
|
|
99
|
+
// of at least `RESYNC_AWAY_MS` over a connection that never dropped (one that
|
|
100
|
+
// dropped is sent a WORLD anyway). Marks the gate asked when it says yes.
|
|
101
|
+
export function ask(gate, now) {
|
|
102
|
+
if (!gate.armed || gate.dropped || gate.asked || now - gate.since < RESYNC_AWAY_MS) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
gate.asked = true;
|
|
106
|
+
return true;
|
|
83
107
|
}
|
|
84
108
|
|
|
85
109
|
// Note whether the connection is connected at page time `now`, while armed.
|
|
@@ -119,6 +143,10 @@ export function current(gate, msg) {
|
|
|
119
143
|
if (msg.k === WORLD) {
|
|
120
144
|
return true;
|
|
121
145
|
}
|
|
146
|
+
// A resync was asked for: no broadcast can say what the dropped ones did.
|
|
147
|
+
if (gate.asked) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
122
150
|
if (gate.serverAt === null) {
|
|
123
151
|
return true;
|
|
124
152
|
}
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
//
|
|
20
20
|
// Poses are the full object form of `poses.js`, `[x, y, z, qx, qy, qz, qw]`.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// The physics-3d kit's own Rapier build, whose world this runs in; the npm
|
|
23
|
+
// package would add a second, uncompressed copy of the wasm to every page.
|
|
24
|
+
import * as RAPIER from '@imports/castle.physics-3d/engine3d/rapier.js';
|
|
23
25
|
import * as THREE from 'three';
|
|
24
26
|
import * as Poses from './poses.js';
|
|
25
27
|
|
|
@@ -23,6 +23,11 @@ import { showSoloBadge, updateSoloBadge } from '@imports/castle.real-time/code/c
|
|
|
23
23
|
import { showJoinOverlay } from '@imports/castle.real-time/code/client/joinOverlay.js';
|
|
24
24
|
import { GONE, SCENE, STATE, WORLD } from '@imports/castle.real-time/code/client/messages.js';
|
|
25
25
|
|
|
26
|
+
// The real-time kit's RESYNC kind, named here rather than imported so this
|
|
27
|
+
// kit still builds against a real-time that predates it; only a session whose
|
|
28
|
+
// WORLD says `rs: 1` is ever sent one.
|
|
29
|
+
const RESYNC = 'r';
|
|
30
|
+
|
|
26
31
|
// How long the joining overlay may hold the card before giving up.
|
|
27
32
|
const JOIN_WAIT_MS = 10000;
|
|
28
33
|
const JOIN_WATCHDOG_MS = 20000;
|
|
@@ -213,6 +218,8 @@ class MultiplayerSystem {
|
|
|
213
218
|
this.gaveUp = false;
|
|
214
219
|
this.outAt = null;
|
|
215
220
|
this.onVisibility = null;
|
|
221
|
+
// Whether the session's last WORLD offered a resync (`rs`).
|
|
222
|
+
this.resyncs = false;
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
// Run the network frame after engine behaviors and local physics. Connection,
|
|
@@ -698,6 +705,10 @@ class MultiplayerSystem {
|
|
|
698
705
|
// A snapshot releases the resume gate only once the page is shown and
|
|
699
706
|
// connected again; the whole drain is applied before it does.
|
|
700
707
|
const resuming = this.resume.armed && !pageHidden() && this.net.status().state === 'connected';
|
|
708
|
+
// Asked before this drain, so a broadcast in it cannot release the gate.
|
|
709
|
+
if (resuming && this.resyncs && ResumeGate.ask(this.resume, performance.now())) {
|
|
710
|
+
this.net.send({ k: RESYNC });
|
|
711
|
+
}
|
|
701
712
|
let fresh = false;
|
|
702
713
|
for (const msg of this.net.drain()) {
|
|
703
714
|
if (msg.k !== STATE && msg.k !== WORLD) {
|
|
@@ -723,6 +734,12 @@ class MultiplayerSystem {
|
|
|
723
734
|
// Pair simulation time with the page arrival time before filing samples.
|
|
724
735
|
Clock.noteArrival(this.clock, msg.t, msg.localMs);
|
|
725
736
|
fresh ||= resuming && ResumeGate.current(this.resume, msg);
|
|
737
|
+
// A resync's WORLD (`again`) is the room as it is, sent to a player
|
|
738
|
+
// already placed: it neither moves this player nor restores its block.
|
|
739
|
+
const again = msg.k === WORLD && msg.again === 1;
|
|
740
|
+
if (msg.k === WORLD) {
|
|
741
|
+
this.resyncs = msg.rs === 1;
|
|
742
|
+
}
|
|
726
743
|
if (!this.joined && (msg.k === WORLD || (msg.ps ?? []).some((pose) => pose[0] === selfId))) {
|
|
727
744
|
this.joined = true;
|
|
728
745
|
this.starting = false;
|
|
@@ -737,7 +754,7 @@ class MultiplayerSystem {
|
|
|
737
754
|
// The WORLD snapshot carries this player's own saved block. It goes back
|
|
738
755
|
// on `scene.persistent`, which is where the engine's Player behavior keeps
|
|
739
756
|
// the camera angle and score, before that behavior runs again.
|
|
740
|
-
if (msg.k === WORLD && msg.me) {
|
|
757
|
+
if (msg.k === WORLD && msg.me && !again) {
|
|
741
758
|
Object.assign((scene.persistent ??= {}), msg.me);
|
|
742
759
|
this.sentState = JSON.stringify(scene.persistent);
|
|
743
760
|
}
|
|
@@ -755,6 +772,17 @@ class MultiplayerSystem {
|
|
|
755
772
|
this.dropPlayer(id);
|
|
756
773
|
Avatars.retire(this.avatars, scene, id);
|
|
757
774
|
}
|
|
775
|
+
// A resync's rows are everyone this client sees now. An `out` lost with
|
|
776
|
+
// the dropped frames is never sent again, so whoever they omit goes.
|
|
777
|
+
if (again) {
|
|
778
|
+
const listed = new Set((msg.ps ?? []).map(([id]) => id));
|
|
779
|
+
for (const id of [...this.players.keys()]) {
|
|
780
|
+
if (id !== selfId && !listed.has(id)) {
|
|
781
|
+
this.dropPlayer(id);
|
|
782
|
+
Avatars.retire(this.avatars, scene, id);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
758
786
|
for (const id of msg.in ?? []) {
|
|
759
787
|
this.dropPlayer(id);
|
|
760
788
|
Avatars.enter(this.avatars, id);
|
|
@@ -768,7 +796,7 @@ class MultiplayerSystem {
|
|
|
768
796
|
for (const [id, x, y, z, facing, clamped] of msg.ps ?? []) {
|
|
769
797
|
if (id !== selfId) {
|
|
770
798
|
sample(this.players, msg, id, [x, y, z, facing]);
|
|
771
|
-
} else if (msg.k === WORLD) {
|
|
799
|
+
} else if (msg.k === WORLD && !again) {
|
|
772
800
|
// The WORLD snapshot that starts a session carries where this player
|
|
773
801
|
// left off. The body is moved there in one step, behind the overlay.
|
|
774
802
|
this.placedTo = { x, y, z };
|
|
@@ -116,6 +116,8 @@ async function makeRoom({ objects, players = {} }) {
|
|
|
116
116
|
nextTick: pageMs,
|
|
117
117
|
actors: new Map(),
|
|
118
118
|
frames: [],
|
|
119
|
+
// What the client sent the session.
|
|
120
|
+
outbox: [],
|
|
119
121
|
};
|
|
120
122
|
for (const id of Object.keys(objects)) {
|
|
121
123
|
room.actors.set(id, { id, components: { Transform: { x: 0, y: 0, z: 0 } } });
|
|
@@ -128,7 +130,7 @@ async function makeRoom({ objects, players = {} }) {
|
|
|
128
130
|
roster: () => new Map(),
|
|
129
131
|
userId: () => null,
|
|
130
132
|
sendMove: () => false,
|
|
131
|
-
send: () =>
|
|
133
|
+
send: (msg) => room.outbox.push(msg),
|
|
132
134
|
closed: () => false,
|
|
133
135
|
close() {},
|
|
134
136
|
};
|
|
@@ -197,13 +199,14 @@ function broadcast(room) {
|
|
|
197
199
|
return { k: 's', t: simNow(), os, ps, own: [] };
|
|
198
200
|
}
|
|
199
201
|
|
|
200
|
-
function world(room) {
|
|
202
|
+
function world(room, extra = {}) {
|
|
201
203
|
return {
|
|
202
204
|
k: 'w',
|
|
203
205
|
t: simNow(),
|
|
204
206
|
os: Object.entries(room.objects).map(([id, pose]) => [id, ...pose, 0]),
|
|
205
207
|
ps: [...Object.entries(room.players).map(([id, pose]) => [id, ...pose]), ['self', 0, 0, 0, 0]],
|
|
206
208
|
own: [],
|
|
209
|
+
...extra,
|
|
207
210
|
};
|
|
208
211
|
}
|
|
209
212
|
|
|
@@ -361,6 +364,75 @@ check('prism 30s return, drop seen only by frames', await prismReturn(30000, { r
|
|
|
361
364
|
show(room);
|
|
362
365
|
run(room, pageMs + 1000);
|
|
363
366
|
check('socket kept, hidden 30s', room, { uncoverBy: 2 * FRAME_MS });
|
|
367
|
+
assert.deepEqual(room.outbox.filter((m) => m.k === 'r'), [], 'a session that offers no resync is not asked for one');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// A hub return whose socket stayed up while the host dropped its frames (a
|
|
371
|
+
// backpressured phone, 3 min in the background): Rowan walked off and stopped
|
|
372
|
+
// meanwhile, so no later broadcast names him and a current STATE would show
|
|
373
|
+
// him where he was. A session that offers a resync (`rs` on its WORLD) is
|
|
374
|
+
// asked for one, and the cover holds until that WORLD (`again`) arrives. It
|
|
375
|
+
// moves neither the local player nor its saved block.
|
|
376
|
+
{
|
|
377
|
+
const ROWAN_OLD = [2.45, 1, 9.53, 0, 0, 0, 1];
|
|
378
|
+
const ROWAN_NOW = [14, 1, 22, 0, 0, 0, 1];
|
|
379
|
+
const room = await makeRoom({ objects: { greeter: ROWAN_OLD } });
|
|
380
|
+
// This player holds a lantern through the away.
|
|
381
|
+
const held = [['lantern', 'self', 0, 0, 0, 0, 0, 0, 1]];
|
|
382
|
+
deliver(room, world(room, { rs: 1, me: { cam: 1 }, own: held }), pageMs);
|
|
383
|
+
run(room, pageMs + 2000);
|
|
384
|
+
const local = room.scene.actorWith('Player');
|
|
385
|
+
const body = room.scene.physics3d.bodyOf(local);
|
|
386
|
+
body.setTranslation({ x: 5, y: 0, z: 5 });
|
|
387
|
+
room.scene.persistent.cam = 2;
|
|
388
|
+
hide(room);
|
|
389
|
+
run(room, pageMs + 500);
|
|
390
|
+
room.socket = false;
|
|
391
|
+
run(room, pageMs + 10000);
|
|
392
|
+
room.objects.greeter = ROWAN_NOW;
|
|
393
|
+
run(room, pageMs + 20000);
|
|
394
|
+
room.socket = true;
|
|
395
|
+
run(room, room.hiddenAt + 180000);
|
|
396
|
+
show(room);
|
|
397
|
+
run(room, pageMs + 300);
|
|
398
|
+
assert.deepEqual(room.outbox.filter((m) => m.k === 'r'), [{ k: 'r' }], 'the return asks for a resync once');
|
|
399
|
+
assert.equal(room.system.resume.armed, true, 'current broadcasts do not release a return that asked');
|
|
400
|
+
deliver(room, world(room, { rs: 1, again: 1, me: { cam: 1 }, own: held }));
|
|
401
|
+
run(room, pageMs + 800);
|
|
402
|
+
check('hub frames dropped, socket kept, 3 min', room, { uncoverBy: 300 + 3 * FRAME_MS + TRANSIT_MS });
|
|
403
|
+
assert.deepEqual(body.translation(), { x: 5, y: 0, z: 5 }, 'the resync does not move the local player');
|
|
404
|
+
assert.equal(room.scene.persistent.cam, 2, 'nor restore its saved block');
|
|
405
|
+
assert.ok(room.system.own.mine.has('lantern'), 'a held object stays held');
|
|
406
|
+
assert.equal(room.system.objects.size, 1, 'and nothing is drawn twice');
|
|
407
|
+
assert.equal(room.outbox.filter((m) => m.k === 'r').length, 1, 'and is not asked for again');
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// A player who left this viewer's interest while its frames were dropped: the
|
|
411
|
+
// `out` that said so is gone, and the session's own record already counts it
|
|
412
|
+
// sent. The resync WORLD lists everyone this client sees, so whoever it does
|
|
413
|
+
// not list goes, rather than standing frozen where last seen.
|
|
414
|
+
{
|
|
415
|
+
const room = await makeRoom({ objects: { greeter: [2.45, 1, 9.53, 0, 0, 0, 1] }, players: { partner: [1, 0, 1, 0], friend: [2, 0, 2, 0] } });
|
|
416
|
+
// Both stay in the session; only this viewer's interest changes.
|
|
417
|
+
room.system.net.others = () => new Map([['partner', 'partner'], ['friend', 'friend']]);
|
|
418
|
+
deliver(room, world(room, { rs: 1 }), pageMs);
|
|
419
|
+
run(room, pageMs + 2000);
|
|
420
|
+
assert.ok(room.system.players.has('partner'));
|
|
421
|
+
hide(room);
|
|
422
|
+
run(room, pageMs + 500);
|
|
423
|
+
room.socket = false;
|
|
424
|
+
run(room, pageMs + 10000);
|
|
425
|
+
delete room.players.partner;
|
|
426
|
+
run(room, pageMs + 10000);
|
|
427
|
+
room.socket = true;
|
|
428
|
+
run(room, room.hiddenAt + 60000);
|
|
429
|
+
show(room);
|
|
430
|
+
run(room, pageMs + 300);
|
|
431
|
+
deliver(room, world(room, { rs: 1, again: 1 }));
|
|
432
|
+
run(room, pageMs + 800);
|
|
433
|
+
assert.equal(room.system.resume.armed, false);
|
|
434
|
+
assert.equal(room.system.players.has('partner'), false, 'a player the resync does not list is dropped');
|
|
435
|
+
assert.equal(room.system.players.has('friend'), true, 'one it lists stays');
|
|
364
436
|
}
|
|
365
437
|
|
|
366
438
|
// A socket that died at the suspension with frames still in its buffer: they
|
|
@@ -32,7 +32,7 @@ bottom }`; any ref can pick a frame of a multi-frame sprite with
|
|
|
32
32
|
`path#<frame>`. A flat `color` with no art is a fine look.
|
|
33
33
|
- Motion goes through `scene.physics3d`, never by writing a dynamic actor's
|
|
34
34
|
Transform: `setVelocity(actor, {x,y,z})`, `applyImpulse`, `getVelocity`,
|
|
35
|
-
`mass`, `castRay(origin, dir, maxToi, excludeActor)` (rays skip sensors).
|
|
35
|
+
`mass`, `castRay(origin, dir, maxToi, excludeActor, skip?)` (rays skip sensors, and any actor `skip(actorId)` answers true for).
|
|
36
36
|
`addForce(actor, {x,y,z})` pushes through this frame's physics steps only
|
|
37
37
|
(ask every frame from `update` for a steady push; `resetForces(actor)`
|
|
38
38
|
drops what the frame asked): docs/engine-camera.md has the rule.
|