make hyperspeed not update ui so much

This commit is contained in:
Benji Dial 2023-05-30 22:14:40 -04:00
parent a988f6a27d
commit 21d36220c8
2 changed files with 18 additions and 3 deletions

View file

@ -141,6 +141,8 @@ const lib94::warrior *bench_window::do_step() {
return result;
}
static constexpr std::chrono::nanoseconds min_hyperspeed_ui_update_distance(1000000);
void bench_window::runner_main() {
std::chrono::system_clock::time_point last_step = std::chrono::system_clock::now();
@ -154,10 +156,21 @@ void bench_window::runner_main() {
break;
core_mutex.unlock();
runner_update_ui_dispatcher.emit();
if (!runner_hyperspeed)
if (runner_hyperspeed) {
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
if (now - last_hyperspeed_ui_update >= min_hyperspeed_ui_update_distance) {
last_hyperspeed_ui_update = now;
runner_update_ui_dispatcher.emit();
}
}
else {
runner_update_ui_dispatcher.emit();
std::this_thread::sleep_until(last_step + time_between_steps);
last_step = std::chrono::system_clock::now();
last_step = std::chrono::system_clock::now();
}
core_mutex.lock();
}

View file

@ -109,6 +109,8 @@ private:
std::thread runner;
bool runner_active;
std::chrono::system_clock::time_point last_hyperspeed_ui_update;
void update_buttons();
void update_ui();