修复了QuerySystem在销毁实体时的内存泄漏问题

实现了完整的onAdded/onRemoved回调系统
修复了override修饰符和类型兼容性问题
This commit is contained in:
YHH
2025-08-06 09:39:08 +08:00
parent 69655f1936
commit ccbfa78070
7 changed files with 105 additions and 140 deletions

View File

@@ -9,8 +9,9 @@ class TestPositionComponent extends Component {
public y: number = 0;
public z: number = 0;
constructor(x = 0, y = 0, z = 0) {
constructor(...args: unknown[]) {
super();
const [x = 0, y = 0, z = 0] = args as [number?, number?, number?];
this.x = x;
this.y = y;
this.z = z;
@@ -24,8 +25,9 @@ class TestVelocityComponent extends Component {
public vz: number = 0;
public maxSpeed: number = 100;
constructor(vx = 0, vy = 0, vz = 0) {
constructor(...args: unknown[]) {
super();
const [vx = 0, vy = 0, vz = 0] = args as [number?, number?, number?];
this.vx = vx;
this.vy = vy;
this.vz = vz;
@@ -38,8 +40,9 @@ class TestHealthComponent extends Component {
public max: number = 100;
public regeneration: number = 1;
constructor(current = 100, max = 100) {
constructor(...args: unknown[]) {
super();
const [current = 100, max = 100] = args as [number?, number?];
this.current = current;
this.max = max;
}
@@ -51,8 +54,9 @@ class OriginalPositionComponent extends Component {
public y: number = 0;
public z: number = 0;
constructor(x = 0, y = 0, z = 0) {
constructor(...args: unknown[]) {
super();
const [x = 0, y = 0, z = 0] = args as [number?, number?, number?];
this.x = x;
this.y = y;
this.z = z;
@@ -65,8 +69,9 @@ class OriginalVelocityComponent extends Component {
public vz: number = 0;
public maxSpeed: number = 100;
constructor(vx = 0, vy = 0, vz = 0) {
constructor(...args: unknown[]) {
super();
const [vx = 0, vy = 0, vz = 0] = args as [number?, number?, number?];
this.vx = vx;
this.vy = vy;
this.vz = vz;
@@ -78,8 +83,9 @@ class OriginalHealthComponent extends Component {
public max: number = 100;
public regeneration: number = 1;
constructor(current = 100, max = 100) {
constructor(...args: unknown[]) {
super();
const [current = 100, max = 100] = args as [number?, number?];
this.current = current;
this.max = max;
}

View File

@@ -24,9 +24,16 @@ class TrackingSystem extends EntitySystem {
const wasInitialized = (this as any)._initialized;
super.initialize();
// 只有在真正执行初始化时才增加计数
// 只有在真正执行初始化时才增加计数和处理实体
if (!wasInitialized) {
this.initializeCallCount++;
// 处理所有现有实体
if (this.scene) {
for (const entity of this.scene.entities.buffer) {
this.onChanged(entity);
}
}
}
}