@woosh/meep-engine 2.124.11 → 2.124.13

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 (51) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/core/assert.d.ts +8 -0
  4. package/src/core/assert.d.ts.map +1 -1
  5. package/src/core/assert.js +14 -0
  6. package/src/core/debug/matchers/IsFinite.d.ts +6 -0
  7. package/src/core/debug/matchers/IsFinite.d.ts.map +1 -0
  8. package/src/core/debug/matchers/IsFinite.js +11 -0
  9. package/src/core/debug/matchers/IsInteger.d.ts +6 -0
  10. package/src/core/debug/matchers/IsInteger.d.ts.map +1 -0
  11. package/src/core/debug/matchers/IsInteger.js +11 -0
  12. package/src/core/debug/matchers/IsUndefined.js +1 -0
  13. package/src/core/debug/matchers/matchers.d.ts +5 -0
  14. package/src/core/debug/matchers/matchers.d.ts.map +1 -1
  15. package/src/core/debug/matchers/matchers.js +14 -0
  16. package/src/core/math/interval/NumericInterval.d.ts +49 -9
  17. package/src/core/math/interval/NumericInterval.d.ts.map +1 -1
  18. package/src/core/math/interval/NumericInterval.js +91 -13
  19. package/src/core/math/spline/spline_hermite3_bounds.d.ts +7 -7
  20. package/src/core/math/spline/spline_hermite3_bounds.d.ts.map +1 -1
  21. package/src/core/math/spline/spline_hermite3_bounds.js +13 -7
  22. package/src/core/model/ObservedBoolean.d.ts +3 -3
  23. package/src/core/model/ObservedBoolean.d.ts.map +1 -1
  24. package/src/core/model/ObservedBoolean.js +3 -3
  25. package/src/core/model/ObservedEnum.d.ts.map +1 -1
  26. package/src/core/model/ObservedEnum.js +52 -11
  27. package/src/core/model/ObservedInteger.d.ts +7 -7
  28. package/src/core/model/ObservedInteger.d.ts.map +1 -1
  29. package/src/core/model/ObservedInteger.js +12 -11
  30. package/src/engine/animation/AnimationUtils.js +1 -1
  31. package/src/engine/animation/curve/AnimationCurve.d.ts +25 -9
  32. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  33. package/src/engine/animation/curve/AnimationCurve.js +40 -18
  34. package/src/engine/animation/curve/Keyframe.d.ts +4 -2
  35. package/src/engine/animation/curve/Keyframe.d.ts.map +1 -1
  36. package/src/engine/animation/curve/Keyframe.js +6 -2
  37. package/src/engine/animation/curve/animation_curve_compute_aabb.js +1 -1
  38. package/src/engine/animation/curve/animation_curve_optimize.d.ts +2 -1
  39. package/src/engine/animation/curve/animation_curve_optimize.d.ts.map +1 -1
  40. package/src/engine/animation/curve/animation_curve_optimize.js +6 -0
  41. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  42. package/src/engine/ecs/EntityComponentDataset.js +25 -7
  43. package/src/engine/ecs/EntityManager.d.ts +1 -1
  44. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  45. package/src/engine/ecs/EntityManager.js +49 -23
  46. package/src/engine/ecs/EntityObserver.d.ts.map +1 -1
  47. package/src/engine/ecs/EntityObserver.js +9 -0
  48. package/src/engine/ecs/util/EntityBuilderUtils.d.ts.map +1 -0
  49. package/src/engine/ecs/{EntityBuilderUtils.js → util/EntityBuilderUtils.js} +1 -1
  50. package/src/engine/ecs/EntityBuilderUtils.d.ts.map +0 -1
  51. /package/src/engine/ecs/{EntityBuilderUtils.d.ts → util/EntityBuilderUtils.d.ts} +0 -0
