@woosh/meep-engine 2.110.1 → 2.110.4

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.
@@ -97938,71 +97938,89 @@ class ImmutableObjectPool {
97938
97938
  }
97939
97939
  }
97940
97940
 
97941
+ /**
97942
+ * Object Pool pattern implementation.
97943
+ * Reuse objects instead of relying on garbage collector. Useful in cases where creating or destroying an object is costly, and objects are relatively short-lived
97944
+ * @template T
97945
+ */
97941
97946
  class ObjectPoolFactory {
97942
97947
  /**
97943
- * @template T
97948
+ * @private
97949
+ * @type {Array<T>}
97950
+ */
97951
+ pool = [];
97952
+
97953
+ /**
97954
+ * @type {number}
97955
+ */
97956
+ maxSize = 256;
97957
+
97958
+ /**
97944
97959
  * @param {function():T} creator
97945
97960
  * @param {function(T)} destroyer
97946
97961
  * @param {function(T)} resetter
97947
- * @constructor
97948
97962
  */
97949
- constructor(creator, destroyer, resetter) {
97963
+ constructor(
97964
+ creator,
97965
+ destroyer = noop,
97966
+ resetter = noop
97967
+ ) {
97968
+
97950
97969
  /**
97951
97970
  * @private
97952
97971
  * @type {function(): T}
97953
97972
  */
97954
97973
  this.creator = creator;
97974
+
97955
97975
  /**
97956
97976
  * @private
97957
97977
  * @type {function(T)}
97958
97978
  */
97959
97979
  this.destroyer = destroyer;
97980
+
97960
97981
  /**
97961
97982
  * @private
97962
97983
  * @type {function(T)}
97963
97984
  */
97964
97985
  this.resetter = resetter;
97965
97986
 
97966
- /**
97967
- * @private
97968
- * @type {Array<T>}
97969
- */
97970
- this.pool = [];
97971
-
97972
- /**
97973
- * @private
97974
- * @type {number}
97975
- */
97976
- this.maxSize = 256;
97977
97987
  }
97978
97988
 
97979
97989
  /**
97980
97990
  *
97981
97991
  * @returns {T}
97982
97992
  */
97983
- create() {
97984
- if (this.pool.length > 0) {
97985
- const oldInstance = this.pool.pop();
97993
+ get() {
97994
+ const pool = this.pool;
97995
+
97996
+ if (pool.length > 0) {
97997
+
97998
+ const oldInstance = pool.pop();
97986
97999
 
97987
98000
  //reset the object
97988
98001
  this.resetter(oldInstance);
97989
98002
 
97990
98003
  return oldInstance;
98004
+
97991
98005
  } else {
98006
+
97992
98007
  const newInstance = this.creator();
97993
98008
 
97994
98009
  return newInstance;
98010
+
97995
98011
  }
97996
98012
  }
97997
98013
 
97998
98014
  /**
97999
98015
  *
98000
98016
  * @param {T} object
98001
- * @returns {boolean}
98017
+ * @returns {boolean} true if object was added back to the pool, false if pool was full and object was destroyed instead
98002
98018
  */
98003
98019
  release(object) {
98004
98020
 
98005
- if (this.pool.length >= this.maxSize) {
98021
+ const pool = this.pool;
98022
+
98023
+ if (pool.length >= this.maxSize) {
98006
98024
  //pool is too large, destroy and discard the object
98007
98025
  if (this.destroyer !== noop) {
98008
98026
  this.destroyer(object);
@@ -98012,11 +98030,18 @@ class ObjectPoolFactory {
98012
98030
  }
98013
98031
 
98014
98032
  //add it to the pool
98015
- this.pool.push(object);
98033
+ pool.push(object);
98016
98034
 
98017
98035
  return true;
98018
98036
  }
98019
- }
98037
+ }
98038
+
98039
+
98040
+ /**
98041
+ * @deprecated use `get` instead
98042
+ * @type {function(): T}
98043
+ */
98044
+ ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get;
98020
98045
 
98021
98046
  /**
98022
98047
  * Will invoke A.equals(B) on members if such exists
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.110.1",
8
+ "version": "2.110.4",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,12 +1,24 @@
1
- export class ObjectPoolFactory {
1
+ /**
2
+ * Object Pool pattern implementation.
3
+ * Reuse objects instead of relying on garbage collector. Useful in cases where creating or destroying an object is costly, and objects are relatively short-lived
4
+ * @template T
5
+ */
6
+ export class ObjectPoolFactory<T> {
2
7
  /**
3
- * @template T
4
8
  * @param {function():T} creator
5
9
  * @param {function(T)} destroyer
6
10
  * @param {function(T)} resetter
7
- * @constructor
8
11
  */
9
- constructor(creator: () => T, destroyer: (arg0: T) => any, resetter: (arg0: T) => any);
12
+ constructor(creator: () => T, destroyer?: (arg0: T) => any, resetter?: (arg0: T) => any);
13
+ /**
14
+ * @private
15
+ * @type {Array<T>}
16
+ */
17
+ private pool;
18
+ /**
19
+ * @type {number}
20
+ */
21
+ maxSize: number;
10
22
  /**
11
23
  * @private
12
24
  * @type {function(): T}
@@ -22,26 +34,21 @@ export class ObjectPoolFactory {
22
34
  * @type {function(T)}
23
35
  */
24
36
  private resetter;
25
- /**
26
- * @private
27
- * @type {Array<T>}
28
- */
29
- private pool;
30
- /**
31
- * @private
32
- * @type {number}
33
- */
34
- private maxSize;
35
37
  /**
36
38
  *
37
39
  * @returns {T}
38
40
  */
39
- create(): T;
41
+ get(): T;
40
42
  /**
41
43
  *
42
44
  * @param {T} object
43
- * @returns {boolean}
45
+ * @returns {boolean} true if object was added back to the pool, false if pool was full and object was destroyed instead
44
46
  */
45
47
  release(object: T): boolean;
48
+ /**
49
+ * @deprecated use `get` instead
50
+ * @type {function(): T}
51
+ */
52
+ create: () => T;
46
53
  }
47
54
  //# sourceMappingURL=ObjectPoolFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectPoolFactory.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/ObjectPoolFactory.js"],"names":[],"mappings":"AAIA;IACI;;;;;;OAMG;IACH,uFA4BC;IA3BG;;;OAGG;IACH,gBAAsB;IACtB;;;OAGG;IACH,kBAA0B;IAC1B;;;OAGG;IACH,iBAAwB;IAExB;;;OAGG;IACH,aAAc;IAEd;;;OAGG;IACH,gBAAkB;IAGtB;;;OAGG;IACH,YAoBC;IAED;;;;OAIG;IACH,oBAFa,OAAO,CAqBnB;CACJ"}
1
+ {"version":3,"file":"ObjectPoolFactory.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/ObjectPoolFactory.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH;IAYI;;;;OAIG;IACH,2BAJsB,CAAC,qBACH,CAAC,4BACD,CAAC,UA6BpB;IA3CD;;;OAGG;IACH,aAAU;IAEV;;OAEG;IACH,SAFU,MAAM,CAEF;IAgBV;;;OAGG;IACH,gBAAsB;IAEtB;;;OAGG;IACH,kBAA0B;IAE1B;;;OAGG;IACH,iBAAwB;IAI5B;;;OAGG;IACH,OAFa,CAAC,CA2Bb;IAED;;;;OAIG;IACH,gBAHW,CAAC,GACC,OAAO,CAuBnB;IAIL;;;OAGG;IACH,cAFsB,CAAC,CAEW;CAPjC"}
@@ -2,51 +2,67 @@ import { assert } from "../../assert.js";
2
2
 
3
3
  import { noop } from "../../function/noop.js";
4
4
 
5
+ /**
6
+ * Object Pool pattern implementation.
7
+ * Reuse objects instead of relying on garbage collector. Useful in cases where creating or destroying an object is costly, and objects are relatively short-lived
8
+ * @template T
9
+ */
5
10
  export class ObjectPoolFactory {
6
11
  /**
7
- * @template T
12
+ * @private
13
+ * @type {Array<T>}
14
+ */
15
+ pool = [];
16
+
17
+ /**
18
+ * @type {number}
19
+ */
20
+ maxSize = 256;
21
+
22
+ /**
8
23
  * @param {function():T} creator
9
24
  * @param {function(T)} destroyer
10
25
  * @param {function(T)} resetter
11
- * @constructor
12
26
  */
13
- constructor(creator, destroyer, resetter) {
27
+ constructor(
28
+ creator,
29
+ destroyer = noop,
30
+ resetter = noop
31
+ ) {
32
+ assert.isFunction(creator, 'creator');
33
+ assert.isFunction(destroyer, 'destroyer');
34
+ assert.isFunction(resetter, 'resetter');
35
+
14
36
  /**
15
37
  * @private
16
38
  * @type {function(): T}
17
39
  */
18
40
  this.creator = creator;
41
+
19
42
  /**
20
43
  * @private
21
44
  * @type {function(T)}
22
45
  */
23
46
  this.destroyer = destroyer;
47
+
24
48
  /**
25
49
  * @private
26
50
  * @type {function(T)}
27
51
  */
28
52
  this.resetter = resetter;
29
53
 
30
- /**
31
- * @private
32
- * @type {Array<T>}
33
- */
34
- this.pool = [];
35
-
36
- /**
37
- * @private
38
- * @type {number}
39
- */
40
- this.maxSize = 256;
41
54
  }
42
55
 
43
56
  /**
44
57
  *
45
58
  * @returns {T}
46
59
  */
47
- create() {
48
- if (this.pool.length > 0) {
49
- const oldInstance = this.pool.pop();
60
+ get() {
61
+ const pool = this.pool;
62
+
63
+ if (pool.length > 0) {
64
+
65
+ const oldInstance = pool.pop();
50
66
 
51
67
  //reset the object
52
68
  this.resetter(oldInstance);
@@ -55,29 +71,33 @@ export class ObjectPoolFactory {
55
71
  assert.defined(oldInstance, 'oldInstance');
56
72
 
57
73
  return oldInstance;
74
+
58
75
  } else {
59
- const newInstance = this.creator();
60
76
 
77
+ const newInstance = this.creator();
61
78
 
62
79
  assert.notNull(newInstance, 'newInstance');
63
80
  assert.defined(newInstance, 'newInstance');
64
81
 
65
82
  return newInstance;
83
+
66
84
  }
67
85
  }
68
86
 
69
87
  /**
70
88
  *
71
89
  * @param {T} object
72
- * @returns {boolean}
90
+ * @returns {boolean} true if object was added back to the pool, false if pool was full and object was destroyed instead
73
91
  */
74
92
  release(object) {
75
93
  assert.notNull(object, 'object');
76
94
  assert.defined(object, 'object');
77
95
 
78
- assert.arrayHasNo(this.pool, object, `Pool already contains object that is being attempted to be release`);
96
+ const pool = this.pool;
79
97
 
80
- if (this.pool.length >= this.maxSize) {
98
+ assert.arrayHasNo(pool, object, `Pool already contains object that is being attempted to be release`);
99
+
100
+ if (pool.length >= this.maxSize) {
81
101
  //pool is too large, destroy and discard the object
82
102
  if (this.destroyer !== noop) {
83
103
  this.destroyer(object);
@@ -87,8 +107,15 @@ export class ObjectPoolFactory {
87
107
  }
88
108
 
89
109
  //add it to the pool
90
- this.pool.push(object);
110
+ pool.push(object);
91
111
 
92
112
  return true;
93
113
  }
94
114
  }
115
+
116
+
117
+ /**
118
+ * @deprecated use `get` instead
119
+ * @type {function(): T}
120
+ */
121
+ ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get
@@ -16,6 +16,7 @@ export class IKProblem {
16
16
  terrain: Terrain;
17
17
  }
18
18
  export namespace IKProblem {
19
- let pool: any;
19
+ let pool: ObjectPoolFactory<IKProblem>;
20
20
  }
21
+ import { ObjectPoolFactory } from "../../../core/model/object/ObjectPoolFactory.js";
21
22
  //# sourceMappingURL=IKProblem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IKProblem.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/ik/IKProblem.js"],"names":[],"mappings":"AAGA;IAEI;;;OAGG;IACH,yBAAkB;IAClB;;;OAGG;IACH,mBAAgB;IAChB;;;OAGG;IACH,iBAAe;CAElB"}
1
+ {"version":3,"file":"IKProblem.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/ik/IKProblem.js"],"names":[],"mappings":"AAGA;IAEI;;;OAGG;IACH,yBAAkB;IAClB;;;OAGG;IACH,mBAAgB;IAChB;;;OAGG;IACH,iBAAe;CAElB;;cAIS,kBAAkB,SAAS,CAAC;;kCAxBJ,iDAAiD"}
@@ -11,4 +11,13 @@ export default class Ticker {
11
11
 
12
12
  resume(): void
13
13
 
14
+ /**
15
+ * @deprecated
16
+ */
17
+ subscribe(callback: Function, thisArg?: any): void
18
+
19
+ /**
20
+ * @deprecated
21
+ */
22
+ unsubscribe(callback: Function, thisArg?: any): void
14
23
  }
@@ -1,25 +0,0 @@
1
- /**
2
- * @template T
3
- */
4
- export class SimpleObjectPoolFactory<T> {
5
- /**
6
- * @template T
7
- * @param {Function|Class<T>} type
8
- * @param {number} size
9
- */
10
- constructor({ type, size }: Function | Class<T_1>);
11
- Type: any;
12
- /**
13
- * @private
14
- * @type {T}
15
- */
16
- private pool;
17
- /**
18
- * @private
19
- * @type {number}
20
- */
21
- private maxSize;
22
- get(): any;
23
- release(o: any): void;
24
- }
25
- //# sourceMappingURL=SimpleObjectPoolFactory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SimpleObjectPoolFactory.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/SimpleObjectPoolFactory.js"],"names":[],"mappings":"AAAA;;GAEG;AACH;IACI;;;;OAIG;IACH,4BAHW,qBAAiB,EAkB3B;IAbG,UAAgB;IAEhB;;;OAGG;IACH,aAAc;IAEd;;;OAGG;IACH,gBAAmB;IAGvB,WAMC;IAED,sBAMC;CACJ"}
@@ -1,42 +0,0 @@
1
- /**
2
- * @template T
3
- */
4
- export class SimpleObjectPoolFactory {
5
- /**
6
- * @template T
7
- * @param {Function|Class<T>} type
8
- * @param {number} size
9
- */
10
- constructor({ type, size = 256 }) {
11
-
12
- this.Type = type;
13
-
14
- /**
15
- * @private
16
- * @type {T}
17
- */
18
- this.pool = [];
19
-
20
- /**
21
- * @private
22
- * @type {number}
23
- */
24
- this.maxSize = size;
25
- }
26
-
27
- get() {
28
- if (this.pool.length > 0) {
29
- return this.pool.pop();
30
- } else {
31
- return new this.Type();
32
- }
33
- }
34
-
35
- release(o) {
36
- if (this.pool.length < this.maxSize) {
37
- this.pool.push(o);
38
- } else {
39
- // do nothing, just skip
40
- }
41
- }
42
- }