castle-web-cli 0.4.230 → 0.4.232
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/castle-host/host.js +81 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +22 -12
- package/dist/devSessionServer.js +8 -2
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/init.js +1 -1
- package/dist/serve.js +5 -1
- package/dist/serverBundle.js +5 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +148 -1
- package/kits/base/sdk/castle.d.ts +4 -0
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +15 -0
- package/kits/base/sdk/multiplayer.js +52 -4
- 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/storage.d.ts +3 -2
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +4 -0
- package/kits/base/sdk/server/wrapper.js +2 -0
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/hub-game/CLAUDE.md +29 -4
- package/kits/hub-game/code/client/avatar.js +39 -0
- package/kits/hub-game/code/client/chat.js +12 -0
- package/kits/hub-game/code/client/chrome.js +237 -13
- package/kits/hub-game/code/client/grab.js +166 -7
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +36 -3
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/state.js +35 -1
- package/kits/hub-game/code/client/talk.js +10 -36
- package/kits/hub-game/code/client/tiers.js +505 -0
- package/kits/hub-game/code/client/together.js +144 -4
- package/kits/hub-game/code/client/wear.js +96 -14
- package/kits/hub-game/code/server/actors.js +5 -0
- package/kits/hub-game/code/server/grab.js +299 -13
- package/kits/hub-game/code/server/hub.js +162 -7
- package/kits/hub-game/code/server/manifest.js +80 -8
- package/kits/hub-game/code/server/npcs.js +21 -33
- package/kits/hub-game/code/server/party.js +75 -6
- package/kits/hub-game/code/server/say.js +8 -2
- package/kits/hub-game/code/server/wear.js +116 -11
- package/kits/hub-game/code/systems/hub.js +386 -21
- package/kits/hub-game/docs/contract.md +285 -19
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-chat.mjs +32 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
- package/kits/hub-game/scripts/test-grab.mjs +857 -3
- package/kits/hub-game/scripts/test-hats.mjs +229 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
- package/kits/hub-game/scripts/test-manifest.mjs +122 -1
- package/kits/hub-game/scripts/test-npcs.mjs +34 -24
- package/kits/hub-game/scripts/test-party.mjs +108 -4
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-tiers.mjs +854 -0
- package/kits/hub-game/scripts/test-together.mjs +33 -1
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +127 -0
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
- package/kits/physics-3d/CLAUDE.md +531 -0
- package/kits/physics-3d/behaviors/Player.jsx +437 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +4 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/optimize.js +49 -0
- package/kits/physics-3d/engine3d/orbitinput.js +277 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +525 -11
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
- package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +667 -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/scripts/test-steady-hover.mjs +633 -0
- package/kits/physics-3d/systems/physics3d.js +273 -9
- package/package.json +1 -1
|
@@ -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
|
+
}
|