From e97b61ef1669b1a20a6de4cbb9c2d577c205d8c2 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 16 Nov 2023 22:02:31 +0100 Subject: [PATCH] gol: Use EventLoop timers --- apps/gol.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/apps/gol.cpp b/apps/gol.cpp index 2f7c1162..08e0324c 100644 --- a/apps/gol.cpp +++ b/apps/gol.cpp @@ -101,6 +101,13 @@ static void next_generation() for (isize i = 0; i < (g_num_rows * g_num_columns); i++) g_cells[i].state = g_cells[i].new_state; } +static void update() +{ + next_generation(); + draw_cells(); + os::EventLoop::the().register_timer(100, update); +} + Result luna_main(int argc, char** argv) { ui::App app; @@ -112,20 +119,7 @@ Result luna_main(int argc, char** argv) TRY(fill_cells()); - int counter = 0; + os::EventLoop::the().register_timer(100, update); - while (app.process_events()) - { - if (counter >= 10) - { - next_generation(); - draw_cells(); - counter = 0; - } - else - counter++; - usleep(10000); - } - - return 0; + return app.run(); }