gol: Use EventLoop timers
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-11-16 22:02:31 +01:00
parent d1d53c6891
commit e97b61ef16
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -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<int> luna_main(int argc, char** argv)
{
ui::App app;
@ -112,20 +119,7 @@ Result<int> 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();
}