fix: 收敛战斗内存增长并强化战斗结束清理
This commit is contained in:
@@ -19,7 +19,15 @@ 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 = 128;
|
||||
static readonly MAX_POOL_SIZE: number = 48;
|
||||
static readonly MAX_POOL_TOTAL: number = 192;
|
||||
private static totalPoolSize(): number {
|
||||
let total = 0;
|
||||
this.pools.forEach((pool) => {
|
||||
total += pool.size();
|
||||
});
|
||||
return total;
|
||||
}
|
||||
|
||||
static getFromPool(path: string): Node | null {
|
||||
if (this.pools.has(path)) {
|
||||
@@ -40,7 +48,7 @@ export class Skill extends ecs.Entity {
|
||||
this.pools.set(path, new NodePool());
|
||||
}
|
||||
const pool = this.pools.get(path)!;
|
||||
if (pool.size() >= this.MAX_POOL_SIZE) {
|
||||
if (pool.size() >= this.MAX_POOL_SIZE || this.totalPoolSize() >= this.MAX_POOL_TOTAL) {
|
||||
node.destroy();
|
||||
return;
|
||||
}
|
||||
@@ -49,6 +57,12 @@ export class Skill extends ecs.Entity {
|
||||
|
||||
static clearPools() {
|
||||
this.pools.forEach((pool) => {
|
||||
while (pool.size() > 0) {
|
||||
const node = pool.get();
|
||||
if (node && node.isValid) {
|
||||
node.destroy();
|
||||
}
|
||||
}
|
||||
pool.clear();
|
||||
});
|
||||
this.pools.clear();
|
||||
@@ -62,7 +76,8 @@ export class Skill extends ecs.Entity {
|
||||
return {
|
||||
paths: this.pools.size,
|
||||
total,
|
||||
maxPerPath: this.MAX_POOL_SIZE
|
||||
maxPerPath: this.MAX_POOL_SIZE,
|
||||
maxTotal: this.MAX_POOL_TOTAL
|
||||
};
|
||||
}
|
||||
|
||||
@@ -229,6 +244,7 @@ export class Skill extends ecs.Entity {
|
||||
Skill.putToPool(this.prefabPath, this.skillNode);
|
||||
this.skillNode = null;
|
||||
}
|
||||
this.prefabPath = "";
|
||||
|
||||
super.destroy();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user