summaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/web')
-rw-r--r--src/web/app.mjs36
1 files changed, 3 insertions, 33 deletions
diff --git a/src/web/app.mjs b/src/web/app.mjs
index 11d8f228..280239d5 100644
--- a/src/web/app.mjs
+++ b/src/web/app.mjs
@@ -1,7 +1,5 @@
const CELL_SIZE = 20;
const ATTR_TAGLINE = 1 << 7;
-const ANIMATION_FRAME_MS = 1000 / 60;
-const MAX_ANIMATION_TICKS = 4;
const DEFAULT_FG = "#cccccc";
const DEFAULT_BG = "#121212";
const decoder = new TextDecoder();
@@ -325,7 +323,6 @@ export class PardesRuntime {
this.running = false;
this.pointer = null;
this.frameHandle = 0;
- this.animationClock = { last: null, lag: 0 };
this.bindEvents();
}
@@ -338,7 +335,6 @@ export class PardesRuntime {
this.wasm.pardes_tick();
this.renderer.render();
this.running = true;
- this.animationClock = { last: null, lag: 0 };
this.frameHandle = requestAnimationFrame((timestamp) => this.frame(timestamp));
this.root.focus({ preventScroll: true });
}
@@ -355,13 +351,9 @@ export class PardesRuntime {
this.resize();
this.root.style.setProperty("--pardes-tagline-font-size", `${this.measuredTaglinePercent}%`);
}
- // JS owns the animation clock; the pump that follows applies those ticks,
- // runs the core's effects and presents one frame however fast the display
- // is. Both halves are needed: an idle core still has input and effects.
- for (let ticks = animationTicks(this.animationClock, timestamp); ticks > 0; ticks -= 1) {
- this.wasm.pardes_animation_tick();
- }
- this.wasm.pardes_tick();
+ // The core's clock is this timestamp: it steps its own animations
+ // by it, however fast the display refreshes.
+ this.wasm.pardes_tick(timestamp);
if (this.wasm.pardes_should_quit()) this.running = false;
this.renderer.render();
this.frameHandle = requestAnimationFrame((nextTimestamp) => this.frame(nextTimestamp));
@@ -559,28 +551,6 @@ export class PardesRuntime {
}
}
-/// Spend monotonic requestAnimationFrame time as fixed 60 Hz core ticks. A
-/// high-refresh display therefore renders repeated states rather than making
-/// frame-count transitions run twice as fast. Long suspension is capped so a
-/// returning tab cannot execute an unbounded loop before drawing.
-export function animationTicks(clock, timestamp) {
- if (!Number.isFinite(timestamp)) return 0;
- if (clock.last === null || timestamp < clock.last) {
- clock.last = timestamp;
- clock.lag = 0;
- return 0;
- }
- const elapsed = Math.min(timestamp - clock.last, ANIMATION_FRAME_MS * MAX_ANIMATION_TICKS);
- clock.last = timestamp;
- clock.lag += elapsed;
- const ticks = Math.min(MAX_ANIMATION_TICKS, Math.floor((clock.lag + 1e-7) / ANIMATION_FRAME_MS));
- clock.lag -= ticks * ANIMATION_FRAME_MS;
- return ticks;
-}
-
-/// The four things the core asks the page for, as the module's imports. The
-/// holder exists because the import object has to be built before the instance
-/// whose memory those imports read.
export function browserHost() {
const host = { wasm: null };
const view = (ptr, len) => new Uint8Array(host.wasm.memory.buffer, ptr, len);