openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
754 stars 367 forks source link

Use `performance.now()` for HTML5 timing. #1657

Closed player-03 closed 1 year ago

player-03 commented 1 year ago

This way, changing the computer clock can't mess up animations. Resolves #1367.

There is a fallback if window.performance isn't available, and I left that intact.


I was going to update Timer.stamp() to use self.performance, because that's available in web workers as well as normal windows. It would look like this:

#elseif js
-return Date.now().getTime() / 1000;
+return js.Browser.self.performance.now() / 1000;
#elseif cpp

However, I later realized that I was editing the standard library version of Timer, and my changes would be overwritten the next time we updated it. So I'm leaving the change out, but perhaps it could be submitted upstream.