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
|
@@ -473,9 +473,13 @@ function updateOrbiting(actor, scene, props, dt) {
|
|
|
473
473
|
if (typeof rt.facing !== 'number') rt.facing = Math.PI - per.camAngle;
|
|
474
474
|
const shape = actor.components.Shape;
|
|
475
475
|
const grounded = hoverSteadily(phys, actor, t, { radius: shape?.radius ?? 0.35, height: shape?.height ?? 1.4 });
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
476
|
+
if (scene.playerDrive?.step) {
|
|
477
|
+
scene.playerDrive.step(actor, phys, { keys: scene.keys, stick: scene.moveInput, grounded }, dt);
|
|
478
|
+
} else {
|
|
479
|
+
applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt);
|
|
480
|
+
t.rotationY = rt.facing / DEG;
|
|
481
|
+
jumpOrbiting(phys, actor, scene, rt, grounded, props.jumpSpeed, dt);
|
|
482
|
+
}
|
|
479
483
|
hudOrbiting(scene, actor, t, per, rt.facing);
|
|
480
484
|
}
|
|
481
485
|
|
|
@@ -1147,31 +1151,37 @@ export class Player {
|
|
|
1147
1151
|
// every call below is the one made before the keys had this meaning.
|
|
1148
1152
|
const steady = scene.cameraFollowsRigidly === true || scene.maxFps > 0;
|
|
1149
1153
|
const grounded = steady ? hoverSteadily(phys, actor, t, dims) : applyHover(phys, actor, t, dims, dt);
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1154
|
+
// Optional local controller supplied by another system. Hover, camera and
|
|
1155
|
+
// HUD remain Player's; without it the walking path is unchanged.
|
|
1156
|
+
if (scene.playerDrive?.step) {
|
|
1157
|
+
scene.playerDrive.step(actor, phys, { keys: scene.keys, stick: scene.moveInput, grounded }, dt);
|
|
1158
|
+
} else {
|
|
1159
|
+
const drive = readDrive(scene.keys, scene.moveInput);
|
|
1160
|
+
per.camAngle += drive.turn * this.props.turnSpeed * dt;
|
|
1161
|
+
rt.facing = Math.PI - per.camAngle;
|
|
1162
|
+
const move =
|
|
1163
|
+
drive.forward !== 0
|
|
1164
|
+
? {
|
|
1165
|
+
x: Math.sin(per.camAngle) * drive.forward,
|
|
1166
|
+
z: -Math.cos(per.camAngle) * drive.forward,
|
|
1167
|
+
}
|
|
1168
|
+
: null;
|
|
1169
|
+
applyMove(phys, actor, move, this.props.speed, grounded, dt);
|
|
1170
|
+
t.rotationY = rt.facing / DEG;
|
|
1162
1171
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1172
|
+
// Jump: Space on keyboard, or a short tap anywhere on the canvas (which
|
|
1173
|
+
// works while another finger drives the drag stick). A tap is buffered
|
|
1174
|
+
// briefly so one made just before touchdown still fires.
|
|
1175
|
+
if (scene.moveInput?.consumeJump?.()) rt.jumpBuffer = 0.18;
|
|
1176
|
+
else rt.jumpBuffer = Math.max(0, (rt.jumpBuffer ?? 0) - dt);
|
|
1177
|
+
if ((keyDown(scene.keys, 'Space') || rt.jumpBuffer > 0) && grounded) {
|
|
1178
|
+
rt.jumpBuffer = 0;
|
|
1179
|
+
const vel = phys.getVelocity(actor);
|
|
1180
|
+
phys.setVelocity(actor, { x: vel.x, y: this.props.jumpSpeed, z: vel.z });
|
|
1181
|
+
// The jump replaces the velocity the hover was holding; this frame's
|
|
1182
|
+
// lift goes too, or it would be added to the jump.
|
|
1183
|
+
if (steady) phys.resetForces(actor);
|
|
1184
|
+
}
|
|
1175
1185
|
}
|
|
1176
1186
|
// Fall faster than the rise: extra downward pull past the jump apex kills
|
|
1177
1187
|
// the floaty arc.
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
},
|
|
55
55
|
"castle.base": {
|
|
56
56
|
"deckId": "yRcmH4_aYllE",
|
|
57
|
-
"version": "2026-10-
|
|
57
|
+
"version": "2026-10-21T18:36:51.857Z"
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"main": "main.jsx",
|
|
61
61
|
"autoUpdateWhenImported": true,
|
|
62
62
|
"deckId": "JH0SclbPVP0y",
|
|
63
63
|
"cardId": "eXfAaUdbSU5A",
|
|
64
|
-
"publishedVersion": "2026-10-
|
|
64
|
+
"publishedVersion": "2026-10-21T18:38:09.393Z"
|
|
65
65
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# CPU geometry retention under low memory
|
|
2
|
+
|
|
3
|
+
The low-memory profile currently retains geometry arrays. The upload-discard
|
|
4
|
+
pattern (`attribute.onUpload(function () { this.array = null; })`) is unsafe
|
|
5
|
+
for every substantial category audited here. No geometry category is opted in;
|
|
6
|
+
expected geometry saving is **0 MB**, including on iOS 15.
|
|
7
|
+
|
|
8
|
+
| Consumer | Audit result |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| Mesh raycasts and pointer picking | `three`'s `Mesh.raycast` reads index, position, normal and UV attributes. `editorWorld.js` and `modelEditorWorld.js` pick recursively. Hub `decor.js` also picks runtime actor nodes and clones previews. Static/frozen does not mean unpickable. |
|
|
11
|
+
| Camera collision and physics | `systems/physics3d.js` builds primitive colliders from Shape; its fixed-solid ray queries use Rapier, not render arrays. `frozenphysics.js` reconciles these bodies and does not read model geometry. These consumers alone would allow release, but the others do not. |
|
|
12
|
+
| Bounds | `optimize.js` computes mesh bounds during optimization and instance construction; Three can lazily compute missing bounds. Caching both box and sphere before upload only removes this one reader. |
|
|
13
|
+
| Look and AO | `look.js` reads positions, normals and indices and writes occlusion/outline attributes. `lookbake.js` queues work after frames have already drawn and propagates it into clones; first upload does not imply completion. Later model builds/merges may still read shared sources. |
|
|
14
|
+
| Merge and instancing | `optimize.js` clones attributes, bakes materials/transforms and merges geometry. Render-only scene instances disable raycasts, but share geometry with model templates, ordinary copies and outline meshes. They do not own disposable CPU arrays. Instance matrices also update every frame. |
|
|
15
|
+
| Far avatars | Hub `farAvatars.js` clones, transforms and merges template geometry after deferred look baking ends. Avatars, far-avatar proxies, animated/skinned/morph meshes and per-part motion remain excluded. `motion.js` clones geometry and updates partGlow attributes. |
|
|
16
|
+
| Frozen scenery | `frozenstatics.js` freezes transforms only, permits immediate thaw, and explicitly supports node cloning. It does not establish immutable, render-only geometry ownership. |
|
|
17
|
+
| Editor and reload | Editor worlds remain ordinary pickable meshes. Runtime models share cached templates; clones, rebuilds, resident scenes and later actors can reuse geometry. No player-only ownership boundary currently makes array disposal safe. |
|
|
18
|
+
| Screenshots | `preserveDrawingBuffer` supports canvas readback without reading attributes; a capture can still require another frame, or wait for deferred look work. It does not make upload data disposable. |
|
|
19
|
+
| Dispose, context loss and re-upload | Three r180 `WebGLAttributes.createBuffer` reads array.byteLength and the typed array. A restored WebGL context has a fresh attribute cache and re-uploads existing objects. Geometry disposal followed by reuse also recreates GPU buffers. needsUpdate reads array.byteLength and uploads it again. A material/program change may use previously unused attributes; changing a material alone does not recreate every existing GPU attribute buffer. `world3d.js` prevents default context loss for automatic restoration but does not reconstruct CPU arrays. Even an unpickable sky dome still needs its arrays after restoration. |
|
|
20
|
+
|
|
21
|
+
A future discard path needs exclusive render-only geometry ownership and
|
|
22
|
+
regeneration before these readers or a fresh GPU upload; freezing transforms
|
|
23
|
+
is not that contract.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Deliberately narrow: desktop-mode iPads and devices with no iOS version
|
|
2
|
+
// stay on the normal path unless the player explicitly overrides it.
|
|
3
|
+
export function lowMemoryDevice({ navigator = globalThis.navigator, storage } = {}) {
|
|
4
|
+
try {
|
|
5
|
+
const override = (storage === undefined ? globalThis.localStorage : storage)?.getItem('castle.engine3d.lowMemory');
|
|
6
|
+
if (override === 'on' || override === 'off') {
|
|
7
|
+
return { on: override === 'on', reason: `storage:${override}` };
|
|
8
|
+
}
|
|
9
|
+
} catch { /* Blocked storage is the same as no override. */ }
|
|
10
|
+
|
|
11
|
+
const ua = navigator?.userAgent ?? '';
|
|
12
|
+
const ios = /\bOS (\d+)_/.exec(ua);
|
|
13
|
+
if (/\b(iPhone|iPad|iPod)\b/.test(ua) && ios && Number(ios[1]) <= 15) {
|
|
14
|
+
return { on: true, reason: `ios:${ios[1]}` };
|
|
15
|
+
}
|
|
16
|
+
return { on: false, reason: 'default' };
|
|
17
|
+
}
|
|
@@ -13,6 +13,7 @@ import { attachOrbitInput } from './orbitinput';
|
|
|
13
13
|
import { renderHidingOwnModel } from './ownmodel';
|
|
14
14
|
import { makeFrameClock, makeInputLatch, nextFrame, updateLending } from './framecap';
|
|
15
15
|
import { prepareModelConsumers } from './modelready.js';
|
|
16
|
+
import { lowMemoryDevice } from './memoryprofile.js';
|
|
16
17
|
|
|
17
18
|
export function mountScene3D({
|
|
18
19
|
canvas,
|
|
@@ -29,7 +30,11 @@ export function mountScene3D({
|
|
|
29
30
|
onStage?.('runtime:start');
|
|
30
31
|
const runtime = makeScene(sceneData, behaviorClasses, sprites, files, scenePath);
|
|
31
32
|
onStage?.('runtime:built');
|
|
32
|
-
const
|
|
33
|
+
const profile = typeof sceneData.engine?.lowMemory === 'boolean'
|
|
34
|
+
? { on: sceneData.engine.lowMemory, reason: `scene:${sceneData.engine.lowMemory ? 'on' : 'off'}` }
|
|
35
|
+
: lowMemoryDevice();
|
|
36
|
+
const world = makeWorld3D(canvas, { lowMemory: profile.on });
|
|
37
|
+
world.lowMemoryReason = profile.reason;
|
|
33
38
|
if (onStage) world.onStage = onStage;
|
|
34
39
|
onStage?.('world:built');
|
|
35
40
|
runtime.three = world;
|
|
@@ -519,9 +519,14 @@ export function visibleBounds(node) {
|
|
|
519
519
|
return bounds;
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
// A part's mesh sits in its group at `offset`, stretched by `scale`.
|
|
522
|
+
// A part's mesh sits in its group at `offset`, stretched by `scale`. A
|
|
523
|
+
// `paint` part (id, name or material, as hub-game's car tint finds it) is
|
|
524
|
+
// marked so the hub scene export can name its material for native tinting.
|
|
523
525
|
function placePartMesh(mesh, part, group) {
|
|
524
526
|
mesh.userData.partMesh = part.id;
|
|
527
|
+
if (part.id === 'paint' || part.name === 'paint' || part.material === 'paint') {
|
|
528
|
+
mesh.userData.paint = true;
|
|
529
|
+
}
|
|
525
530
|
mesh.position.set(part.offset[0], part.offset[1], part.offset[2]);
|
|
526
531
|
mesh.scale.set(part.scale[0], part.scale[1], part.scale[2]);
|
|
527
532
|
group.add(mesh);
|
|
@@ -47,7 +47,8 @@ import {
|
|
|
47
47
|
|
|
48
48
|
const GROUND_SIZE = 60;
|
|
49
49
|
|
|
50
|
-
export function makeWorld3D(canvas) {
|
|
50
|
+
export function makeWorld3D(canvas, options = {}) {
|
|
51
|
+
const lowMemory = options.lowMemory === true;
|
|
51
52
|
const scene = new THREE.Scene();
|
|
52
53
|
const aspect = canvas.clientWidth / Math.max(1, canvas.clientHeight);
|
|
53
54
|
const camera = new THREE.PerspectiveCamera(50, aspect, 0.1, 1000);
|
|
@@ -56,13 +57,14 @@ export function makeWorld3D(canvas) {
|
|
|
56
57
|
|
|
57
58
|
const renderer = new THREE.WebGLRenderer({
|
|
58
59
|
canvas,
|
|
59
|
-
|
|
60
|
+
// Composer targets have no MSAA; canvas MSAA only smooths OutputPass's quad.
|
|
61
|
+
antialias: false,
|
|
60
62
|
preserveDrawingBuffer: true, // screenshots read the canvas after the frame
|
|
61
63
|
});
|
|
62
64
|
// If the browser reclaims this context (live-context cap), ask for the
|
|
63
65
|
// automatic restore instead of staying a white canvas forever.
|
|
64
66
|
canvas.addEventListener('webglcontextlost', (event) => event.preventDefault());
|
|
65
|
-
renderer.setPixelRatio(window.devicePixelRatio);
|
|
67
|
+
renderer.setPixelRatio(lowMemory ? Math.min(window.devicePixelRatio, 2) : window.devicePixelRatio);
|
|
66
68
|
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
|
|
67
69
|
renderer.setClearColor(0x000000);
|
|
68
70
|
renderer.shadowMap.enabled = true;
|
|
@@ -94,6 +96,7 @@ export function makeWorld3D(canvas) {
|
|
|
94
96
|
camera,
|
|
95
97
|
renderer,
|
|
96
98
|
composer,
|
|
99
|
+
lowMemory,
|
|
97
100
|
nodes: new Map(),
|
|
98
101
|
// The scene path `nodes` were built for, and the nodes of scenes the
|
|
99
102
|
// runtime keeps resident while another one plays (`residentScenes`).
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"scripts": {
|
|
6
6
|
"restart": "castle-web restart .",
|
|
7
7
|
"screenshot": "castle-web screenshot .",
|
|
8
|
-
"check": "eslint . && jscpd && node scripts/test-rapier-gz.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
|
|
8
|
+
"check": "eslint . && jscpd && node scripts/test-rapier-gz.mjs && node scripts/test-memory-profile.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
|
|
9
9
|
},
|
|
10
10
|
"jscpd": {
|
|
11
11
|
"path": [
|
|
@@ -467,9 +467,14 @@ function updateOrbiting(actor, scene, props, dt) {
|
|
|
467
467
|
rt.facing = Math.PI - per.camAngle;
|
|
468
468
|
const shape = actor.components.Shape;
|
|
469
469
|
const grounded = hoverSteadily(phys, actor, t, { radius: shape?.radius ?? 0.35, height: shape?.height ?? 1.4 });
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
470
|
+
if (scene.playerDrive?.step) {
|
|
471
|
+
scene.playerDrive.step(actor, phys, { keys: scene.keys, stick: scene.moveInput, grounded }, dt);
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt);
|
|
475
|
+
t.rotationY = rt.facing / DEG;
|
|
476
|
+
jumpOrbiting(phys, actor, scene, rt, grounded, props.jumpSpeed, dt);
|
|
477
|
+
}
|
|
473
478
|
hudOrbiting(scene, actor, t, per, rt.facing);
|
|
474
479
|
}
|
|
475
480
|
const finiteOr = (value, otherwise) => (Number.isFinite(value) ? value : otherwise);
|
|
@@ -1150,32 +1155,39 @@ class Player {
|
|
|
1150
1155
|
// every call below is the one made before the keys had this meaning.
|
|
1151
1156
|
const steady = scene.cameraFollowsRigidly === true || scene.maxFps > 0;
|
|
1152
1157
|
const grounded = steady ? hoverSteadily(phys, actor, t, dims) : applyHover(phys, actor, t, dims, dt);
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1158
|
+
// Optional local controller supplied by another system. Hover, camera and
|
|
1159
|
+
// HUD remain Player's; without it the walking path is unchanged.
|
|
1160
|
+
if (scene.playerDrive?.step) {
|
|
1161
|
+
scene.playerDrive.step(actor, phys, { keys: scene.keys, stick: scene.moveInput, grounded }, dt);
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
const drive = readDrive(scene.keys, scene.moveInput);
|
|
1165
|
+
per.camAngle += drive.turn * this.props.turnSpeed * dt;
|
|
1166
|
+
rt.facing = Math.PI - per.camAngle;
|
|
1167
|
+
const move = drive.forward !== 0
|
|
1168
|
+
? {
|
|
1169
|
+
x: Math.sin(per.camAngle) * drive.forward,
|
|
1170
|
+
z: -Math.cos(per.camAngle) * drive.forward,
|
|
1171
|
+
}
|
|
1172
|
+
: null;
|
|
1173
|
+
applyMove(phys, actor, move, this.props.speed, grounded, dt);
|
|
1174
|
+
t.rotationY = rt.facing / DEG;
|
|
1175
|
+
// Jump: Space on keyboard, or a short tap anywhere on the canvas (which
|
|
1176
|
+
// works while another finger drives the drag stick). A tap is buffered
|
|
1177
|
+
// briefly so one made just before touchdown still fires.
|
|
1178
|
+
if (scene.moveInput?.consumeJump?.())
|
|
1179
|
+
rt.jumpBuffer = 0.18;
|
|
1180
|
+
else
|
|
1181
|
+
rt.jumpBuffer = Math.max(0, (rt.jumpBuffer ?? 0) - dt);
|
|
1182
|
+
if ((keyDown(scene.keys, 'Space') || rt.jumpBuffer > 0) && grounded) {
|
|
1183
|
+
rt.jumpBuffer = 0;
|
|
1184
|
+
const vel = phys.getVelocity(actor);
|
|
1185
|
+
phys.setVelocity(actor, { x: vel.x, y: this.props.jumpSpeed, z: vel.z });
|
|
1186
|
+
// The jump replaces the velocity the hover was holding; this frame's
|
|
1187
|
+
// lift goes too, or it would be added to the jump.
|
|
1188
|
+
if (steady)
|
|
1189
|
+
phys.resetForces(actor);
|
|
1160
1190
|
}
|
|
1161
|
-
: null;
|
|
1162
|
-
applyMove(phys, actor, move, this.props.speed, grounded, dt);
|
|
1163
|
-
t.rotationY = rt.facing / DEG;
|
|
1164
|
-
// Jump: Space on keyboard, or a short tap anywhere on the canvas (which
|
|
1165
|
-
// works while another finger drives the drag stick). A tap is buffered
|
|
1166
|
-
// briefly so one made just before touchdown still fires.
|
|
1167
|
-
if (scene.moveInput?.consumeJump?.())
|
|
1168
|
-
rt.jumpBuffer = 0.18;
|
|
1169
|
-
else
|
|
1170
|
-
rt.jumpBuffer = Math.max(0, (rt.jumpBuffer ?? 0) - dt);
|
|
1171
|
-
if ((keyDown(scene.keys, 'Space') || rt.jumpBuffer > 0) && grounded) {
|
|
1172
|
-
rt.jumpBuffer = 0;
|
|
1173
|
-
const vel = phys.getVelocity(actor);
|
|
1174
|
-
phys.setVelocity(actor, { x: vel.x, y: this.props.jumpSpeed, z: vel.z });
|
|
1175
|
-
// The jump replaces the velocity the hover was holding; this frame's
|
|
1176
|
-
// lift goes too, or it would be added to the jump.
|
|
1177
|
-
if (steady)
|
|
1178
|
-
phys.resetForces(actor);
|
|
1179
1191
|
}
|
|
1180
1192
|
// Fall faster than the rise: extra downward pull past the jump apex kills
|
|
1181
1193
|
// the floaty arc.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { register } from 'node:module';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { lowMemoryDevice } from '../engine3d/memoryprofile.js';
|
|
5
|
+
|
|
6
|
+
const phone15 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_8 like Mac OS X)';
|
|
7
|
+
const phone16 = phone15.replace('15_8', '16_0');
|
|
8
|
+
const ipad15 = 'Mozilla/5.0 (iPad; CPU OS 15_7 like Mac OS X)';
|
|
9
|
+
const desktopIpad = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15)';
|
|
10
|
+
const storage = (value) => ({ getItem(key) { assert.equal(key, 'castle.engine3d.lowMemory'); return value; } });
|
|
11
|
+
const detect = (userAgent, extra = {}) => lowMemoryDevice({ navigator: { userAgent }, storage: null, ...extra });
|
|
12
|
+
|
|
13
|
+
for (const ua of [phone15, ipad15, phone15.replace('iPhone', 'iPod'), phone15.replace('15_8', '12_5')]) {
|
|
14
|
+
assert.equal(detect(ua).on, true, ua);
|
|
15
|
+
}
|
|
16
|
+
for (const ua of [phone16, 'Mozilla/5.0 (Linux; Android 10)', '', 'iPhone without an OS version']) {
|
|
17
|
+
assert.equal(detect(ua).on, false, ua);
|
|
18
|
+
}
|
|
19
|
+
assert.equal(detect(desktopIpad, { navigator: { userAgent: desktopIpad, maxTouchPoints: 5 } }).on, false);
|
|
20
|
+
assert.equal(detect(phone15, { storage: storage('off') }).on, false);
|
|
21
|
+
assert.equal(detect(phone16, { storage: storage('on') }).on, true);
|
|
22
|
+
assert.equal(detect(desktopIpad, { storage: storage('on') }).on, true);
|
|
23
|
+
for (const value of ['ON', 'true', '', null]) assert.equal(detect(phone15, { storage: storage(value) }).on, true);
|
|
24
|
+
for (const throwing of [
|
|
25
|
+
{ getItem() { throw Error('blocked'); } },
|
|
26
|
+
{ get getItem() { throw Error('blocked property'); } },
|
|
27
|
+
]) {
|
|
28
|
+
assert.equal(detect(phone15, { storage: throwing }).on, true);
|
|
29
|
+
assert.equal(detect(phone16, { storage: throwing }).on, false);
|
|
30
|
+
}
|
|
31
|
+
const beforeStorage = Object.getOwnPropertyDescriptor(globalThis, 'localStorage');
|
|
32
|
+
try {
|
|
33
|
+
Object.defineProperty(globalThis, 'localStorage', { configurable: true, get() { throw Error('blocked global'); } });
|
|
34
|
+
assert.equal(lowMemoryDevice({ navigator: { userAgent: phone15 } }).on, true);
|
|
35
|
+
Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: storage('off') });
|
|
36
|
+
assert.deepEqual(lowMemoryDevice({ navigator: { userAgent: phone15 } }), { on: false, reason: 'storage:off' });
|
|
37
|
+
} finally {
|
|
38
|
+
if (beforeStorage) Object.defineProperty(globalThis, 'localStorage', beforeStorage);
|
|
39
|
+
else delete globalThis.localStorage;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Use real three objects, passes and composer/targets; replace only the GPU
|
|
43
|
+
// renderer. Both profiles retain linear-space blending and OutputPass.
|
|
44
|
+
const threeURL = import.meta.resolve('three');
|
|
45
|
+
const rendererStub = `
|
|
46
|
+
import * as THREE from ${JSON.stringify(threeURL)};
|
|
47
|
+
export * from ${JSON.stringify(threeURL)};
|
|
48
|
+
export class WebGLRenderer {
|
|
49
|
+
constructor(options) {
|
|
50
|
+
this.options = options; this.domElement = options.canvas;
|
|
51
|
+
this.shadowMap = { autoUpdate: true }; this.capabilities = { maxTextureSize: 4096 };
|
|
52
|
+
this.toneMapping = THREE.NoToneMapping; this.toneMappingExposure = 1;
|
|
53
|
+
this.outputColorSpace = THREE.SRGBColorSpace; this.autoClear = true;
|
|
54
|
+
this.autoClearColor = true; this.autoClearDepth = true; this.autoClearStencil = true;
|
|
55
|
+
this.calls = []; this.target = null; this.draws = 0;
|
|
56
|
+
}
|
|
57
|
+
setPixelRatio(value) { this.ratio = value; }
|
|
58
|
+
getPixelRatio() { return this.ratio; }
|
|
59
|
+
setSize(...args) { this.size = args; }
|
|
60
|
+
getSize(out) { return out.set(this.size[0], this.size[1]); }
|
|
61
|
+
setClearColor() {}
|
|
62
|
+
clear() {}
|
|
63
|
+
getRenderTarget() { return this.target; }
|
|
64
|
+
setRenderTarget(target) { this.target = target; }
|
|
65
|
+
render(scene, camera) {
|
|
66
|
+
scene.updateMatrixWorld(); camera.updateMatrixWorld();
|
|
67
|
+
this.calls.push({ scene, camera, target: this.target, toneMapping: this.toneMapping,
|
|
68
|
+
exposure: this.toneMappingExposure, colorSpace: this.outputColorSpace });
|
|
69
|
+
this.draws++;
|
|
70
|
+
this.onRender?.(scene, camera);
|
|
71
|
+
}
|
|
72
|
+
dispose() { this.disposed = true; }
|
|
73
|
+
}`;
|
|
74
|
+
const sceneStub = `export function makeScene(data) {
|
|
75
|
+
return globalThis.__memoryRuntime = { data, keys: new Set(), dispose() { this.disposed = true; } };
|
|
76
|
+
}`;
|
|
77
|
+
register('data:text/javascript,' + encodeURIComponent(String.raw`
|
|
78
|
+
import { existsSync } from 'node:fs';
|
|
79
|
+
import { fileURLToPath } from 'node:url';
|
|
80
|
+
const data = (source) => ({ url: 'data:text/javascript,' + encodeURIComponent(source), shortCircuit: true });
|
|
81
|
+
export async function resolve(specifier, context, next) {
|
|
82
|
+
const parent = context.parentURL ?? '';
|
|
83
|
+
if (parent.endsWith('/engine3d/world3d.js')) {
|
|
84
|
+
if (specifier === 'three') return data(${JSON.stringify(rendererStub)});
|
|
85
|
+
}
|
|
86
|
+
if (parent.endsWith('/engine3d/playerRun.js') && specifier.endsWith('/engine/scene')) return data(${JSON.stringify(sceneStub)});
|
|
87
|
+
if (specifier.startsWith('@imports/castle.physics-2d/')) {
|
|
88
|
+
specifier = parent.replace(/\/kits\/.*/, '/kits/physics-2d/') + specifier.slice(27);
|
|
89
|
+
}
|
|
90
|
+
if ((specifier.startsWith('.') || specifier.startsWith('file:')) && parent.includes('/kits/') && !/\.(m?js|jsx|json)$/.test(specifier)) {
|
|
91
|
+
const base = new URL(specifier, parent).href;
|
|
92
|
+
if (existsSync(fileURLToPath(base + '.js'))) return next(base + '.js', context);
|
|
93
|
+
}
|
|
94
|
+
return next(specifier, context);
|
|
95
|
+
}
|
|
96
|
+
`));
|
|
97
|
+
const { makeWorld3D, resizeWorld, renderWorld, disposeWorld } = await import('../engine3d/world3d.js');
|
|
98
|
+
const { mountScene3D } = await import('../engine3d/playerRun.js');
|
|
99
|
+
const { readSkyKey } = await import('../../physics-2d/engine/skyKey.js');
|
|
100
|
+
const globals = ['window', 'document', 'ResizeObserver', 'requestAnimationFrame', 'cancelAnimationFrame', 'navigator', 'localStorage'];
|
|
101
|
+
const saved = globals.map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]);
|
|
102
|
+
// Existing composer ownership/disposal stays unchanged; release test resources.
|
|
103
|
+
function releaseComposer(world) {
|
|
104
|
+
world.composer.passes.forEach((pass) => pass.dispose());
|
|
105
|
+
world.composer.dispose();
|
|
106
|
+
}
|
|
107
|
+
function release(world) {
|
|
108
|
+
releaseComposer(world);
|
|
109
|
+
disposeWorld(world);
|
|
110
|
+
}
|
|
111
|
+
const canvas = () => ({ clientWidth: 320, clientHeight: 640, addEventListener() {}, removeEventListener() {}, focus() {} });
|
|
112
|
+
try {
|
|
113
|
+
globalThis.window = { devicePixelRatio: 3, addEventListener() {}, removeEventListener() {} };
|
|
114
|
+
globalThis.document = { hasFocus: () => false };
|
|
115
|
+
globalThis.ResizeObserver = class { observe() {} disconnect() {} };
|
|
116
|
+
globalThis.requestAnimationFrame = () => 1; // Mount without running a game loop.
|
|
117
|
+
globalThis.cancelAnimationFrame = () => {};
|
|
118
|
+
Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: null });
|
|
119
|
+
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { userAgent: phone15 } });
|
|
120
|
+
|
|
121
|
+
const normal = makeWorld3D(canvas());
|
|
122
|
+
const low = makeWorld3D(canvas(), { lowMemory: true });
|
|
123
|
+
assert.equal(normal.lowMemory, false);
|
|
124
|
+
assert.equal(low.lowMemory, true);
|
|
125
|
+
|
|
126
|
+
const sky = readSkyKey({ engine: { sky: { zones: [{ id: 'home', color: '#bfe3f2' }] } } }, 'memory.scene');
|
|
127
|
+
assert(sky);
|
|
128
|
+
const runtime = { sky, nearShadowDistance: 30 };
|
|
129
|
+
for (const [world, ratio] of [[normal, 3], [low, 2]]) {
|
|
130
|
+
const { renderer, composer } = world;
|
|
131
|
+
assert.equal(renderer.options.antialias, false);
|
|
132
|
+
assert.equal(renderer.options.preserveDrawingBuffer, true, 'screenshots still read the canvas after a frame');
|
|
133
|
+
assert.equal(renderer.getPixelRatio(), ratio);
|
|
134
|
+
assert.deepEqual(composer.passes.map((pass) => pass.constructor.name), ['RenderPass', 'OutputPass']);
|
|
135
|
+
assert.equal(composer._pixelRatio, ratio, 'DPR is set before composer construction');
|
|
136
|
+
for (const target of [composer.renderTarget1, composer.renderTarget2]) {
|
|
137
|
+
assert.equal(target.width, 320 * ratio, 'targets start at the profile DPR');
|
|
138
|
+
assert.equal(target.height, 640 * ratio);
|
|
139
|
+
assert.equal(target.samples, 0);
|
|
140
|
+
}
|
|
141
|
+
assert.equal(renderer.shadowMap.enabled, true);
|
|
142
|
+
assert.equal(renderer.shadowMap.type, THREE.PCFSoftShadowMap);
|
|
143
|
+
resizeWorld(world, 480, 240);
|
|
144
|
+
assert.deepEqual(renderer.size, [480, 240, false]);
|
|
145
|
+
assert.equal(world.camera.aspect, 2);
|
|
146
|
+
for (const target of [composer.renderTarget1, composer.renderTarget2]) {
|
|
147
|
+
assert.equal(target.width, 480 * ratio);
|
|
148
|
+
assert.equal(target.height, 240 * ratio);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// A scene draws into a linear target; only the final quad writes the
|
|
152
|
+
// canvas. Keep the real OutputPass and its renderer-derived settings.
|
|
153
|
+
const output = composer.passes[1];
|
|
154
|
+
for (const toneMapping of [THREE.NoToneMapping, THREE.ACESFilmicToneMapping, THREE.AgXToneMapping]) {
|
|
155
|
+
for (const colorSpace of [THREE.SRGBColorSpace, THREE.LinearSRGBColorSpace]) {
|
|
156
|
+
Object.assign(renderer, { toneMapping, toneMappingExposure: 1.7, outputColorSpace: colorSpace });
|
|
157
|
+
const before = renderer.draws;
|
|
158
|
+
const sceneTarget = composer.readBuffer;
|
|
159
|
+
renderWorld(world);
|
|
160
|
+
assert.equal(renderer.draws, before + 2, 'scene plus output quad on both profiles');
|
|
161
|
+
const [sceneDraw, outputDraw] = renderer.calls.slice(-2);
|
|
162
|
+
assert.equal(sceneDraw.scene, world.scene);
|
|
163
|
+
assert.equal(sceneDraw.camera, world.camera);
|
|
164
|
+
assert.equal(sceneDraw.target, sceneTarget);
|
|
165
|
+
assert.equal(output.uniforms.tDiffuse.value, sceneTarget.texture);
|
|
166
|
+
assert.equal(sceneDraw.target.texture.colorSpace, THREE.NoColorSpace);
|
|
167
|
+
assert.equal(outputDraw.scene.material, output.material);
|
|
168
|
+
assert.equal(outputDraw.target, null);
|
|
169
|
+
assert.equal(output._toneMapping, toneMapping);
|
|
170
|
+
assert.equal(output._outputColorSpace, colorSpace);
|
|
171
|
+
assert.equal(output.uniforms.toneMappingExposure.value, 1.7);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const sun = world.scene.children.find((node) => node.isDirectionalLight);
|
|
176
|
+
const ownShadow = sun.shadow;
|
|
177
|
+
// A real renderer allocates this on its first shadow pass.
|
|
178
|
+
ownShadow.map = new THREE.WebGLRenderTarget(2048, 2048);
|
|
179
|
+
let sawSky = 0, sawNear = 0;
|
|
180
|
+
renderer.onRender = (scene) => {
|
|
181
|
+
if (scene !== world.scene) return; // OutputPass draws its own quad.
|
|
182
|
+
const dome = scene.getObjectByName('engine.sky');
|
|
183
|
+
assert(dome, 'sky is present during the composer scene draw');
|
|
184
|
+
assert.equal(dome.material.toneMapped, false, 'sky still relies on OutputPass');
|
|
185
|
+
assert.doesNotMatch(dome.material.fragmentShader, /tonemapping_fragment/);
|
|
186
|
+
sawSky++;
|
|
187
|
+
if (sun.shadow !== ownShadow) sawNear++;
|
|
188
|
+
};
|
|
189
|
+
for (let i = 0; i < 3; i++) renderWorld(world, runtime);
|
|
190
|
+
assert.equal(sawSky, 3);
|
|
191
|
+
assert(sawNear > 0, 'near-shadow frames still use the composer');
|
|
192
|
+
assert.equal(sun.shadow, ownShadow);
|
|
193
|
+
const skyMesh = world.sky.mesh;
|
|
194
|
+
assert.equal(skyMesh.parent, null, 'sky wrapper restores the scene');
|
|
195
|
+
renderer.onRender = () => { throw Error('composer draw failed'); };
|
|
196
|
+
assert.throws(() => renderWorld(world, runtime), /composer draw failed/);
|
|
197
|
+
assert.equal(sun.shadow, ownShadow);
|
|
198
|
+
assert.equal(skyMesh.parent, null);
|
|
199
|
+
release(world);
|
|
200
|
+
assert.equal(renderer.disposed, true);
|
|
201
|
+
assert.equal(world.sky, null);
|
|
202
|
+
assert.equal(world.disposed, true);
|
|
203
|
+
ownShadow.map.dispose();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
window.devicePixelRatio = 1.5;
|
|
207
|
+
const lower = makeWorld3D(canvas(), { lowMemory: true });
|
|
208
|
+
assert.equal(lower.renderer.getPixelRatio(), 1.5, 'cap never increases DPR');
|
|
209
|
+
assert.equal(lower.composer.renderTarget1.width, 320 * 1.5);
|
|
210
|
+
assert.equal(lower.renderer.options.preserveDrawingBuffer, true);
|
|
211
|
+
release(lower);
|
|
212
|
+
|
|
213
|
+
for (const [ua, engine, expected, reason] of [
|
|
214
|
+
[phone15, undefined, true, 'ios:15'], [phone16, undefined, false, 'default'],
|
|
215
|
+
[phone15, { lowMemory: false }, false, 'scene:off'], [phone16, { lowMemory: true }, true, 'scene:on'],
|
|
216
|
+
]) {
|
|
217
|
+
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { userAgent: ua } });
|
|
218
|
+
const stop = mountScene3D({ canvas: canvas(), sceneData: { engine }, sprites: {}, files: {}, behaviorClasses: [] });
|
|
219
|
+
const runtime = globalThis.__memoryRuntime;
|
|
220
|
+
assert.equal(runtime.three.lowMemory, expected);
|
|
221
|
+
assert.equal(runtime.three.lowMemoryReason, reason);
|
|
222
|
+
assert.equal(runtime.three.renderer.options.antialias, false);
|
|
223
|
+
assert.equal(runtime.three.renderer.options.preserveDrawingBuffer, true);
|
|
224
|
+
assert.deepEqual(runtime.three.composer.passes.map((pass) => pass.constructor.name), ['RenderPass', 'OutputPass']);
|
|
225
|
+
releaseComposer(runtime.three);
|
|
226
|
+
stop();
|
|
227
|
+
assert.equal(runtime.three.renderer.disposed, true);
|
|
228
|
+
assert.equal(runtime.disposed, true);
|
|
229
|
+
}
|
|
230
|
+
} finally {
|
|
231
|
+
for (const [key, descriptor] of saved) {
|
|
232
|
+
if (descriptor) Object.defineProperty(globalThis, key, descriptor);
|
|
233
|
+
else delete globalThis[key];
|
|
234
|
+
}
|
|
235
|
+
delete globalThis.__memoryRuntime;
|
|
236
|
+
}
|
|
237
|
+
console.log('memory profile: detection, overrides, player selection, preserved capture buffers, capped composer targets, resize/render/sky/near-shadows/disposal passed');
|
|
@@ -847,7 +847,9 @@ function makeApi(system, runtime) {
|
|
|
847
847
|
system.forces?.delete(idOf(actor));
|
|
848
848
|
if (system.forces?.size === 0) system.forces = null;
|
|
849
849
|
},
|
|
850
|
-
|
|
850
|
+
// `skip(actorId)`, when given, passes over the colliders of any actor it
|
|
851
|
+
// answers true for, so what stands behind them is what the ray meets.
|
|
852
|
+
castRay: (origin, dir, maxToi, excludeActor, skip) => {
|
|
851
853
|
if (!system.world) return null;
|
|
852
854
|
const ray = new RAPIER.Ray(origin, dir);
|
|
853
855
|
const exclude = excludeActor ? bodyOf(excludeActor) : undefined;
|
|
@@ -858,7 +860,8 @@ function makeApi(system, runtime) {
|
|
|
858
860
|
RAPIER.QueryFilterFlags.EXCLUDE_SENSORS,
|
|
859
861
|
undefined,
|
|
860
862
|
undefined,
|
|
861
|
-
exclude ?? undefined
|
|
863
|
+
exclude ?? undefined,
|
|
864
|
+
typeof skip === 'function' ? (collider) => !skip(system.byCollider.get(collider.handle) ?? null) : undefined
|
|
862
865
|
);
|
|
863
866
|
if (!hit) return null;
|
|
864
867
|
return {
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"imports": {
|
|
4
4
|
"castle.base": {
|
|
5
5
|
"deckId": "yRcmH4_aYllE",
|
|
6
|
-
"version": "2026-10-
|
|
6
|
+
"version": "2026-10-21T18:36:51.857Z"
|
|
7
7
|
}
|
|
8
8
|
},
|
|
9
9
|
"autoUpdateWhenImported": true,
|
|
10
10
|
"deckId": "xFVr-afOLuUQ",
|
|
11
11
|
"cardId": "w6G45sy3_P_m",
|
|
12
|
-
"publishedVersion": "2026-10-
|
|
12
|
+
"publishedVersion": "2026-10-21T18:37:16.504Z"
|
|
13
13
|
}
|
|
@@ -30,6 +30,11 @@ export const UNLOADED = 'x';
|
|
|
30
30
|
// session's player to name a scene decides it; later ones change nothing.
|
|
31
31
|
export const SCENE = 'c';
|
|
32
32
|
|
|
33
|
+
// A client back from an away with no WORLD since asks for the world again:
|
|
34
|
+
// `{ k: RESYNC }`. Only a session whose hooks offer `resync` (its WORLD says
|
|
35
|
+
// `rs: 1`) answers, with a WORLD marked `again: 1`.
|
|
36
|
+
export const RESYNC = 'r';
|
|
37
|
+
|
|
33
38
|
// Movement reports run below the render rate and below the platform's roughly
|
|
34
39
|
// 30-message-per-second client cap. A second report inside one server tick would
|
|
35
40
|
// be overwritten before the simulation read it.
|