fixing some things

This commit is contained in:
2026-04-14 06:26:38 -05:00
parent f812b09c8c
commit 43129e95c7
2 changed files with 80 additions and 15 deletions
+44
View File
@@ -0,0 +1,44 @@
const std = @import("std");
const mem = std.mem;
const Allocator = mem.Allocator;
const Matrix = @import("../grome/matrix.zig").Matrix;
/// DoubleBufferWriter manages two buffers for efficient rendering: a display buffer
/// showing the current screen state, and a write buffer for accumulating changes
/// that will be committed to the display on the next render cycle. This ABO
/// approach minimizes unnecessary updates by only diffing changed cells.
pub fn DoubleBufferWriter(width: usize, height: usize) type {
return struct {
// display holds the existing data.
display: Matrix(Cell, width, height),
// write is where we are writing the active changes which will be commited
// on the next rendering
write: Matrix(Cell, width, height),
pub fn init(gpa: Allocator, len: usize) DoubleBufferWriter {
const display = gpa.alloc(Cell, len);
const write = gpa.alloc(Cell, len);
return .{
.display = display,
.write = write,
};
}
pub fn deinit(self: *@This(), gpa: Allocator) void {
gpa.free(self.display);
gpa.free(self.write);
}
};
}
pub const Cell = struct {
char: [8]u8,
width: usize,
/// eql returns
pub fn eql(self: *const Cell, b: *const Cell) bool {
return mem.eql(u8, self.char, b.char) and self.width == b.width;
}
};