From 770a5e6b7d654c4ada2830ef0927373b1b623642 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 25 May 2024 07:27:08 -0400 Subject: [PATCH] Hack around animation wackiness when user switches windows for awhile. --- game.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/game.scm b/game.scm index eb5f005..fe28a30 100644 --- a/game.scm +++ b/game.scm @@ -570,11 +570,19 @@ (let* ((time (/ time 1000.0)) (dt (- time *frame-time*))) (set! *frame-time* time) - (update-animation anim:player dt) - (update-animation anim:electron-head dt) - (update-animation anim:electron-tail dt) - (update-animation anim:gem dt) - (update-animation anim:ghost-gem dt) + ;; Prevent SUPER SPEED animations when the user switches away from + ;; the browser for awhile. To my surprise, + ;; blur/focus/visibilitychanged events *DO NOT* trigger when the + ;; user switches to another program window, at least on my + ;; machine, so they are useless to prevent this problem. Instead, + ;; we hack: Don't update animations if dt is unreasonably high, + ;; for some definition of unreasonable. + (unless (> dt 0.2) + (update-animation anim:player dt) + (update-animation anim:electron-head dt) + (update-animation anim:electron-tail dt) + (update-animation anim:gem dt) + (update-animation anim:ghost-gem dt)) (clear-rect context 0.0 0.0 *canvas-width* *canvas-height*) (set-transform! context 1.0 0.0 0.0 1.0 0.0 0.0) (scale! context *canvas-scale* *canvas-scale*)