diff --git a/README.md b/README.md index 6b45a27..1e085d9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # DOOMFIRE -Test your TTY might! +## Test your TTY's might! ![demo](https://user-images.githubusercontent.com/76228776/149635702-a331f892-7799-4f7f-a4a6-7048d3529dcf.mp4) @@ -8,7 +8,11 @@ The doom-fire algo can push upwards of 180k a frame - results may vary! It is, As a comparable, this is the younger sibling of a node variant ( https://github.com/const-void/DOOM-fire-node ). # INSTALL -Tested on OX Monterey / M1 w/zig 0.9...unsure if it will work on Win or Linux, sadly, due to TIOCGWINSZ flag. No third party dependencies! +Tested on OX Monterey / M1 w/zig 0.9... + +EDIT: Now tested on Artix Linux - links against libc to get the size of the TTY. + +This means that the program does rely on libc, this shouldn't be a problem. ``` $ git clone https://github.com/const-void/DOOM-fire-zig/ @@ -22,6 +26,7 @@ $ zig build run * kitty.app - great * Terminal.app - poor -- seems to drop framerates * VS Code - great +* Alacritty (artix linux) - great # Inspiration / Credits * doom fire - https://github.com/filipedeschamps/doom-fire-algorithm, https://github.com/fabiensanglard/DoomFirePSX/blob/master/flames.html diff --git a/build.zig b/build.zig index 5068f9c..442d13e 100644 --- a/build.zig +++ b/build.zig @@ -12,6 +12,8 @@ pub fn build(b: *std.build.Builder) void { const mode = b.standardReleaseOptions(); const exe = b.addExecutable("DOOM-fire", "src/main.zig"); + + exe.linkLibC(); exe.setTarget(target); exe.setBuildMode(mode); exe.install(); diff --git a/src/main.zig b/src/main.zig index d94fc2f..f1ca33a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4,6 +4,9 @@ // Copy/paste as it helps! // const std = @import("std"); +const c = @cImport({ + @cInclude("sys/ioctl.h"); +}); const allocator = std.heap.page_allocator; @@ -11,7 +14,7 @@ const stdout = std.io.getStdOut().writer(); const stdin = std.io.getStdIn().reader(); /////////////////////////////////// -// Tested on M1 osx12.1 +// Tested on M1 osx12.1 + Artix Linux. // fast - vs code terminal // slow - Terminal.app /////////////////////////////////// @@ -79,8 +82,8 @@ pub fn emitFmt(comptime s: []const u8, args: anytype) void { //// Settings -//OSX specific ... maybe -const TIOCGWINSZ = 0x40087468; //ioctl flag +// Get this value from libc. +const TIOCGWINSZ = c.TIOCGWINSZ; // ioctl flag //term size const TermSz = struct { height: usize, width: usize }; @@ -143,7 +146,7 @@ pub fn initColor() void { //get terminal size given a tty pub fn getTermSz(tty: std.os.fd_t) !TermSz { - var winsz = std.os.system.winsize{ .ws_col = 0, .ws_row = 0, .ws_xpixel = 0, .ws_ypixel = 0 }; + var winsz = c.winsize{ .ws_col = 0, .ws_row = 0, .ws_xpixel = 0, .ws_ypixel = 0 }; const rv = std.os.system.ioctl(tty, TIOCGWINSZ, @ptrToInt(&winsz)); const err = std.os.errno(rv); if (rv == 0) {