keep track of maximum average step time

This commit is contained in:
Crispy 2024-12-07 20:46:06 +01:00
parent 1d001be403
commit 28213da9f3

View file

@ -63,6 +63,7 @@ pub struct Editor {
selected_blueprint: usize, selected_blueprint: usize,
blueprint_scroll: usize, blueprint_scroll: usize,
step_time: u128, step_time: u128,
max_step_time:u128,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -139,6 +140,7 @@ impl Editor {
selected_blueprint: usize::MAX, selected_blueprint: usize::MAX,
blueprint_scroll: 0, blueprint_scroll: 0,
step_time: 0, step_time: 0,
max_step_time: 0,
} }
} }
@ -163,6 +165,7 @@ impl Editor {
} }
fn start_sim(&mut self) { fn start_sim(&mut self) {
self.max_step_time = 0;
self.machine.reset(); self.machine.reset();
self.machine.set_board(self.source_board.clone()); self.machine.set_board(self.source_board.clone());
} }
@ -355,6 +358,7 @@ impl Editor {
.checked_div(steps_taken) .checked_div(steps_taken)
.unwrap_or_default(); .unwrap_or_default();
self.step_time = avg_step_time; self.step_time = avg_step_time;
self.max_step_time = avg_step_time.max(self.max_step_time);
} }
if rl.is_key_pressed(KeyboardKey::KEY_SPACE) { if rl.is_key_pressed(KeyboardKey::KEY_SPACE) {
self.step_pressed() self.step_pressed()
@ -597,6 +601,7 @@ impl Editor {
draw_usize(d, textures, self.machine.step_count(), 420, 4, 9, 2); draw_usize(d, textures, self.machine.step_count(), 420, 4, 9, 2);
draw_usize(d, textures, self.step_time as usize, 540, 42, 9, 1); draw_usize(d, textures, self.step_time as usize, 540, 42, 9, 1);
draw_usize(d, textures, self.max_step_time as usize, 540, 58, 9, 1);
d.draw_text("input:", 603, 8, 10, Color::WHITE); d.draw_text("input:", 603, 8, 10, Color::WHITE);
if simple_button(d, 600, 20, 35, 15) { if simple_button(d, 600, 20, 35, 15) {