@esengine/ecs-framework 2.1.4 → 2.1.6

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.
Files changed (201) hide show
  1. package/README.md +385 -0
  2. package/{bin/index.d.ts → index.d.ts} +9 -6
  3. package/index.js +7 -0
  4. package/index.js.map +7 -0
  5. package/package.json +21 -46
  6. package/{bin/wasm → wasm}/ecs_wasm_core_bg.wasm +0 -0
  7. package/bin/Core.d.ts +0 -198
  8. package/bin/Core.d.ts.map +0 -1
  9. package/bin/Core.js +0 -247
  10. package/bin/Core.js.map +0 -1
  11. package/bin/ECS/Component.d.ts +0 -119
  12. package/bin/ECS/Component.d.ts.map +0 -1
  13. package/bin/ECS/Component.js +0 -129
  14. package/bin/ECS/Component.js.map +0 -1
  15. package/bin/ECS/Components/IUpdatable.d.ts +0 -22
  16. package/bin/ECS/Components/IUpdatable.d.ts.map +0 -1
  17. package/bin/ECS/Components/IUpdatable.js +0 -22
  18. package/bin/ECS/Components/IUpdatable.js.map +0 -1
  19. package/bin/ECS/Components/SceneComponent.d.ts +0 -40
  20. package/bin/ECS/Components/SceneComponent.d.ts.map +0 -1
  21. package/bin/ECS/Components/SceneComponent.js +0 -61
  22. package/bin/ECS/Components/SceneComponent.js.map +0 -1
  23. package/bin/ECS/Core/BitMaskOptimizer.d.ts +0 -75
  24. package/bin/ECS/Core/BitMaskOptimizer.d.ts.map +0 -1
  25. package/bin/ECS/Core/BitMaskOptimizer.js +0 -161
  26. package/bin/ECS/Core/BitMaskOptimizer.js.map +0 -1
  27. package/bin/ECS/Core/ComponentPool.d.ts +0 -72
  28. package/bin/ECS/Core/ComponentPool.d.ts.map +0 -1
  29. package/bin/ECS/Core/ComponentPool.js +0 -123
  30. package/bin/ECS/Core/ComponentPool.js.map +0 -1
  31. package/bin/ECS/Core/ComponentStorage.d.ts +0 -182
  32. package/bin/ECS/Core/ComponentStorage.d.ts.map +0 -1
  33. package/bin/ECS/Core/ComponentStorage.js +0 -346
  34. package/bin/ECS/Core/ComponentStorage.js.map +0 -1
  35. package/bin/ECS/Core/EventSystem.d.ts +0 -236
  36. package/bin/ECS/Core/EventSystem.d.ts.map +0 -1
  37. package/bin/ECS/Core/EventSystem.js +0 -476
  38. package/bin/ECS/Core/EventSystem.js.map +0 -1
  39. package/bin/ECS/Core/FluentAPI.d.ts +0 -371
  40. package/bin/ECS/Core/FluentAPI.d.ts.map +0 -1
  41. package/bin/ECS/Core/FluentAPI.js +0 -543
  42. package/bin/ECS/Core/FluentAPI.js.map +0 -1
  43. package/bin/ECS/Core/IndexUpdateBatcher.d.ts +0 -100
  44. package/bin/ECS/Core/IndexUpdateBatcher.d.ts.map +0 -1
  45. package/bin/ECS/Core/IndexUpdateBatcher.js +0 -219
  46. package/bin/ECS/Core/IndexUpdateBatcher.js.map +0 -1
  47. package/bin/ECS/Core/QuerySystem.d.ts +0 -422
  48. package/bin/ECS/Core/QuerySystem.d.ts.map +0 -1
  49. package/bin/ECS/Core/QuerySystem.js +0 -937
  50. package/bin/ECS/Core/QuerySystem.js.map +0 -1
  51. package/bin/ECS/CoreEvents.d.ts +0 -19
  52. package/bin/ECS/CoreEvents.d.ts.map +0 -1
  53. package/bin/ECS/CoreEvents.js +0 -20
  54. package/bin/ECS/CoreEvents.js.map +0 -1
  55. package/bin/ECS/Entity.d.ts +0 -538
  56. package/bin/ECS/Entity.d.ts.map +0 -1
  57. package/bin/ECS/Entity.js +0 -1030
  58. package/bin/ECS/Entity.js.map +0 -1
  59. package/bin/ECS/Scene.d.ts +0 -226
  60. package/bin/ECS/Scene.d.ts.map +0 -1
  61. package/bin/ECS/Scene.js +0 -308
  62. package/bin/ECS/Scene.js.map +0 -1
  63. package/bin/ECS/Systems/EntitySystem.d.ts +0 -185
  64. package/bin/ECS/Systems/EntitySystem.d.ts.map +0 -1
  65. package/bin/ECS/Systems/EntitySystem.js +0 -278
  66. package/bin/ECS/Systems/EntitySystem.js.map +0 -1
  67. package/bin/ECS/Systems/IntervalSystem.d.ts +0 -33
  68. package/bin/ECS/Systems/IntervalSystem.d.ts.map +0 -1
  69. package/bin/ECS/Systems/IntervalSystem.js +0 -50
  70. package/bin/ECS/Systems/IntervalSystem.js.map +0 -1
  71. package/bin/ECS/Systems/PassiveSystem.d.ts +0 -20
  72. package/bin/ECS/Systems/PassiveSystem.d.ts.map +0 -1
  73. package/bin/ECS/Systems/PassiveSystem.js +0 -21
  74. package/bin/ECS/Systems/PassiveSystem.js.map +0 -1
  75. package/bin/ECS/Systems/ProcessingSystem.d.ts +0 -24
  76. package/bin/ECS/Systems/ProcessingSystem.d.ts.map +0 -1
  77. package/bin/ECS/Systems/ProcessingSystem.js +0 -22
  78. package/bin/ECS/Systems/ProcessingSystem.js.map +0 -1
  79. package/bin/ECS/Systems/index.d.ts +0 -5
  80. package/bin/ECS/Systems/index.d.ts.map +0 -1
  81. package/bin/ECS/Systems/index.js +0 -6
  82. package/bin/ECS/Systems/index.js.map +0 -1
  83. package/bin/ECS/Utils/Bits.d.ts +0 -74
  84. package/bin/ECS/Utils/Bits.d.ts.map +0 -1
  85. package/bin/ECS/Utils/Bits.js +0 -142
  86. package/bin/ECS/Utils/Bits.js.map +0 -1
  87. package/bin/ECS/Utils/ComponentTypeManager.d.ts +0 -50
  88. package/bin/ECS/Utils/ComponentTypeManager.d.ts.map +0 -1
  89. package/bin/ECS/Utils/ComponentTypeManager.js +0 -84
  90. package/bin/ECS/Utils/ComponentTypeManager.js.map +0 -1
  91. package/bin/ECS/Utils/EntityList.d.ts +0 -108
  92. package/bin/ECS/Utils/EntityList.d.ts.map +0 -1
  93. package/bin/ECS/Utils/EntityList.js +0 -249
  94. package/bin/ECS/Utils/EntityList.js.map +0 -1
  95. package/bin/ECS/Utils/EntityProcessorList.d.ts +0 -53
  96. package/bin/ECS/Utils/EntityProcessorList.d.ts.map +0 -1
  97. package/bin/ECS/Utils/EntityProcessorList.js +0 -96
  98. package/bin/ECS/Utils/EntityProcessorList.js.map +0 -1
  99. package/bin/ECS/Utils/IdentifierPool.d.ts +0 -18
  100. package/bin/ECS/Utils/IdentifierPool.d.ts.map +0 -1
  101. package/bin/ECS/Utils/IdentifierPool.js +0 -27
  102. package/bin/ECS/Utils/IdentifierPool.js.map +0 -1
  103. package/bin/ECS/Utils/Matcher.d.ts +0 -63
  104. package/bin/ECS/Utils/Matcher.d.ts.map +0 -1
  105. package/bin/ECS/Utils/Matcher.js +0 -140
  106. package/bin/ECS/Utils/Matcher.js.map +0 -1
  107. package/bin/ECS/Utils/index.d.ts +0 -7
  108. package/bin/ECS/Utils/index.d.ts.map +0 -1
  109. package/bin/ECS/Utils/index.js +0 -8
  110. package/bin/ECS/Utils/index.js.map +0 -1
  111. package/bin/ECS/index.d.ts +0 -7
  112. package/bin/ECS/index.d.ts.map +0 -1
  113. package/bin/ECS/index.js +0 -29
  114. package/bin/ECS/index.js.map +0 -1
  115. package/bin/Testing/Performance/benchmark.d.ts +0 -6
  116. package/bin/Testing/Performance/benchmark.d.ts.map +0 -1
  117. package/bin/Testing/Performance/benchmark.js +0 -639
  118. package/bin/Testing/Performance/benchmark.js.map +0 -1
  119. package/bin/Testing/Performance/component-performance.d.ts +0 -2
  120. package/bin/Testing/Performance/component-performance.d.ts.map +0 -1
  121. package/bin/Testing/Performance/component-performance.js +0 -43
  122. package/bin/Testing/Performance/component-performance.js.map +0 -1
  123. package/bin/Testing/Unit/bitmask-optimizer.test.d.ts +0 -2
  124. package/bin/Testing/Unit/bitmask-optimizer.test.d.ts.map +0 -1
  125. package/bin/Testing/Unit/bitmask-optimizer.test.js +0 -164
  126. package/bin/Testing/Unit/bitmask-optimizer.test.js.map +0 -1
  127. package/bin/Testing/Unit/component-pool.test.d.ts +0 -5
  128. package/bin/Testing/Unit/component-pool.test.d.ts.map +0 -1
  129. package/bin/Testing/Unit/component-pool.test.js +0 -149
  130. package/bin/Testing/Unit/component-pool.test.js.map +0 -1
  131. package/bin/Testing/test-runner.d.ts +0 -51
  132. package/bin/Testing/test-runner.d.ts.map +0 -1
  133. package/bin/Testing/test-runner.js +0 -159
  134. package/bin/Testing/test-runner.js.map +0 -1
  135. package/bin/Types/index.d.ts +0 -22
  136. package/bin/Types/index.d.ts.map +0 -1
  137. package/bin/Types/index.js +0 -20
  138. package/bin/Types/index.js.map +0 -1
  139. package/bin/Utils/Emitter.d.ts +0 -43
  140. package/bin/Utils/Emitter.d.ts.map +0 -1
  141. package/bin/Utils/Emitter.js +0 -69
  142. package/bin/Utils/Emitter.js.map +0 -1
  143. package/bin/Utils/Extensions/NumberExtension.d.ts +0 -13
  144. package/bin/Utils/Extensions/NumberExtension.d.ts.map +0 -1
  145. package/bin/Utils/Extensions/NumberExtension.js +0 -17
  146. package/bin/Utils/Extensions/NumberExtension.js.map +0 -1
  147. package/bin/Utils/Extensions/TypeUtils.d.ts +0 -13
  148. package/bin/Utils/Extensions/TypeUtils.d.ts.map +0 -1
  149. package/bin/Utils/Extensions/TypeUtils.js +0 -15
  150. package/bin/Utils/Extensions/TypeUtils.js.map +0 -1
  151. package/bin/Utils/Extensions/index.d.ts +0 -3
  152. package/bin/Utils/Extensions/index.d.ts.map +0 -1
  153. package/bin/Utils/Extensions/index.js +0 -4
  154. package/bin/Utils/Extensions/index.js.map +0 -1
  155. package/bin/Utils/GlobalManager.d.ts +0 -32
  156. package/bin/Utils/GlobalManager.d.ts.map +0 -1
  157. package/bin/Utils/GlobalManager.js +0 -53
  158. package/bin/Utils/GlobalManager.js.map +0 -1
  159. package/bin/Utils/PerformanceMonitor.d.ts +0 -211
  160. package/bin/Utils/PerformanceMonitor.d.ts.map +0 -1
  161. package/bin/Utils/PerformanceMonitor.js +0 -270
  162. package/bin/Utils/PerformanceMonitor.js.map +0 -1
  163. package/bin/Utils/Pool.d.ts +0 -239
  164. package/bin/Utils/Pool.d.ts.map +0 -1
  165. package/bin/Utils/Pool.js +0 -449
  166. package/bin/Utils/Pool.js.map +0 -1
  167. package/bin/Utils/Time.d.ts +0 -55
  168. package/bin/Utils/Time.d.ts.map +0 -1
  169. package/bin/Utils/Time.js +0 -78
  170. package/bin/Utils/Time.js.map +0 -1
  171. package/bin/Utils/Timers/ITimer.d.ts +0 -16
  172. package/bin/Utils/Timers/ITimer.d.ts.map +0 -1
  173. package/bin/Utils/Timers/ITimer.js +0 -2
  174. package/bin/Utils/Timers/ITimer.js.map +0 -1
  175. package/bin/Utils/Timers/Timer.d.ts +0 -22
  176. package/bin/Utils/Timers/Timer.d.ts.map +0 -1
  177. package/bin/Utils/Timers/Timer.js +0 -46
  178. package/bin/Utils/Timers/Timer.js.map +0 -1
  179. package/bin/Utils/Timers/TimerManager.d.ts +0 -19
  180. package/bin/Utils/Timers/TimerManager.d.ts.map +0 -1
  181. package/bin/Utils/Timers/TimerManager.js +0 -33
  182. package/bin/Utils/Timers/TimerManager.js.map +0 -1
  183. package/bin/Utils/WasmCore.d.ts +0 -234
  184. package/bin/Utils/WasmCore.d.ts.map +0 -1
  185. package/bin/Utils/WasmCore.js +0 -596
  186. package/bin/Utils/WasmCore.js.map +0 -1
  187. package/bin/Utils/index.d.ts +0 -16
  188. package/bin/Utils/index.d.ts.map +0 -1
  189. package/bin/Utils/index.js +0 -37
  190. package/bin/Utils/index.js.map +0 -1
  191. package/bin/index.cjs +0 -51
  192. package/bin/index.d.ts.map +0 -1
  193. package/bin/index.esm.d.ts +0 -45
  194. package/bin/index.esm.d.ts.map +0 -1
  195. package/bin/index.esm.js +0 -46
  196. package/bin/index.esm.js.map +0 -1
  197. package/bin/index.js.map +0 -1
  198. /package/{bin/wasm → wasm}/ecs_wasm_core.d.ts +0 -0
  199. /package/{bin/wasm → wasm}/ecs_wasm_core.js +0 -0
  200. /package/{bin/wasm → wasm}/ecs_wasm_core_bg.wasm.d.ts +0 -0
  201. /package/{bin/wasm → wasm}/package.json +0 -0
