perf: less memory churn

This commit is contained in:
cha0s 2024-08-04 22:34:49 -05:00
parent 030bf436c4
commit 4378ef2a12

View File

@ -41,25 +41,19 @@ function tick(now) {
ecs.tick(elapsed);
emitter.tick(elapsed);
const update = {};
const lastNearby = new Set(memory);
for (const id in ecs.$$entities) {
const entity = ecs.$$entities[id];
if (ecs.$$detached.has(entity.id)) {
continue;
for (const id in ecs.diff) {
if (false === ecs.diff[id]) {
memory.delete(id);
update[id] = false;
}
lastNearby.delete(id);
if (!memory.has(id)) {
update[id] = entity.toJSON();
else if (!memory.has(id)) {
update[id] = ecs.$$entities[id].toJSON();
}
else if (ecs.diff[id]) {
update[id] = ecs.diff[id];
}
memory.add(id);
}
for (const id of lastNearby) {
memory.delete(id);
update[id] = false;
}
if ('1' in update) {
delete update['1'];
}