summaryrefslogtreecommitdiff
path: root/bench/bench_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bench/bench_window.cpp')
-rw-r--r--bench/bench_window.cpp50
1 files changed, 34 insertions, 16 deletions
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));