fix: destruction order

This commit is contained in:
cha0s 2024-07-23 15:05:55 -05:00
parent aacfd6271f
commit b04392756b
2 changed files with 12 additions and 2 deletions

View File

@ -38,6 +38,14 @@ export default class Collider extends Component {
return distance(entity.Position, l) > distance(entity.Position, r) ? -1 : 1;
});
}
destroy() {
const entity = ecs.get(this.entity);
for (const otherId in this.collidingWith) {
const other = ecs.get(otherId);
delete entity.Collider.collidingWith[other.id];
delete other.Collider.collidingWith[entity.id];
}
}
isCollidingWith(other) {
const {aabb, aabbs} = this;
const {aabb: otherAabb, aabbs: otherAabbs} = other;

View File

@ -233,12 +233,14 @@ export default class Ecs {
}
destroying[componentName].push(entityId);
}
this.$$entities[entityId] = undefined;
this.diff[entityId] = false;
}
for (const i in destroying) {
this.Components[i].destroyMany(destroying[i]);
}
for (const entityId of entityIds) {
this.$$entities[entityId] = undefined;
this.diff[entityId] = false;
}
}
get entities() {