perf: 优化战斗系统内存与性能,增加对象池限制与内存监控面板

- 为Skill和Monster对象池添加最大容量限制(64/24),防止内存泄漏
- 实现DamageQueueComp的环形队列优化,减少数组操作开销
- 在MissionComp中添加内存监控面板,实时显示堆内存、实体数量、对象池状态
- 优化MoveSystem的渲染排序性能,缓存查询结果减少GC压力
- 调整角色控制器UI位置与样式,关闭调试日志减少性能开销
- 战斗结束时自动清理对象池,确保内存可回收
This commit is contained in:
panw
2026-03-16 18:49:43 +08:00
parent fb7b10b7e1
commit 5d24dbff29
8 changed files with 285 additions and 63 deletions

View File

@@ -38,7 +38,7 @@ interface IntervalBuffState {
}
@ecs.register('HeroAttrs')
export class HeroAttrsComp extends ecs.Comp {
public debugMode: boolean = true;
public debugMode: boolean = false;
Ebus:any=null!
// ==================== 角色基础信息 ====================
@@ -159,7 +159,9 @@ export class HeroAttrsComp extends ecs.Comp {
this.hp += addValue;
this.hp = Math.max(0, Math.min(this.hp, this.hp_max));
this.dirty_hp = true; // ✅ 仅标记需要更新
mLogger.log(this.debugMode, 'HeroAttrs', ` HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`);
if (this.debugMode) {
mLogger.log(this.debugMode, 'HeroAttrs', ` HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`);
}
}
add_shield(value:number,isValue:boolean){
@@ -173,7 +175,9 @@ export class HeroAttrsComp extends ecs.Comp {
if (this.shield < 0) this.shield = 0;
if (this.shield_max < 0) this.shield_max = 0;
this.dirty_shield = true; // 标记护盾需要更新
mLogger.log(this.debugMode, 'HeroAttrs', ` 护盾变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldShield.toFixed(1)} -> ${this.shield.toFixed(1)}`);
if (this.debugMode) {
mLogger.log(this.debugMode, 'HeroAttrs', ` 护盾变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldShield.toFixed(1)} -> ${this.shield.toFixed(1)}`);
}
}
// ==================== BUFF 管理 ====================
/**
@@ -225,7 +229,9 @@ export class HeroAttrsComp extends ecs.Comp {
this.applyAttrChange(buffConf.buff, normalized.value, normalized.BType);
mLogger.log(this.debugMode, 'HeroAttrs', `添加Buff: ${buffConf.name}, 属性:${buffConf.buff}, 值:${normalized.value}, 时间:${duration}`);
if (this.debugMode) {
mLogger.log(this.debugMode, 'HeroAttrs', `添加Buff: ${buffConf.name}, 属性:${buffConf.buff}, 值:${normalized.value}, 时间:${duration}`);
}
}
/**
@@ -410,7 +416,9 @@ export class HeroAttrsComp extends ecs.Comp {
this.applyAttrChange(buff.attr, buff.value, buff.BType, true);
buffs.splice(i, 1);
mLogger.log(this.debugMode, 'HeroAttrs', `Buff过期: 属性:${buff.attr}, 恢复值:${buff.value}`);
if (this.debugMode) {
mLogger.log(this.debugMode, 'HeroAttrs', `Buff过期: 属性:${buff.attr}, 恢复值:${buff.value}`);
}
}
}