Worker now self-clocks; no heartbeats needed

GameRunner exposes pending work via a new hasPendingTurns() so the worker can check whether more ticks need to be processed.
Worker auto-runs ticks: as soon as it initializes or receives a new turn, it calls processPendingTurns() and loops executeNextTick() while hasPendingTurns() is true. No more "heartbeat" message type; the worker no longer depends on the main thread’s RAF loop to advance the simulation.
Client main thread simplified:
Removed CATCH_UP_HEARTBEATS_PER_FRAME, the heartbeat loop, and the lastBeatsPerFrame tracking.
keepWorkerAlive now just manages frame skipping + draining. When it decides to render (based on renderEveryN), it drains pendingUpdates, merges them, updates GameView, and runs renderer.tick().
Because rendering a batch always implies draining, we restored the invariant that every GameView.update is paired with a layer tick() (no more lost incremental updates).
MAX_RENDER_EVERY_N is now 5 to keep the queue from growing too large while the worker sprints.
This commit is contained in:
scamiv
2025-11-26 21:35:05 +01:00
parent b6515d4366
commit dcd5b550cf
4 changed files with 35 additions and 19 deletions
@@ -435,7 +435,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
private renderEveryN: number = 1;
@state()
private beatsPerFrame: number = 1;
private beatsPerFrame: number | null = null;
updateTickMetrics(
tickExecutionDuration?: number,
@@ -491,7 +491,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
this.renderEveryN = renderEveryN;
}
if (beatsPerFrame !== undefined) {
this.beatsPerFrame = beatsPerFrame;
this.beatsPerFrame = beatsPerFrame ?? null;
}
this.requestUpdate();
@@ -647,7 +647,8 @@ export class PerformanceOverlay extends LitElement implements Layer {
${this.inCatchUpMode
? html`<div class="performance-line">
Render every <span>${this.renderEveryN}</span> frame(s),
heartbeats per frame: <span>${this.beatsPerFrame}</span>
heartbeats per frame:
<span>${this.beatsPerFrame ?? "auto"}</span>
</div>`
: html``}
${this.layerBreakdown.length