Refactor rendering and metrics emission in ClientGameRunner to ensure updates occur only after all processing is complete.

This commit is contained in:
scamiv
2025-11-25 18:31:08 +01:00
parent 85ad3b1997
commit 0b0753d5e1
+22 -20
View File
@@ -511,33 +511,35 @@ export class ClientGameRunner {
this.pendingStart = 0;
}
if (batch.length > 0 && lastTick !== undefined) {
// Only update view and render when ALL processing is complete
if (
this.pendingStart >= this.pendingUpdates.length &&
batch.length > 0 &&
lastTick !== undefined
) {
const combinedGu = this.mergeGameUpdates(batch);
if (combinedGu) {
this.gameView.update(combinedGu);
}
// Only emit metrics when ALL processing is complete
if (this.pendingStart >= this.pendingUpdates.length) {
const ticksPerRender =
this.lastRenderedTick === 0
? lastTick
: lastTick - this.lastRenderedTick;
this.lastRenderedTick = lastTick;
const ticksPerRender =
this.lastRenderedTick === 0
? lastTick
: lastTick - this.lastRenderedTick;
this.lastRenderedTick = lastTick;
this.renderer.tick();
this.eventBus.emit(
new TickMetricsEvent(
lastTickDuration,
this.currentTickDelay,
this.backlogTurns,
ticksPerRender,
),
);
this.renderer.tick();
this.eventBus.emit(
new TickMetricsEvent(
lastTickDuration,
this.currentTickDelay,
this.backlogTurns,
ticksPerRender,
),
);
// Reset tick delay for next measurement
this.currentTickDelay = undefined;
}
// Reset tick delay for next measurement
this.currentTickDelay = undefined;
}
if (this.pendingStart < this.pendingUpdates.length) {