From 8a2214f2fbf041f1e9885420f1d0959519ea5d89 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 17 Nov 2025 01:10:46 +0000 Subject: [PATCH] Simulation only runs if SPACE is held or PERIOD is pressed. KEY_SPACE, held, will keep the simulation running. KEY_PERIOD will do exactly one iteration per press. --- src/main.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a1743bf..4668b25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,9 +154,9 @@ int main(void) std::stringstream format_stream; std::string format_str; word_t format_str_width = 0; - Fraction previous_leftmost, previous_rightmost; // Setup timer + bool is_playing = false; auto time_current = Clock::now(); auto time_previous = time_current; constexpr auto time_delta = 1; @@ -166,8 +166,9 @@ int main(void) { // timer logic time_current = Clock::now(); - if (std::chrono::duration_cast(time_current - time_previous).count() >= - time_delta) + if (is_playing && + std::chrono::duration_cast(time_current - time_previous).count() >= + time_delta) { time_previous = time_current; state.do_iteration(); @@ -175,7 +176,16 @@ int main(void) } // Input logic - if (IsKeyPressed(KEY_SPACE)) + if (IsKeyDown(KEY_SPACE)) + { + is_playing = true; + } + else if (IsKeyUp(KEY_SPACE)) + { + is_playing = false; + } + + if (IsKeyPressed(KEY_PERIOD)) { state.do_iteration(); count += 2;