@woosh/meep-engine 2.127.0 → 2.128.0
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/package.json +1 -1
- package/src/core/geom/packing/miniball/Miniball.d.ts +12 -10
- package/src/core/geom/packing/miniball/Miniball.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/Miniball.js +76 -54
- package/src/engine/Clock.d.ts +2 -1
- package/src/engine/Clock.d.ts.map +1 -1
- package/src/engine/Clock.js +1 -0
- package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
- package/src/engine/ecs/EntityComponentDataset.js +2 -1
- package/src/engine/ecs/EntityManager.d.ts +5 -6
- package/src/engine/ecs/EntityManager.d.ts.map +1 -1
- package/src/engine/ecs/EntityManager.js +83 -37
- package/src/engine/ecs/System.d.ts +2 -2
- package/src/engine/ecs/System.d.ts.map +1 -1
- package/src/engine/ecs/System.js +41 -19
- package/src/engine/ecs/dynamic_actions/DynamicActorSystem.d.ts +1 -1
- package/src/engine/ecs/dynamic_actions/DynamicActorSystem.d.ts.map +1 -1
- package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +1 -4
- package/src/engine/ecs/fow/FogOfWarSystem.d.ts +2 -4
- package/src/engine/ecs/fow/FogOfWarSystem.d.ts.map +1 -1
- package/src/engine/ecs/fow/FogOfWarSystem.js +15 -21
- package/src/engine/ecs/gui/GUIElementSystem.d.ts.map +1 -1
- package/src/engine/ecs/gui/GUIElementSystem.js +7 -18
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.d.ts.map +1 -1
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +3 -10
- package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts +2 -2
- package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts.map +1 -1
- package/src/engine/ecs/gui/position/ViewportPositionSystem.js +2 -6
- package/src/engine/ecs/renderable/RenderSystem.d.ts.map +1 -1
- package/src/engine/ecs/renderable/RenderSystem.js +3 -7
- package/src/engine/ecs/speaker/VoiceSystem.d.ts +1 -1
- package/src/engine/ecs/speaker/VoiceSystem.d.ts.map +1 -1
- package/src/engine/ecs/speaker/VoiceSystem.js +2 -4
- package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -5
- package/src/engine/ecs/tooltip/TooltipComponentSystem.d.ts +2 -2
- package/src/engine/ecs/tooltip/TooltipComponentSystem.d.ts.map +1 -1
- package/src/engine/ecs/tooltip/TooltipComponentSystem.js +10 -12
- package/src/engine/ecs/validateSystem.d.ts.map +1 -1
- package/src/engine/ecs/validateSystem.js +11 -2
- package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/CameraSystem.js +5 -8
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -6
- package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.js +14 -27
- package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/LightSystem.js +2 -6
- package/src/engine/graphics/ecs/mesh/MeshSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +2 -6
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -5
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +1 -2
- package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/PathDisplaySystem.js +13 -17
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +2 -6
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts +2 -2
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/water/WaterSystem.js +5 -11
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts.map +1 -1
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +2 -6
- package/src/engine/graphics/render/frame_graph/RenderGraph.d.ts +51 -7
- package/src/engine/graphics/render/frame_graph/RenderGraph.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/RenderGraph.js +109 -8
- package/src/engine/graphics/render/frame_graph/RenderPassBuilder.d.ts +44 -0
- package/src/engine/graphics/render/frame_graph/RenderPassBuilder.d.ts.map +1 -0
- package/src/engine/graphics/render/frame_graph/{RenderGraphBuilder.js → RenderPassBuilder.js} +25 -6
- package/src/engine/graphics/render/frame_graph/RenderPassNode.d.ts +1 -0
- package/src/engine/graphics/render/frame_graph/RenderPassNode.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/RenderPassNode.js +1 -0
- package/src/engine/graphics/render/frame_graph/ResourceEntry.d.ts +8 -0
- package/src/engine/graphics/render/frame_graph/ResourceEntry.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/ResourceEntry.js +8 -0
- package/src/engine/graphics/render/frame_graph/resource/ResourceDescriptor.d.ts +1 -0
- package/src/engine/graphics/render/frame_graph/resource/ResourceDescriptor.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/resource/ResourceDescriptor.js +3 -0
- package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
- package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -2
- package/src/engine/intelligence/behavior/ecs/BehaviorSystem.d.ts +2 -2
- package/src/engine/intelligence/behavior/ecs/BehaviorSystem.d.ts.map +1 -1
- package/src/engine/intelligence/behavior/ecs/BehaviorSystem.js +3 -5
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts +2 -2
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +2 -6
- package/src/engine/graphics/render/frame_graph/RenderGraphBuilder.d.ts +0 -33
- package/src/engine/graphics/render/frame_graph/RenderGraphBuilder.d.ts.map +0 -1
- package/src/engine/graphics/render/frame_graph/RenderPass.d.ts +0 -50
- package/src/engine/graphics/render/frame_graph/RenderPass.d.ts.map +0 -1
- package/src/engine/graphics/render/frame_graph/RenderPass.js +0 -74
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"description": "Pure JavaScript game engine. Fully featured and production ready.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.
|
|
8
|
+
"version": "2.128.0",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Computes the miniball of the given point set.
|
|
3
3
|
*
|
|
4
|
+
* Based on paper "Fast Smallest-Enclosing-Ball Computation in High Dimensions" by "Kaspar Fischer" et. al.
|
|
4
5
|
* @copyright Company Named Limited (c) 2025
|
|
5
6
|
*/
|
|
6
7
|
export class Miniball {
|
|
@@ -152,16 +153,17 @@ export class Miniball {
|
|
|
152
153
|
*
|
|
153
154
|
* Iteratively, we compute the point in support that is closest to the current center and then
|
|
154
155
|
* walk towards this target as far as we can, i.e., we move until some new point touches the
|
|
155
|
-
* boundary of the ball and must thus be inserted into support.
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
156
|
+
* boundary of the ball and must thus be inserted into support.
|
|
157
|
+
*
|
|
158
|
+
* In each of these two alternating phases, we always have to check whether some point must be dropped from support,
|
|
159
|
+
* which is the case when the center lies in <i>aff(support)</i>.
|
|
160
|
+
* If such an attempt to drop fails, we are done; because then the center lies even <i>conv(support)</i>.
|
|
159
161
|
* @private
|
|
160
162
|
*/
|
|
161
163
|
private compute;
|
|
162
164
|
/**
|
|
163
165
|
* If center doesn't already lie in <i>conv(support)</i> and is thus not optimal yet,
|
|
164
|
-
* {@link
|
|
166
|
+
* {@link successfulDrop()} elects a suitable point <i>k</i> to be removed from the support and
|
|
165
167
|
* returns true. If the center lies in the convex hull, however, false is returned (and the
|
|
166
168
|
* support remains unaltered).
|
|
167
169
|
*
|
|
@@ -171,16 +173,16 @@ export class Miniball {
|
|
|
171
173
|
successfulDrop(): boolean;
|
|
172
174
|
/**
|
|
173
175
|
* Given the center of the current enclosing ball and the walking direction `centerToAff`,
|
|
174
|
-
* determine how much we can walk into this direction without losing a point from <i>S</i>.
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* was found.
|
|
176
|
+
* determine how much we can walk into this direction without losing a point from <i>S</i>.
|
|
177
|
+
*
|
|
178
|
+
* The (positive) factor by which we can walk along `centerToAff` is returned.
|
|
179
|
+
* Further, `stopper` is set to the index of the most restricting point and to -1 if no such point was found.
|
|
178
180
|
* @return {number}
|
|
179
181
|
* @private
|
|
180
182
|
*/
|
|
181
183
|
private findStopFraction;
|
|
182
184
|
/**
|
|
183
|
-
* Outputs information about the
|
|
185
|
+
* Outputs information about the Miniball
|
|
184
186
|
* @return {string}
|
|
185
187
|
*/
|
|
186
188
|
toString(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Miniball.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/packing/miniball/Miniball.js"],"names":[],"mappings":"AAwBA
|
|
1
|
+
{"version":3,"file":"Miniball.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/packing/miniball/Miniball.js"],"names":[],"mappings":"AAwBA;;;;;GAKG;AACH;IA8CI;;;;;OAKG;IACH,8BA4DC;IA9GD;;;OAGG;IACH,WAFU,MAAM,CAEF;IAEd;;;OAGG;IACH,WAFU,MAAM,CAEF;IAEd;;;OAGG;IACH,iBAFU,MAAM,CAEI;IAEpB;;;;;;;;;;OAUG;IACH,wBAAoB;IAEpB;;;;OAIG;IACH,iBAAa;IAEb;;;OAGG;IACH,SAFU,MAAM,CAEJ;IAYR;;OAEG;IACH,YAAe;IAEf;;;;OAIG;IACH,eAA2B;IAI3B;;;OAGG;IACH,KAFU,MAAM,CAEU;IAM1B;;;;OAIG;IACH,iBAA4D;IAE5D;;;OAGG;IACH,aAFU,MAAM,EAAE,GAAC,YAAY,CAEkD;IAEjF;;;OAGG;IACH,eAFU,MAAM,EAAE,GAAC,YAAY,CAEwD;IAEvF;;;OAGG;IACH,SAFU,MAAM,EAAE,GAAC,YAAY,CAEsD;IAErF;;;;OAIG;IACH,kBAAgC;IAIpC;;;;;;;OAOG;IACH,WAFY,OAAO,CAIlB;IAED;;;;;;OAMG;IACH,UAFY,MAAM,CAIjB;IAED;;;;;;OAMG;IACH,UAFY,MAAM,EAAE,CAInB;IAED;;;OAGG;IACH,uBAEC;IAED;;;;;;OAMG;IACH,QAJY,MAAM,CAMjB;IAED;;;;;;;;OAQG;IACH,iBAkCC;IAED;;OAEG;IACH,yBAGC;IAED;;OAEG;IACH,qBAcC;IAED;;;;;;;;;;;OAWG;IACH,gBA4CC;IAED;;;;;;;;OAQG;IACH,kBAFY,OAAO,CA4BlB;IAED;;;;;;;;OAQG;IACH,yBA8DC;IAGD;;;OAGG;IACH,YAFY,MAAM,CA0BjB;CACJ;wBAzcuB,cAAc"}
|
|
@@ -14,10 +14,10 @@ import { Subspan } from "./Subspan.js";
|
|
|
14
14
|
* Small number
|
|
15
15
|
* @type {number}
|
|
16
16
|
*/
|
|
17
|
-
const Epsilon =
|
|
17
|
+
const Epsilon = 1e-14;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Limit to how many iterations algorithm is allowed to perform, this is to cover poorly converging cases
|
|
20
|
+
* Limit to how many iterations the algorithm is allowed to perform, this is to cover poorly converging cases
|
|
21
21
|
* @type {number}
|
|
22
22
|
*/
|
|
23
23
|
const MAX_ITERATIONS = 10000;
|
|
@@ -25,9 +25,55 @@ const MAX_ITERATIONS = 10000;
|
|
|
25
25
|
/**
|
|
26
26
|
* Computes the miniball of the given point set.
|
|
27
27
|
*
|
|
28
|
+
* Based on paper "Fast Smallest-Enclosing-Ball Computation in High Dimensions" by "Kaspar Fischer" et. al.
|
|
28
29
|
* @copyright Company Named Limited (c) 2025
|
|
29
30
|
*/
|
|
30
31
|
export class Miniball {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @type {number}
|
|
36
|
+
*/
|
|
37
|
+
iteration = 0;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @type {number}
|
|
42
|
+
*/
|
|
43
|
+
distToAff = 0;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
distToAffSquare = 0;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* The squared radius of the miniball.
|
|
54
|
+
*
|
|
55
|
+
* This is equivalent to `radius() * radius()`.
|
|
56
|
+
*
|
|
57
|
+
* Precondition: `!isEmpty()`
|
|
58
|
+
*
|
|
59
|
+
* @type {number}
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
__squaredRadius = 0;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @type {number}
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
__radius = 0;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @type {number}
|
|
74
|
+
*/
|
|
75
|
+
stopper = 0;
|
|
76
|
+
|
|
31
77
|
/**
|
|
32
78
|
* Notice that the point set `points` is assumed to be immutable during the computation.
|
|
33
79
|
* That is, if you add, remove, or change points in the point set, you have to create a new instance of {@link Miniball}.
|
|
@@ -37,44 +83,6 @@ export class Miniball {
|
|
|
37
83
|
constructor(points) {
|
|
38
84
|
assert.defined(points, 'points');
|
|
39
85
|
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @type {number}
|
|
43
|
-
*/
|
|
44
|
-
this.iteration = 0;
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @type {number}
|
|
48
|
-
*/
|
|
49
|
-
this.distToAff = 0;
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
* @type {number}
|
|
53
|
-
*/
|
|
54
|
-
this.distToAffSquare = 0;
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* The squared radius of the miniball.
|
|
58
|
-
*
|
|
59
|
-
* This is equivalent to `radius() * radius()`.
|
|
60
|
-
*
|
|
61
|
-
* Precondition: `!isEmpty()`
|
|
62
|
-
*
|
|
63
|
-
* @type {number}
|
|
64
|
-
* @private
|
|
65
|
-
*/
|
|
66
|
-
this.__squaredRadius = 0;
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @type {number}
|
|
70
|
-
* @private
|
|
71
|
-
*/
|
|
72
|
-
this.__radius = 0;
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* @type {number}
|
|
76
|
-
*/
|
|
77
|
-
this.stopper = 0;
|
|
78
86
|
|
|
79
87
|
/**
|
|
80
88
|
* @type {PointSet}
|
|
@@ -264,10 +272,11 @@ export class Miniball {
|
|
|
264
272
|
*
|
|
265
273
|
* Iteratively, we compute the point in support that is closest to the current center and then
|
|
266
274
|
* walk towards this target as far as we can, i.e., we move until some new point touches the
|
|
267
|
-
* boundary of the ball and must thus be inserted into support.
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
275
|
+
* boundary of the ball and must thus be inserted into support.
|
|
276
|
+
*
|
|
277
|
+
* In each of these two alternating phases, we always have to check whether some point must be dropped from support,
|
|
278
|
+
* which is the case when the center lies in <i>aff(support)</i>.
|
|
279
|
+
* If such an attempt to drop fails, we are done; because then the center lies even <i>conv(support)</i>.
|
|
271
280
|
* @private
|
|
272
281
|
*/
|
|
273
282
|
compute() {
|
|
@@ -318,7 +327,7 @@ export class Miniball {
|
|
|
318
327
|
|
|
319
328
|
/**
|
|
320
329
|
* If center doesn't already lie in <i>conv(support)</i> and is thus not optimal yet,
|
|
321
|
-
* {@link
|
|
330
|
+
* {@link successfulDrop()} elects a suitable point <i>k</i> to be removed from the support and
|
|
322
331
|
* returns true. If the center lies in the convex hull, however, false is returned (and the
|
|
323
332
|
* support remains unaltered).
|
|
324
333
|
*
|
|
@@ -355,10 +364,10 @@ export class Miniball {
|
|
|
355
364
|
|
|
356
365
|
/**
|
|
357
366
|
* Given the center of the current enclosing ball and the walking direction `centerToAff`,
|
|
358
|
-
* determine how much we can walk into this direction without losing a point from <i>S</i>.
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* was found.
|
|
367
|
+
* determine how much we can walk into this direction without losing a point from <i>S</i>.
|
|
368
|
+
*
|
|
369
|
+
* The (positive) factor by which we can walk along `centerToAff` is returned.
|
|
370
|
+
* Further, `stopper` is set to the index of the most restricting point and to -1 if no such point was found.
|
|
362
371
|
* @return {number}
|
|
363
372
|
* @private
|
|
364
373
|
*/
|
|
@@ -379,7 +388,11 @@ export class Miniball {
|
|
|
379
388
|
const centerToPoint = this.centerToPoint;
|
|
380
389
|
const centerToAff = this.centerToAff;
|
|
381
390
|
|
|
391
|
+
const distToAffSquare = this.distToAffSquare;
|
|
392
|
+
const squaredRadius = this.__squaredRadius;
|
|
393
|
+
|
|
382
394
|
const size = this.__size;
|
|
395
|
+
const distance_error = Epsilon * this.__radius * this.distToAff;
|
|
383
396
|
|
|
384
397
|
for (j = 0; j < size; ++j) {
|
|
385
398
|
|
|
@@ -388,6 +401,7 @@ export class Miniball {
|
|
|
388
401
|
}
|
|
389
402
|
|
|
390
403
|
for (i = 0; i < dim; ++i) {
|
|
404
|
+
// read out a single point, offset by center
|
|
391
405
|
centerToPoint[i] = pointSet.coord(j, i) - center[i];
|
|
392
406
|
}
|
|
393
407
|
|
|
@@ -397,7 +411,7 @@ export class Miniball {
|
|
|
397
411
|
dirPointProd += centerToAff[i] * centerToPoint[i];
|
|
398
412
|
}
|
|
399
413
|
|
|
400
|
-
if ((
|
|
414
|
+
if ((distToAffSquare - dirPointProd) < distance_error) {
|
|
401
415
|
continue;
|
|
402
416
|
}
|
|
403
417
|
|
|
@@ -407,7 +421,7 @@ export class Miniball {
|
|
|
407
421
|
bound += centerToPoint[i] * centerToPoint[i];
|
|
408
422
|
}
|
|
409
423
|
|
|
410
|
-
bound = (
|
|
424
|
+
bound = (squaredRadius - bound) / 2 / (distToAffSquare - dirPointProd);
|
|
411
425
|
|
|
412
426
|
if (bound > 0 && bound < scale) {
|
|
413
427
|
//if (com.dreizak.miniball.highdim.Logging.log)
|
|
@@ -423,15 +437,20 @@ export class Miniball {
|
|
|
423
437
|
|
|
424
438
|
|
|
425
439
|
/**
|
|
426
|
-
* Outputs information about the
|
|
440
|
+
* Outputs information about the Miniball
|
|
427
441
|
* @return {string}
|
|
428
442
|
*/
|
|
429
443
|
toString() {
|
|
430
444
|
let s = "Miniball [";
|
|
445
|
+
|
|
431
446
|
if (this.isEmpty()) {
|
|
432
|
-
|
|
447
|
+
|
|
448
|
+
s += "isEmpty=true";
|
|
449
|
+
|
|
433
450
|
} else {
|
|
434
|
-
|
|
451
|
+
|
|
452
|
+
s += "center=(";
|
|
453
|
+
|
|
435
454
|
for (let i = 0; i < this.dim; ++i) {
|
|
436
455
|
s += (this.__center[i]);
|
|
437
456
|
if (i < this.dim - 1)
|
|
@@ -439,8 +458,11 @@ export class Miniball {
|
|
|
439
458
|
}
|
|
440
459
|
|
|
441
460
|
s += `), radius=${this.__radius}, squaredRadius=${this.__squaredRadius}`;
|
|
461
|
+
|
|
442
462
|
}
|
|
463
|
+
|
|
443
464
|
s += "]";
|
|
465
|
+
|
|
444
466
|
return s;
|
|
445
467
|
}
|
|
446
468
|
}
|
package/src/engine/Clock.d.ts
CHANGED
|
@@ -31,8 +31,9 @@ declare class Clock {
|
|
|
31
31
|
* Allows us to slow down or speed up flow of time via modifiers, see {@link Stat} for details
|
|
32
32
|
* Default speed is x1, i.e. - unmodified
|
|
33
33
|
* @type {Stat}
|
|
34
|
+
* @readonly
|
|
34
35
|
*/
|
|
35
|
-
speed: Stat;
|
|
36
|
+
readonly speed: Stat;
|
|
36
37
|
/**
|
|
37
38
|
*
|
|
38
39
|
* @param {number} v
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Clock.d.ts","sourceRoot":"","sources":["../../../src/engine/Clock.js"],"names":[],"mappings":";AAcA;;GAEG;AACH;IAEI;;;;OAIG;IACH,0BAAsB;IAEtB;;;OAGG;IACH,aAFU,MAAM,CAEA;IAEhB;;;;OAIG;IACH,aAFU,MAAM,CAEA;IAEhB;;;;OAIG;IACH,oBAAoB;IAGpB
|
|
1
|
+
{"version":3,"file":"Clock.d.ts","sourceRoot":"","sources":["../../../src/engine/Clock.js"],"names":[],"mappings":";AAcA;;GAEG;AACH;IAEI;;;;OAIG;IACH,0BAAsB;IAEtB;;;OAGG;IACH,aAFU,MAAM,CAEA;IAEhB;;;;OAIG;IACH,aAFU,MAAM,CAEA;IAEhB;;;;OAIG;IACH,oBAAoB;IAGpB;;;;;;OAMG;IACH,gBAHU,IAAI,CAGM;IAMpB;;;OAGG;IACH,4BAEC;IAED;;;OAGG;IACH,yBAEC;IAED,cAIC;IAED,aAEC;IAED,cAIC;IAED;;;OAGG;IACH,YAFa,MAAM,CAOlB;IAED;;;OAGG;IACH,qBAFa,MAAM,CAOlB;IAED;;;;OAIG;IACH,kBAFY,MAAM,CAIjB;IAED,cAGC;CACJ;iBA/HgB,4BAA4B"}
|
package/src/engine/Clock.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AAyHA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wDAfyB,MAAM;IAiB3B;;;;OAIG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC;;;;;;;;;OASG;IACH,2BAAkC;IAElC;;;;;OAKG;IACH,yBAAsB;IAEtB;;;;OAIG;IACH,4BAAgC;IAEhC;;;;OAIG;IACH,2BAAuB;IAEvB;;;;OAIG;IACH,mBAAgB;IAEhB;;;;OAIG;IACH,oBAAgB;IAEhB;;;;;;;OAOG;IACH,mBAAe;IAEf;;;OAGG;IACH,0BAFU,OAAO,MAAM,CAAC,CAEO;IAE/B;;;OAGG;IACH,0BAFU,OAAO,MAAM,CAAC,CAEO;IAG/B;;;;OAIG;IACH,+BAA4B;IAE5B;;;;OAIG;IACH,kCAA+B;IAE/B;;;OAGG;IACH,kBAAe;IAGf;;;;;;OAMG;IACH,mEAkCC;IAED;;;;;OAKG;IACH,kDAHW,OAAO,GACL,OAAO,CAqDnB;IAED;;;;;OAKG;IACH,qDAHW,OAAO,GACL,OAAO,CA6DnB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,yBAFa,MAAM,CAIlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,qBACN,EAAE,SAmCZ;IAED
|
|
1
|
+
{"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"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"}
|
|
@@ -477,7 +477,8 @@ export class EntityComponentDataset {
|
|
|
477
477
|
}
|
|
478
478
|
|
|
479
479
|
/**
|
|
480
|
-
* Get all components associated with a given entity
|
|
480
|
+
* Get all components associated with a given entity.
|
|
481
|
+
* Note that this method allocates. If performance is important - prefer alternatives.
|
|
481
482
|
* @param {number} entity_id
|
|
482
483
|
* @returns {[]} all components attached to the entity, array is not compacted
|
|
483
484
|
*/
|
|
@@ -141,7 +141,7 @@ export class EntityManager {
|
|
|
141
141
|
/**
|
|
142
142
|
* If the {@link EntityManager} is already started, the system will be started automatically before being added
|
|
143
143
|
* @param {System} system
|
|
144
|
-
* @returns {Promise}
|
|
144
|
+
* @returns {Promise} resolution depends on {@link EntityManager}'s state, if running - promise resolves after system startup. Otherwise, the promise will be resolved immediately.
|
|
145
145
|
* @throws {IllegalStateException}
|
|
146
146
|
*/
|
|
147
147
|
addSystem(system: System<any, any, any, any, any>): Promise<any>;
|
|
@@ -166,8 +166,8 @@ export class EntityManager {
|
|
|
166
166
|
*/
|
|
167
167
|
private startSystem;
|
|
168
168
|
/**
|
|
169
|
-
* This method is asynchronous by nature, it has to wait for each
|
|
170
|
-
* Make sure to register callback
|
|
169
|
+
* This method is asynchronous by nature, it has to wait for each system to finish its own startup.
|
|
170
|
+
* Make sure to register callback to be notified when the startup has finished
|
|
171
171
|
* @param {function} [readyCallback] executed once entity manager successfully completes startup
|
|
172
172
|
* @param {function} [errorCallback] executed if entity manager encounters an error during startup
|
|
173
173
|
*/
|
|
@@ -179,17 +179,16 @@ export class EntityManager {
|
|
|
179
179
|
*/
|
|
180
180
|
promiseSystem(systemClass: Class): Promise<System<any, any, any, any, any>>;
|
|
181
181
|
/**
|
|
182
|
-
*
|
|
183
182
|
* @param {Class} systemClass
|
|
184
183
|
* @param {SystemState} state
|
|
185
184
|
* @returns {Promise.<System>}
|
|
186
185
|
*/
|
|
187
186
|
promiseSystemInState(systemClass: Class, state: SystemState): Promise<System<any, any, any, any, any>>;
|
|
188
187
|
/**
|
|
189
|
-
* This method is asynchronous by nature, it will not be done until each
|
|
188
|
+
* This method is asynchronous by nature, it will not be done until each system has finished its shutdown
|
|
190
189
|
* Make sure to use callback to be notified when the shutdown has completed
|
|
191
190
|
* @param {function} [readyCallback] Called when shutdown finishes successfully. defaults to no-operation
|
|
192
|
-
* @param {function} [errorCallback] Called when an error occurs during shutdown process. defaults to console error output
|
|
191
|
+
* @param {function} [errorCallback] Called when an error occurs during the shutdown process. defaults to console error output
|
|
193
192
|
*/
|
|
194
193
|
shutdown(readyCallback?: Function, errorCallback?: Function): void;
|
|
195
194
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAgBU,MAAM;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAgBU,MAAM;;;;;;;;;AAiBhB;;;;;;GAMG;AACH;IAEI;;;;OAIG;IACH,kBAFU,iCAAQ,CAEL;IAEb;;;;;;OAMG;IACH,uCAA2B;IAE3B;;;;;OAKG;IACH,iCAA4B;IAE5B;;OAEG;IACH;;;QAGI;;WAEG;qBADO,uCAAc;;MAI1B;IAEF;;;OAGG;IACH,OAFU,kBAAkB,CAEO;IAEnC;;;;;;OAMG;IACH,gDAA2C;IAE3C;;;;;;;;;OASG;IACH,qBAFU,MAAM,CAEqB;IAErC;;;;;OAKG;IACH,wCAFU,MAAM,CAE4B;IAE5C;;;;OAIG;IACH,SAFU,sBAAsB,CAEjB;IAEf;;;;;OAKG;IACH,uCAAsC;IAEtC;;;OAGG;IACH,6BAmFC;IAED;;;OAGG;IACH,uBAFa,OAAO,CAuBnB;IAED;;;;;OAKG;IACH,uBAJW,sBAAsB,QA4ChC;IAGD;;;OAGG;IACH,sBA2BC;IAED;;;;OAIG;IACH,qCAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,6CAgBC;IAED;;;;;OAKG;IACH,wCAHW,MAAM,GACJ,IAAI,aAAS,CAiBzB;IAGD;;;OAGG;IACH,oBAFW,MAAM,QAoEhB;IAED;;;;;OAKG;IACH,iEA6DC;IAED;;;;OAIG;IACH,uDAFa,QAAQ,OAAO,CAAC,CA2C5B;IAED;;;;;OAKG;IACH,mBAmCC;IAED;;;;;OAKG;IACH,oBAqFC;IAED;;;;;OAKG;IACH,kEAyEC;IAED;;;;OAIG;IACH,mCAFa,wCAAgB,CA0B5B;IAED;;;;OAIG;IACH,8DAFa,wCAAgB,CAsB5B;IAED;;;;;OAKG;IACH,mEAoFC;IAGL;;OAEG;IACH,yBAxrBe,sBAAsB,UAwrBA;IACrC;;OAEG;IACH,0BAAqC;CATpC;uBAh6BmC,aAAa;mBAR9B,oCAAoC;uCAMhB,6BAA6B"}
|
|
@@ -25,6 +25,12 @@ export const EntityManagerState = {
|
|
|
25
25
|
Stopped: 5
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* In seconds
|
|
30
|
+
* @type {number}
|
|
31
|
+
*/
|
|
32
|
+
const DEFAULT_SYSTEM_STARTUP_TIMEOUT_CHECK = 5;
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* Brings together {@link System}s and an {@link EntityComponentDataset}
|
|
30
36
|
* Main entry point into the simulation process
|
|
@@ -261,7 +267,7 @@ export class EntityManager {
|
|
|
261
267
|
|
|
262
268
|
const localComponentTypeMap = this.getComponentTypeMap();
|
|
263
269
|
|
|
264
|
-
//ensure compatibility with system-used component map
|
|
270
|
+
// ensure compatibility with system-used component map
|
|
265
271
|
dataset.registerManyComponentTypes(localComponentTypeMap);
|
|
266
272
|
|
|
267
273
|
this.dataset = dataset;
|
|
@@ -450,7 +456,7 @@ export class EntityManager {
|
|
|
450
456
|
/**
|
|
451
457
|
* If the {@link EntityManager} is already started, the system will be started automatically before being added
|
|
452
458
|
* @param {System} system
|
|
453
|
-
* @returns {Promise}
|
|
459
|
+
* @returns {Promise} resolution depends on {@link EntityManager}'s state, if running - promise resolves after system startup. Otherwise, the promise will be resolved immediately.
|
|
454
460
|
* @throws {IllegalStateException}
|
|
455
461
|
*/
|
|
456
462
|
addSystem(system) {
|
|
@@ -472,17 +478,17 @@ export class EntityManager {
|
|
|
472
478
|
try {
|
|
473
479
|
validateSystem(system);
|
|
474
480
|
} catch (e) {
|
|
475
|
-
console.error(`
|
|
481
|
+
console.error(`Validation of '${computeSystemName(system)}' failed : `, e, system);
|
|
476
482
|
}
|
|
477
483
|
|
|
478
484
|
//check system state
|
|
479
485
|
const systemState = system.state.getValue();
|
|
480
486
|
|
|
481
|
-
const
|
|
487
|
+
const valid_states = [SystemState.INITIAL, SystemState.STOPPED];
|
|
482
488
|
|
|
483
|
-
if (
|
|
489
|
+
if (valid_states.indexOf(systemState) === -1) {
|
|
484
490
|
//illegal state
|
|
485
|
-
throw new IllegalStateException(`System must be in one of these states: [${
|
|
491
|
+
throw new IllegalStateException(`System must be in one of these states: [${valid_states.join(",")}], instead was ${systemState}`);
|
|
486
492
|
}
|
|
487
493
|
|
|
488
494
|
const systems = this.systems;
|
|
@@ -495,22 +501,16 @@ export class EntityManager {
|
|
|
495
501
|
const entityObserver = new EntityObserver(system.dependencies, system.link, system.unlink, system);
|
|
496
502
|
this.systemObservers.set(system, entityObserver);
|
|
497
503
|
|
|
498
|
-
let
|
|
504
|
+
let result_promise;
|
|
499
505
|
if (this.state === EntityManagerState.Running) {
|
|
500
506
|
//initialize the system
|
|
501
|
-
|
|
507
|
+
result_promise = new Promise((resolve, reject) => {
|
|
502
508
|
this.startSystem(system, resolve, reject);
|
|
503
509
|
});
|
|
504
510
|
} else {
|
|
505
|
-
|
|
511
|
+
result_promise = Promise.resolve();
|
|
506
512
|
}
|
|
507
513
|
|
|
508
|
-
// Link EntityManager
|
|
509
|
-
if (system.entityManager === null) {
|
|
510
|
-
system.entityManager = this;
|
|
511
|
-
} else if (system.entityManager !== this) {
|
|
512
|
-
throw new Error(`System is bound to another EntityManager`);
|
|
513
|
-
}
|
|
514
514
|
|
|
515
515
|
// link dependency components
|
|
516
516
|
this.dataset?.registerManyComponentTypes(system.referenced_components);
|
|
@@ -519,8 +519,7 @@ export class EntityManager {
|
|
|
519
519
|
|
|
520
520
|
this.on.systemAdded.send1(system);
|
|
521
521
|
|
|
522
|
-
|
|
523
|
-
return startup_promise;
|
|
522
|
+
return result_promise;
|
|
524
523
|
}
|
|
525
524
|
|
|
526
525
|
/**
|
|
@@ -601,7 +600,13 @@ export class EntityManager {
|
|
|
601
600
|
}
|
|
602
601
|
|
|
603
602
|
try {
|
|
604
|
-
system.shutdown(self
|
|
603
|
+
const promise = system.shutdown(self);
|
|
604
|
+
|
|
605
|
+
assert.defined(promise, "promise");
|
|
606
|
+
assert.notNull(promise, "promise");
|
|
607
|
+
assert.isFunction(promise.then, "promise.then");
|
|
608
|
+
|
|
609
|
+
promise.then(systemReady, systemFailed);
|
|
605
610
|
} catch (e) {
|
|
606
611
|
console.error(`Failed to execute system shutdown`, e);
|
|
607
612
|
errorCallback(e);
|
|
@@ -662,25 +667,53 @@ export class EntityManager {
|
|
|
662
667
|
successCallback(system);
|
|
663
668
|
}
|
|
664
669
|
|
|
665
|
-
function systemFailed(reason) {
|
|
666
|
-
errorCallback(reason);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
670
|
try {
|
|
670
|
-
|
|
671
|
+
|
|
672
|
+
const deprecation_check = () => {
|
|
673
|
+
throw new Error("'success' callback was deprecated in meep 2.128.0, please use `async` instead.");
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// Link EntityManager
|
|
677
|
+
if (system.entityManager === null) {
|
|
678
|
+
system.entityManager = this;
|
|
679
|
+
} else if (system.entityManager !== this) {
|
|
680
|
+
throw new Error(`System is bound to another EntityManager`);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const promise = system.startup(self, deprecation_check);
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
assert.defined(promise, "promise");
|
|
687
|
+
assert.notNull(promise, "promise");
|
|
688
|
+
assert.isFunction(promise.then, "promise.then");
|
|
689
|
+
|
|
690
|
+
const startup_check_timeout = setTimeout(
|
|
691
|
+
() => {
|
|
692
|
+
console.warn(`System '${computeSystemName(system)}' failed to complete startup process in ${DEFAULT_SYSTEM_STARTUP_TIMEOUT_CHECK}s, check your code for potential deadlocks.`);
|
|
693
|
+
},
|
|
694
|
+
DEFAULT_SYSTEM_STARTUP_TIMEOUT_CHECK * 1000,
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
promise.finally(() => {
|
|
698
|
+
clearTimeout(startup_check_timeout);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
promise.then(systemReady, errorCallback);
|
|
702
|
+
|
|
671
703
|
} catch (e) {
|
|
672
704
|
console.error(`Failed to execute system startup`, e);
|
|
673
|
-
|
|
705
|
+
errorCallback(e);
|
|
674
706
|
}
|
|
675
707
|
}
|
|
676
708
|
|
|
677
709
|
/**
|
|
678
|
-
* This method is asynchronous by nature, it has to wait for each
|
|
679
|
-
* Make sure to register callback
|
|
710
|
+
* This method is asynchronous by nature, it has to wait for each system to finish its own startup.
|
|
711
|
+
* Make sure to register callback to be notified when the startup has finished
|
|
680
712
|
* @param {function} [readyCallback] executed once entity manager successfully completes startup
|
|
681
713
|
* @param {function} [errorCallback] executed if entity manager encounters an error during startup
|
|
682
714
|
*/
|
|
683
715
|
startup(readyCallback = noop, errorCallback = console.error) {
|
|
716
|
+
|
|
684
717
|
if (this.state === EntityManagerState.Starting) {
|
|
685
718
|
throw new IllegalStateException(`System is currently in starting state`);
|
|
686
719
|
}
|
|
@@ -743,15 +776,15 @@ export class EntityManager {
|
|
|
743
776
|
return;
|
|
744
777
|
}
|
|
745
778
|
|
|
746
|
-
|
|
779
|
+
for (const system of systems) {
|
|
747
780
|
//ensure eventManager are there
|
|
748
781
|
//start the system
|
|
749
782
|
const cbOK = systemReady.bind(null, system);
|
|
750
783
|
const cbError = systemError.bind(null, system);
|
|
751
784
|
|
|
752
|
-
|
|
785
|
+
this.startSystem(system, cbOK, cbError);
|
|
753
786
|
|
|
754
|
-
}
|
|
787
|
+
}
|
|
755
788
|
}
|
|
756
789
|
|
|
757
790
|
/**
|
|
@@ -786,7 +819,6 @@ export class EntityManager {
|
|
|
786
819
|
}
|
|
787
820
|
|
|
788
821
|
/**
|
|
789
|
-
*
|
|
790
822
|
* @param {Class} systemClass
|
|
791
823
|
* @param {SystemState} state
|
|
792
824
|
* @returns {Promise.<System>}
|
|
@@ -814,21 +846,24 @@ export class EntityManager {
|
|
|
814
846
|
}
|
|
815
847
|
|
|
816
848
|
/**
|
|
817
|
-
* This method is asynchronous by nature, it will not be done until each
|
|
849
|
+
* This method is asynchronous by nature, it will not be done until each system has finished its shutdown
|
|
818
850
|
* Make sure to use callback to be notified when the shutdown has completed
|
|
819
851
|
* @param {function} [readyCallback] Called when shutdown finishes successfully. defaults to no-operation
|
|
820
|
-
* @param {function} [errorCallback] Called when an error occurs during shutdown process. defaults to console error output
|
|
852
|
+
* @param {function} [errorCallback] Called when an error occurs during the shutdown process. defaults to console error output
|
|
821
853
|
*/
|
|
822
854
|
shutdown(readyCallback = noop, errorCallback = console.error) {
|
|
823
855
|
if (this.state !== EntityManagerState.Running) {
|
|
824
856
|
throw new IllegalStateException(`System is wrong state, expected '${EntityManagerState.Running}'`);
|
|
825
857
|
}
|
|
826
858
|
|
|
859
|
+
assert.isFunction(readyCallback, 'readyCallback');
|
|
860
|
+
assert.isFunction(errorCallback, 'errorCallback');
|
|
861
|
+
|
|
827
862
|
this.state = EntityManagerState.Stopping;
|
|
828
863
|
|
|
829
864
|
if (this.dataset !== null) {
|
|
830
865
|
// a dataset is still attached, to properly dispose of all the component-bound resources, we first detach the dataset
|
|
831
|
-
this.
|
|
866
|
+
this.detachDataset();
|
|
832
867
|
}
|
|
833
868
|
|
|
834
869
|
const self = this;
|
|
@@ -877,18 +912,29 @@ export class EntityManager {
|
|
|
877
912
|
finalizeShutdown();
|
|
878
913
|
}
|
|
879
914
|
|
|
880
|
-
|
|
915
|
+
for (const system of systems) {
|
|
916
|
+
|
|
881
917
|
system.state.set(SystemState.STOPPING);
|
|
882
|
-
|
|
918
|
+
|
|
883
919
|
const cbOK = systemReady.bind(null, system);
|
|
884
920
|
const cbError = systemError.bind(null, system);
|
|
921
|
+
|
|
885
922
|
try {
|
|
886
|
-
system.shutdown(
|
|
923
|
+
const promise = system.shutdown(this);
|
|
924
|
+
|
|
925
|
+
assert.defined(promise, 'promise');
|
|
926
|
+
assert.notNull(promise, 'promise');
|
|
927
|
+
assert.isFunction(promise.then, 'promise.then');
|
|
928
|
+
|
|
929
|
+
// TODO add timeout
|
|
930
|
+
|
|
931
|
+
promise.then(cbOK, cbError);
|
|
887
932
|
} catch (e) {
|
|
888
933
|
//failure in shutdown function
|
|
889
934
|
cbError(e);
|
|
890
935
|
}
|
|
891
|
-
|
|
936
|
+
|
|
937
|
+
}
|
|
892
938
|
}
|
|
893
939
|
}
|
|
894
940
|
|
|
@@ -11,9 +11,9 @@ export class System<A, B = any, C = any, D = any, E = any> {
|
|
|
11
11
|
|
|
12
12
|
protected readonly entityManager: EntityManager
|
|
13
13
|
|
|
14
|
-
startup(em: EntityManager
|
|
14
|
+
startup(em: EntityManager): Promise<void>
|
|
15
15
|
|
|
16
|
-
shutdown(em: EntityManager
|
|
16
|
+
shutdown(em: EntityManager): Promise<void>
|
|
17
17
|
|
|
18
18
|
link(a: A, entity: number): void
|
|
19
19
|
link(a: A, b: B, entity: number): void
|