perf(英雄属性): 使用脏标签模式优化属性UI更新性能
在 HeroAttrsComp 中添加脏标签标记,仅在属性变化时更新UI 移除 HeroViewComp 中每帧不必要的UI更新调用 添加文档说明优化方案
This commit is contained in:
@@ -38,7 +38,12 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
Talents: Record<number, talTrigger> = {};
|
||||
//数值型天赋buff
|
||||
BUFFS_TAL: Record<number, {count:number,BType:BType,attrIndex:number,value: number}> = {};
|
||||
|
||||
|
||||
// ==================== 脏标签标记 ====================
|
||||
dirty_hp: boolean = false; // 血量变更标记
|
||||
dirty_mp: boolean = false; // 魔法值变更标记
|
||||
dirty_shield: boolean = false; // 护盾变更标记
|
||||
|
||||
// ==================== 技能距离缓存 ====================
|
||||
maxSkillDistance: number = 0; // 最远技能攻击距离(缓存,受MP影响)
|
||||
minSkillDistance: number = 0; // 最近技能攻击距离(缓存,不受MP影响,用于停止位置判断)
|
||||
@@ -128,6 +133,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
this.hp += addValue;
|
||||
this.hp = Math.max(0, Math.min(this.hp, this.Attrs[Attrs.HP_MAX]));
|
||||
this.dirty_hp = true; // 标记血量需要更新
|
||||
}
|
||||
add_mp(value:number,isValue:boolean){
|
||||
let addValue = value;
|
||||
@@ -140,6 +146,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
this.mp += addValue;
|
||||
this.mp = Math.max(0, Math.min(this.mp, this.Attrs[Attrs.MP_MAX]));
|
||||
this.dirty_mp = true; // 标记魔法值需要更新
|
||||
}
|
||||
add_shield(value:number,isValue:boolean){
|
||||
let addValue = value;
|
||||
@@ -148,6 +155,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
this.shield += addValue;
|
||||
this.shield = Math.max(0, Math.min(this.shield, this.Attrs[Attrs.HP_MAX]));
|
||||
this.dirty_shield = true; // 标记护盾需要更新
|
||||
}
|
||||
// ==================== BUFF 管理 ====================
|
||||
/**
|
||||
@@ -561,6 +569,10 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.atk_count = 0;
|
||||
this.atked_count = 0;
|
||||
this.killed_count =0;
|
||||
// 重置脏标签
|
||||
this.dirty_hp = false;
|
||||
this.dirty_mp = false;
|
||||
this.dirty_shield = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user