@woosh/meep-engine 2.127.1 → 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.
Files changed (75) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/packing/miniball/Miniball.d.ts +12 -10
  3. package/src/core/geom/packing/miniball/Miniball.d.ts.map +1 -1
  4. package/src/core/geom/packing/miniball/Miniball.js +76 -54
  5. package/src/engine/Clock.d.ts +2 -1
  6. package/src/engine/Clock.d.ts.map +1 -1
  7. package/src/engine/Clock.js +1 -0
  8. package/src/engine/ecs/EntityManager.d.ts +5 -6
  9. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  10. package/src/engine/ecs/EntityManager.js +83 -37
  11. package/src/engine/ecs/System.d.ts +2 -2
  12. package/src/engine/ecs/System.d.ts.map +1 -1
  13. package/src/engine/ecs/System.js +41 -19
  14. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.d.ts +1 -1
  15. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.d.ts.map +1 -1
  16. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +1 -4
  17. package/src/engine/ecs/fow/FogOfWarSystem.d.ts +2 -4
  18. package/src/engine/ecs/fow/FogOfWarSystem.d.ts.map +1 -1
  19. package/src/engine/ecs/fow/FogOfWarSystem.js +15 -21
  20. package/src/engine/ecs/gui/GUIElementSystem.d.ts.map +1 -1
  21. package/src/engine/ecs/gui/GUIElementSystem.js +7 -18
  22. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.d.ts.map +1 -1
  23. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +3 -10
  24. package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts +2 -2
  25. package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts.map +1 -1
  26. package/src/engine/ecs/gui/position/ViewportPositionSystem.js +2 -6
  27. package/src/engine/ecs/renderable/RenderSystem.d.ts.map +1 -1
  28. package/src/engine/ecs/renderable/RenderSystem.js +3 -7
  29. package/src/engine/ecs/speaker/VoiceSystem.d.ts +1 -1
  30. package/src/engine/ecs/speaker/VoiceSystem.d.ts.map +1 -1
  31. package/src/engine/ecs/speaker/VoiceSystem.js +2 -4
  32. package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
  33. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -5
  34. package/src/engine/ecs/tooltip/TooltipComponentSystem.d.ts +2 -2
  35. package/src/engine/ecs/tooltip/TooltipComponentSystem.d.ts.map +1 -1
  36. package/src/engine/ecs/tooltip/TooltipComponentSystem.js +10 -12
  37. package/src/engine/ecs/validateSystem.d.ts.map +1 -1
  38. package/src/engine/ecs/validateSystem.js +11 -2
  39. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
  40. package/src/engine/graphics/ecs/camera/CameraSystem.js +5 -8
  41. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts.map +1 -1
  42. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -6
  43. package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.d.ts.map +1 -1
  44. package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.js +14 -27
  45. package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
  46. package/src/engine/graphics/ecs/light/LightSystem.js +2 -6
  47. package/src/engine/graphics/ecs/mesh/MeshSystem.d.ts.map +1 -1
  48. package/src/engine/graphics/ecs/mesh/MeshSystem.js +2 -6
  49. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
  50. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -5
  51. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.d.ts.map +1 -1
  52. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +1 -2
  53. package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts.map +1 -1
  54. package/src/engine/graphics/ecs/path/PathDisplaySystem.js +13 -17
  55. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts.map +1 -1
  56. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +2 -6
  57. package/src/engine/graphics/ecs/water/WaterSystem.d.ts +2 -2
  58. package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
  59. package/src/engine/graphics/ecs/water/WaterSystem.js +5 -11
  60. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts.map +1 -1
  61. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +2 -6
  62. package/src/engine/graphics/render/frame_graph/RenderGraph.d.ts +2 -1
  63. package/src/engine/graphics/render/frame_graph/RenderGraph.d.ts.map +1 -1
  64. package/src/engine/graphics/render/frame_graph/RenderGraph.js +2 -1
  65. package/src/engine/graphics/render/frame_graph/resource/ResourceDescriptor.d.ts +1 -0
  66. package/src/engine/graphics/render/frame_graph/resource/ResourceDescriptor.d.ts.map +1 -1
  67. package/src/engine/graphics/render/frame_graph/resource/ResourceDescriptor.js +3 -0
  68. package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
  69. package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -2
  70. package/src/engine/intelligence/behavior/ecs/BehaviorSystem.d.ts +2 -2
  71. package/src/engine/intelligence/behavior/ecs/BehaviorSystem.d.ts.map +1 -1
  72. package/src/engine/intelligence/behavior/ecs/BehaviorSystem.js +3 -5
  73. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts +2 -2
  74. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts.map +1 -1
  75. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +2 -6
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.127.1",
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. In each of these two alternating
156
- * phases, we always have to check whether some point must be dropped from support, which is the
157
- * case when the center lies in <i>aff(support)</i>. If such an attempt to drop fails, we are
158
- * done; because then the center lies even <i>conv(support)</i>.
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 #successfulDrop()} elects a suitable point <i>k</i> to be removed from the support and
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>. The
175
- * (positive) factor by which we can walk along `centerToAff` is returned. Further,
176
- * `stopper` is set to the index of the most restricting point and to -1 if no such point
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 miniball
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;;;;GAIG;AACH;IACI;;;;;OAKG;IACH,8BAkGC;IA/FG;;;OAGG;IACH,WAFU,MAAM,CAEE;IAClB;;;OAGG;IACH,WAFU,MAAM,CAEE;IAClB;;;OAGG;IACH,iBAFU,MAAM,CAEQ;IACxB;;;;;;;;;;OAUG;IACH,wBAAwB;IACxB;;;;OAIG;IACH,iBAAiB;IACjB;;;OAGG;IACH,SAFU,MAAM,CAEA;IAEhB;;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;;;;;;;;;;OAUG;IACH,gBA4CC;IAED;;;;;;;;OAQG;IACH,kBAFY,OAAO,CA4BlB;IAED;;;;;;;;OAQG;IACH,yBAyDC;IAGD;;;OAGG;IACH,YAFY,MAAM,CAkBjB;CACJ;wBAnbuB,cAAc"}
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 = 1.0E-14;
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. In each of these two alternating
268
- * phases, we always have to check whether some point must be dropped from support, which is the
269
- * case when the center lies in <i>aff(support)</i>. If such an attempt to drop fails, we are
270
- * done; because then the center lies even <i>conv(support)</i>.
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 #successfulDrop()} elects a suitable point <i>k</i> to be removed from the support and
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>. The
359
- * (positive) factor by which we can walk along `centerToAff` is returned. Further,
360
- * `stopper` is set to the index of the most restricting point and to -1 if no such point
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 ((this.distToAffSquare - dirPointProd) < (Epsilon * this.__radius * this.distToAff)) {
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 = (this.__squaredRadius - bound) / 2 / (this.distToAffSquare - dirPointProd);
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 miniball
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
- s += ("isEmpty=true");
447
+
448
+ s += "isEmpty=true";
449
+
433
450
  } else {
434
- s += ("center=(");
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
  }
