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
|
@@ -39,6 +39,9 @@ export function Scene3DPlayer({
|
|
|
39
39
|
// camera angle live here so they cross scene switches.
|
|
40
40
|
runtime.persistent = {};
|
|
41
41
|
runtime.currentScenePath = scenePath ?? 'scenes/main.scene';
|
|
42
|
+
// This loop applies `requestedContent` with `requestedScene` (another
|
|
43
|
+
// deck's content, mounted as data); a caller checks before asking.
|
|
44
|
+
runtime.mountsContent = true;
|
|
42
45
|
|
|
43
46
|
const detachInput = attachInput(canvas, runtime, world);
|
|
44
47
|
const stopResize = attachResize(canvas, world);
|
|
@@ -205,15 +208,13 @@ function startLoop(runtime, world, sprites, hudRefs, onFirstFrame, onError) {
|
|
|
205
208
|
// registered systems -- the rapier world frees and lazily rebuilds --
|
|
206
209
|
// while `runtime.persistent` carries the player's cross-scene state.
|
|
207
210
|
if (runtime.requestedScene) {
|
|
208
|
-
const next = runtime
|
|
209
|
-
runtime.requestedScene = null;
|
|
210
|
-
runtime.loadFromFile(next);
|
|
211
|
+
const next = loadRequestedScene(runtime);
|
|
211
212
|
runtime.currentScenePath = next;
|
|
212
213
|
runtime.persistent.sceneChangeGraceUntil = runtime.time + 1;
|
|
213
214
|
}
|
|
214
|
-
syncActors(world, runtime, sprites, dt);
|
|
215
|
+
syncActors(world, runtime, runtime.sprites ?? sprites, dt);
|
|
215
216
|
if (world.debugLines.visible) updatePhysicsDebug(world, runtime.physics3d?.debugRender());
|
|
216
|
-
renderWorld(world);
|
|
217
|
+
renderWorld(world, runtime);
|
|
217
218
|
updateHud(runtime, hudRefs);
|
|
218
219
|
} catch (err) {
|
|
219
220
|
onError?.(err);
|
|
@@ -229,6 +230,33 @@ function startLoop(runtime, world, sprites, hudRefs, onFirstFrame, onError) {
|
|
|
229
230
|
return () => cancelAnimationFrame(raf);
|
|
230
231
|
}
|
|
231
232
|
|
|
233
|
+
// Load the scene a behavior asked for, with the content it comes from when
|
|
234
|
+
// that is another deck's (a hub content pack; `null` puts this deck's own
|
|
235
|
+
// back). Content that fails to load puts the scene that was running back and
|
|
236
|
+
// leaves the error on `runtime.mountError` for the asker. Returns the path now
|
|
237
|
+
// loaded.
|
|
238
|
+
function loadRequestedScene(runtime) {
|
|
239
|
+
const next = runtime.requestedScene;
|
|
240
|
+
runtime.requestedScene = null;
|
|
241
|
+
if (runtime.requestedContent === undefined) {
|
|
242
|
+
runtime.loadFromFile(next);
|
|
243
|
+
return next;
|
|
244
|
+
}
|
|
245
|
+
const before = { content: runtime.content ?? null, path: runtime.currentScenePath };
|
|
246
|
+
runtime.setContent(runtime.requestedContent);
|
|
247
|
+
runtime.requestedContent = undefined;
|
|
248
|
+
try {
|
|
249
|
+
runtime.loadFromFile(next);
|
|
250
|
+
return next;
|
|
251
|
+
} catch (err) {
|
|
252
|
+
console.error('[engine] content failed to load; staying where we were', err);
|
|
253
|
+
runtime.setContent(before.content);
|
|
254
|
+
runtime.loadFromFile(before.path);
|
|
255
|
+
runtime.mountError = err;
|
|
256
|
+
return before.path;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
232
260
|
// Behaviors write `scene.hud = { score, look }`; the loop pushes it into the
|
|
233
261
|
// overlay divs imperatively (no react re-render at frame rate).
|
|
234
262
|
function updateHud(runtime, hudRefs) {
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// The terms of `"engine": { "skipUnchangedActors": true }`:
|
|
2
|
+
//
|
|
3
|
+
// With the key absent, a scene runs the engine exactly as before. With the key
|
|
4
|
+
// present, each frame equals what the engine would have produced without it
|
|
5
|
+
// PROVIDED the scene's components are plain stored data (no accessors, Proxies,
|
|
6
|
+
// toJSON, custom iterators) and three.js objects under actors are changed only
|
|
7
|
+
// through position/rotation/quaternion/scale/visible/parenting. A scene that does
|
|
8
|
+
// not meet that is unsupported under the key and must not set it.
|
|
9
|
+
//
|
|
10
|
+
// The three.js group an actor is drawn under in a scene that set
|
|
11
|
+
// `"engine": { "skipUnchangedActors": true }`. It is a THREE.Group whose
|
|
12
|
+
// `updateMatrixWorld` does nothing when doing it would change nothing.
|
|
13
|
+
//
|
|
14
|
+
// three.js recomputes the local and the world matrix of every object under
|
|
15
|
+
// the scene on every render, whether or not anything moved. For a scene of
|
|
16
|
+
// several hundred actors that stand still that is most of a frame's script
|
|
17
|
+
// time. An ActorNode remembers, as numbers, what its subtree's matrices were
|
|
18
|
+
// last computed from and what they came out as: its parent's id and world
|
|
19
|
+
// matrix, the ids of the objects under it in order, each one's position,
|
|
20
|
+
// quaternion and scale, and each one's world matrix. While all of that reads
|
|
21
|
+
// the same, the matrices three.js would compute are the ones already there,
|
|
22
|
+
// so the walk is skipped. The moment any of it differs, by anyone's hand,
|
|
23
|
+
// three.js's own `updateMatrixWorld` runs for the whole subtree, exactly as it
|
|
24
|
+
// always did. That covers a world matrix written directly, a child moved to
|
|
25
|
+
// another parent and back between two renders, and a transform changed, used
|
|
26
|
+
// and put back: each leaves a matrix that is not the remembered one.
|
|
27
|
+
//
|
|
28
|
+
// Nothing about the objects is changed: `matrixAutoUpdate` stays on, so every
|
|
29
|
+
// other three.js path (`updateWorldMatrix`, a clone, a child moved under
|
|
30
|
+
// another parent) behaves as it does under a plain Group. A subtree holding
|
|
31
|
+
// anything that manages its own matrices (`matrixAutoUpdate` or
|
|
32
|
+
// `matrixWorldAutoUpdate` off, an `updateMatrix` or `updateMatrixWorld` of its
|
|
33
|
+
// own such as a camera's or a skinned mesh's, an object of another copy of
|
|
34
|
+
// three.js) is never skipped.
|
|
35
|
+
//
|
|
36
|
+
// `skipping` is the world's `{ on }`, shared by every node of the world: while
|
|
37
|
+
// it is off (the scene now playing did not ask), a node left from a scene
|
|
38
|
+
// that did is a plain Group again, after one test, and drops its record.
|
|
39
|
+
import * as THREE from 'three';
|
|
40
|
+
|
|
41
|
+
const baseUpdateMatrix = THREE.Object3D.prototype.updateMatrix;
|
|
42
|
+
const baseUpdateMatrixWorld = THREE.Object3D.prototype.updateMatrixWorld;
|
|
43
|
+
|
|
44
|
+
// Numbers remembered per object: position, quaternion and scale, then the
|
|
45
|
+
// local matrix and the world matrix they came out as.
|
|
46
|
+
const INPUTS = 10;
|
|
47
|
+
const STRIDE = INPUTS + 16;
|
|
48
|
+
|
|
49
|
+
const OFF = { on: false };
|
|
50
|
+
const NO_PARENT = -1;
|
|
51
|
+
|
|
52
|
+
export class ActorNode extends THREE.Group {
|
|
53
|
+
constructor(skipping = OFF) {
|
|
54
|
+
super();
|
|
55
|
+
this.skipping = skipping ?? OFF;
|
|
56
|
+
// What the subtree's matrices were last computed from, or null when they
|
|
57
|
+
// must be computed again whatever reads the same.
|
|
58
|
+
this.computedFrom = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
updateMatrixWorld(force) {
|
|
62
|
+
// While the scene playing did not ask it is Group's method, after one
|
|
63
|
+
// test; a record left from a scene that did is dropped on the way.
|
|
64
|
+
if (!this.skipping.on) {
|
|
65
|
+
if (this.computedFrom !== null) this.computedFrom = null;
|
|
66
|
+
super.updateMatrixWorld(force);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const from = this.computedFrom;
|
|
70
|
+
if (from !== null && unchanged(this, from)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
super.updateMatrixWorld(force);
|
|
74
|
+
this.computedFrom = remember(this, from);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// The record (`computedFrom`) holds numbers and nothing else: the parent's id
|
|
79
|
+
// and world matrix, and for each object of the subtree, in the order three.js
|
|
80
|
+
// walks it, its id, how many objects its own subtree has, and its position,
|
|
81
|
+
// quaternion, scale and world matrix. It refers to no object, so it can keep
|
|
82
|
+
// nothing alive, whoever holds the node and for however long.
|
|
83
|
+
|
|
84
|
+
// Where the walk below has got to in the record.
|
|
85
|
+
let at = 0;
|
|
86
|
+
|
|
87
|
+
// Whether three.js's walk of the subtree would leave every matrix as it is.
|
|
88
|
+
function unchanged(node, from) {
|
|
89
|
+
if (!sameParent(node.parent, from)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
at = 0;
|
|
93
|
+
return sameSubtree(node, true, from) && at === from.ids.length;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Whether `object` is the next object of the record, reads as recorded, and
|
|
97
|
+
// has under it exactly the subtree recorded for it.
|
|
98
|
+
function sameSubtree(object, isRoot, from) {
|
|
99
|
+
const index = at;
|
|
100
|
+
if (index >= from.ids.length || from.ids[index] !== object.id) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (
|
|
104
|
+
!computesItself(object, isRoot) ||
|
|
105
|
+
object.matrixWorldNeedsUpdate !== false ||
|
|
106
|
+
!sameNumbers(object, from.numbers, index * STRIDE)
|
|
107
|
+
) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
at = index + 1;
|
|
111
|
+
const children = object.children;
|
|
112
|
+
for (let c = 0; c < children.length; c++) {
|
|
113
|
+
if (!sameSubtree(children[c], false, from)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return at === index + from.sizes[index];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function sameParent(parent, from) {
|
|
121
|
+
if ((parent === null ? NO_PARENT : parent.id) !== from.parentId) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (parent === null) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
const now = parent.matrixWorld.elements;
|
|
128
|
+
const was = from.parentWorld;
|
|
129
|
+
for (let i = 0; i < 16; i++) {
|
|
130
|
+
if (!Object.is(now[i], was[i])) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// `Object.is`, not `===`: a matrix composed from -0 differs from one composed
|
|
138
|
+
// from 0 in the sign of its zeros, and the two must not pass for each other.
|
|
139
|
+
function sameNumbers(object, numbers, k) {
|
|
140
|
+
const p = object.position;
|
|
141
|
+
const q = object.quaternion;
|
|
142
|
+
const s = object.scale;
|
|
143
|
+
return (
|
|
144
|
+
sameMatrix(object.matrixWorld.elements, numbers, k + INPUTS) &&
|
|
145
|
+
Object.is(p.x, numbers[k]) &&
|
|
146
|
+
Object.is(p.y, numbers[k + 1]) &&
|
|
147
|
+
Object.is(p.z, numbers[k + 2]) &&
|
|
148
|
+
Object.is(q.x, numbers[k + 3]) &&
|
|
149
|
+
Object.is(q.y, numbers[k + 4]) &&
|
|
150
|
+
Object.is(q.z, numbers[k + 5]) &&
|
|
151
|
+
Object.is(q.w, numbers[k + 6]) &&
|
|
152
|
+
Object.is(s.x, numbers[k + 7]) &&
|
|
153
|
+
Object.is(s.y, numbers[k + 8]) &&
|
|
154
|
+
Object.is(s.z, numbers[k + 9])
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Whether the object's world matrix is still the one the last walk left.
|
|
159
|
+
function sameMatrix(world, numbers, k) {
|
|
160
|
+
for (let i = 0; i < 16; i++) {
|
|
161
|
+
if (!Object.is(world[i], numbers[k + i])) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// An object whose matrices three.js's plain walk computes from its position,
|
|
169
|
+
// quaternion and scale, and nothing else.
|
|
170
|
+
function computesItself(object, isRoot) {
|
|
171
|
+
return (
|
|
172
|
+
object.matrixAutoUpdate === true &&
|
|
173
|
+
object.matrixWorldAutoUpdate === true &&
|
|
174
|
+
object.updateMatrix === baseUpdateMatrix &&
|
|
175
|
+
(isRoot || object.updateMatrixWorld === baseUpdateMatrixWorld)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function everyObjectComputesItself(object, isRoot) {
|
|
180
|
+
if (!computesItself(object, isRoot)) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const children = object.children;
|
|
184
|
+
for (let i = 0; i < children.length; i++) {
|
|
185
|
+
if (!everyObjectComputesItself(children[i], false)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function countObjects(object) {
|
|
193
|
+
let count = 1;
|
|
194
|
+
const children = object.children;
|
|
195
|
+
for (let i = 0; i < children.length; i++) {
|
|
196
|
+
count += countObjects(children[i]);
|
|
197
|
+
}
|
|
198
|
+
return count;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// What the walk that just ran computed the subtree from. `from` is the last
|
|
202
|
+
// record; its arrays are written over when the subtree has as many objects as
|
|
203
|
+
// before, so an actor that moves every frame allocates nothing.
|
|
204
|
+
function remember(node, from) {
|
|
205
|
+
if (!everyObjectComputesItself(node, true)) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const count = countObjects(node);
|
|
209
|
+
const record =
|
|
210
|
+
from !== null && from.ids.length === count
|
|
211
|
+
? from
|
|
212
|
+
: {
|
|
213
|
+
parentId: NO_PARENT,
|
|
214
|
+
parentWorld: new Float64Array(16),
|
|
215
|
+
ids: new Int32Array(count),
|
|
216
|
+
sizes: new Int32Array(count),
|
|
217
|
+
numbers: new Float64Array(count * STRIDE),
|
|
218
|
+
};
|
|
219
|
+
record.parentId = node.parent === null ? NO_PARENT : node.parent.id;
|
|
220
|
+
if (node.parent !== null) {
|
|
221
|
+
record.parentWorld.set(node.parent.matrixWorld.elements);
|
|
222
|
+
}
|
|
223
|
+
at = 0;
|
|
224
|
+
write(node, record);
|
|
225
|
+
return record;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function write(object, record) {
|
|
229
|
+
const index = at;
|
|
230
|
+
at = index + 1;
|
|
231
|
+
const { numbers } = record;
|
|
232
|
+
const k = index * STRIDE;
|
|
233
|
+
const p = object.position;
|
|
234
|
+
const q = object.quaternion;
|
|
235
|
+
const s = object.scale;
|
|
236
|
+
record.ids[index] = object.id;
|
|
237
|
+
numbers[k] = p.x;
|
|
238
|
+
numbers[k + 1] = p.y;
|
|
239
|
+
numbers[k + 2] = p.z;
|
|
240
|
+
numbers[k + 3] = q.x;
|
|
241
|
+
numbers[k + 4] = q.y;
|
|
242
|
+
numbers[k + 5] = q.z;
|
|
243
|
+
numbers[k + 6] = q.w;
|
|
244
|
+
numbers[k + 7] = s.x;
|
|
245
|
+
numbers[k + 8] = s.y;
|
|
246
|
+
numbers[k + 9] = s.z;
|
|
247
|
+
numbers.set(object.matrixWorld.elements, k + INPUTS);
|
|
248
|
+
const children = object.children;
|
|
249
|
+
for (let c = 0; c < children.length; c++) {
|
|
250
|
+
write(children[c], record);
|
|
251
|
+
}
|
|
252
|
+
record.sizes[index] = at - index;
|
|
253
|
+
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// change a part's materials after they are built.
|
|
8
8
|
|
|
9
9
|
import * as THREE from 'three';
|
|
10
|
-
import { makeMaterial, resolveArtTexture } from './materials';
|
|
10
|
+
import { makeMaterial, resolveArtTexture, trackDerivedTexture } from './materials';
|
|
11
11
|
import { needsModelGeometry } from './partgeometry';
|
|
12
12
|
|
|
13
13
|
const DEG = Math.PI / 180;
|
|
@@ -117,7 +117,7 @@ function specTexture(spec, part, sprites) {
|
|
|
117
117
|
texture.center.set(0.5, 0.5);
|
|
118
118
|
texture.rotation = rotation * DEG;
|
|
119
119
|
texture.needsUpdate = true;
|
|
120
|
-
variants.set(key, texture);
|
|
120
|
+
variants.set(key, trackDerivedTexture(base, texture));
|
|
121
121
|
}
|
|
122
122
|
return texture;
|
|
123
123
|
}
|
|
@@ -13,6 +13,20 @@ import { renderArtFrame, artReady, artFrameCount } from '@imports/castle.physics
|
|
|
13
13
|
// Baked textures cached per art object per frame (sprites are re-parsed only
|
|
14
14
|
// when the file changes, so object identity is a good key).
|
|
15
15
|
const textureCache = new WeakMap();
|
|
16
|
+
// Textures cloned from a cached one (tiling here, per-part variants in
|
|
17
|
+
// artobjects.js), by the texture they came from, so releasing an art's
|
|
18
|
+
// textures releases these too.
|
|
19
|
+
const derivedTextures = new WeakMap();
|
|
20
|
+
|
|
21
|
+
export function trackDerivedTexture(base, derived) {
|
|
22
|
+
let set = derivedTextures.get(base);
|
|
23
|
+
if (!set) {
|
|
24
|
+
set = new Set();
|
|
25
|
+
derivedTextures.set(base, set);
|
|
26
|
+
}
|
|
27
|
+
set.add(derived);
|
|
28
|
+
return derived;
|
|
29
|
+
}
|
|
16
30
|
|
|
17
31
|
function albedoTexture(art, frame) {
|
|
18
32
|
if (!art || !artReady(art)) return null;
|
|
@@ -35,6 +49,20 @@ function albedoTexture(art, frame) {
|
|
|
35
49
|
return texture;
|
|
36
50
|
}
|
|
37
51
|
|
|
52
|
+
// Dispose the textures baked for one art object, for art that is going away
|
|
53
|
+
// for good (a mounted content pack being dropped). A live mesh still using one
|
|
54
|
+
// would draw black, so callers release only art nothing draws any more.
|
|
55
|
+
export function releaseArtTextures(art) {
|
|
56
|
+
const byFrame = art ? textureCache.get(art) : null;
|
|
57
|
+
if (!byFrame) return;
|
|
58
|
+
for (const texture of byFrame.values()) {
|
|
59
|
+
for (const derived of derivedTextures.get(texture) ?? []) derived.dispose();
|
|
60
|
+
derivedTextures.delete(texture);
|
|
61
|
+
texture.dispose();
|
|
62
|
+
}
|
|
63
|
+
textureCache.delete(art);
|
|
64
|
+
}
|
|
65
|
+
|
|
38
66
|
// 'drawings/door.sprite#1' -> { path, frame }
|
|
39
67
|
function parseArtRef(ref) {
|
|
40
68
|
const hash = ref.lastIndexOf('#');
|
|
@@ -56,7 +84,7 @@ export function resolveArtTexture(ref, sprites, repeat) {
|
|
|
56
84
|
tiled.wrapT = THREE.RepeatWrapping;
|
|
57
85
|
tiled.repeat.set(repeat[0] ?? 1, repeat[1] ?? 1);
|
|
58
86
|
tiled.needsUpdate = true;
|
|
59
|
-
return tiled;
|
|
87
|
+
return trackDerivedTexture(texture, tiled);
|
|
60
88
|
}
|
|
61
89
|
|
|
62
90
|
function artRefsOf(shape) {
|