@@ -1,239 +0,0 @@
1
- /**
2
- * 可池化对象接口
3
- */
4
- export interface IPoolable {
5
- /**
6
- * 重置对象状态,准备重用
7
- */
8
- reset(): void;
9
- }
10
- /**
11
- * 对象池统计信息
12
- */
13
- export interface PoolStats {
14
- /** 池中对象数量 */
15
- size: number;
16
- /** 池的最大大小 */
17
- maxSize: number;
18
- /** 总共创建的对象数量 */
19
- totalCreated: number;
20
- /** 总共获取的次数 */
21
- totalObtained: number;
22
- /** 总共释放的次数 */
23
- totalReleased: number;
24
- /** 命中率(从池中获取的比例) */
25
- hitRate: number;
26
- /** 内存使用估算(字节) */
27
- estimatedMemoryUsage: number;
28
- }
29
- /**
30
- * 高性能通用对象池
31
- * 支持任意类型的对象池化,包含详细的统计信息
32
- */
33
- export declare class Pool<T extends IPoolable> {
34
- private static _pools;
35
- private _objects;
36
- private _createFn;
37
- private _maxSize;
38
- private _stats;
39
- private _objectSize;
40
- /**
41
- * 构造函数
42
- * @param createFn 创建对象的函数
43
- * @param maxSize 池的最大大小,默认100
44
- * @param estimatedObjectSize 估算的单个对象大小(字节),默认1024
45
- */
46
- constructor(createFn: () => T, maxSize?: number, estimatedObjectSize?: number);
47
- /**
48
- * 获取指定类型的对象池
49
- * @param type 对象类型
50
- * @param maxSize 池的最大大小
51
- * @param estimatedObjectSize 估算的单个对象大小
52
- * @returns 对象池实例
53
- */
54
- static getPool<T extends IPoolable>(type: new (...args: any[]) => T, maxSize?: number, estimatedObjectSize?: number): Pool<T>;
55
- /**
56
- * 从池中获取对象
57
- * @returns 对象实例
58
- */
59
- obtain(): T;
60
- /**
61
- * 将对象归还到池中
62
- * @param obj 要归还的对象
63
- */
64
- free(obj: T): void;
65
- /**
66
- * 预热池,创建指定数量的对象
67
- * @param count 要创建的对象数量
68
- */
69
- warmUp(count: number): void;
70
- /**
71
- * 清空池
72
- */
73
- clear(): void;
74
- /**
75
- * 获取池中对象数量
76
- */
77
- get size(): number;
78
- /**
79
- * 获取池的最大大小
80
- */
81
- get maxSize(): number;
82
- /**
83
- * 设置池的最大大小
84
- */
85
- set maxSize(value: number);
86
- /**
87
- * 获取池的统计信息
88
- */
89
- getStats(): PoolStats;
90
- /**
91
- * 重置统计信息
92
- */
93
- resetStats(): void;
94
- /**
95
- * 更新命中率
96
- */
97
- private _updateHitRate;
98
- /**
99
- * 更新内存使用估算
100
- */
101
- private _updateMemoryUsage;
102
- /**
103
- * 静态方法:从指定类型的池中获取对象
104
- * @param type 对象类型
105
- * @returns 对象实例
106
- */
107
- static obtain<T extends IPoolable>(type: new (...args: any[]) => T): T;
108
- /**
109
- * 静态方法:将对象归还到对应类型的池中
110
- * @param type 对象类型
111
- * @param obj 要归还的对象
112
- */
113
- static free<T extends IPoolable>(type: new (...args: any[]) => T, obj: T): void;
114
- /**
115
- * 静态方法:预热指定类型的池
116
- * @param type 对象类型
117
- * @param count 要创建的对象数量
118
- */
119
- static warmUp<T extends IPoolable>(type: new (...args: any[]) => T, count: number): void;
120
- /**
121
- * 静态方法:清空指定类型的池
122
- * @param type 对象类型
123
- */
124
- static clearPool<T extends IPoolable>(type: new (...args: any[]) => T): void;
125
- /**
126
- * 静态方法:清空所有池
127
- */
128
- static clearAllPools(): void;
129
- /**
130
- * 静态方法:获取池的统计信息
131
- * @returns 池的统计信息
132
- */
133
- static getStats(): {
134
- [typeName: string]: PoolStats;
135
- };
136
- /**
137
- * 静态方法:获取所有池的总内存使用量
138
- * @returns 总内存使用量(字节)
139
- */
140
- static getTotalMemoryUsage(): number;
141
- /**
142
- * 静态方法:获取性能报告
143
- * @returns 格式化的性能报告
144
- */
145
- static getPerformanceReport(): string;
146
- }
147
- /**
148
- * 分层对象池
149
- * 使用多个不同大小的池来优化内存使用
150
- */
151
- export declare class TieredObjectPool<T extends IPoolable> {
152
- private pools;
153
- private createFn;
154
- private resetFn;
155
- private tierSizes;
156
- private totalObtained;
157
- private totalReleased;
158
- /**
159
- * 构造函数
160
- * @param createFn 创建对象的函数
161
- * @param resetFn 重置对象的函数
162
- * @param tierSizes 各层级的大小,默认[10, 50, 200]
163
- * @param estimatedObjectSize 估算的单个对象大小
164
- */
165
- constructor(createFn: () => T, resetFn: (obj: T) => void, tierSizes?: number[], estimatedObjectSize?: number);
166
- /**
167
- * 获取对象
168
- * @returns 对象实例
169
- */
170
- obtain(): T;
171
- /**
172
- * 释放对象
173
- * @param obj 要释放的对象
174
- */
175
- release(obj: T): void;
176
- /**
177
- * 预热所有池
178
- * @param totalCount 总预热数量
179
- */
180
- warmUp(totalCount: number): void;
181
- /**
182
- * 清空所有池
183
- */
184
- clear(): void;
185
- /**
186
- * 获取统计信息
187
- */
188
- getStats(): {
189
- totalSize: number;
190
- totalMaxSize: number;
191
- totalMemoryUsage: number;
192
- tierStats: PoolStats[];
193
- hitRate: number;
194
- };
195
- /**
196
- * 获取总创建数量
197
- */
198
- private getTotalCreated;
199
- }
200
- /**
201
- * 池管理器
202
- * 统一管理所有对象池
203
- */
204
- export declare class PoolManager {
205
- private static instance;
206
- private pools;
207
- private autoCompactInterval;
208
- private lastCompactTime;
209
- static getInstance(): PoolManager;
210
- /**
211
- * 注册池
212
- * @param name 池名称
213
- * @param pool 池实例
214
- */
215
- registerPool<T extends IPoolable>(name: string, pool: Pool<T> | TieredObjectPool<T>): void;
216
- /**
217
- * 获取池
218
- * @param name 池名称
219
- * @returns 池实例
220
- */
221
- getPool<T extends IPoolable>(name: string): Pool<T> | TieredObjectPool<T> | null;
222
- /**
223
- * 更新池管理器(应在游戏循环中调用)
224
- */
225
- update(): void;
226
- /**
227
- * 压缩所有池(清理碎片)
228
- */
229
- compactAllPools(): void;
230
- /**
231
- * 获取所有池的统计信息
232
- */
233
- getAllStats(): Map<string, any>;
234
- /**
235
- * 生成性能报告
236
- */
237
- generateReport(): string;
238
- }
239
- //# sourceMappingURL=Pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Pool.d.ts","sourceRoot":"","sources":["../../src/Utils/Pool.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,aAAa;IACb,I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ELETED
@@ -1,449 +0,0 @@
1
- /**
2
- * 高性能通用对象池
3
- * 支持任意类型的对象池化,包含详细的统计信息
4
- */
5
- export class Pool {
6
- /**
7
- * 构造函数
8
- * @param createFn 创建对象的函数
9
- * @param maxSize 池的最大大小,默认100
10
- * @param estimatedObjectSize 估算的单个对象大小(字节),默认1024
11
- */
12
- constructor(createFn, maxSize = 100, estimatedObjectSize = 1024) {
13
- this._objects = [];
14
- this._createFn = createFn;
15
- this._maxSize = maxSize;
16
- this._objectSize = estimatedObjectSize;
17
- this._stats = {
18
- size: 0,
19
- maxSize,
20
- totalCreated: 0,
21
- totalObtained: 0,
22
- totalReleased: 0,
23
- hitRate: 0,
24
- estimatedMemoryUsage: 0
25
- };
26
- }
27
- /**
28
- * 获取指定类型的对象池
29
- * @param type 对象类型
30
- * @param maxSize 池的最大大小
31
- * @param estimatedObjectSize 估算的单个对象大小
32
- * @returns 对象池实例
33
- */
34
- static getPool(type, maxSize = 100, estimatedObjectSize = 1024) {
35
- let pool = this._pools.get(type);
36
- if (!pool) {
37
- pool = new Pool(() => new type(), maxSize, estimatedObjectSize);
38
- this._pools.set(type, pool);
39
- }
40
- return pool;
41
- }
42
- /**
43
- * 从池中获取对象
44
- * @returns 对象实例
45
- */
46
- obtain() {
47
- this._stats.totalObtained++;
48
- if (this._objects.length > 0) {
49
- const obj = this._objects.pop();
50
- this._stats.size--;
51
- this._updateHitRate();
52
- this._updateMemoryUsage();
53
- return obj;
54
- }
55
- // 池中没有对象,创建新的
56
- const obj = this._createFn();
57
- this._stats.totalCreated++;
58
- this._updateHitRate();
59
- return obj;
60
- }
61
- /**
62
- * 将对象归还到池中
63
- * @param obj 要归还的对象
64
- */
65
- free(obj) {
66
- if (this._objects.length < this._maxSize) {
67
- obj.reset();
68
- this._objects.push(obj);
69
- this._stats.size++;
70
- this._stats.totalReleased++;
71
- this._updateMemoryUsage();
72
- }
73
- // 如果池已满,对象会被丢弃(由GC回收)
74
- }
75
- /**
76
- * 预热池,创建指定数量的对象
77
- * @param count 要创建的对象数量
78
- */
79
- warmUp(count) {
80
- const targetSize = Math.min(count, this._maxSize);
81
- while (this._objects.length < targetSize) {
82
- const obj = this._createFn();
83
- this._stats.totalCreated++;
84
- this._objects.push(obj);
85
- this._stats.size++;
86
- }
87
- this._updateMemoryUsage();
88
- }
89
- /**
90
- * 清空池
91
- */
92
- clear() {
93
- this._objects.length = 0;
94
- this._stats.size = 0;
95
- this._updateMemoryUsage();
96
- }
97
- /**
98
- * 获取池中对象数量
99
- */
100
- get size() {
101
- return this._objects.length;
102
- }
103
- /**
104
- * 获取池的最大大小
105
- */
106
- get maxSize() {
107
- return this._maxSize;
108
- }
109
- /**
110
- * 设置池的最大大小
111
- */
112
- set maxSize(value) {
113
- this._maxSize = value;
114
- this._stats.maxSize = value;
115
- // 如果当前池大小超过新的最大值,则移除多余的对象
116
- while (this._objects.length > this._maxSize) {
117
- this._objects.pop();
118
- this._stats.size--;
119
- }
120
- this._updateMemoryUsage();
121
- }
122
- /**
123
- * 获取池的统计信息
124
- */
125
- getStats() {
126
- return { ...this._stats };
127
- }
128
- /**
129
- * 重置统计信息
130
- */
131
- resetStats() {
132
- this._stats.totalCreated = 0;
133
- this._stats.totalObtained = 0;
134
- this._stats.totalReleased = 0;
135
- this._stats.hitRate = 0;
136
- }
137
- /**
138
- * 更新命中率
139
- */
140
- _updateHitRate() {
141
- if (this._stats.totalObtained > 0) {
142
- const hits = this._stats.totalObtained - this._stats.totalCreated;
143
- this._stats.hitRate = hits / this._stats.totalObtained;
144
- }
145
- }
146
- /**
147
- * 更新内存使用估算
148
- */
149
- _updateMemoryUsage() {
150
- this._stats.estimatedMemoryUsage = this._stats.size * this._objectSize;
151
- }
152
- /**
153
- * 静态方法:从指定类型的池中获取对象
154
- * @param type 对象类型
155
- * @returns 对象实例
156
- */
157
- static obtain(type) {
158
- return this.getPool(type).obtain();
159
- }
160
- /**
161
- * 静态方法:将对象归还到对应类型的池中
162
- * @param type 对象类型
163
- * @param obj 要归还的对象
164
- */
165
- static free(type, obj) {
166
- this.getPool(type).free(obj);
167
- }
168
- /**
169
- * 静态方法:预热指定类型的池
170
- * @param type 对象类型
171
- * @param count 要创建的对象数量
172
- */
173
- static warmUp(type, count) {
174
- this.getPool(type).warmUp(count);
175
- }
176
- /**
177
- * 静态方法:清空指定类型的池
178
- * @param type 对象类型
179
- */
180
- static clearPool(type) {
181
- const pool = this._pools.get(type);
182
- if (pool) {
183
- pool.clear();
184
- }
185
- }
186
- /**
187
- * 静态方法:清空所有池
188
- */
189
- static clearAllPools() {
190
- for (const pool of this._pools.values()) {
191
- pool.clear();
192
- }
193
- this._pools.clear();
194
- }
195
- /**
196
- * 静态方法:获取池的统计信息
197
- * @returns 池的统计信息
198
- */
199
- static getStats() {
200
- const stats = {};
201
- for (const [type, pool] of this._pools.entries()) {
202
- const typeName = type.name || 'Unknown';
203
- stats[typeName] = pool.getStats();
204
- }
205
- return stats;
206
- }
207
- /**
208
- * 静态方法:获取所有池的总内存使用量
209
- * @returns 总内存使用量(字节)
210
- */
211
- static getTotalMemoryUsage() {
212
- let total = 0;
213
- for (const pool of this._pools.values()) {
214
- total += pool.getStats().estimatedMemoryUsage;
215
- }
216
- return total;
217
- }
218
- /**
219
- * 静态方法:获取性能报告
220
- * @returns 格式化的性能报告
221
- */
222
- static getPerformanceReport() {
223
- const stats = this.getStats();
224
- const lines = [];
225
- lines.push('=== Object Pool Performance Report ===');
226
- lines.push(`Total Memory Usage: ${(this.getTotalMemoryUsage() / 1024 / 1024).toFixed(2)} MB`);
227
- lines.push('');
228
- for (const [typeName, stat] of Object.entries(stats)) {
229
- lines.push(`${typeName}:`);
230
- lines.push(` Size: ${stat.size}/${stat.maxSize}`);
231
- lines.push(` Hit Rate: ${(stat.hitRate * 100).toFixed(1)}%`);
232
- lines.push(` Total Created: ${stat.totalCreated}`);
233
- lines.push(` Total Obtained: ${stat.totalObtained}`);
234
- lines.push(` Memory: ${(stat.estimatedMemoryUsage / 1024).toFixed(1)} KB`);
235
- lines.push('');
236
- }
237
- return lines.join('\n');
238
- }
239
- }
240
- Pool._pools = new Map();
241
- /**
242
- * 分层对象池
243
- * 使用多个不同大小的池来优化内存使用
244
- */
245
- export class TieredObjectPool {
246
- /**
247
- * 构造函数
248
- * @param createFn 创建对象的函数
249
- * @param resetFn 重置对象的函数
250
- * @param tierSizes 各层级的大小,默认[10, 50, 200]
251
- * @param estimatedObjectSize 估算的单个对象大小
252
- */
253
- constructor(createFn, resetFn, tierSizes = [10, 50, 200], estimatedObjectSize = 1024) {
254
- this.pools = [];
255
- this.totalObtained = 0;
256
- this.totalReleased = 0;
257
- this.createFn = createFn;
258
- this.resetFn = resetFn;
259
- this.tierSizes = tierSizes;
260
- // 初始化不同层级的池
261
- for (const size of tierSizes) {
262
- this.pools.push(new Pool(createFn, size, estimatedObjectSize));
263
- }
264
- }
265
- /**
266
- * 获取对象
267
- * @returns 对象实例
268
- */
269
- obtain() {
270
- this.totalObtained++;
271
- // 从最小的池开始尝试获取
272
- for (const pool of this.pools) {
273
- if (pool.size > 0) {
274
- return pool.obtain();
275
- }
276
- }
277
- // 所有池都空了,创建新对象
278
- return this.createFn();
279
- }
280
- /**
281
- * 释放对象
282
- * @param obj 要释放的对象
283
- */
284
- release(obj) {
285
- this.totalReleased++;
286
- this.resetFn(obj);
287
- // 放入第一个有空间的池
288
- for (const pool of this.pools) {
289
- if (pool.size < pool.maxSize) {
290
- pool.free(obj);
291
- return;
292
- }
293
- }
294
- // 所有池都满了,直接丢弃
295
- }
296
- /**
297
- * 预热所有池
298
- * @param totalCount 总预热数量
299
- */
300
- warmUp(totalCount) {
301
- let remaining = totalCount;
302
- for (const pool of this.pools) {
303
- const warmUpCount = Math.min(remaining, pool.maxSize);
304
- pool.warmUp(warmUpCount);
305
- remaining -= warmUpCount;
306
- if (remaining <= 0)
307
- break;
308
- }
309
- }
310
- /**
311
- * 清空所有池
312
- */
313
- clear() {
314
- for (const pool of this.pools) {
315
- pool.clear();
316
- }
317
- }
318
- /**
319
- * 获取统计信息
320
- */
321
- getStats() {
322
- let totalSize = 0;
323
- let totalMaxSize = 0;
324
- let totalMemoryUsage = 0;
325
- const tierStats = [];
326
- for (const pool of this.pools) {
327
- const stats = pool.getStats();
328
- tierStats.push(stats);
329
- totalSize += stats.size;
330
- totalMaxSize += stats.maxSize;
331
- totalMemoryUsage += stats.estimatedMemoryUsage;
332
- }
333
- const hitRate = this.totalObtained > 0 ?
334
- (this.totalObtained - this.getTotalCreated()) / this.totalObtained : 0;
335
- return {
336
- totalSize,
337
- totalMaxSize,
338
- totalMemoryUsage,
339
- tierStats,
340
- hitRate
341
- };
342
- }
343
- /**
344
- * 获取总创建数量
345
- */
346
- getTotalCreated() {
347
- return this.pools.reduce((total, pool) => total + pool.getStats().totalCreated, 0);
348
- }
349
- }
350
- /**
351
- * 池管理器
352
- * 统一管理所有对象池
353
- */
354
- export class PoolManager {
355
- constructor() {
356
- this.pools = new Map();
357
- this.autoCompactInterval = 60000; // 60秒
358
- this.lastCompactTime = 0;
359
- }
360
- static getInstance() {
361
- if (!PoolManager.instance) {
362
- PoolManager.instance = new PoolManager();
363
- }
364
- return PoolManager.instance;
365
- }
366
- /**
367
- * 注册池
368
- * @param name 池名称
369
- * @param pool 池实例
370
- */
371
- registerPool(name, pool) {
372
- this.pools.set(name, pool);
373
- }
374
- /**
375
- * 获取池
376
- * @param name 池名称
377
- * @returns 池实例
378
- */
379
- getPool(name) {
380
- return this.pools.get(name) || null;
381
- }
382
- /**
383
- * 更新池管理器(应在游戏循环中调用)
384
- */
385
- update() {
386
- const now = Date.now();
387
- if (now - this.lastCompactTime > this.autoCompactInterval) {
388
- this.compactAllPools();
389
- this.lastCompactTime = now;
390
- }
391
- }
392
- /**
393
- * 压缩所有池(清理碎片)
394
- */
395
- compactAllPools() {
396
- // 对于标准池,可以考虑清理一些长时间未使用的对象
397
- // 这里简单实现为重置统计信息
398
- for (const pool of this.pools.values()) {
399
- if (pool instanceof Pool) {
400
- pool.resetStats();
401
- }
402
- }
403
- }
404
- /**
405
- * 获取所有池的统计信息
406
- */
407
- getAllStats() {
408
- const stats = new Map();
409
- for (const [name, pool] of this.pools.entries()) {
410
- if (pool instanceof Pool) {
411
- stats.set(name, pool.getStats());
412
- }
413
- else if (pool instanceof TieredObjectPool) {
414
- stats.set(name, pool.getStats());
415
- }
416
- }
417
- return stats;
418
- }
419
- /**
420
- * 生成性能报告
421
- */
422
- generateReport() {
423
- const lines = [];
424
- lines.push('=== Pool Manager Report ===');
425
- let totalMemory = 0;
426
- for (const [name, pool] of this.pools.entries()) {
427
- lines.push(`\n${name}:`);
428
- if (pool instanceof Pool) {
429
- const stats = pool.getStats();
430
- lines.push(` Type: Standard Pool`);
431
- lines.push(` Size: ${stats.size}/${stats.maxSize}`);
432
- lines.push(` Hit Rate: ${(stats.hitRate * 100).toFixed(1)}%`);
433
- lines.push(` Memory: ${(stats.estimatedMemoryUsage / 1024).toFixed(1)} KB`);
434
- totalMemory += stats.estimatedMemoryUsage;
435
- }
436
- else if (pool instanceof TieredObjectPool) {
437
- const stats = pool.getStats();
438
- lines.push(` Type: Tiered Pool`);
439
- lines.push(` Total Size: ${stats.totalSize}/${stats.totalMaxSize}`);
440
- lines.push(` Hit Rate: ${(stats.hitRate * 100).toFixed(1)}%`);
441
- lines.push(` Memory: ${(stats.totalMemoryUsage / 1024).toFixed(1)} KB`);
442
- totalMemory += stats.totalMemoryUsage;
443
- }
444
- }
445
- lines.push(`\nTotal Memory Usage: ${(totalMemory / 1024 / 1024).toFixed(2)} MB`);
446
- return lines.join('\n');
447
- }
448
- }
449
- //# sourceMappingURL=Pool.js.map