From c1fe1abfca0f90b36f3e5f763fffe67d5d8cd5ae Mon Sep 17 00:00:00 2001 From: Jacob Hinchliffe Date: Sun, 16 Jan 2022 21:35:03 +0000 Subject: [PATCH] Resolve the conflicts --- build.zig | 1 - src/main.zig | 91 ++++++++++++++++++---------------------------------- 2 files changed, 31 insertions(+), 61 deletions(-) diff --git a/build.zig b/build.zig index 13c66c4..442d13e 100644 --- a/build.zig +++ b/build.zig @@ -13,7 +13,6 @@ pub fn build(b: *std.build.Builder) void { const exe = b.addExecutable("DOOM-fire", "src/main.zig"); - exe.addIncludeDir("src"); exe.linkLibC(); exe.setTarget(target); exe.setBuildMode(mode); diff --git a/src/main.zig b/src/main.zig index 8541eb2..2ece217 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4,8 +4,6 @@ // Copy/paste as it helps! // const std = @import("std"); - -// Gets the correct TIOCGWINSZ value from libc. const c = @cImport({ @cInclude("sys/ioctl.h"); }); @@ -16,7 +14,7 @@ const stdout = std.io.getStdOut().writer(); const stdin = std.io.getStdIn().reader(); /////////////////////////////////// -// Tested on M1 osx12.1 + Linux +// Tested on M1 osx12.1 + Artix Linux. // fast - vs code terminal // slow - Terminal.app /////////////////////////////////// @@ -40,7 +38,7 @@ const stdin = std.io.getStdIn().reader(); /////////////////////////////////// // do or do not - there is no try: catch unreachable instead of try on memory / file io // - put all try to initXXX() -// for (i=0; i var i=0; while (i var i=0; while (i 243) { fg_idx = 0; emit(fg[fg_idx]); } emit(bg[bg_idx]); - emit_fmt("{u}{d} ", .{ sep, bg_idx }); + emitFmt("{u}{d} ", .{ sep, bg_idx }); } emit(nl); @@ -388,14 +376,10 @@ pub fn scrollMarquee() void { var fade_idx: u8 = 0; var txt_idx: u8 = 0; - while (txt_idx < txt_len) { - defer txt_idx += 1; - + while (txt_idx < txt_len) : (txt_idx += 1) { //fade in fade_idx = 0; - while (fade_idx < fade_len) { - defer fade_idx += 1; - + while (fade_idx < fade_len) : (fade_idx += 1) { //reset to 1,1 of marquee emit(cursor_load); emit(bg[bg_idx]); @@ -418,9 +402,7 @@ pub fn scrollMarquee() void { //fade out fade_idx = fade_len - 1; - while (fade_idx > 0) { - defer fade_idx -= 1; - + while (fade_idx > 0) : (fade_idx -= 1) { //reset to 1,1 of marquee emit(cursor_load); emit(bg[bg_idx]); @@ -524,7 +506,7 @@ pub fn paintBuf() void { fps = @intToFloat(f64, bs_frame_tic) / t_dur; emit(fg[0]); - emit_fmt("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 }); + 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 }); } // initBuf(); defer freeBuf(); @@ -551,16 +533,13 @@ pub fn showDoomFire() void { //init buffer var buf_idx: u16 = 0; - while (buf_idx < FIRE_SZ) { - defer buf_idx += 1; - + while (buf_idx < FIRE_SZ) : (buf_idx += 1) { screen_buf[buf_idx] = fire_black; } //last row is white...white is "fire source" buf_idx = 0; - while (buf_idx < FIRE_W) { - defer buf_idx += 1; + while (buf_idx < FIRE_W) : (buf_idx += 1) { screen_buf[FIRE_LAST_ROW + buf_idx] = fire_white; } @@ -603,13 +582,9 @@ pub fn showDoomFire() void { //update fire buf doFire_x = 0; - while (doFire_x < FIRE_W) { - defer doFire_x += 1; - + while (doFire_x < FIRE_W) : (doFire_x += 1) { doFire_y = 0; - while (doFire_y < FIRE_H) { - defer doFire_y += 1; - + while (doFire_y < FIRE_H) : (doFire_y += 1) { doFire_idx = doFire_y * FIRE_W + doFire_x; //spread fire @@ -636,14 +611,10 @@ pub fn showDoomFire() void { // for each row frame_y = 0; - while (frame_y < FIRE_H) { - defer frame_y += 2; // 'paint' two rows at a time because of half height char - + while (frame_y < FIRE_H) : (frame_y += 2) { // 'paint' two rows at a time because of half height char // for each col frame_x = 0; - while (frame_x < FIRE_W) { - defer frame_x += 1; - + while (frame_x < FIRE_W) : (frame_x += 1) { //each character rendered is actually to rows of 'pixels' // - "hi" (current px row => fg char) // - "low" (next row => bg color)