changes fire parameters

This commit is contained in:
Matthew Rothlisberger 2025-07-07 21:01:36 -04:00
parent 2a8e221e80
commit 99f3ab96ba
4 changed files with 19 additions and 32 deletions

View File

@ -107,15 +107,14 @@ default_input = login
# DOOM animation fire height (1 thru 9) # DOOM animation fire height (1 thru 9)
doom_fire_height = 6 doom_fire_height = 6
# DOOM animation use natural fire colors # DOOM animation fire spread (0 thru 4)
# If false, below custom colors used doom_fire_spread = 2
doom_default_colors = true
# DOOM animation custom top color (low intensity flames) # DOOM animation custom top color (low intensity flames)
doom_top_color = 0x00FF0000 doom_top_color = 0x009F2707
# DOOM animation custom middle color (medium intensity flames) # DOOM animation custom middle color (medium intensity flames)
doom_middle_color = 0x00FFFF00 doom_middle_color = 0x00C78F17
# DOOM animation custom bottom color (high intensity flames) # DOOM animation custom bottom color (high intensity flames)
doom_bottom_color = 0x00FFFFFF doom_bottom_color = 0x00FFFFFF

View File

@ -7,34 +7,21 @@ const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
const Doom = @This(); const Doom = @This();
pub const STEPS = 12; pub const STEPS = 12;
pub const HEIGHT_MAX = 9;
pub const SPREAD_MAX = 4;
allocator: Allocator, allocator: Allocator,
terminal_buffer: *TerminalBuffer, terminal_buffer: *TerminalBuffer,
buffer: []u8, buffer: []u8,
height: u8, height: u8,
spread: u8,
fire: [STEPS + 1]Cell, fire: [STEPS + 1]Cell,
pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fire_height: u8, default_colors: bool, top_color: u32, middle_color: u32, bottom_color: u32) !Doom { pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, top_color: u32, middle_color: u32, bottom_color: u32, fire_height: u8, fire_spread: u8) !Doom {
const buffer = try allocator.alloc(u8, terminal_buffer.width * terminal_buffer.height); const buffer = try allocator.alloc(u8, terminal_buffer.width * terminal_buffer.height);
initBuffer(buffer, terminal_buffer.width); initBuffer(buffer, terminal_buffer.width);
const levels = if (default_colors) const levels =
[_]Cell{
Cell.init(' ', TerminalBuffer.Color.DEFAULT, TerminalBuffer.Color.DEFAULT),
Cell.init(0x2591, 0x009F2707, TerminalBuffer.Color.DEFAULT),
Cell.init(0x2592, 0x009F2707, TerminalBuffer.Color.DEFAULT),
Cell.init(0x2593, 0x009F2707, TerminalBuffer.Color.DEFAULT),
Cell.init(0x2588, 0x009F2707, TerminalBuffer.Color.DEFAULT),
Cell.init(0x2591, 0x00C78F17, 0x009F2707),
Cell.init(0x2592, 0x00C78F17, 0x009F2707),
Cell.init(0x2593, 0x00C78F17, 0x009F2707),
Cell.init(0x2588, 0x00C78F17, 0x009F2707),
Cell.init(0x2591, 0x00FFFFFF, 0x00C78F17),
Cell.init(0x2592, 0x00FFFFFF, 0x00C78F17),
Cell.init(0x2593, 0x00FFFFFF, 0x00C78F17),
Cell.init(0x2588, 0x00FFFFFF, 0x00C78F17),
}
else
[_]Cell{ [_]Cell{
Cell.init(' ', TerminalBuffer.Color.DEFAULT, TerminalBuffer.Color.DEFAULT), Cell.init(' ', TerminalBuffer.Color.DEFAULT, TerminalBuffer.Color.DEFAULT),
Cell.init(0x2591, top_color, TerminalBuffer.Color.DEFAULT), Cell.init(0x2591, top_color, TerminalBuffer.Color.DEFAULT),
@ -55,7 +42,8 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fire_height:
.allocator = allocator, .allocator = allocator,
.terminal_buffer = terminal_buffer, .terminal_buffer = terminal_buffer,
.buffer = buffer, .buffer = buffer,
.height = @min(9, fire_height), .height = @min(HEIGHT_MAX, fire_height),
.spread = @min(SPREAD_MAX, fire_spread),
.fire = levels, .fire = levels,
}; };
} }
@ -81,11 +69,12 @@ fn draw(self: *Doom) void {
// Get index of current cell in fire level buffer // Get index of current cell in fire level buffer
const from = y * self.terminal_buffer.width + x; const from = y * self.terminal_buffer.width + x;
// Generate random datum for fire propagation // Generate random data for fire propagation
const random = (self.terminal_buffer.random.int(u8) % 10); const rand_loss = self.terminal_buffer.random.intRangeAtMost(u8, 0, HEIGHT_MAX);
const rand_spread = self.terminal_buffer.random.intRangeAtMost(u8, 0, self.spread * 2);
// Select semi-random target cell // Select semi-random target cell
const to = from -| self.terminal_buffer.width -| (random & 3) + 1; const to = from -| self.terminal_buffer.width + self.spread -| rand_spread;
const to_x = to % self.terminal_buffer.width; const to_x = to % self.terminal_buffer.width;
const to_y = to / self.terminal_buffer.width; const to_y = to / self.terminal_buffer.width;
@ -93,9 +82,8 @@ fn draw(self: *Doom) void {
const level_buf_from = self.buffer[from]; const level_buf_from = self.buffer[from];
// Choose new fire level and store in level buffer // Choose new fire level and store in level buffer
var level_buf_to = level_buf_from; const level_buf_to = level_buf_from -| @intFromBool(rand_loss >= self.height);
if (random >= self.height) level_buf_to -|= 1; self.buffer[to] = level_buf_to;
self.buffer[to] = @intCast(level_buf_to);
// Send known fire levels to terminal buffer // Send known fire levels to terminal buffer
const from_cell = self.fire[level_buf_from]; const from_cell = self.fire[level_buf_from];

View File

@ -30,7 +30,7 @@ colormix_col2: u32 = 0x000000FF,
colormix_col3: u32 = 0x20000000, colormix_col3: u32 = 0x20000000,
default_input: Input = .login, default_input: Input = .login,
doom_fire_height: u8 = 6, doom_fire_height: u8 = 6,
doom_default_colors: bool = true, doom_fire_spread: u8 = 2,
doom_top_color: u32 = 0x00FF0000, doom_top_color: u32 = 0x00FF0000,
doom_middle_color: u32 = 0x00FFFF00, doom_middle_color: u32 = 0x00FFFF00,
doom_bottom_color: u32 = 0x00FFFFFF, doom_bottom_color: u32 = 0x00FFFFFF,

View File

@ -354,7 +354,7 @@ pub fn main() !void {
animation = dummy.animation(); animation = dummy.animation();
}, },
.doom => { .doom => {
var doom = try Doom.init(allocator, &buffer, config.doom_fire_height, config.doom_default_colors, config.doom_top_color, config.doom_middle_color, config.doom_bottom_color); var doom = try Doom.init(allocator, &buffer, config.doom_top_color, config.doom_middle_color, config.doom_bottom_color, config.doom_fire_height, config.doom_fire_spread);
animation = doom.animation(); animation = doom.animation();
}, },
.matrix => { .matrix => {