mirror of
https://github.com/fairyglade/ly.git
synced 2026-09-22 12:00:19 +00:00
Add Widget.calculateTimeout function
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -33,6 +33,7 @@ frame_delay: usize,
|
||||
initial_density: f32,
|
||||
animate: *bool,
|
||||
timeout_sec: u12,
|
||||
animation_frame_delay: u16,
|
||||
dead_cell: Cell,
|
||||
width: usize,
|
||||
height: usize,
|
||||
@@ -46,6 +47,7 @@ pub fn init(
|
||||
initial_density: f32,
|
||||
animate: *bool,
|
||||
timeout_sec: u12,
|
||||
animation_frame_delay: u16,
|
||||
) !GameOfLife {
|
||||
const width = terminal_buffer.width;
|
||||
const height = terminal_buffer.height;
|
||||
@@ -68,6 +70,7 @@ pub fn init(
|
||||
.initial_density = initial_density,
|
||||
.animate = animate,
|
||||
.timeout_sec = timeout_sec,
|
||||
.animation_frame_delay = animation_frame_delay,
|
||||
.dead_cell = .{ .ch = DEAD_CHAR, .fg = @intCast(TerminalBuffer.Color.DEFAULT), .bg = terminal_buffer.bg },
|
||||
.width = width,
|
||||
.height = height,
|
||||
@@ -88,6 +91,7 @@ pub fn widget(self: *GameOfLife) Widget {
|
||||
draw,
|
||||
update,
|
||||
null,
|
||||
calculateTimeout,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -149,6 +153,10 @@ fn update(self: *GameOfLife, _: *anyopaque) !void {
|
||||
}
|
||||
}
|
||||
|
||||
fn calculateTimeout(self: *GameOfLife, _: *anyopaque) !?usize {
|
||||
return self.animation_frame_delay;
|
||||
}
|
||||
|
||||
fn updateGeneration(self: *GameOfLife) void {
|
||||
// Conway's Game of Life rules with optimized neighbor counting
|
||||
for (0..self.height) |y| {
|
||||
|
||||
Reference in New Issue
Block a user