feat: ticking destruction dependencies

This commit is contained in:
cha0s 2024-07-29 07:44:12 -05:00
parent 82e37f9b91
commit b719e3227b

View File

@ -1,7 +1,7 @@
import {Encoder, Decoder} from '@msgpack/msgpack';
import {LRUCache} from 'lru-cache';
import {withResolvers} from '@/util/promise.js';
import {Ticker, withResolvers} from '@/util/promise.js';
import Script from '@/util/script.js';
import EntityFactory from './entity-factory.js';
@ -462,10 +462,17 @@ export default class Ecs {
}
}
const destroying = new Set();
for (const [entityId, {promises, resolvers}] of this.$$destructionDependencies) {
if (0 === promises.size && resolvers) {
for (const [entityId, {promises}] of this.$$destructionDependencies) {
if (0 === promises.size) {
destroying.add(entityId);
}
else {
for (const promise of promises) {
if (promise instanceof Ticker) {
promise.tick(elapsed);
}
}
}
}
if (destroying.size > 0) {
this.destroyMany(destroying);