summaryrefslogtreecommitdiff
path: root/platform/javascript
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-05-07 14:06:46 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-05-07 21:51:14 +0200
commita1fe6d6899c5ed4cf13c16f9d6bcd64958ab8254 (patch)
tree7fb7f62fe237d3b66f68e8d9f968cd1339022143 /platform/javascript
parent9a98c09bb2681765160cc9ddcbd4eea37511eec2 (diff)
[HTML5] Fix target_fps when window loses focus.
We don't get updates when the window is unfocused/minimized, so we must detect the situation where the counted ticks start drifting away resulting in more frames drawn than needed. This commit adds a check to ensure that the target ticks do not drift away more than one second.
Diffstat (limited to 'platform/javascript')
-rw-r--r--platform/javascript/javascript_main.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index 0fe95b0a8f..40771d1882 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -66,6 +66,11 @@ void main_loop_callback() {
int target_fps = Engine::get_singleton()->get_target_fps();
if (target_fps > 0) {
+ if (current_ticks - target_ticks > 1000000) {
+ // When the window loses focus, we stop getting updates and accumulate delay.
+ // For this reason, if the difference is too big, we reset target ticks to the current ticks.
+ target_ticks = current_ticks;
+ }
target_ticks += (uint64_t)(1000000 / target_fps);
}
if (os->main_loop_iterate()) {