Skip to content

Commit

Permalink
Cross platform update -- merge branch 'JacobHin2-jacobhin2'
Browse files Browse the repository at this point in the history
  • Loading branch information
const-void committed Jan 22, 2022
2 parents be6440f + 089ddd6 commit 3f80a33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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/
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
// Copy/paste as it helps!
//
const std = @import("std");
const c = @cImport({
@cInclude("sys/ioctl.h");
});

const allocator = std.heap.page_allocator;

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
///////////////////////////////////
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3f80a33

Please sign in to comment.