Hack around animation wackiness when user switches windows for awhile.

This commit is contained in:
David Thompson 2024-05-25 07:27:08 -04:00
parent faf4fa7124
commit 770a5e6b7d

View file

@ -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*)