things
This commit is contained in:
+42
-24
@@ -1,37 +1,55 @@
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
|
||||
const Allocator = mem.Allocator;
|
||||
const Matrix = @import("../grome/matrix.zig").Matrix;
|
||||
const grome = @import("root");
|
||||
|
||||
/// DoubleBufferWriter manages two buffers for efficient rendering: a display buffer
|
||||
const Allocator = mem.Allocator;
|
||||
const Matrix = grome.matrix.Matrix;
|
||||
const SubMatrix = grome.matrix.SubMatrix;
|
||||
const Point = grome.matrix.Point;
|
||||
const Rect = grome.matrix.Rect;
|
||||
|
||||
/// DoubleBuffer 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 const DoubleBuffer = struct {
|
||||
// display holds the existing data.
|
||||
display: Matrix(Cell),
|
||||
// write is where we are writing the active changes which will be commited
|
||||
// on the next rendering
|
||||
write: Matrix(Cell),
|
||||
|
||||
pub fn init(gpa: Allocator, len: usize) DoubleBufferWriter {
|
||||
const display = gpa.alloc(Cell, len);
|
||||
const write = gpa.alloc(Cell, len);
|
||||
pub fn init(gpa: Allocator, size: Rect) !DoubleBuffer {
|
||||
const display = try gpa.alloc(Cell, size.area());
|
||||
const write = try gpa.alloc(Cell, size.area());
|
||||
|
||||
return .{
|
||||
.display = display,
|
||||
.write = write,
|
||||
};
|
||||
}
|
||||
return .{
|
||||
.display = display,
|
||||
.write = write,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This(), gpa: Allocator) void {
|
||||
gpa.free(self.display);
|
||||
gpa.free(self.write);
|
||||
}
|
||||
};
|
||||
}
|
||||
pub fn deinit(self: *@This(), gpa: Allocator) void {
|
||||
gpa.free(self.display);
|
||||
gpa.free(self.write);
|
||||
}
|
||||
|
||||
pub fn frame(m: Matrix, loc: Point, size: Rect) Frame {
|
||||
return .init(m, loc, size);
|
||||
}
|
||||
};
|
||||
|
||||
/// Frame is a location in the matrix so you can change things if you want
|
||||
pub const Frame = struct {
|
||||
data: SubMatrix(Cell),
|
||||
|
||||
pub fn init(m: Matrix, loc: Point, size: Rect) Frame {
|
||||
return .{
|
||||
.data = SubMatrix(Cell).init(m, loc, size),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Cell = struct {
|
||||
char: [8]u8,
|
||||
|
||||
Reference in New Issue
Block a user