From f1dec33ef0f6639736d510765547eda6e8b94d29 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sun, 16 Apr 2023 13:21:51 -0400 Subject: [PATCH] Use `performance.now()` for HTML5 timing. This way, changing the computer clock can't mess up animations. (Unless we're using the fallback, in which case everything will act as before.) --- src/lime/_internal/backend/html5/HTML5Application.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lime/_internal/backend/html5/HTML5Application.hx b/src/lime/_internal/backend/html5/HTML5Application.hx index 78a4c3bfb..3b137e92b 100644 --- a/src/lime/_internal/backend/html5/HTML5Application.hx +++ b/src/lime/_internal/backend/html5/HTML5Application.hx @@ -325,7 +325,7 @@ class HTML5Application if (!window.requestAnimationFrame) window.requestAnimationFrame = function(callback, element) { - var currTime = new Date().getTime(); + var currTime = window.performance.now(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); @@ -341,7 +341,7 @@ class HTML5Application window.requestAnimFrame = window.requestAnimationFrame; "); - lastUpdate = Date.now().getTime(); + lastUpdate = Browser.window.performance.now(); handleApplicationEvent(); @@ -361,7 +361,7 @@ class HTML5Application updateGameDevices(); - currentUpdate = Date.now().getTime(); + currentUpdate = Browser.window.performance.now(); if (currentUpdate >= nextUpdate) {