DOOM's fire algo, in zig, for 256 color terminals w/no dependencies
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update to zig 0.11.0

+20 -14
+15 -9
build.zig
··· 9 9 10 10 // Standard release options allow the person running `zig build` to select 11 11 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. 12 - const mode = b.standardReleaseOptions(); 12 + const optimize = b.standardOptimizeOption(.{}); 13 13 14 - const exe = b.addExecutable("DOOM-fire", "src/main.zig"); 14 + const exe = b.addExecutable(.{ 15 + .name = "DOOM-fire", 16 + .root_source_file = .{ .path = "src/main.zig" }, 17 + .target = target, 18 + .optimize = optimize, 19 + }); 15 20 16 21 exe.linkLibC(); 17 - exe.setTarget(target); 18 - exe.setBuildMode(mode); 19 - exe.install(); 22 + b.installArtifact(exe); 20 23 21 - const run_cmd = exe.run(); 24 + const run_cmd = b.addRunArtifact(exe); 22 25 run_cmd.step.dependOn(b.getInstallStep()); 23 26 if (b.args) |args| { 24 27 run_cmd.addArgs(args); ··· 27 30 const run_step = b.step("run", "Run the app"); 28 31 run_step.dependOn(&run_cmd.step); 29 32 30 - const exe_tests = b.addTest("src/main.zig"); 31 - exe_tests.setTarget(target); 32 - exe_tests.setBuildMode(mode); 33 + const exe_tests = b.addTest(.{ 34 + .name = "exe_tests", 35 + .root_source_file = .{ .path = "src/main.zig" }, 36 + .target = target, 37 + .optimize = optimize, 38 + }); 33 39 34 40 const test_step = b.step("test", "Run unit tests"); 35 41 test_step.dependOn(&exe_tests.step);
+5 -5
src/main.zig
··· 147 147 //get terminal size given a tty 148 148 pub fn getTermSz(tty: std.os.fd_t) !TermSz { 149 149 var winsz = c.winsize{ .ws_col = 0, .ws_row = 0, .ws_xpixel = 0, .ws_ypixel = 0 }; 150 - const rv = std.os.system.ioctl(tty, TIOCGWINSZ, @ptrToInt(&winsz)); 150 + const rv = std.os.system.ioctl(tty, TIOCGWINSZ, @intFromPtr(&winsz)); 151 151 const err = std.os.errno(rv); 152 152 if (rv == 0) { 153 153 return TermSz{ .height = winsz.ws_row, .width = winsz.ws_col }; ··· 502 502 bs_sz_avg = bs_sz_avg * (bs_frame_tic - 1) / bs_frame_tic + bs_len / bs_frame_tic; 503 503 } 504 504 505 - t_dur = @intToFloat(f64, t_now - t_start) / 1000.0; 506 - fps = @intToFloat(f64, bs_frame_tic) / t_dur; 505 + t_dur = @as(f64, @floatFromInt(t_now - t_start)) / 1000.0; 506 + fps = @as(f64, @floatFromInt(bs_frame_tic)) / t_dur; 507 507 508 508 emit(fg[0]); 509 509 emitFmt("mem: {s:.2} min / {s:.2} avg / {s:.2} max [ {d:.2} fps ]", .{ std.fmt.fmtIntSizeBin(bs_sz_min), std.fmt.fmtIntSizeBin(bs_sz_avg), std.fmt.fmtIntSizeBin(bs_sz_max), fps }); ··· 516 516 517 517 pub fn showDoomFire() void { 518 518 //term size => fire size 519 - const FIRE_H: u16 = @intCast(u16, term_sz.height) * 2; 520 - const FIRE_W: u16 = @intCast(u16, term_sz.width); 519 + const FIRE_H: u16 = @as(u16, @intCast(term_sz.height)) * 2; 520 + const FIRE_W: u16 = @as(u16, @intCast(term_sz.width)); 521 521 const FIRE_SZ: u16 = FIRE_H * FIRE_W; 522 522 const FIRE_LAST_ROW: u16 = (FIRE_H - 1) * FIRE_W; 523 523