gol: Use EventLoop timers
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d1d53c6891
commit
e97b61ef16
24
apps/gol.cpp
24
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<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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user