@al8b/runtime 0.1.0
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/README.md +87 -0
- package/dist/assets/constructors.d.mts +6 -0
- package/dist/assets/constructors.d.ts +6 -0
- package/dist/assets/constructors.js +40 -0
- package/dist/assets/constructors.js.map +1 -0
- package/dist/assets/constructors.mjs +12 -0
- package/dist/assets/constructors.mjs.map +1 -0
- package/dist/assets/index.d.mts +11 -0
- package/dist/assets/index.d.ts +11 -0
- package/dist/assets/index.js +276 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/index.mjs +247 -0
- package/dist/assets/index.mjs.map +1 -0
- package/dist/assets/loader.d.mts +83 -0
- package/dist/assets/loader.d.ts +83 -0
- package/dist/assets/loader.js +260 -0
- package/dist/assets/loader.js.map +1 -0
- package/dist/assets/loader.mjs +237 -0
- package/dist/assets/loader.mjs.map +1 -0
- package/dist/browser/index.js +16599 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/index.min.js +171 -0
- package/dist/constants.d.mts +16 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +49 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +18 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core/api-factory.d.mts +63 -0
- package/dist/core/api-factory.d.ts +63 -0
- package/dist/core/api-factory.js +239 -0
- package/dist/core/api-factory.js.map +1 -0
- package/dist/core/api-factory.mjs +214 -0
- package/dist/core/api-factory.mjs.map +1 -0
- package/dist/core/assets-registry.d.mts +14 -0
- package/dist/core/assets-registry.d.ts +14 -0
- package/dist/core/assets-registry.js +64 -0
- package/dist/core/assets-registry.js.map +1 -0
- package/dist/core/assets-registry.mjs +41 -0
- package/dist/core/assets-registry.mjs.map +1 -0
- package/dist/core/controller.d.mts +109 -0
- package/dist/core/controller.d.ts +109 -0
- package/dist/core/controller.js +1782 -0
- package/dist/core/controller.js.map +1 -0
- package/dist/core/controller.mjs +1758 -0
- package/dist/core/controller.mjs.map +1 -0
- package/dist/core/debug-logger.d.mts +35 -0
- package/dist/core/debug-logger.d.ts +35 -0
- package/dist/core/debug-logger.js +177 -0
- package/dist/core/debug-logger.js.map +1 -0
- package/dist/core/debug-logger.mjs +154 -0
- package/dist/core/debug-logger.mjs.map +1 -0
- package/dist/core/error-handler.d.mts +25 -0
- package/dist/core/error-handler.d.ts +25 -0
- package/dist/core/error-handler.js +106 -0
- package/dist/core/error-handler.js.map +1 -0
- package/dist/core/error-handler.mjs +81 -0
- package/dist/core/error-handler.mjs.map +1 -0
- package/dist/core/index.d.mts +14 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.js +1782 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +1757 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/hot-reload/index.d.mts +7 -0
- package/dist/hot-reload/index.d.ts +7 -0
- package/dist/hot-reload/index.js +103 -0
- package/dist/hot-reload/index.js.map +1 -0
- package/dist/hot-reload/index.mjs +78 -0
- package/dist/hot-reload/index.mjs.map +1 -0
- package/dist/hot-reload/updater.d.mts +33 -0
- package/dist/hot-reload/updater.d.ts +33 -0
- package/dist/hot-reload/updater.js +101 -0
- package/dist/hot-reload/updater.js.map +1 -0
- package/dist/hot-reload/updater.mjs +78 -0
- package/dist/hot-reload/updater.mjs.map +1 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +1859 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1817 -0
- package/dist/index.mjs.map +1 -0
- package/dist/input/index.d.mts +2 -0
- package/dist/input/index.d.ts +2 -0
- package/dist/input/index.js +79 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/index.mjs +54 -0
- package/dist/input/index.mjs.map +1 -0
- package/dist/input/manager.d.mts +37 -0
- package/dist/input/manager.d.ts +37 -0
- package/dist/input/manager.js +77 -0
- package/dist/input/manager.js.map +1 -0
- package/dist/input/manager.mjs +54 -0
- package/dist/input/manager.mjs.map +1 -0
- package/dist/loop/game-loop.d.mts +63 -0
- package/dist/loop/game-loop.d.ts +63 -0
- package/dist/loop/game-loop.js +156 -0
- package/dist/loop/game-loop.js.map +1 -0
- package/dist/loop/game-loop.mjs +131 -0
- package/dist/loop/game-loop.mjs.map +1 -0
- package/dist/loop/index.d.mts +1 -0
- package/dist/loop/index.d.ts +1 -0
- package/dist/loop/index.js +156 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/index.mjs +131 -0
- package/dist/loop/index.mjs.map +1 -0
- package/dist/storage/index.d.mts +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +31 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.mjs +6 -0
- package/dist/storage/index.mjs.map +1 -0
- package/dist/system/api.d.mts +28 -0
- package/dist/system/api.d.ts +28 -0
- package/dist/system/api.js +126 -0
- package/dist/system/api.js.map +1 -0
- package/dist/system/api.mjs +101 -0
- package/dist/system/api.mjs.map +1 -0
- package/dist/system/index.d.mts +2 -0
- package/dist/system/index.d.ts +2 -0
- package/dist/system/index.js +126 -0
- package/dist/system/index.js.map +1 -0
- package/dist/system/index.mjs +101 -0
- package/dist/system/index.mjs.map +1 -0
- package/dist/types/assets.d.mts +43 -0
- package/dist/types/assets.d.ts +43 -0
- package/dist/types/assets.js +19 -0
- package/dist/types/assets.js.map +1 -0
- package/dist/types/assets.mjs +1 -0
- package/dist/types/assets.mjs.map +1 -0
- package/dist/types/bridge.d.mts +66 -0
- package/dist/types/bridge.d.ts +66 -0
- package/dist/types/bridge.js +19 -0
- package/dist/types/bridge.js.map +1 -0
- package/dist/types/bridge.mjs +1 -0
- package/dist/types/bridge.mjs.map +1 -0
- package/dist/types/index.d.mts +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/runtime.d.mts +71 -0
- package/dist/types/runtime.d.ts +71 -0
- package/dist/types/runtime.js +19 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/runtime.mjs +1 -0
- package/dist/types/runtime.mjs.map +1 -0
- package/dist/types/vm.d.mts +1 -0
- package/dist/types/vm.d.ts +1 -0
- package/dist/types/vm.js +19 -0
- package/dist/types/vm.js.map +1 -0
- package/dist/types/vm.mjs +1 -0
- package/dist/types/vm.mjs.map +1 -0
- package/dist/utils/deep-clone.d.mts +14 -0
- package/dist/utils/deep-clone.d.ts +14 -0
- package/dist/utils/deep-clone.js +42 -0
- package/dist/utils/deep-clone.js.map +1 -0
- package/dist/utils/deep-clone.mjs +19 -0
- package/dist/utils/deep-clone.mjs.map +1 -0
- package/dist/utils/index.d.mts +3 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +156 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +129 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/object-pool.d.mts +66 -0
- package/dist/utils/object-pool.d.ts +66 -0
- package/dist/utils/object-pool.js +113 -0
- package/dist/utils/object-pool.js.map +1 -0
- package/dist/utils/object-pool.mjs +90 -0
- package/dist/utils/object-pool.mjs.map +1 -0
- package/dist/utils/shallow-equal.d.mts +15 -0
- package/dist/utils/shallow-equal.d.ts +15 -0
- package/dist/utils/shallow-equal.js +53 -0
- package/dist/utils/shallow-equal.js.map +1 -0
- package/dist/utils/shallow-equal.mjs +30 -0
- package/dist/utils/shallow-equal.mjs.map +1 -0
- package/dist/vm/index.d.mts +1 -0
- package/dist/vm/index.d.ts +1 -0
- package/dist/vm/index.js +37 -0
- package/dist/vm/index.js.map +1 -0
- package/dist/vm/index.mjs +9 -0
- package/dist/vm/index.mjs.map +1 -0
- package/package.json +52 -0
package/dist/types/vm.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/vm.ts
|
|
17
|
+
var vm_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(vm_exports);
|
|
19
|
+
//# sourceMappingURL=vm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/vm.ts"],"sourcesContent":["// VM types are re-exported from ../vm/index.ts — import from there or directly from \"@al8b/vm\".\nexport type {\n\tErrorInfo,\n\tGlobalAPI,\n\tMetaFunctions,\n\tSystemAPI,\n\tVMContext,\n\tVMWarnings,\n\tWarningInfo,\n} from \"@al8b/vm\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=vm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep clone utility using structuredClone
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Deep clone a value using the native structuredClone API
|
|
6
|
+
* Supports all structured-cloneable types: objects, arrays, primitives, Date, Set, Map, etc.
|
|
7
|
+
* Does NOT support: Functions, Symbols, DOM nodes
|
|
8
|
+
*
|
|
9
|
+
* @param value The value to deep clone
|
|
10
|
+
* @returns A deep clone of the value
|
|
11
|
+
*/
|
|
12
|
+
declare function deepClone(value: unknown): unknown;
|
|
13
|
+
|
|
14
|
+
export { deepClone };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep clone utility using structuredClone
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Deep clone a value using the native structuredClone API
|
|
6
|
+
* Supports all structured-cloneable types: objects, arrays, primitives, Date, Set, Map, etc.
|
|
7
|
+
* Does NOT support: Functions, Symbols, DOM nodes
|
|
8
|
+
*
|
|
9
|
+
* @param value The value to deep clone
|
|
10
|
+
* @returns A deep clone of the value
|
|
11
|
+
*/
|
|
12
|
+
declare function deepClone(value: unknown): unknown;
|
|
13
|
+
|
|
14
|
+
export { deepClone };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/utils/deep-clone.ts
|
|
22
|
+
var deep_clone_exports = {};
|
|
23
|
+
__export(deep_clone_exports, {
|
|
24
|
+
deepClone: () => deepClone
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(deep_clone_exports);
|
|
27
|
+
function deepClone(value) {
|
|
28
|
+
if (typeof structuredClone !== "undefined") {
|
|
29
|
+
return structuredClone(value);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(JSON.stringify(value));
|
|
33
|
+
} catch {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
__name(deepClone, "deepClone");
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
deepClone
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=deep-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/deep-clone.ts"],"sourcesContent":["/**\n * Deep clone utility using structuredClone\n */\n\n/**\n * Deep clone a value using the native structuredClone API\n * Supports all structured-cloneable types: objects, arrays, primitives, Date, Set, Map, etc.\n * Does NOT support: Functions, Symbols, DOM nodes\n *\n * @param value The value to deep clone\n * @returns A deep clone of the value\n */\nexport function deepClone(value: unknown): unknown {\n\t// Use native structuredClone if available (Node 17.5+, modern browsers)\n\tif (typeof structuredClone !== \"undefined\") {\n\t\treturn structuredClone(value);\n\t}\n\n\t// Fallback for older environments: JSON round-trip\n\t// WARNING: This loses Date, Map, Set, undefined, Function, Symbol values\n\ttry {\n\t\treturn JSON.parse(JSON.stringify(value));\n\t} catch {\n\t\t// If JSON fails (circular reference, etc.), return the original\n\t\t// This is safe but means mutations will affect the original\n\t\treturn value;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAYO,SAASA,UAAUC,OAAc;AAEvC,MAAI,OAAOC,oBAAoB,aAAa;AAC3C,WAAOA,gBAAgBD,KAAAA;EACxB;AAIA,MAAI;AACH,WAAOE,KAAKC,MAAMD,KAAKE,UAAUJ,KAAAA,CAAAA;EAClC,QAAQ;AAGP,WAAOA;EACR;AACD;AAfgBD;","names":["deepClone","value","structuredClone","JSON","parse","stringify"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/utils/deep-clone.ts
|
|
5
|
+
function deepClone(value) {
|
|
6
|
+
if (typeof structuredClone !== "undefined") {
|
|
7
|
+
return structuredClone(value);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(JSON.stringify(value));
|
|
11
|
+
} catch {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
__name(deepClone, "deepClone");
|
|
16
|
+
export {
|
|
17
|
+
deepClone
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=deep-clone.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/deep-clone.ts"],"sourcesContent":["/**\n * Deep clone utility using structuredClone\n */\n\n/**\n * Deep clone a value using the native structuredClone API\n * Supports all structured-cloneable types: objects, arrays, primitives, Date, Set, Map, etc.\n * Does NOT support: Functions, Symbols, DOM nodes\n *\n * @param value The value to deep clone\n * @returns A deep clone of the value\n */\nexport function deepClone(value: unknown): unknown {\n\t// Use native structuredClone if available (Node 17.5+, modern browsers)\n\tif (typeof structuredClone !== \"undefined\") {\n\t\treturn structuredClone(value);\n\t}\n\n\t// Fallback for older environments: JSON round-trip\n\t// WARNING: This loses Date, Map, Set, undefined, Function, Symbol values\n\ttry {\n\t\treturn JSON.parse(JSON.stringify(value));\n\t} catch {\n\t\t// If JSON fails (circular reference, etc.), return the original\n\t\t// This is safe but means mutations will affect the original\n\t\treturn value;\n\t}\n}\n"],"mappings":";;;;AAYO,SAASA,UAAUC,OAAc;AAEvC,MAAI,OAAOC,oBAAoB,aAAa;AAC3C,WAAOA,gBAAgBD,KAAAA;EACxB;AAIA,MAAI;AACH,WAAOE,KAAKC,MAAMD,KAAKE,UAAUJ,KAAAA,CAAAA;EAClC,QAAQ;AAGP,WAAOA;EACR;AACD;AAfgBD;","names":["deepClone","value","structuredClone","JSON","parse","stringify"]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/utils/index.ts
|
|
22
|
+
var utils_exports = {};
|
|
23
|
+
__export(utils_exports, {
|
|
24
|
+
ObjectPool: () => ObjectPool,
|
|
25
|
+
deepClone: () => deepClone,
|
|
26
|
+
shallowEqual: () => shallowEqual
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
|
|
30
|
+
// src/utils/deep-clone.ts
|
|
31
|
+
function deepClone(value) {
|
|
32
|
+
if (typeof structuredClone !== "undefined") {
|
|
33
|
+
return structuredClone(value);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(JSON.stringify(value));
|
|
37
|
+
} catch {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
__name(deepClone, "deepClone");
|
|
42
|
+
|
|
43
|
+
// src/utils/object-pool.ts
|
|
44
|
+
var ObjectPool = class {
|
|
45
|
+
static {
|
|
46
|
+
__name(this, "ObjectPool");
|
|
47
|
+
}
|
|
48
|
+
pool = [];
|
|
49
|
+
factory;
|
|
50
|
+
reset;
|
|
51
|
+
maxSize;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new object pool
|
|
54
|
+
*
|
|
55
|
+
* @param factory - Function to create new objects
|
|
56
|
+
* @param reset - Function to reset object state for reuse
|
|
57
|
+
* @param maxSize - Maximum pool size (default: 100)
|
|
58
|
+
*/
|
|
59
|
+
constructor(factory, reset, maxSize = 100) {
|
|
60
|
+
this.factory = factory;
|
|
61
|
+
this.reset = reset;
|
|
62
|
+
this.maxSize = maxSize;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Acquire an object from the pool
|
|
66
|
+
*
|
|
67
|
+
* Returns a new object if pool is empty, otherwise reuses a pooled object.
|
|
68
|
+
*
|
|
69
|
+
* @returns Object from pool or newly created
|
|
70
|
+
*/
|
|
71
|
+
acquire() {
|
|
72
|
+
if (this.pool.length > 0) {
|
|
73
|
+
return this.pool.pop();
|
|
74
|
+
}
|
|
75
|
+
return this.factory();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Release an object back to the pool
|
|
79
|
+
*
|
|
80
|
+
* Resets the object and adds it back to the pool for reuse.
|
|
81
|
+
* If pool is at max size, the object is discarded.
|
|
82
|
+
*
|
|
83
|
+
* @param obj - Object to release
|
|
84
|
+
*/
|
|
85
|
+
release(obj) {
|
|
86
|
+
if (this.pool.length >= this.maxSize) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.reset(obj);
|
|
90
|
+
this.pool.push(obj);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clear all objects from the pool
|
|
94
|
+
*/
|
|
95
|
+
clear() {
|
|
96
|
+
this.pool = [];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get current pool size
|
|
100
|
+
*
|
|
101
|
+
* @returns Number of objects in pool
|
|
102
|
+
*/
|
|
103
|
+
size() {
|
|
104
|
+
return this.pool.length;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get maximum pool size
|
|
108
|
+
*
|
|
109
|
+
* @returns Maximum pool size
|
|
110
|
+
*/
|
|
111
|
+
getMaxSize() {
|
|
112
|
+
return this.maxSize;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Set maximum pool size
|
|
116
|
+
*
|
|
117
|
+
* @param maxSize - New maximum pool size
|
|
118
|
+
*/
|
|
119
|
+
setMaxSize(maxSize) {
|
|
120
|
+
this.maxSize = maxSize;
|
|
121
|
+
if (this.pool.length > maxSize) {
|
|
122
|
+
this.pool = this.pool.slice(0, maxSize);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/utils/shallow-equal.ts
|
|
128
|
+
function shallowEqual(a, b) {
|
|
129
|
+
if (a === b) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const aObj = a;
|
|
136
|
+
const bObj = b;
|
|
137
|
+
const aKeys = Object.keys(aObj);
|
|
138
|
+
const bKeys = Object.keys(bObj);
|
|
139
|
+
if (aKeys.length !== bKeys.length) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
for (const key of aKeys) {
|
|
143
|
+
if (!(key in bObj) || aObj[key] !== bObj[key]) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
__name(shallowEqual, "shallowEqual");
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
ObjectPool,
|
|
153
|
+
deepClone,
|
|
154
|
+
shallowEqual
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/deep-clone.ts","../../src/utils/object-pool.ts","../../src/utils/shallow-equal.ts"],"sourcesContent":["/**\n * Runtime utilities\n */\n\nexport * from \"./deep-clone\";\nexport * from \"./object-pool\";\nexport * from \"./shallow-equal\";\n","/**\n * Deep clone utility using structuredClone\n */\n\n/**\n * Deep clone a value using the native structuredClone API\n * Supports all structured-cloneable types: objects, arrays, primitives, Date, Set, Map, etc.\n * Does NOT support: Functions, Symbols, DOM nodes\n *\n * @param value The value to deep clone\n * @returns A deep clone of the value\n */\nexport function deepClone(value: unknown): unknown {\n\t// Use native structuredClone if available (Node 17.5+, modern browsers)\n\tif (typeof structuredClone !== \"undefined\") {\n\t\treturn structuredClone(value);\n\t}\n\n\t// Fallback for older environments: JSON round-trip\n\t// WARNING: This loses Date, Map, Set, undefined, Function, Symbol values\n\ttry {\n\t\treturn JSON.parse(JSON.stringify(value));\n\t} catch {\n\t\t// If JSON fails (circular reference, etc.), return the original\n\t\t// This is safe but means mutations will affect the original\n\t\treturn value;\n\t}\n}\n","/**\n * Object Pool utility for game entities\n *\n * Provides object pooling to reduce GC pressure and improve performance\n * for frequently created/destroyed game objects.\n */\n\n/**\n * Object pool for reusing objects\n *\n * @template T - Type of objects in the pool\n */\nexport class ObjectPool<T> {\n\tprivate pool: T[] = [];\n\tprivate factory: () => T;\n\tprivate reset: (obj: T) => void;\n\tprivate maxSize: number;\n\n\t/**\n\t * Create a new object pool\n\t *\n\t * @param factory - Function to create new objects\n\t * @param reset - Function to reset object state for reuse\n\t * @param maxSize - Maximum pool size (default: 100)\n\t */\n\tconstructor(factory: () => T, reset: (obj: T) => void, maxSize: number = 100) {\n\t\tthis.factory = factory;\n\t\tthis.reset = reset;\n\t\tthis.maxSize = maxSize;\n\t}\n\n\t/**\n\t * Acquire an object from the pool\n\t *\n\t * Returns a new object if pool is empty, otherwise reuses a pooled object.\n\t *\n\t * @returns Object from pool or newly created\n\t */\n\tacquire(): T {\n\t\tif (this.pool.length > 0) {\n\t\t\treturn this.pool.pop()!;\n\t\t}\n\t\treturn this.factory();\n\t}\n\n\t/**\n\t * Release an object back to the pool\n\t *\n\t * Resets the object and adds it back to the pool for reuse.\n\t * If pool is at max size, the object is discarded.\n\t *\n\t * @param obj - Object to release\n\t */\n\trelease(obj: T): void {\n\t\tif (this.pool.length >= this.maxSize) {\n\t\t\t// Pool is full, discard object\n\t\t\treturn;\n\t\t}\n\n\t\tthis.reset(obj);\n\t\tthis.pool.push(obj);\n\t}\n\n\t/**\n\t * Clear all objects from the pool\n\t */\n\tclear(): void {\n\t\tthis.pool = [];\n\t}\n\n\t/**\n\t * Get current pool size\n\t *\n\t * @returns Number of objects in pool\n\t */\n\tsize(): number {\n\t\treturn this.pool.length;\n\t}\n\n\t/**\n\t * Get maximum pool size\n\t *\n\t * @returns Maximum pool size\n\t */\n\tgetMaxSize(): number {\n\t\treturn this.maxSize;\n\t}\n\n\t/**\n\t * Set maximum pool size\n\t *\n\t * @param maxSize - New maximum pool size\n\t */\n\tsetMaxSize(maxSize: number): void {\n\t\tthis.maxSize = maxSize;\n\t\t// Trim pool if it exceeds new max size\n\t\tif (this.pool.length > maxSize) {\n\t\t\tthis.pool = this.pool.slice(0, maxSize);\n\t\t}\n\t}\n}\n","/**\n * Shallow equality comparison for objects and arrays\n */\n\n/**\n * Compare two values for shallow equality\n * For objects and arrays, only checks if top-level properties have the same references\n * For primitives, uses === comparison\n *\n * @param a First value\n * @param b Second value\n * @returns true if values are shallowly equal\n */\nexport function shallowEqual(a: unknown, b: unknown): boolean {\n\t// Same reference\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\t// Different types\n\tif (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) {\n\t\treturn false;\n\t}\n\n\tconst aObj = a as Record<string, unknown>;\n\tconst bObj = b as Record<string, unknown>;\n\n\t// Get keys\n\tconst aKeys = Object.keys(aObj);\n\tconst bKeys = Object.keys(bObj);\n\n\t// Different number of keys\n\tif (aKeys.length !== bKeys.length) {\n\t\treturn false;\n\t}\n\n\t// Check all keys have same reference values\n\tfor (const key of aKeys) {\n\t\tif (!(key in bObj) || aObj[key] !== bObj[key]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACYO,SAASA,UAAUC,OAAc;AAEvC,MAAI,OAAOC,oBAAoB,aAAa;AAC3C,WAAOA,gBAAgBD,KAAAA;EACxB;AAIA,MAAI;AACH,WAAOE,KAAKC,MAAMD,KAAKE,UAAUJ,KAAAA,CAAAA;EAClC,QAAQ;AAGP,WAAOA;EACR;AACD;AAfgBD;;;ACAT,IAAMM,aAAN,MAAMA;EAZb,OAYaA;;;EACJC,OAAY,CAAA;EACZC;EACAC;EACAC;;;;;;;;EASR,YAAYF,SAAkBC,OAAyBC,UAAkB,KAAK;AAC7E,SAAKF,UAAUA;AACf,SAAKC,QAAQA;AACb,SAAKC,UAAUA;EAChB;;;;;;;;EASAC,UAAa;AACZ,QAAI,KAAKJ,KAAKK,SAAS,GAAG;AACzB,aAAO,KAAKL,KAAKM,IAAG;IACrB;AACA,WAAO,KAAKL,QAAO;EACpB;;;;;;;;;EAUAM,QAAQC,KAAc;AACrB,QAAI,KAAKR,KAAKK,UAAU,KAAKF,SAAS;AAErC;IACD;AAEA,SAAKD,MAAMM,GAAAA;AACX,SAAKR,KAAKS,KAAKD,GAAAA;EAChB;;;;EAKAE,QAAc;AACb,SAAKV,OAAO,CAAA;EACb;;;;;;EAOAW,OAAe;AACd,WAAO,KAAKX,KAAKK;EAClB;;;;;;EAOAO,aAAqB;AACpB,WAAO,KAAKT;EACb;;;;;;EAOAU,WAAWV,SAAuB;AACjC,SAAKA,UAAUA;AAEf,QAAI,KAAKH,KAAKK,SAASF,SAAS;AAC/B,WAAKH,OAAO,KAAKA,KAAKc,MAAM,GAAGX,OAAAA;IAChC;EACD;AACD;;;ACvFO,SAASY,aAAaC,GAAYC,GAAU;AAElD,MAAID,MAAMC,GAAG;AACZ,WAAO;EACR;AAGA,MAAI,OAAOD,MAAM,YAAY,OAAOC,MAAM,YAAYD,MAAM,QAAQC,MAAM,MAAM;AAC/E,WAAO;EACR;AAEA,QAAMC,OAAOF;AACb,QAAMG,OAAOF;AAGb,QAAMG,QAAQC,OAAOC,KAAKJ,IAAAA;AAC1B,QAAMK,QAAQF,OAAOC,KAAKH,IAAAA;AAG1B,MAAIC,MAAMI,WAAWD,MAAMC,QAAQ;AAClC,WAAO;EACR;AAGA,aAAWC,OAAOL,OAAO;AACxB,QAAI,EAAEK,OAAON,SAASD,KAAKO,GAAAA,MAASN,KAAKM,GAAAA,GAAM;AAC9C,aAAO;IACR;EACD;AAEA,SAAO;AACR;AA/BgBV;","names":["deepClone","value","structuredClone","JSON","parse","stringify","ObjectPool","pool","factory","reset","maxSize","acquire","length","pop","release","obj","push","clear","size","getMaxSize","setMaxSize","slice","shallowEqual","a","b","aObj","bObj","aKeys","Object","keys","bKeys","length","key"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/utils/deep-clone.ts
|
|
5
|
+
function deepClone(value) {
|
|
6
|
+
if (typeof structuredClone !== "undefined") {
|
|
7
|
+
return structuredClone(value);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(JSON.stringify(value));
|
|
11
|
+
} catch {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
__name(deepClone, "deepClone");
|
|
16
|
+
|
|
17
|
+
// src/utils/object-pool.ts
|
|
18
|
+
var ObjectPool = class {
|
|
19
|
+
static {
|
|
20
|
+
__name(this, "ObjectPool");
|
|
21
|
+
}
|
|
22
|
+
pool = [];
|
|
23
|
+
factory;
|
|
24
|
+
reset;
|
|
25
|
+
maxSize;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new object pool
|
|
28
|
+
*
|
|
29
|
+
* @param factory - Function to create new objects
|
|
30
|
+
* @param reset - Function to reset object state for reuse
|
|
31
|
+
* @param maxSize - Maximum pool size (default: 100)
|
|
32
|
+
*/
|
|
33
|
+
constructor(factory, reset, maxSize = 100) {
|
|
34
|
+
this.factory = factory;
|
|
35
|
+
this.reset = reset;
|
|
36
|
+
this.maxSize = maxSize;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Acquire an object from the pool
|
|
40
|
+
*
|
|
41
|
+
* Returns a new object if pool is empty, otherwise reuses a pooled object.
|
|
42
|
+
*
|
|
43
|
+
* @returns Object from pool or newly created
|
|
44
|
+
*/
|
|
45
|
+
acquire() {
|
|
46
|
+
if (this.pool.length > 0) {
|
|
47
|
+
return this.pool.pop();
|
|
48
|
+
}
|
|
49
|
+
return this.factory();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Release an object back to the pool
|
|
53
|
+
*
|
|
54
|
+
* Resets the object and adds it back to the pool for reuse.
|
|
55
|
+
* If pool is at max size, the object is discarded.
|
|
56
|
+
*
|
|
57
|
+
* @param obj - Object to release
|
|
58
|
+
*/
|
|
59
|
+
release(obj) {
|
|
60
|
+
if (this.pool.length >= this.maxSize) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.reset(obj);
|
|
64
|
+
this.pool.push(obj);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clear all objects from the pool
|
|
68
|
+
*/
|
|
69
|
+
clear() {
|
|
70
|
+
this.pool = [];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get current pool size
|
|
74
|
+
*
|
|
75
|
+
* @returns Number of objects in pool
|
|
76
|
+
*/
|
|
77
|
+
size() {
|
|
78
|
+
return this.pool.length;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get maximum pool size
|
|
82
|
+
*
|
|
83
|
+
* @returns Maximum pool size
|
|
84
|
+
*/
|
|
85
|
+
getMaxSize() {
|
|
86
|
+
return this.maxSize;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set maximum pool size
|
|
90
|
+
*
|
|
91
|
+
* @param maxSize - New maximum pool size
|
|
92
|
+
*/
|
|
93
|
+
setMaxSize(maxSize) {
|
|
94
|
+
this.maxSize = maxSize;
|
|
95
|
+
if (this.pool.length > maxSize) {
|
|
96
|
+
this.pool = this.pool.slice(0, maxSize);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/utils/shallow-equal.ts
|
|
102
|
+
function shallowEqual(a, b) {
|
|
103
|
+
if (a === b) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
const aObj = a;
|
|
110
|
+
const bObj = b;
|
|
111
|
+
const aKeys = Object.keys(aObj);
|
|
112
|
+
const bKeys = Object.keys(bObj);
|
|
113
|
+
if (aKeys.length !== bKeys.length) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
for (const key of aKeys) {
|
|
117
|
+
if (!(key in bObj) || aObj[key] !== bObj[key]) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
__name(shallowEqual, "shallowEqual");
|
|
124
|
+
export {
|
|
125
|
+
ObjectPool,
|
|
126
|
+
deepClone,
|
|
127
|
+
shallowEqual
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/deep-clone.ts","../../src/utils/object-pool.ts","../../src/utils/shallow-equal.ts"],"sourcesContent":["/**\n * Deep clone utility using structuredClone\n */\n\n/**\n * Deep clone a value using the native structuredClone API\n * Supports all structured-cloneable types: objects, arrays, primitives, Date, Set, Map, etc.\n * Does NOT support: Functions, Symbols, DOM nodes\n *\n * @param value The value to deep clone\n * @returns A deep clone of the value\n */\nexport function deepClone(value: unknown): unknown {\n\t// Use native structuredClone if available (Node 17.5+, modern browsers)\n\tif (typeof structuredClone !== \"undefined\") {\n\t\treturn structuredClone(value);\n\t}\n\n\t// Fallback for older environments: JSON round-trip\n\t// WARNING: This loses Date, Map, Set, undefined, Function, Symbol values\n\ttry {\n\t\treturn JSON.parse(JSON.stringify(value));\n\t} catch {\n\t\t// If JSON fails (circular reference, etc.), return the original\n\t\t// This is safe but means mutations will affect the original\n\t\treturn value;\n\t}\n}\n","/**\n * Object Pool utility for game entities\n *\n * Provides object pooling to reduce GC pressure and improve performance\n * for frequently created/destroyed game objects.\n */\n\n/**\n * Object pool for reusing objects\n *\n * @template T - Type of objects in the pool\n */\nexport class ObjectPool<T> {\n\tprivate pool: T[] = [];\n\tprivate factory: () => T;\n\tprivate reset: (obj: T) => void;\n\tprivate maxSize: number;\n\n\t/**\n\t * Create a new object pool\n\t *\n\t * @param factory - Function to create new objects\n\t * @param reset - Function to reset object state for reuse\n\t * @param maxSize - Maximum pool size (default: 100)\n\t */\n\tconstructor(factory: () => T, reset: (obj: T) => void, maxSize: number = 100) {\n\t\tthis.factory = factory;\n\t\tthis.reset = reset;\n\t\tthis.maxSize = maxSize;\n\t}\n\n\t/**\n\t * Acquire an object from the pool\n\t *\n\t * Returns a new object if pool is empty, otherwise reuses a pooled object.\n\t *\n\t * @returns Object from pool or newly created\n\t */\n\tacquire(): T {\n\t\tif (this.pool.length > 0) {\n\t\t\treturn this.pool.pop()!;\n\t\t}\n\t\treturn this.factory();\n\t}\n\n\t/**\n\t * Release an object back to the pool\n\t *\n\t * Resets the object and adds it back to the pool for reuse.\n\t * If pool is at max size, the object is discarded.\n\t *\n\t * @param obj - Object to release\n\t */\n\trelease(obj: T): void {\n\t\tif (this.pool.length >= this.maxSize) {\n\t\t\t// Pool is full, discard object\n\t\t\treturn;\n\t\t}\n\n\t\tthis.reset(obj);\n\t\tthis.pool.push(obj);\n\t}\n\n\t/**\n\t * Clear all objects from the pool\n\t */\n\tclear(): void {\n\t\tthis.pool = [];\n\t}\n\n\t/**\n\t * Get current pool size\n\t *\n\t * @returns Number of objects in pool\n\t */\n\tsize(): number {\n\t\treturn this.pool.length;\n\t}\n\n\t/**\n\t * Get maximum pool size\n\t *\n\t * @returns Maximum pool size\n\t */\n\tgetMaxSize(): number {\n\t\treturn this.maxSize;\n\t}\n\n\t/**\n\t * Set maximum pool size\n\t *\n\t * @param maxSize - New maximum pool size\n\t */\n\tsetMaxSize(maxSize: number): void {\n\t\tthis.maxSize = maxSize;\n\t\t// Trim pool if it exceeds new max size\n\t\tif (this.pool.length > maxSize) {\n\t\t\tthis.pool = this.pool.slice(0, maxSize);\n\t\t}\n\t}\n}\n","/**\n * Shallow equality comparison for objects and arrays\n */\n\n/**\n * Compare two values for shallow equality\n * For objects and arrays, only checks if top-level properties have the same references\n * For primitives, uses === comparison\n *\n * @param a First value\n * @param b Second value\n * @returns true if values are shallowly equal\n */\nexport function shallowEqual(a: unknown, b: unknown): boolean {\n\t// Same reference\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\t// Different types\n\tif (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) {\n\t\treturn false;\n\t}\n\n\tconst aObj = a as Record<string, unknown>;\n\tconst bObj = b as Record<string, unknown>;\n\n\t// Get keys\n\tconst aKeys = Object.keys(aObj);\n\tconst bKeys = Object.keys(bObj);\n\n\t// Different number of keys\n\tif (aKeys.length !== bKeys.length) {\n\t\treturn false;\n\t}\n\n\t// Check all keys have same reference values\n\tfor (const key of aKeys) {\n\t\tif (!(key in bObj) || aObj[key] !== bObj[key]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n"],"mappings":";;;;AAYO,SAASA,UAAUC,OAAc;AAEvC,MAAI,OAAOC,oBAAoB,aAAa;AAC3C,WAAOA,gBAAgBD,KAAAA;EACxB;AAIA,MAAI;AACH,WAAOE,KAAKC,MAAMD,KAAKE,UAAUJ,KAAAA,CAAAA;EAClC,QAAQ;AAGP,WAAOA;EACR;AACD;AAfgBD;;;ACAT,IAAMM,aAAN,MAAMA;EAZb,OAYaA;;;EACJC,OAAY,CAAA;EACZC;EACAC;EACAC;;;;;;;;EASR,YAAYF,SAAkBC,OAAyBC,UAAkB,KAAK;AAC7E,SAAKF,UAAUA;AACf,SAAKC,QAAQA;AACb,SAAKC,UAAUA;EAChB;;;;;;;;EASAC,UAAa;AACZ,QAAI,KAAKJ,KAAKK,SAAS,GAAG;AACzB,aAAO,KAAKL,KAAKM,IAAG;IACrB;AACA,WAAO,KAAKL,QAAO;EACpB;;;;;;;;;EAUAM,QAAQC,KAAc;AACrB,QAAI,KAAKR,KAAKK,UAAU,KAAKF,SAAS;AAErC;IACD;AAEA,SAAKD,MAAMM,GAAAA;AACX,SAAKR,KAAKS,KAAKD,GAAAA;EAChB;;;;EAKAE,QAAc;AACb,SAAKV,OAAO,CAAA;EACb;;;;;;EAOAW,OAAe;AACd,WAAO,KAAKX,KAAKK;EAClB;;;;;;EAOAO,aAAqB;AACpB,WAAO,KAAKT;EACb;;;;;;EAOAU,WAAWV,SAAuB;AACjC,SAAKA,UAAUA;AAEf,QAAI,KAAKH,KAAKK,SAASF,SAAS;AAC/B,WAAKH,OAAO,KAAKA,KAAKc,MAAM,GAAGX,OAAAA;IAChC;EACD;AACD;;;ACvFO,SAASY,aAAaC,GAAYC,GAAU;AAElD,MAAID,MAAMC,GAAG;AACZ,WAAO;EACR;AAGA,MAAI,OAAOD,MAAM,YAAY,OAAOC,MAAM,YAAYD,MAAM,QAAQC,MAAM,MAAM;AAC/E,WAAO;EACR;AAEA,QAAMC,OAAOF;AACb,QAAMG,OAAOF;AAGb,QAAMG,QAAQC,OAAOC,KAAKJ,IAAAA;AAC1B,QAAMK,QAAQF,OAAOC,KAAKH,IAAAA;AAG1B,MAAIC,MAAMI,WAAWD,MAAMC,QAAQ;AAClC,WAAO;EACR;AAGA,aAAWC,OAAOL,OAAO;AACxB,QAAI,EAAEK,OAAON,SAASD,KAAKO,GAAAA,MAASN,KAAKM,GAAAA,GAAM;AAC9C,aAAO;IACR;EACD;AAEA,SAAO;AACR;AA/BgBV;","names":["deepClone","value","structuredClone","JSON","parse","stringify","ObjectPool","pool","factory","reset","maxSize","acquire","length","pop","release","obj","push","clear","size","getMaxSize","setMaxSize","slice","shallowEqual","a","b","aObj","bObj","aKeys","Object","keys","bKeys","length","key"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object Pool utility for game entities
|
|
3
|
+
*
|
|
4
|
+
* Provides object pooling to reduce GC pressure and improve performance
|
|
5
|
+
* for frequently created/destroyed game objects.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Object pool for reusing objects
|
|
9
|
+
*
|
|
10
|
+
* @template T - Type of objects in the pool
|
|
11
|
+
*/
|
|
12
|
+
declare class ObjectPool<T> {
|
|
13
|
+
private pool;
|
|
14
|
+
private factory;
|
|
15
|
+
private reset;
|
|
16
|
+
private maxSize;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new object pool
|
|
19
|
+
*
|
|
20
|
+
* @param factory - Function to create new objects
|
|
21
|
+
* @param reset - Function to reset object state for reuse
|
|
22
|
+
* @param maxSize - Maximum pool size (default: 100)
|
|
23
|
+
*/
|
|
24
|
+
constructor(factory: () => T, reset: (obj: T) => void, maxSize?: number);
|
|
25
|
+
/**
|
|
26
|
+
* Acquire an object from the pool
|
|
27
|
+
*
|
|
28
|
+
* Returns a new object if pool is empty, otherwise reuses a pooled object.
|
|
29
|
+
*
|
|
30
|
+
* @returns Object from pool or newly created
|
|
31
|
+
*/
|
|
32
|
+
acquire(): T;
|
|
33
|
+
/**
|
|
34
|
+
* Release an object back to the pool
|
|
35
|
+
*
|
|
36
|
+
* Resets the object and adds it back to the pool for reuse.
|
|
37
|
+
* If pool is at max size, the object is discarded.
|
|
38
|
+
*
|
|
39
|
+
* @param obj - Object to release
|
|
40
|
+
*/
|
|
41
|
+
release(obj: T): void;
|
|
42
|
+
/**
|
|
43
|
+
* Clear all objects from the pool
|
|
44
|
+
*/
|
|
45
|
+
clear(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get current pool size
|
|
48
|
+
*
|
|
49
|
+
* @returns Number of objects in pool
|
|
50
|
+
*/
|
|
51
|
+
size(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get maximum pool size
|
|
54
|
+
*
|
|
55
|
+
* @returns Maximum pool size
|
|
56
|
+
*/
|
|
57
|
+
getMaxSize(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Set maximum pool size
|
|
60
|
+
*
|
|
61
|
+
* @param maxSize - New maximum pool size
|
|
62
|
+
*/
|
|
63
|
+
setMaxSize(maxSize: number): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { ObjectPool };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object Pool utility for game entities
|
|
3
|
+
*
|
|
4
|
+
* Provides object pooling to reduce GC pressure and improve performance
|
|
5
|
+
* for frequently created/destroyed game objects.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Object pool for reusing objects
|
|
9
|
+
*
|
|
10
|
+
* @template T - Type of objects in the pool
|
|
11
|
+
*/
|
|
12
|
+
declare class ObjectPool<T> {
|
|
13
|
+
private pool;
|
|
14
|
+
private factory;
|
|
15
|
+
private reset;
|
|
16
|
+
private maxSize;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new object pool
|
|
19
|
+
*
|
|
20
|
+
* @param factory - Function to create new objects
|
|
21
|
+
* @param reset - Function to reset object state for reuse
|
|
22
|
+
* @param maxSize - Maximum pool size (default: 100)
|
|
23
|
+
*/
|
|
24
|
+
constructor(factory: () => T, reset: (obj: T) => void, maxSize?: number);
|
|
25
|
+
/**
|
|
26
|
+
* Acquire an object from the pool
|
|
27
|
+
*
|
|
28
|
+
* Returns a new object if pool is empty, otherwise reuses a pooled object.
|
|
29
|
+
*
|
|
30
|
+
* @returns Object from pool or newly created
|
|
31
|
+
*/
|
|
32
|
+
acquire(): T;
|
|
33
|
+
/**
|
|
34
|
+
* Release an object back to the pool
|
|
35
|
+
*
|
|
36
|
+
* Resets the object and adds it back to the pool for reuse.
|
|
37
|
+
* If pool is at max size, the object is discarded.
|
|
38
|
+
*
|
|
39
|
+
* @param obj - Object to release
|
|
40
|
+
*/
|
|
41
|
+
release(obj: T): void;
|
|
42
|
+
/**
|
|
43
|
+
* Clear all objects from the pool
|
|
44
|
+
*/
|
|
45
|
+
clear(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get current pool size
|
|
48
|
+
*
|
|
49
|
+
* @returns Number of objects in pool
|
|
50
|
+
*/
|
|
51
|
+
size(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get maximum pool size
|
|
54
|
+
*
|
|
55
|
+
* @returns Maximum pool size
|
|
56
|
+
*/
|
|
57
|
+
getMaxSize(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Set maximum pool size
|
|
60
|
+
*
|
|
61
|
+
* @param maxSize - New maximum pool size
|
|
62
|
+
*/
|
|
63
|
+
setMaxSize(maxSize: number): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { ObjectPool };
|