@@ -359,6 +359,11 @@ export class EntityComponentDataset {
359
359
  * @returns {boolean}
360
360
  */
361
361
  removeObserver(observer, immediate) {
362
+ if (observer.dataset !== this) {
363
+ // not connected to this dataset
364
+ return false;
365
+ }
366
+
362
367
  let i;
363
368
  let foundFlag = false;
364
369
 
@@ -1028,9 +1033,9 @@ export class EntityComponentDataset {
1028
1033
  }
1029
1034
 
1030
1035
  /**
1031
- *
1036
+ * Internally every component class is mapped to an index, this method is used to retrieve such mapping.
1032
1037
  * @param {Function|Class} klass
1033
- * @returns {number}
1038
+ * @returns {number} integer index, -1 if not found
1034
1039
  */
1035
1040
  computeComponentTypeIndex(klass) {
1036
1041
  assert.defined(klass, "klass");
@@ -1061,6 +1066,9 @@ export class EntityComponentDataset {
1061
1066
  }
1062
1067
 
1063
1068
  /**
1069
+ * Retrieves any instance of a given component.
1070
+ * If no component instances exist - component will be `null` and entity will be `-1`.
1071
+ * Useful for singleton components such as a camera or an audio listener.
1064
1072
  * @template T
1065
1073
  * @param {Class<T>} component_type
1066
1074
  * @returns {{entity:number, component:T}}
@@ -1069,12 +1077,22 @@ export class EntityComponentDataset {
1069
1077
  let entity = -1;
1070
1078
  let component = null;
1071
1079
 
1072
- this.traverseComponents(component_type, (c, i) => {
1073
- entity = i;
1074
- component = c;
1080
+ const index = this.computeComponentTypeIndex(component_type);
1075
1081
 
1076
- return false;
1077
- });
1082
+ if (index !== -1) {
1083
+
1084
+ const components = this.components[index];
1085
+ for (const entity_key in components) {
1086
+ const c = components[entity_key];
1087
+
1088
+ if (c !== undefined) {
1089
+ entity = Number(entity_key);
1090
+ component = c;
1091
+ break;
1092
+ }
1093
+
1094
+ }
1095
+ }
1078
1096
 
1079
1097
  return {
1080
1098
  entity,
@@ -26,7 +26,7 @@ export class EntityManager {
26
26
  /**
27
27
  * @readonly
28
28
  * @private
29
- * @type {EntityObserver[]}
29
+ * @type {Map<System,EntityObserver>}
30
30
  */
31
31
  private readonly systemObservers;
32
32
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAeU,MAAM;;;;;;;;;AAWhB;;;GAGG;AACH;IAEI;;;OAGG;IACH,kBAFU,iCAAQ,CAEL;IAEb;;;;OAIG;IACH,uCAA2B;IAE3B;;;;OAIG;IACH,iCAAqB;IAErB;;OAEG;IACH;;;QAGI;;WAEG;qBADO,MAAM,iCAAQ;;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,6BA8EC;IAED,sBAcC;IAED;;;OAGG;IACH,uBAFa,KAAK,EAAE,CAuBnB;IAED;;;;;OAKG;IACH,uBAJW,sBAAsB,QA0BhC;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,OAAO,CAInB;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,GAAC,IAAI,CAgBlB;IAED;;;;;OAKG;IACH,wBAJa,CAAC,aACH,MAAM,GACJ,IAAI,GAAC,KAAK,CAAC,CAAC,CAAC,CAezB;IAGD;;;OAGG;IACH,oBAFW,MAAM,QAoEhB;IAED;;;;;OAKG;IACH,iEA0EC;IAED;;;;OAIG;IACH,uDAFa,OAAO,CAAC,OAAO,CAAC,CAyC5B;IAED;;;;;OAKG;IACH,mBA6BC;IAED;;;;;OAKG;IACH,oBAwCC;IAED;;;;;OAKG;IACH,kEAwEC;IAED;;;;OAIG;IACH,2BAHW,KAAK,GACH,OAAO,iCAAS,CA0B5B;IAED;;;;;OAKG;IACH,kCAJW,KAAK,SACL,WAAW,GACT,OAAO,iCAAS,CAsB5B;IAED;;;;;OAKG;IACH,mEAsEC;CACJ;uBAhzBmC,aAAa;mBAP9B,oCAAoC"}
1
+ {"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAeU,MAAM;;;;;;;;;AAWhB;;;GAGG;AACH;IAEI;;;OAGG;IACH,kBAFU,iCAAQ,CAEL;IAEb;;;;OAIG;IACH,uCAA2B;IAE3B;;;;OAIG;IACH,iCAA4B;IAE5B;;OAEG;IACH;;;QAGI;;WAEG;qBADO,MAAM,iCAAQ;;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,sBAkBC;IAED;;;OAGG;IACH,uBAFa,KAAK,EAAE,CAuBnB;IAED;;;;;OAKG;IACH,uBAJW,sBAAsB,QA+BhC;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,OAAO,CAInB;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,GAAC,IAAI,CAkBlB;IAED;;;;;OAKG;IACH,wBAJa,CAAC,aACH,MAAM,GACJ,IAAI,GAAC,KAAK,CAAC,CAAC,CAAC,CAiBzB;IAGD;;;OAGG;IACH,oBAFW,MAAM,QAoEhB;IAED;;;;;OAKG;IACH,iEAoEC;IAED;;;;OAIG;IACH,uDAFa,OAAO,CAAC,OAAO,CAAC,CAyC5B;IAED;;;;;OAKG;IACH,mBA6BC;IAED;;;;;OAKG;IACH,oBAsDC;IAED;;;;;OAKG;IACH,kEAwEC;IAED;;;;OAIG;IACH,2BAHW,KAAK,GACH,OAAO,iCAAS,CA0B5B;IAED;;;;;OAKG;IACH,kCAJW,KAAK,SACL,WAAW,GACT,OAAO,iCAAS,CAsB5B;IAED;;;;;OAKG;IACH,mEAsEC;CACJ;uBA10BmC,aAAa;mBAP9B,oCAAoC"}
@@ -46,9 +46,9 @@ export class EntityManager {
46
46
  /**
47
47
  * @readonly
48
48
  * @private
49
- * @type {EntityObserver[]}
49
+ * @type {Map<System,EntityObserver>}
50
50
  */
51
- systemObservers = [];
51
+ systemObservers = new Map();
52
52
 
53
53
  /**
54
54
  * @readonly
@@ -132,6 +132,11 @@ export class EntityManager {
132
132
  for (let i = 0; i < system_count; i++) {
133
133
  const system = systems[i];
134
134
 
135
+ if (system.state.get() !== SystemState.RUNNING) {
136
+ // exclude systems that are not running
137
+ continue;
138
+ }
139
+
135
140
  if (system.update === noop && system.fixedUpdate === noop) {
136
141
  // not a simulation system
137
142
  continue;
@@ -206,9 +211,13 @@ export class EntityManager {
206
211
  }
207
212
 
208
213
  //remove system observers
209
- this.systemObservers.forEach(function (observer) {
214
+ for (const [_, observer] of this.systemObservers) {
215
+ if (!observer.isConnected) {
216
+ continue;
217
+ }
218
+
210
219
  dataset.removeObserver(observer, true);
211
- });
220
+ }
212
221
 
213
222
  this.dataset = null;
214
223
  }
@@ -255,7 +264,7 @@ export class EntityManager {
255
264
  return;
256
265
  }
257
266
 
258
- throw new Error("Illegal status, another dataset is currently attached");
267
+ throw new Error("Illegal status, another dataset is currently attached, you must detach it first");
259
268
  }
260
269
 
261
270
  const localComponentTypeMap = this.getComponentTypeMap();
@@ -265,9 +274,14 @@ export class EntityManager {
265
274
 
266
275
  this.dataset = dataset;
267
276
 
268
- this.systemObservers.forEach(function (observer) {
277
+ for (const [s, observer] of this.systemObservers) {
278
+ if (s.state.get() !== SystemState.RUNNING) {
279
+ continue;
280
+ }
281
+
269
282
  dataset.addObserver(observer, true);
270
- });
283
+ }
284
+
271
285
  }
272
286
 
273
287
  /**
@@ -285,6 +299,8 @@ export class EntityManager {
285
299
  * @returns {T|null}
286
300
  */
287
301
  getSystem(systemClass) {
302
+ assert.isFunction(systemClass, 'systemClass');
303
+
288
304
  const systems = this.systems;
289
305
  const numSystems = systems.length;
290
306
 
@@ -307,6 +323,8 @@ export class EntityManager {
307
323
  * @returns {null|Class<T>}
308
324
  */
309
325
  getComponentClassByName(className) {
326
+ assert.isString(className, 'className');
327
+
310
328
  const componentTypes = this.getComponentTypeMap();
311
329
 
312
330
  let i = 0;
@@ -330,18 +348,17 @@ export class EntityManager {
330
348
  assert.isNumber(timeDelta, 'timeDelta');
331
349
  assert.notNaN(timeDelta, 'timeDelta');
332
350
  assert.greaterThanOrEqual(timeDelta, 0, 'timeDelta must be >= 0');
333
- assert.isFiniteNumber(timeDelta, 'timeDelta');
351
+ assert.isFinite(timeDelta, 'timeDelta');
334
352
 
335
353
  if (this.__execution_order_needs_update) {
336
354
  this.updateExecutionOrder();
337
355
  }
338
356
 
339
-
340
357
  /**
341
358
  *
342
359
  * @type {System[]}
343
360
  */
344
- const systems = this.systems;
361
+ const systems = this.systemsExecutionOrder;
345
362
 
346
363
  const system_count = systems.length;
347
364
 
@@ -360,6 +377,7 @@ export class EntityManager {
360
377
  let accumulated_time = accumulatedTime.get(system) + timeDelta;
361
378
 
362
379
  const t0 = performance.now();
380
+
363
381
  while (accumulated_time >= fixed_step) {
364
382
 
365
383
  try {
@@ -437,12 +455,10 @@ export class EntityManager {
437
455
 
438
456
  systems[systemIndex] = system;
439
457
 
440
- // request exec order update
441
- this.__execution_order_needs_update = true;
442
458
 
443
459
  //build observer
444
- const linkObserver = new EntityObserver(system.dependencies, system.link, system.unlink, system);
445
- this.systemObservers[systemIndex] = linkObserver;
460
+ const entityObserver = new EntityObserver(system.dependencies, system.link, system.unlink, system);
461
+ this.systemObservers.set(system, entityObserver);
446
462
 
447
463
  let startup_promise;
448
464
  if (this.state === EntityManagerState.Running) {
@@ -461,18 +477,14 @@ export class EntityManager {
461
477
  throw new Error(`System is bound to another EntityManager`);
462
478
  }
463
479
 
464
- if (this.dataset !== null) {
465
-
466
- // link dependency components
467
- this.dataset.registerManyComponentTypes(system.referenced_components);
468
-
469
- this.dataset.addObserver(linkObserver);
470
- }
480
+ // link dependency components
481
+ this.dataset?.registerManyComponentTypes(system.referenced_components);
471
482
 
472
483
  this.systemAccumulatedFixedStepTime.set(system, 0);
473
484
 
474
485
  this.on.systemAdded.send1(system);
475
486
 
487
+
476
488
  return startup_promise;
477
489
  }
478
490
 
@@ -493,8 +505,8 @@ export class EntityManager {
493
505
  }
494
506
 
495
507
  //unlink system observer
496
- const systemObserver = this.systemObservers[systemIndex];
497
- this.systemObservers.splice(systemIndex, 1);
508
+ const systemObserver = this.systemObservers.get(system);
509
+ this.systemObservers.delete(system);
498
510
 
499
511
  assert.notEqual(systemObserver, undefined, "System observer is undefined, it was possibly removed illegally or was not created");
500
512
 
@@ -592,6 +604,20 @@ export class EntityManager {
592
604
 
593
605
  self.on.systemStarted.dispatch(system);
594
606
 
607
+ const i = self.systems.indexOf(system);
608
+
609
+ assert.notEqual(i, -1, "System was not found in the system list");
610
+
611
+ const observer = self.systemObservers.get(system);
612
+
613
+ if (observer !== undefined) {
614
+ // only link the observer once startup has succeeded
615
+ self.dataset?.addObserver(observer, true);
616
+ }
617
+
618
+ // request exec order update
619
+ self.__execution_order_needs_update = true;
620
+
595
621
  successCallback(system);
596
622
  }
597
623
 
@@ -1 +1 @@
1
- {"version":3,"file":"EntityObserver.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityObserver.js"],"names":[],"mappings":"AAGA;IAoBI;;;;;;;OAOG;IACH,0FAHW,GAAC,EA+CX;IAvED;;;OAGG;IACH,eAFU,MAAM,CAEa;IAE7B;;;;OAIG;IACH,uBAFU,MAAM,EAAE,CAES;IAE3B;;;OAGG;IACH,SAFU,sBAAsB,GAAC,IAAI,CAEtB;IA0BX;;OAEG;IACH,oBAFU,MAAM,CAE2B;IAE3C;;;OAGG;IACH,kBAFU,CAAS,IAAK,eAAC,CAEgB;IAEzC;;;OAGG;IACH,gBAFU,CAAS,IAAK,eAAC,CAEW;IAEpC;;;OAGG;IACH,sBAAoC;IAEpC;;;OAGG;IACH,SAFU,GAAC,CAEW;IAG1B;;;OAGG;IACH,qCAqBC;IAED;;;OAGG;IACH,iBAFW,sBAAsB,QAIhC;IAED,mBAGC;CACJ;uBAnHsB,6BAA6B"}
1
+ {"version":3,"file":"EntityObserver.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityObserver.js"],"names":[],"mappings":"AAGA;IAoBI;;;;;;;OAOG;IACH,0FAHW,GAAC,EA+CX;IAvED;;;OAGG;IACH,eAFU,MAAM,CAEa;IAE7B;;;;OAIG;IACH,uBAFU,MAAM,EAAE,CAES;IAE3B;;;OAGG;IACH,SAFU,sBAAsB,GAAC,IAAI,CAEtB;IA0BX;;OAEG;IACH,oBAFU,MAAM,CAE2B;IAE3C;;;OAGG;IACH,kBAFU,CAAS,IAAK,eAAC,CAEgB;IAEzC;;;OAGG;IACH,gBAFU,CAAS,IAAK,eAAC,CAEW;IAEpC;;;OAGG;IACH,sBAAoC;IAEpC;;;OAGG;IACH,SAFU,GAAC,CAEW;IAG1B;;;OAGG;IACH,qCAqBC;IAED;;;OAGG;IACH,iBAFW,sBAAsB,QAIhC;IAED;;;OAGG;IACH,mBAFY,OAAO,CAIlB;IAED,mBAIC;CACJ;uBA5HsB,6BAA6B"}
@@ -110,8 +110,17 @@ export class EntityObserver {
110
110
  dataset.addObserver(this, true);
111
111
  }
112
112
 
113
+ /**
114
+ *
115
+ * @return {boolean}
116
+ */
117
+ get isConnected() {
118
+ return this.dataset === null;
119
+ }
120
+
113
121
  disconnect() {
114
122
  //de-register updates
115
123
  this.dataset.removeObserver(this);
124
+ this.dataset = null;
116
125
  }
117
126
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityBuilderUtils.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/util/EntityBuilderUtils.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,mDAHW,MAAM,EAAE,gBAKlB;AAED;;;;GAIG;AACH,6CAHW,MAAM,gBAOhB"}
@@ -1,4 +1,4 @@
1
- import { EventType } from "./EventType.js";
1
+ import { EventType } from "../EventType.js";
2
2
 
3
3
  /**
4
4
  *
@@ -1 +0,0 @@
1
- {"version":3,"file":"EntityBuilderUtils.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityBuilderUtils.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,mDAHW,MAAM,EAAE,gBAKlB;AAED;;;;GAIG;AACH,6CAHW,MAAM,gBAOhB"}