浏览代码

[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.

(cherry picked from commit a1fe6d6899c5ed4cf13c16f9d6bcd64958ab8254)
Fabio Alessandrelli 4 年之前
父节点
当前提交
0a7193c5f4
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      platform/javascript/javascript_main.cpp

+ 5 - 0
platform/javascript/javascript_main.cpp

@@ -65,6 +65,11 @@ void main_loop_callback() {
 
 
 	int target_fps = Engine::get_singleton()->get_target_fps();
 	int target_fps = Engine::get_singleton()->get_target_fps();
 	if (target_fps > 0) {
 	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);
 		target_ticks += (uint64_t)(1000000 / target_fps);
 	}
 	}
 	if (os->main_loop_iterate()) {
 	if (os->main_loop_iterate()) {