This commit is contained in:
David Allemang
2026-07-04 13:24:41 -04:00
parent a92ac6d736
commit 9e05d39044
3 changed files with 75 additions and 2 deletions

View File

@@ -97,6 +97,9 @@ export class Engine {
this.worldMeshes = new Map();
this.renderRequested = false;
this.observedWorlds = new Set();
this.updateRequested = false;
window.addEventListener('resize', () => {
this.resize();
this.requestRender();
@@ -105,6 +108,19 @@ export class Engine {
this.resize();
}
requestUpdate() {
if (!this.updateRequested) {
this.updateRequested = true;
// Promise.resolve().then() executes immediately after the current synchronous
// call stack finishes, ensuring 10 simultaneous setBlock calls only trigger 1 update.
Promise.resolve().then(() => {
this.updateRequested = false;
this.updateAll();
});
}
}
requestRender() {
if (!this.renderRequested) {
this.renderRequested = true;
@@ -122,6 +138,14 @@ export class Engine {
addDiorama(diorama) {
this.dioramas.push(diorama);
// Subscribe to the world if we aren't already watching it
if (!this.observedWorlds.has(diorama.world)) {
this.observedWorlds.add(diorama.world);
// Whenever the world changes, queue a single, debounced geometry rebuild
diorama.world.subscribe(() => this.requestUpdate());
}
}
async updateAll() {