@@ -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;;;;;OAKG;IACH,OAFU,IAAI,CAEM;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;iBA9HgB,4BAA4B"}
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"}
@@ -50,6 +50,7 @@ class Clock {
50
50
  * Allows us to slow down or speed up flow of time via modifiers, see {@link Stat} for details
51
51
  * Default speed is x1, i.e. - unmodified
52
52
  * @type {Stat}
53
+ * @readonly
53
54
  */
54
55
  speed = new Stat(1);
55
56
 
@@ -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 individual system to finish its own statup.
170
- * Make sure to register callback in order to be notified when the startup has finished
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 individual system has finished its shutdown
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;;;;;;;;;AAWhB;;;;;;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,iEAoEC;IAED;;;;OAIG;IACH,uDAFa,QAAQ,OAAO,CAAC,CA2C5B;IAED;;;;;OAKG;IACH,mBA6BC;IAED;;;;;OAKG;IACH,oBA0DC;IAED;;;;;OAKG;IACH,kEAwEC;IAED;;;;OAIG;IACH,mCAFa,wCAAgB,CA0B5B;IAED;;;;;OAKG;IACH,8DAFa,wCAAgB,CAsB5B;IAED;;;;;OAKG;IACH,mEAsEC;IAGL;;OAEG;IACH,yBAhpBe,sBAAsB,UAgpBA;IACrC;;OAEG;IACH,0BAAqC;CATpC;uBAl3BmC,aAAa;mBAR9B,oCAAoC;uCAMhB,6BAA6B"}
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(`System validation failed '${computeSystemName(system)}' : `, e, system);
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 legalStates = [SystemState.INITIAL, SystemState.STOPPED];
487
+ const valid_states = [SystemState.INITIAL, SystemState.STOPPED];
482
488
 
483
- if (legalStates.indexOf(systemState) === -1) {
489
+ if (valid_states.indexOf(systemState) === -1) {
484
490
  //illegal state
485
- throw new IllegalStateException(`System must be in one of these states: [${legalStates.join(",")}], instead was ${systemState}`);
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 startup_promise;
504
+ let result_promise;
499
505
  if (this.state === EntityManagerState.Running) {
500
506
  //initialize the system
501
- startup_promise = new Promise((resolve, reject) => {
507
+ result_promise = new Promise((resolve, reject) => {
502
508
  this.startSystem(system, resolve, reject);
503
509
  });
504
510
  } else {
505
- startup_promise = Promise.resolve();
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, systemReady, systemFailed);
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
- system.startup(self, systemReady, systemFailed);
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
- systemFailed(e);
705
+ errorCallback(e);
674
706
  }
675
707
  }
676
708
 
677
709
  /**
678
- * This method is asynchronous by nature, it has to wait for each individual system to finish its own statup.
679
- * Make sure to register callback in order to be notified when the startup has finished
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
- systems.forEach(function (system) {
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
- self.startSystem(system, cbOK, cbError);
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 individual system has finished its shutdown
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.detachDataSet();
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
- systems.forEach(function (system) {
915
+ for (const system of systems) {
916
+
881
917
  system.state.set(SystemState.STOPPING);
882
- //start the system
918
+
883
919
  const cbOK = systemReady.bind(null, system);
884
920
  const cbError = systemError.bind(null, system);
921
+
885
922
  try {
886
- system.shutdown(self, cbOK, cbError);
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, ready_callback: () => void, error_callback: () => void): void
14
+ startup(em: EntityManager): Promise<void>
15
15
 
16
- shutdown(em: EntityManager, ready_callback: () => void, error_callback: () => void): void
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
@@ -1 +1 @@
1
- {"version":3,"file":"System.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/System.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH;IAEI;;;;;OAKG;IACH,uCAAqB;IAErB;;;;OAIG;IACH,oBAA+C;IAE/C;;;;;OAKG;IACH,oBAAkB;IAElB;;;;;;;;;OASG;IACH,iBAFU,6BAA6B,CAElB;IAGrB;;OAEG;IACH,mCAcC;IAED;;;;OAIG;IACH,oCAFY,MAAM,CA8BjB;IAED;;;;;;OAMG;IACH,8FAGC;IAED;;;;;;;OAOG;IACH,+FAEC;IAGD;;;;OAIG;IACH,wCAEC;IAED;;;;OAIG;IACH,0CAEC;IAED;;;;;;;;OAQG;IACH,6DAEC;IAED;;;;;;;;OAQG;IACH,6DAEC;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;IAEzB;;;;OAIG;IACH,yBAA4B;IAG5B;;;;;;OAMG;IACH,oBAAuB;CAvBtB;;;;0BA8CS,MAAM;;;;;;;;qBAjPK,6BAA6B"}
1
+ {"version":3,"file":"System.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/System.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH;IAEI;;;;;OAKG;IACH,uCAAqB;IAErB;;;;OAIG;IACH,oBAA+C;IAE/C;;;;;;;OAOG;IACH,6BAAkB;IAElB;;;;;;;;;;OAUG;IACH,0BAFU,6BAA6B,CAElB;IAGrB;;OAEG;IACH,mCAcC;IAED;;;;;OAKG;IACH,oCAFY,MAAM,CA8BjB;IAED;;;;;;OAMG;IACH,uCAHa,QAAQ,IAAI,CAAC,CAKzB;IAED;;;;;;;OAOG;IACH,wCAHa,QAAQ,IAAI,CAAC,CAKzB;IAGD;;;;OAIG;IACH,wCAEC;IAED;;;;OAIG;IACH,0CAEC;IAED;;;;;;;;;;OAUG;IACH,6DAEC;IAED;;;;;;;;;;OAUG;IACH,6DAEC;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;IAEzB;;;;OAIG;IACH,yBAA4B;IAG5B;;;;;;OAMG;IACH,oBAAuB;CAvBtB;;;;0BA8CS,MAAM;;;;;;;;qBAxPK,6BAA6B"}