@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.cjs
CHANGED
|
@@ -97941,9 +97941,22 @@ class ImmutableObjectPool {
|
|
|
97941
97941
|
}
|
|
97942
97942
|
|
|
97943
97943
|
/**
|
|
97944
|
+
* Object Pool pattern implementation.
|
|
97945
|
+
* 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
97946
|
* @template T
|
|
97945
97947
|
*/
|
|
97946
97948
|
class ObjectPoolFactory {
|
|
97949
|
+
/**
|
|
97950
|
+
* @private
|
|
97951
|
+
* @type {Array<T>}
|
|
97952
|
+
*/
|
|
97953
|
+
pool = [];
|
|
97954
|
+
|
|
97955
|
+
/**
|
|
97956
|
+
* @type {number}
|
|
97957
|
+
*/
|
|
97958
|
+
maxSize = 256;
|
|
97959
|
+
|
|
97947
97960
|
/**
|
|
97948
97961
|
* @param {function():T} creator
|
|
97949
97962
|
* @param {function(T)} destroyer
|
|
@@ -97960,36 +97973,31 @@ class ObjectPoolFactory {
|
|
|
97960
97973
|
* @type {function(): T}
|
|
97961
97974
|
*/
|
|
97962
97975
|
this.creator = creator;
|
|
97976
|
+
|
|
97963
97977
|
/**
|
|
97964
97978
|
* @private
|
|
97965
97979
|
* @type {function(T)}
|
|
97966
97980
|
*/
|
|
97967
97981
|
this.destroyer = destroyer;
|
|
97982
|
+
|
|
97968
97983
|
/**
|
|
97969
97984
|
* @private
|
|
97970
97985
|
* @type {function(T)}
|
|
97971
97986
|
*/
|
|
97972
97987
|
this.resetter = resetter;
|
|
97973
97988
|
|
|
97974
|
-
/**
|
|
97975
|
-
* @private
|
|
97976
|
-
* @type {Array<T>}
|
|
97977
|
-
*/
|
|
97978
|
-
this.pool = [];
|
|
97979
|
-
|
|
97980
|
-
/**
|
|
97981
|
-
* @type {number}
|
|
97982
|
-
*/
|
|
97983
|
-
this.maxSize = 256;
|
|
97984
97989
|
}
|
|
97985
97990
|
|
|
97986
97991
|
/**
|
|
97987
97992
|
*
|
|
97988
97993
|
* @returns {T}
|
|
97989
97994
|
*/
|
|
97990
|
-
|
|
97991
|
-
|
|
97992
|
-
|
|
97995
|
+
get() {
|
|
97996
|
+
const pool = this.pool;
|
|
97997
|
+
|
|
97998
|
+
if (pool.length > 0) {
|
|
97999
|
+
|
|
98000
|
+
const oldInstance = pool.pop();
|
|
97993
98001
|
|
|
97994
98002
|
//reset the object
|
|
97995
98003
|
this.resetter(oldInstance);
|
|
@@ -98012,7 +98020,9 @@ class ObjectPoolFactory {
|
|
|
98012
98020
|
*/
|
|
98013
98021
|
release(object) {
|
|
98014
98022
|
|
|
98015
|
-
|
|
98023
|
+
const pool = this.pool;
|
|
98024
|
+
|
|
98025
|
+
if (pool.length >= this.maxSize) {
|
|
98016
98026
|
//pool is too large, destroy and discard the object
|
|
98017
98027
|
if (this.destroyer !== noop) {
|
|
98018
98028
|
this.destroyer(object);
|
|
@@ -98022,11 +98032,18 @@ class ObjectPoolFactory {
|
|
|
98022
98032
|
}
|
|
98023
98033
|
|
|
98024
98034
|
//add it to the pool
|
|
98025
|
-
|
|
98035
|
+
pool.push(object);
|
|
98026
98036
|
|
|
98027
98037
|
return true;
|
|
98028
98038
|
}
|
|
98029
|
-
}
|
|
98039
|
+
}
|
|
98040
|
+
|
|
98041
|
+
|
|
98042
|
+
/**
|
|
98043
|
+
* @deprecated use `get` instead
|
|
98044
|
+
* @type {function(): T}
|
|
98045
|
+
*/
|
|
98046
|
+
ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get;
|
|
98030
98047
|
|
|
98031
98048
|
/**
|
|
98032
98049
|
* Will invoke A.equals(B) on members if such exists
|