diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-27 01:44:07 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-27 01:44:07 +0100 |
commit | 76d407ae1bf8ad9f10a8334826ef2d1ead965229 (patch) | |
tree | b6d1bda07a5ab96122e718a36ee017e6882d2aca /src/main.cpp | |
parent | f1b878c9911124a8856370daebbfebcc65ef4827 (diff) | |
download | cw_tree-76d407ae1bf8ad9f10a8334826ef2d1ead965229.tar.gz cw_tree-76d407ae1bf8ad9f10a8334826ef2d1ead965229.tar.bz2 cw_tree-76d407ae1bf8ad9f10a8334826ef2d1ead965229.zip |
Added timer to automatically do iterations
Looks very cool.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 4ce7449..99b24d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include "./numerics.hpp" +#include <chrono> #include <cmath> #include <cstdio> #include <iostream> @@ -140,6 +141,9 @@ struct State } }; +using Clock = std::chrono::steady_clock; +using Ms = std::chrono::milliseconds; + int main(void) { // Setup state @@ -152,14 +156,31 @@ int main(void) word_t format_str_width = 0; Fraction previous_leftmost, previous_rightmost; + auto time_current = Clock::now(); + auto time_previous = time_current; + constexpr auto time_delta = 10; + InitWindow(WIDTH, HEIGHT, "Calkin-Wilf Tree"); while (!WindowShouldClose()) { + // timer logic + time_current = Clock::now(); + if (std::chrono::duration_cast<Ms>(time_current - time_previous).count() >= + time_delta) + { + time_previous = time_current; + state.do_iteration(); + count += 2; + } + + // Input logic if (IsKeyPressed(KEY_SPACE)) { state.do_iteration(); count += 2; } + + // Meta text logic if (prev_count != count) { prev_count = count; |