From 78c40e1422a86bd184ae1d571b241fa881f78ca0 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 29 May 2023 17:32:58 -0400 Subject: target rate slider, hyperspeed, more --- bench/bench_window.cpp | 50 ++++++++++++++++++++++++++++++++++---------------- bench/bench_window.hpp | 11 ++++++++--- bench/main.cpp | 2 +- bench/main.hpp | 2 +- 4 files changed, 44 insertions(+), 21 deletions(-) (limited to 'bench') diff --git a/bench/bench_window.cpp b/bench/bench_window.cpp index bcdc12d..16110cd 100644 --- a/bench/bench_window.cpp +++ b/bench/bench_window.cpp @@ -7,15 +7,17 @@ bench_window::bench_window() : runner_stop_now(false), runner_stop_on_death(true), runner_stop_on_win(true), - runner_update_ui(true), + runner_hyperspeed(false), control_box(Gtk::Orientation::VERTICAL), new_round_button("new round"), single_step_button("single step"), start_button("start"), stop_button("stop"), - draw_each_step_toggle("draw each step"), + hyperspeed_toggle("hyperspeed"), pause_on_death_toggle("pause on death"), pause_on_win_toggle("pause on win"), + target_core_rate_label(), + target_core_rate_scale(), add_warrior_button("add warrior"), remove_warrior_button("remove warrior"), runner({}), @@ -27,7 +29,6 @@ bench_window::bench_window() warrior_list_view.set_model(warrior_list_store); instructions_view.set_model(instructions_store); - warrior_list_view.get_selection()->set_mode(Gtk::SelectionMode::SINGLE); instructions_view.get_selection()->set_mode(Gtk::SelectionMode::NONE); warrior_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &bench_window::update_buttons)); @@ -46,7 +47,6 @@ bench_window::bench_window() update_ui(); - draw_each_step_toggle.activate(); pause_on_death_toggle.activate(); pause_on_win_toggle.activate(); @@ -57,17 +57,24 @@ bench_window::bench_window() add_warrior_button.signal_clicked().connect(sigc::mem_fun(*this, &bench_window::on_click_add_warrior)); remove_warrior_button.signal_clicked().connect(sigc::mem_fun(*this, &bench_window::on_click_remove_warrior)); - draw_each_step_toggle.signal_toggled().connect(sigc::mem_fun(*this, &bench_window::on_toggle_draw_each_step)); + hyperspeed_toggle.signal_toggled().connect(sigc::mem_fun(*this, &bench_window::on_toggle_hyperspeed)); pause_on_death_toggle.signal_toggled().connect(sigc::mem_fun(*this, &bench_window::on_toggle_pause_on_death)); pause_on_win_toggle.signal_toggled().connect(sigc::mem_fun(*this, &bench_window::on_toggle_pause_on_win)); + target_core_rate_scale.signal_value_changed().connect(sigc::mem_fun(*this, &bench_window::on_target_core_rate_changed)); + + target_core_rate_scale.set_range(0.0, 3.0); + target_core_rate_scale.set_value(std::log10(20.0)); + control_box.append(new_round_button); control_box.append(single_step_button); control_box.append(start_button); control_box.append(stop_button); - control_box.append(draw_each_step_toggle); + control_box.append(hyperspeed_toggle); control_box.append(pause_on_death_toggle); control_box.append(pause_on_win_toggle); + control_box.append(target_core_rate_label); + control_box.append(target_core_rate_scale); control_box.append(add_warrior_button); control_box.append(remove_warrior_button); @@ -136,11 +143,11 @@ void bench_window::runner_main() { break; if (runner_stop_on_win && death && lib94::alive_warrior_count() == 1) break; - if (runner_update_ui) - runner_update_ui_dispatcher.emit(); core_mutex.unlock(); - std::this_thread::sleep_until(last_step + time_between_steps); + runner_update_ui_dispatcher.emit(); + if (!runner_hyperspeed) + std::this_thread::sleep_until(last_step + time_between_steps); last_step = std::chrono::system_clock::now(); core_mutex.lock(); } @@ -190,8 +197,8 @@ void bench_window::on_click_stop() { runner_stop_now = true; } -void bench_window::on_toggle_draw_each_step() { - runner_update_ui = draw_each_step_toggle.get_active(); +void bench_window::on_toggle_hyperspeed() { + runner_hyperspeed = hyperspeed_toggle.get_active(); } void bench_window::on_toggle_pause_on_death() { @@ -202,6 +209,12 @@ void bench_window::on_toggle_pause_on_win() { runner_stop_on_win = pause_on_win_toggle.get_active(); } +void bench_window::on_target_core_rate_changed() { + double target_rate = std::pow(10.0, target_core_rate_scale.get_value()); + target_core_rate_label.set_text("target core rate (" + hz_to_string(target_rate) + ")"); + time_between_steps = std::chrono::nanoseconds((int)(1000000000.0 / target_rate)); +} + void bench_window::on_add_warrior_dialog_response(int response_id, Gtk::FileChooserDialog *dialog) { if (response_id == Gtk::ResponseType::OK) { @@ -282,17 +295,24 @@ void bench_window::update_buttons() { stop_button.set_sensitive(runner_active); add_warrior_button.set_sensitive(!runner_active); remove_warrior_button.set_sensitive(!runner_active && warrior_list_view.get_selection()->get_selected()); + + warrior_list_view.get_selection()->set_mode(runner_active ? Gtk::SelectionMode::NONE : Gtk::SelectionMode::SINGLE); + + core_render_label.set_text("core render: " + ns_to_string(core.last_draw_time)); + core_rate_label.set_text("core rate: " + hz_to_string(1000000000.0 / (double)last_core_step_distance.count())); } void bench_window::update_ui() { + if (runner_active && runner_hyperspeed) { + update_buttons(); + return; + } + if (runner_active) core_mutex.lock(); update_buttons(); - core_render_label.set_text("core render: " + ns_to_string(core.last_draw_time)); - core_rate_label.set_text("core rate: " + hz_to_string(1000000000.0 / (double)last_core_step_distance.count())); - core.queue_draw(); warrior_list_store->clear(); @@ -306,8 +326,6 @@ void bench_window::update_ui() { (*w_row)[warrior_list_columns.next_pc] = procs.size() ? std::to_string(procs[0]) : ""; } - //warrior_list_view.expand_all(); - for (lib94::number_t i : modified_addresses_for_instructions_view) instructions_store->children()[i][instructions_columns.instruction] = lib94::instruction_to_string(lib94::get_instruction(i)); diff --git a/bench/bench_window.hpp b/bench/bench_window.hpp index 86b2f1c..bd15e4b 100644 --- a/bench/bench_window.hpp +++ b/bench/bench_window.hpp @@ -16,7 +16,7 @@ public: bool runner_stop_now; bool runner_stop_on_death; bool runner_stop_on_win; - bool runner_update_ui; + bool runner_hyperspeed; core_widget core; @@ -71,10 +71,13 @@ private: Gtk::Button start_button; Gtk::Button stop_button; - Gtk::CheckButton draw_each_step_toggle; + Gtk::CheckButton hyperspeed_toggle; Gtk::CheckButton pause_on_death_toggle; Gtk::CheckButton pause_on_win_toggle; + Gtk::Label target_core_rate_label; + Gtk::Scale target_core_rate_scale; + Gtk::Button add_warrior_button; Gtk::Button remove_warrior_button; @@ -91,10 +94,12 @@ private: void on_click_start(); void on_click_stop(); - void on_toggle_draw_each_step(); + void on_toggle_hyperspeed(); void on_toggle_pause_on_death(); void on_toggle_pause_on_win(); + void on_target_core_rate_changed(); + void on_click_add_warrior(); void on_click_remove_warrior(); diff --git a/bench/main.cpp b/bench/main.cpp index 9663650..70d3cfa 100644 --- a/bench/main.cpp +++ b/bench/main.cpp @@ -2,7 +2,7 @@ #include "main.hpp" std::vector warriors; -std::chrono::milliseconds time_between_steps(50); +std::chrono::nanoseconds time_between_steps; std::mutex core_mutex; int main(int argc, char **argv) { diff --git a/bench/main.hpp b/bench/main.hpp index ee0e1e3..06243e3 100644 --- a/bench/main.hpp +++ b/bench/main.hpp @@ -7,7 +7,7 @@ #include extern std::vector warriors; -extern std::chrono::milliseconds time_between_steps; +extern std::chrono::nanoseconds time_between_steps; extern std::mutex core_mutex; std::string ns_to_string(std::chrono::nanoseconds dur); -- cgit v1.2.3