From acb8e8163d7a5d3e048eaeaa8a6ffe06d85113f7 Mon Sep 17 00:00:00 2001 From: jonathan santis Date: Wed, 30 Oct 2024 14:56:09 +0100 Subject: [PATCH] day end --- main.zig | 25 +++++++------------------ primitives.zig | 9 +++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/main.zig b/main.zig index 316998d..ff20367 100644 --- a/main.zig +++ b/main.zig @@ -36,13 +36,10 @@ fn draw() !void { var w = Winsize{}; var i: u64 = 0; var ii: u64 = 0; - 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(); buffer_size = w.ws_row; buffer_size = buffer_size * w.ws_col * 4; @@ -51,13 +48,10 @@ fn draw() !void { defer allocator.free(buffer); definitions.obj[0].a.x = 10; - print("definitions.obj[0].a.x:{}\n", .{definitions.obj[0].a.x}); - print("definitions.obj[0].b.x:{}\n", .{definitions.obj[0].b.x}); - print("definitions.obj[9].b.x:{}\n", .{definitions.obj[9].b.x}); - _ = try stdin.readUntilDelimiterOrEof(&buf, '\n'); + wait_for_enter(); + // defer std.heap.page_allocator.free(tmp); //video loop while (true) { - buffer[0] = 0; i = 0; //clear buffer while (i < buffer.len) : (i += 4) { @@ -82,18 +76,8 @@ fn draw() !void { // mv_axis_border_bounce(w, &primitive.vec.c, 'x'); // mv_axis_border_bounce(w, &primitive.vec.c, 'y'); - // try triangle(buffer, w, primitive.vec2); - // mv_axis_border_bounce(w, &primitive.vec2.a, 'x'); - // mv_axis_border_bounce(w, &primitive.vec2.a, 'y'); - // mv_axis_border_bounce(w, &primitive.vec2.b, 'x'); - // mv_axis_border_bounce(w, &primitive.vec2.b, 'Y'); - // mv_axis_border_bounce(w, &primitive.vec2.c, 'x'); - // mv_axis_border_bounce(w, &primitive.vec2.c, 'y'); - //try triangle(buffer, w, definitions.obj.vec); - try fill_draw(w, buffer); try out.print("{s}", .{buffer}); - //_ = try stdin.readUntilDelimiterOrEof(&buf, '\n'); sleep(30000000); } } @@ -133,3 +117,8 @@ fn fill_draw(w: Winsize, buffer: []u8) !void { } } } +fn wait_for_enter() void { + _ = stdin.readUntilDelimiterAlloc(std.heap.page_allocator, '\n', 3) catch |err| { + print("string to long{}", .{err}); + }; //Memory leak? +} diff --git a/primitives.zig b/primitives.zig index 8af3136..5e581cd 100644 --- a/primitives.zig +++ b/primitives.zig @@ -24,6 +24,15 @@ pub const Triangle = struct { bufc: *i32, }; +pub const Polygon = struct{ + const Node = struct{point:Point,*Node}; + + head: *Node; + length: u32; + + pub fn new() Node { + return Node + pub fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void { const i: usize = @intCast(4 * (x + y * w.ws_col)); if (i < buffer.len) { //-1 ??