From 561caf560be0ad9b9ec9e84a906c1445b602d175 Mon Sep 17 00:00:00 2001 From: jonathan santis Date: Fri, 25 Oct 2024 13:47:53 +0200 Subject: [PATCH] sadf --- main.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.zig b/main.zig index bb9d3fe..d3f1b3a 100644 --- a/main.zig +++ b/main.zig @@ -130,18 +130,19 @@ fn fillBuffer() !void { var buf = std.mem.zeroes([2]u8); var slice: []u8 = undefined; var bytes_written: u3 = 0; + var buffer_size: u32 = 0; buf[0] = 0; - w = try getTermDimension(); - const file = try std.fs.cwd().createFile("buffer.out", .{}); - defer file.close(); - var buffer = try allocator.alloc(u8, w.ws_row * w.ws_col * 4); //utf-8 can be 4 bytes long + w = try getTermDimension(); + buffer_size = w.ws_row; + buffer_size = buffer_size * w.ws_col * 4; + var buffer = try allocator.alloc(u8, buffer_size); //utf-8 can be 4 bytes long defer allocator.free(buffer); var vec = Vec3{ .a = Point{ .x = 20, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, - .b = Point{ .x = 50, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, + .b = Point{ .x = 50, .y = 40, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, }; var vec2 = Vec3{ @@ -166,7 +167,7 @@ fn fillBuffer() !void { //_ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 }); try out.print("\x1B[2J", .{}); - //sleep(1000000); + //sleep(100000); try triangle(buffer, w, vec); bounce(w, &vec.a, 'x'); @@ -233,6 +234,7 @@ fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void { if (i < buffer.len) { //-1 ?? const slice = buffer[i .. i + 4]; _ = try std.unicode.utf8Encode(symbol, slice); + //TODO: check length, set not used bytes to zero } else { //print("Error illegal memory access\n", .{}); }