perf(hero): 优化临时buff的更新逻辑以提升性能
将forEach循环改为倒序for循环,避免在删除元素时重复查找index,减少不必要的操作
This commit is contained in:
@@ -302,15 +302,13 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
// 更新临时型buff
|
||||
for (const attrIndex in this.BUFFS_TEMP) {
|
||||
const buffs = this.BUFFS_TEMP[attrIndex];
|
||||
buffs.forEach(buff => {
|
||||
for (let i = buffs.length - 1; i >= 0; i--) {
|
||||
const buff = buffs[i];
|
||||
buff.remainTime -= dt;
|
||||
if (buff.remainTime <= 0) {
|
||||
const index = buffs.indexOf(buff);
|
||||
if (index > -1) {
|
||||
buffs.splice(index, 1);
|
||||
}
|
||||
buffs.splice(i, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (buffs.length === 0) {
|
||||
delete this.BUFFS_TEMP[attrIndex];
|
||||
affectedAttrs.add(parseInt(attrIndex));
|
||||
|
||||
Reference in New Issue
Block a user