MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / main_thread_update

Method main_thread_update

gui/gdre_progress.cpp:448–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448bool GDREProgressDialog::main_thread_update() {
449 ERR_FAIL_COND_V_MSG(!is_safe_to_redraw(), false, "Cannot update progress dialog from non-main thread or while flushing messages.");
450 // This prevents recursive calls to main_thread_update caused by main iteration calling `process()`
451 if (is_updating) {
452 return false;
453 }
454 is_updating = true;
455 bool removed = _process_removals();
456 bool should_update = removed;
457 bool p_can_cancel = false;
458 bool task_initialized = false;
459 bool should_force_redraw = false;
460 uint64_t task_count = 0;
461 uint64_t last_tick = OS::get_singleton()->get_ticks_usec();
462 // if it's been more than 500ms since the last update_ui happened, force a redraw (if we have any tasks to redraw).
463 if (last_tick - last_tick_updated > 500000) {
464 should_force_redraw = true;
465 }
466 Vector<String> tasks_to_print;
467 tasks.for_each_m([&](TaskMap::value_type &E) {
468 Task &t = E.second;
469 if (!t.initialized) {
470 task_initialized = true;
471 should_update = true;
472 t.init(main);
473 }
474 t.force_next_redraw = t.force_next_redraw || should_force_redraw;
475 if (t.update() || (t.is_headless && should_force_redraw)) {
476 should_update = true;
477 if (t.is_headless) {
478 tasks_to_print.push_back(E.first);
479 }
480 }
481 p_can_cancel = p_can_cancel || t.can_cancel;
482 task_count++;
483 });
484 tasks_to_print.reverse();
485 for (const String &task : tasks_to_print) {
486 tasks.if_contains(task, [&](TaskMap::value_type &E) {
487 GDRELogger::stdout_print(GDRELogger::STATUS_BAR_CLEAR);
488 E.second.print_status_bar();
489 });
490 }
491 if (should_update) {
492 last_tick_updated = last_tick;
493 if (task_count == 0) {
494 _hide();
495 } else if (task_initialized || removed) {
496 _post_add_task(p_can_cancel);
497 } else {
498 _update_ui();
499 }
500 }
501 is_updating = false;
502 return should_update;
503}
504
505void GDREProgressDialog::add_host_window(Window *p_window) {

Callers 1

update_progress_bgMethod · 0.80

Calls 6

for_each_mMethod · 0.80
push_backMethod · 0.80
if_containsMethod · 0.80
initMethod · 0.45
updateMethod · 0.45
print_status_barMethod · 0.45

Tested by

no test coverage detected