@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.
- package/build/meep.cjs +46 -21
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +46 -21
- package/package.json +1 -1
- package/src/core/model/object/ObjectPoolFactory.d.ts +23 -16
- package/src/core/model/object/ObjectPoolFactory.d.ts.map +1 -1
- package/src/core/model/object/ObjectPoolFactory.js +49 -22
- package/src/engine/ecs/ik/IKProblem.d.ts +2 -1
- package/src/engine/ecs/ik/IKProblem.d.ts.map +1 -1
- 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
|
@@ -97940,71 +97940,89 @@ class ImmutableObjectPool {
|
|
|
97940
97940
|
}
|
|
97941
97941
|
}
|
|
97942
97942
|
|
|
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
|
|
97946
|
+
* @template T
|
|
97947
|
+
*/
|
|
97943
97948
|
class ObjectPoolFactory {
|
|
97944
97949
|
/**
|
|
97945
|
-
* @
|
|
97950
|
+
* @private
|
|
97951
|
+
* @type {Array<T>}
|
|
97952
|
+
*/
|
|
97953
|
+
pool = [];
|
|
97954
|
+
|
|
97955
|
+
/**
|
|
97956
|
+
* @type {number}
|
|
97957
|
+
*/
|
|
97958
|
+
maxSize = 256;
|
|
97959
|
+
|
|
97960
|
+
/**
|
|
97946
97961
|
* @param {function():T} creator
|
|
97947
97962
|
* @param {function(T)} destroyer
|
|
97948
97963
|
* @param {function(T)} resetter
|
|
97949
|
-
* @constructor
|
|
97950
97964
|
*/
|
|
97951
|
-
constructor(
|
|
97965
|
+
constructor(
|
|
97966
|
+
creator,
|
|
97967
|
+
destroyer = noop,
|
|
97968
|
+
resetter = noop
|
|
97969
|
+
) {
|
|
97970
|
+
|
|
97952
97971
|
/**
|
|
97953
97972
|
* @private
|
|
97954
97973
|
* @type {function(): T}
|
|
97955
97974
|
*/
|
|
97956
97975
|
this.creator = creator;
|
|
97976
|
+
|
|
97957
97977
|
/**
|
|
97958
97978
|
* @private
|
|
97959
97979
|
* @type {function(T)}
|
|
97960
97980
|
*/
|
|
97961
97981
|
this.destroyer = destroyer;
|
|
97982
|
+
|
|
97962
97983
|
/**
|
|
97963
97984
|
* @private
|
|
97964
97985
|
* @type {function(T)}
|
|
97965
97986
|
*/
|
|
97966
97987
|
this.resetter = resetter;
|
|
97967
97988
|
|
|
97968
|
-
/**
|
|
97969
|
-
* @private
|
|
97970
|
-
* @type {Array<T>}
|
|
97971
|
-
*/
|
|
97972
|
-
this.pool = [];
|
|
97973
|
-
|
|
97974
|
-
/**
|
|
97975
|
-
* @private
|
|
97976
|
-
* @type {number}
|
|
97977
|
-
*/
|
|
97978
|
-
this.maxSize = 256;
|
|
97979
97989
|
}
|
|
97980
97990
|
|
|
97981
97991
|
/**
|
|
97982
97992
|
*
|
|
97983
97993
|
* @returns {T}
|
|
97984
97994
|
*/
|
|
97985
|
-
|
|
97986
|
-
|
|
97987
|
-
|
|
97995
|
+
get() {
|
|
97996
|
+
const pool = this.pool;
|
|
97997
|
+
|
|
97998
|
+
if (pool.length > 0) {
|
|
97999
|
+
|
|
98000
|
+
const oldInstance = pool.pop();
|
|
97988
98001
|
|
|
97989
98002
|
//reset the object
|
|
97990
98003
|
this.resetter(oldInstance);
|
|
97991
98004
|
|
|
97992
98005
|
return oldInstance;
|
|
98006
|
+
|
|
97993
98007
|
} else {
|
|
98008
|
+
|
|
97994
98009
|
const newInstance = this.creator();
|
|
97995
98010
|
|
|
97996
98011
|
return newInstance;
|
|
98012
|
+
|
|
97997
98013
|
}
|
|
97998
98014
|
}
|
|
97999
98015
|
|
|
98000
98016
|
/**
|
|
98001
98017
|
*
|
|
98002
98018
|
* @param {T} object
|
|
98003
|
-
* @returns {boolean}
|
|
98019
|
+
* @returns {boolean} true if object was added back to the pool, false if pool was full and object was destroyed instead
|
|
98004
98020
|
*/
|
|
98005
98021
|
release(object) {
|
|
98006
98022
|
|
|
98007
|
-
|
|
98023
|
+
const pool = this.pool;
|
|
98024
|
+
|
|
98025
|
+
if (pool.length >= this.maxSize) {
|
|
98008
98026
|
//pool is too large, destroy and discard the object
|
|
98009
98027
|
if (this.destroyer !== noop) {
|
|
98010
98028
|
this.destroyer(object);
|
|
@@ -98014,11 +98032,18 @@ class ObjectPoolFactory {
|
|
|
98014
98032
|
}
|
|
98015
98033
|
|
|
98016
98034
|
//add it to the pool
|
|
98017
|
-
|
|
98035
|
+
pool.push(object);
|
|
98018
98036
|
|
|
98019
98037
|
return true;
|
|
98020
98038
|
}
|
|
98021
|
-
}
|
|
98039
|
+
}
|
|
98040
|
+
|
|
98041
|
+
|
|
98042
|
+
/**
|
|
98043
|
+
* @deprecated use `get` instead
|
|
98044
|
+
* @type {function(): T}
|
|
98045
|
+
*/
|
|
98046
|
+
ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get;
|
|
98022
98047
|
|
|
98023
98048
|
/**
|
|
98024
98049
|
* Will invoke A.equals(B) on members if such exists
|