Skip to content

Commit b462684

Browse files
authored
Merge pull request #21 from const-void/16-thread-integer-overflow
feat: x64 memory (c/o u64)
2 parents 548a142 + b98a589 commit b462684

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The doom-fire algo can push upwards of 180k a frame - results may vary! It is,
88
As a comparison, this is the younger sibling of a node variant ( https://github.com/const-void/DOOM-fire-node ).
99

1010
# INSTALL
11-
Tested on OX Sequia 15.2 / M1 w/zig 0.13...
11+
Each MR tested on OX Sequia 15.2 / M1 w/zig 0.13 on OSX Kitty, VS Code, Alacritty, Terminal.
1212

1313
EDIT: Now tested on Artix Linux - links against libc to get the size of the TTY.
1414

@@ -25,13 +25,15 @@ $ zig build run
2525

2626
# Results
2727
* iTerm.app - ok
28-
* kitty.app - great
29-
* Terminal.app - poor -- seems to drop framerates
30-
* VS Code - great
28+
* kitty.app (OSX) - great
29+
* Terminal.app (OSX) - poor -- seems to drop framerates
30+
* VS Code (Linux, OSX) - great
3131
* Warp - great
32-
* Alacritty (artix linux) - great
32+
* Alacritty (artix linux, OSX) - great
3333
* Powershell/CMD
3434

35+
Note: Currently uses `u64` and thus is limited to x64 architecture, for now. In the future, will convert to a comptime approach for greater flexibility.
36+
3537
# Inspiration / Credits
3638
* Thanks to contributors for your support!
3739

src/main.zig

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ var stdin: std.fs.File.Reader = undefined;
1717
// slow - Terminal.app
1818
///////////////////////////////////
1919

20+
// TODO
21+
// - How can we better offer cross platform support for multiple bit architectures?
22+
// Currently memory is fixed w/x64 unsigned integers to support high res displays.
23+
// This should probably be a comptime setting so that the integer size can be identified
24+
// based on platform (x64 vs x86 vs ... ).
25+
2026
///////////////////////////////////
2127
// credits / helpful articles / inspirations
2228
///////////////////////////////////
@@ -474,12 +480,12 @@ const px = "▀";
474480

475481
//bs = buffer string
476482
var bs: []u8 = undefined;
477-
var bs_idx: u32 = 0;
478-
var bs_len: u32 = 0;
479-
var bs_sz_min: u32 = 0;
480-
var bs_sz_max: u32 = 0;
481-
var bs_sz_avg: u32 = 0;
482-
var bs_frame_tic: u32 = 0;
483+
var bs_idx: u64 = 0;
484+
var bs_len: u64 = 0;
485+
var bs_sz_min: u64 = 0;
486+
var bs_sz_max: u64 = 0;
487+
var bs_sz_avg: u64 = 0;
488+
var bs_frame_tic: u64 = 0;
483489
var t_start: i64 = 0;
484490
var t_now: i64 = 0;
485491
var t_dur: f64 = 0.0;
@@ -548,10 +554,10 @@ pub fn freeBuf() void {
548554

549555
pub fn showDoomFire() void {
550556
//term size => fire size
551-
const FIRE_H: u32 = @as(u32, @intCast(term_sz.height)) * 2;
552-
const FIRE_W: u32 = @as(u32, @intCast(term_sz.width));
553-
const FIRE_SZ: u32 = FIRE_H * FIRE_W;
554-
const FIRE_LAST_ROW: u32 = (FIRE_H - 1) * FIRE_W;
557+
const FIRE_H: u64 = @as(u64, @intCast(term_sz.height)) * 2;
558+
const FIRE_W: u64 = @as(u64, @intCast(term_sz.width));
559+
const FIRE_SZ: u64 = FIRE_H * FIRE_W;
560+
const FIRE_LAST_ROW: u64 = (FIRE_H - 1) * FIRE_W;
555561

556562
//colors - tinker w/palette as needed!
557563
const fire_palette = [_]u8{ 0, 233, 234, 52, 53, 88, 89, 94, 95, 96, 130, 131, 132, 133, 172, 214, 215, 220, 220, 221, 3, 226, 227, 230, 195, 230 };
@@ -564,7 +570,7 @@ pub fn showDoomFire() void {
564570
defer allocator.free(screen_buf);
565571

566572
//init buffer
567-
var buf_idx: u32 = 0;
573+
var buf_idx: u64 = 0;
568574
while (buf_idx < FIRE_SZ) : (buf_idx += 1) {
569575
screen_buf[buf_idx] = fire_black;
570576
}
@@ -583,22 +589,22 @@ pub fn showDoomFire() void {
583589

584590
//scope cache ////////////////////
585591
//scope cache - update fire buf
586-
var doFire_x: u32 = 0;
587-
var doFire_y: u32 = 0;
588-
var doFire_idx: u32 = 0;
592+
var doFire_x: u64 = 0;
593+
var doFire_y: u64 = 0;
594+
var doFire_idx: u64 = 0;
589595

590596
//scope cache - spread fire
591597
var spread_px: u8 = 0;
592598
var spread_rnd_idx: u8 = 0;
593-
var spread_dst: u32 = 0;
599+
var spread_dst: u64 = 0;
594600

595601
//scope cache - frame reset
596602
const init_frame = std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ cursor_home, bg[0], fg[0] }) catch unreachable;
597603
defer allocator.free(init_frame);
598604

599605
//scope cache - fire 2 screen buffer
600-
var frame_x: u32 = 0;
601-
var frame_y: u32 = 0;
606+
var frame_x: u64 = 0;
607+
var frame_y: u64 = 0;
602608
var px_hi: u8 = fire_black;
603609
var px_lo: u8 = fire_black;
604610
var px_prev_hi = px_hi;

0 commit comments

Comments
 (0)