MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / main_loop_callback

Function main_loop_callback

platform/web/web_main.cpp:76–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void main_loop_callback() {
77#ifndef PROXY_TO_PTHREAD_ENABLED
78 uint64_t current_ticks = os->get_ticks_usec();
79#endif
80
81 bool force_draw = DisplayServerWeb::get_singleton()->check_size_force_redraw();
82 if (force_draw) {
83 Main::force_redraw();
84#ifndef PROXY_TO_PTHREAD_ENABLED
85 } else if (current_ticks < target_ticks) {
86 return; // Skip frame.
87#endif
88 }
89
90#ifndef PROXY_TO_PTHREAD_ENABLED
91 int max_fps = Engine::get_singleton()->get_max_fps();
92 if (max_fps > 0) {
93 if (current_ticks - target_ticks > 1000000) {
94 // When the window loses focus, we stop getting updates and accumulate delay.
95 // For this reason, if the difference is too big, we reset target ticks to the current ticks.
96 target_ticks = current_ticks;
97 }
98 target_ticks += (uint64_t)(1000000 / max_fps);
99 }
100#endif
101
102 if (os->main_loop_iterate()) {
103 emscripten_cancel_main_loop(); // Cancel current loop and set the cleanup one.
104 emscripten_set_main_loop(exit_callback, -1, false);
105 godot_js_os_finish_async(cleanup_after_sync);
106 }
107}
108
109void print_web_header() {
110 // Emscripten.

Callers 1

godot_web_mainFunction · 0.85

Calls 4

get_ticks_usecMethod · 0.45
get_max_fpsMethod · 0.45
main_loop_iterateMethod · 0.45

Tested by

no test coverage detected