@woosh/meep-engine 2.110.2 → 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.
- package/build/meep.cjs +33 -16
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +33 -16
- package/package.json +1 -1
- package/src/core/model/object/ObjectPoolFactory.d.ts +17 -10
- package/src/core/model/object/ObjectPoolFactory.d.ts.map +1 -1
- package/src/core/model/object/ObjectPoolFactory.js +33 -16
- package/src/engine/simulation/Ticker.d.ts +9 -0
- package/src/core/model/object/SimpleObjectPoolFactory.d.ts +0 -25
- package/src/core/model/object/SimpleObjectPoolFactory.d.ts.map +0 -1
- package/src/core/model/object/SimpleObjectPoolFactory.js +0 -42
package/build/meep.module.js
CHANGED
|
@@ -97939,9 +97939,22 @@ class ImmutableObjectPool {
|
|
|
97939
97939
|
}
|
|
97940
97940
|
|
|
97941
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
|
|
97942
97944
|
* @template T
|
|
97943
97945
|
*/
|
|
97944
97946
|
class ObjectPoolFactory {
|
|
97947
|
+
/**
|
|
97948
|
+
* @private
|
|
97949
|
+
* @type {Array<T>}
|
|
97950
|
+
*/
|
|
97951
|
+
pool = [];
|
|
97952
|
+
|
|
97953
|
+
/**
|
|
97954
|
+
* @type {number}
|
|
97955
|
+
*/
|
|
97956
|
+
maxSize = 256;
|
|
97957
|
+
|
|
97945
97958
|
/**
|
|
97946
97959
|
* @param {function():T} creator
|
|
97947
97960
|
* @param {function(T)} destroyer
|
|
@@ -97958,36 +97971,31 @@ class ObjectPoolFactory {
|
|
|
97958
97971
|
* @type {function(): T}
|
|
97959
97972
|
*/
|
|
97960
97973
|
this.creator = creator;
|
|
97974
|
+
|
|
97961
97975
|
/**
|
|
97962
97976
|
* @private
|
|
97963
97977
|
* @type {function(T)}
|
|
97964
97978
|
*/
|
|
97965
97979
|
this.destroyer = destroyer;
|
|
97980
|
+
|
|
97966
97981
|
/**
|
|
97967
97982
|
* @private
|
|
97968
97983
|
* @type {function(T)}
|
|
97969
97984
|
*/
|
|
97970
97985
|
this.resetter = resetter;
|
|
97971
97986
|
|
|
97972
|
-
/**
|
|
97973
|
-
* @private
|
|
97974
|
-
* @type {Array<T>}
|
|
97975
|
-
*/
|
|
97976
|
-
this.pool = [];
|
|
97977
|
-
|
|
97978
|
-
/**
|
|
97979
|
-
* @type {number}
|
|
97980
|
-
*/
|
|
97981
|
-
this.maxSize = 256;
|
|
97982
97987
|
}
|
|
97983
97988
|
|
|
97984
97989
|
/**
|
|
97985
97990
|
*
|
|
97986
97991
|
* @returns {T}
|
|
97987
97992
|
*/
|
|
97988
|
-
|
|
97989
|
-
|
|
97990
|
-
|
|
97993
|
+
get() {
|
|
97994
|
+
const pool = this.pool;
|
|
97995
|
+
|
|
97996
|
+
if (pool.length > 0) {
|
|
97997
|
+
|
|
97998
|
+
const oldInstance = pool.pop();
|
|
97991
97999
|
|
|
97992
98000
|
//reset the object
|
|
97993
98001
|
this.resetter(oldInstance);
|
|
@@ -98010,7 +98018,9 @@ class ObjectPoolFactory {
|
|
|
98010
98018
|
*/
|
|
98011
98019
|
release(object) {
|
|
98012
98020
|
|
|
98013
|
-
|
|
98021
|
+
const pool = this.pool;
|
|
98022
|
+
|
|
98023
|
+
if (pool.length >= this.maxSize) {
|
|
98014
98024
|
//pool is too large, destroy and discard the object
|
|
98015
98025
|
if (this.destroyer !== noop) {
|
|
98016
98026
|
this.destroyer(object);
|
|
@@ -98020,11 +98030,18 @@ class ObjectPoolFactory {
|
|
|
98020
98030
|
}
|
|
98021
98031
|
|
|
98022
98032
|
//add it to the pool
|
|
98023
|
-
|
|
98033
|
+
pool.push(object);
|
|
98024
98034
|
|
|
98025
98035
|
return true;
|
|
98026
98036
|
}
|
|
98027
|
-
}
|
|
98037
|
+
}
|
|
98038
|
+
|
|
98039
|
+
|
|
98040
|
+
/**
|
|
98041
|
+
* @deprecated use `get` instead
|
|
98042
|
+
* @type {function(): T}
|
|
98043
|
+
*/
|
|
98044
|
+
ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get;
|
|
98028
98045
|
|
|
98029
98046
|
/**
|
|
98030
98047
|
* Will invoke A.equals(B) on members if such exists
|
package/package.json
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
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
|
|
2
4
|
* @template T
|
|
3
5
|
*/
|
|
4
6
|
export class ObjectPoolFactory<T> {
|
|
@@ -8,6 +10,15 @@ export class ObjectPoolFactory<T> {
|
|
|
8
10
|
* @param {function(T)} resetter
|
|
9
11
|
*/
|
|
10
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;
|
|
11
22
|
/**
|
|
12
23
|
* @private
|
|
13
24
|
* @type {function(): T}
|
|
@@ -23,25 +34,21 @@ export class ObjectPoolFactory<T> {
|
|
|
23
34
|
* @type {function(T)}
|
|
24
35
|
*/
|
|
25
36
|
private resetter;
|
|
26
|
-
/**
|
|
27
|
-
* @private
|
|
28
|
-
* @type {Array<T>}
|
|
29
|
-
*/
|
|
30
|
-
private pool;
|
|
31
|
-
/**
|
|
32
|
-
* @type {number}
|
|
33
|
-
*/
|
|
34
|
-
maxSize: number;
|
|
35
37
|
/**
|
|
36
38
|
*
|
|
37
39
|
* @returns {T}
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
get(): T;
|
|
40
42
|
/**
|
|
41
43
|
*
|
|
42
44
|
* @param {T} object
|
|
43
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
|
|
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"}
|
|
@@ -3,9 +3,22 @@ import { assert } from "../../assert.js";
|
|
|
3
3
|
import { noop } from "../../function/noop.js";
|
|
4
4
|
|
|
5
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
|
|
6
8
|
* @template T
|
|
7
9
|
*/
|
|
8
10
|
export class ObjectPoolFactory {
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
* @type {Array<T>}
|
|
14
|
+
*/
|
|
15
|
+
pool = [];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
20
|
+
maxSize = 256;
|
|
21
|
+
|
|
9
22
|
/**
|
|
10
23
|
* @param {function():T} creator
|
|
11
24
|
* @param {function(T)} destroyer
|
|
@@ -25,36 +38,31 @@ export class ObjectPoolFactory {
|
|
|
25
38
|
* @type {function(): T}
|
|
26
39
|
*/
|
|
27
40
|
this.creator = creator;
|
|
41
|
+
|
|
28
42
|
/**
|
|
29
43
|
* @private
|
|
30
44
|
* @type {function(T)}
|
|
31
45
|
*/
|
|
32
46
|
this.destroyer = destroyer;
|
|
47
|
+
|
|
33
48
|
/**
|
|
34
49
|
* @private
|
|
35
50
|
* @type {function(T)}
|
|
36
51
|
*/
|
|
37
52
|
this.resetter = resetter;
|
|
38
53
|
|
|
39
|
-
/**
|
|
40
|
-
* @private
|
|
41
|
-
* @type {Array<T>}
|
|
42
|
-
*/
|
|
43
|
-
this.pool = [];
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @type {number}
|
|
47
|
-
*/
|
|
48
|
-
this.maxSize = 256;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
/**
|
|
52
57
|
*
|
|
53
58
|
* @returns {T}
|
|
54
59
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
get() {
|
|
61
|
+
const pool = this.pool;
|
|
62
|
+
|
|
63
|
+
if (pool.length > 0) {
|
|
64
|
+
|
|
65
|
+
const oldInstance = pool.pop();
|
|
58
66
|
|
|
59
67
|
//reset the object
|
|
60
68
|
this.resetter(oldInstance);
|
|
@@ -85,9 +93,11 @@ export class ObjectPoolFactory {
|
|
|
85
93
|
assert.notNull(object, 'object');
|
|
86
94
|
assert.defined(object, 'object');
|
|
87
95
|
|
|
88
|
-
|
|
96
|
+
const pool = this.pool;
|
|
89
97
|
|
|
90
|
-
|
|
98
|
+
assert.arrayHasNo(pool, object, `Pool already contains object that is being attempted to be release`);
|
|
99
|
+
|
|
100
|
+
if (pool.length >= this.maxSize) {
|
|
91
101
|
//pool is too large, destroy and discard the object
|
|
92
102
|
if (this.destroyer !== noop) {
|
|
93
103
|
this.destroyer(object);
|
|
@@ -97,8 +107,15 @@ export class ObjectPoolFactory {
|
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
//add it to the pool
|
|
100
|
-
|
|
110
|
+
pool.push(object);
|
|
101
111
|
|
|
102
112
|
return true;
|
|
103
113
|
}
|
|
104
114
|
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated use `get` instead
|
|
119
|
+
* @type {function(): T}
|
|
120
|
+
*/
|
|
121
|
+
ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get
|
|
@@ -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
|
-
}
|