| 294 | } |
| 295 | |
| 296 | bool TaskManager::wait_until_next_frame(int64_t p_time_usec) { |
| 297 | uint64_t curr_time = OS::get_singleton()->get_ticks_usec(); |
| 298 | if (!Thread::is_main_thread()) { |
| 299 | OS::get_singleton()->delay_usec(p_time_usec); |
| 300 | return is_current_task_canceled(); |
| 301 | } |
| 302 | process_main_thread_dispatch_queue_for(p_time_usec); |
| 303 | bool did_redraw = false; |
| 304 | if (update_progress_bg(true, false, &did_redraw)) { |
| 305 | cancel_main_thread_dispatch_queue(); |
| 306 | return true; |
| 307 | } |
| 308 | if (!did_redraw) { |
| 309 | GDRESettings::main_iteration(); |
| 310 | } |
| 311 | int64_t elapsed_time = OS::get_singleton()->get_ticks_usec() - curr_time; |
| 312 | constexpr int64_t SYNC_WAIT_TIME_US = 1000; |
| 313 | if (elapsed_time < p_time_usec) { |
| 314 | while (elapsed_time < p_time_usec) { |
| 315 | RS::get_singleton()->sync(); |
| 316 | elapsed_time = OS::get_singleton()->get_ticks_usec() - curr_time; |
| 317 | if (p_time_usec - elapsed_time > SYNC_WAIT_TIME_US) { |
| 318 | OS::get_singleton()->delay_usec(SYNC_WAIT_TIME_US); |
| 319 | } else { |
| 320 | if (p_time_usec - elapsed_time > 0) { |
| 321 | OS::get_singleton()->delay_usec(p_time_usec - elapsed_time); |
| 322 | } |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | bool TaskManager::update_progress_bg(bool p_force_refresh, bool called_from_process, bool *r_did_redraw) { |
| 331 | if (updating_bg || (group_id_to_description.empty() && !Thread::is_main_thread())) { |
no outgoing calls
no test coverage detected