perf: 优化战斗系统内存与性能,增加对象池限制与内存监控面板
- 为Skill和Monster对象池添加最大容量限制(64/24),防止内存泄漏 - 实现DamageQueueComp的环形队列优化,减少数组操作开销 - 在MissionComp中添加内存监控面板,实时显示堆内存、实体数量、对象池状态 - 优化MoveSystem的渲染排序性能,缓存查询结果减少GC压力 - 调整角色控制器UI位置与样式,关闭调试日志减少性能开销 - 战斗结束时自动清理对象池,确保内存可回收
This commit is contained in:
@@ -19,6 +19,7 @@ export class Skill extends ecs.Entity {
|
||||
private debugMode: boolean = false;
|
||||
/** 多键对象池:Map<prefabPath, NodePool> */
|
||||
static pools: Map<string, NodePool> = new Map();
|
||||
static readonly MAX_POOL_SIZE: number = 64;
|
||||
|
||||
static getFromPool(path: string): Node | null {
|
||||
if (this.pools.has(path)) {
|
||||
@@ -38,7 +39,31 @@ export class Skill extends ecs.Entity {
|
||||
if (!this.pools.has(path)) {
|
||||
this.pools.set(path, new NodePool());
|
||||
}
|
||||
this.pools.get(path)!.put(node);
|
||||
const pool = this.pools.get(path)!;
|
||||
if (pool.size() >= this.MAX_POOL_SIZE) {
|
||||
node.destroy();
|
||||
return;
|
||||
}
|
||||
pool.put(node);
|
||||
}
|
||||
|
||||
static clearPools() {
|
||||
this.pools.forEach((pool) => {
|
||||
pool.clear();
|
||||
});
|
||||
this.pools.clear();
|
||||
}
|
||||
|
||||
static getPoolStats() {
|
||||
let total = 0;
|
||||
this.pools.forEach((pool) => {
|
||||
total += pool.size();
|
||||
});
|
||||
return {
|
||||
paths: this.pools.size,
|
||||
total,
|
||||
maxPerPath: this.MAX_POOL_SIZE
|
||||
};
|
||||
}
|
||||
|
||||
/** ---------- 数据层 ---------- */
|
||||
|
||||
Reference in New Issue
Block a user