Skip to content

Commit 2ab43da

Browse files
committed
fix: prevent phosphor sweep speed burst on initial load
Cap the phosphor accumulator so excess time from dropped frames is discarded rather than draining over subsequent frames at max tick rate. Also reset timing state when the animation loop starts.
1 parent c212f66 commit 2ab43da

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/ui/RotatorWindow.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,8 @@
390390
const pc = phosphorCtx;
391391
392392
// Run phosphor simulation at fixed 60Hz — accumulate real time, consume in ticks
393-
phosphorAccum += dt;
394-
const maxTicks = PHOSPHOR_MAX_TICKS;
393+
phosphorAccum = Math.min(phosphorAccum + dt, PHOSPHOR_MAX_TICKS * PHOSPHOR_TICK);
395394
let ticks = Math.floor(phosphorAccum / PHOSPHOR_TICK);
396-
if (ticks > maxTicks) ticks = maxTicks;
397395
phosphorAccum -= ticks * PHOSPHOR_TICK;
398396
399397
for (let t = 0; t < ticks; t++) {
@@ -775,6 +773,8 @@
775773
$effect(() => {
776774
if (canvasEl) {
777775
initCanvas();
776+
lastFrameTime = 0;
777+
phosphorAccum = 0;
778778
canvasEl.addEventListener('wheel', onCanvasWheel, { passive: false });
779779
animFrameId = requestAnimationFrame(drawFrame);
780780
return () => {

0 commit comments

Comments
 (0)