Resolve merge conflict

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
Titanium Brain
2026-05-09 21:06:45 +02:00
committed by AnErrupTion
parent f6c44d5e57
commit 692ca9f7b5
2 changed files with 16 additions and 41 deletions

View File

@@ -381,6 +381,12 @@ pub fn setCell(x: usize, y: usize, cell: Cell) void {
); );
} }
pub fn setCellBoundsChecked(self: *TerminalBuffer, x: isize, y: isize, cell: Cell) void {
if (0 <= x and x < self.width and 0 <= y and y < self.height) {
cell.put(@intCast(x), @intCast(y));
}
}
pub fn reclaim(self: TerminalBuffer) !void { pub fn reclaim(self: TerminalBuffer) !void {
if (self.termios) |termios| { if (self.termios) |termios| {
// Take back control of the TTY // Take back control of the TTY

View File

@@ -311,7 +311,6 @@ io: std.Io,
terminal_buffer: *TerminalBuffer, terminal_buffer: *TerminalBuffer,
dur_movie: DurFormat, dur_movie: DurFormat,
frames: usize, frames: usize,
frame_size: UVec2,
start_pos: IVec2, start_pos: IVec2,
full_color: bool, full_color: bool,
animate: *bool, animate: *bool,
@@ -329,14 +328,11 @@ fn center(v: u32) i64 {
} }
fn calc_start_position(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat, offset_alignment: DurOffsetAlignment, offset: IVec2) IVec2 { fn calc_start_position(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat, offset_alignment: DurOffsetAlignment, offset: IVec2) IVec2 {
const buf_width: u32 = @intCast(terminal_buffer.width); const buf_width: i64 = @intCast(terminal_buffer.width);
const buf_height: u32 = @intCast(terminal_buffer.height); const buf_height: i64 = @intCast(terminal_buffer.height);
var movie_width: u32 = @intCast(dur_movie.columns.?); const movie_width: i64 = @intCast(dur_movie.columns.?);
var movie_height: u32 = @intCast(dur_movie.lines.?); const movie_height: i64 = @intCast(dur_movie.lines.?);
if (movie_width > buf_width) movie_width = buf_width;
if (movie_height > buf_height) movie_height = buf_height;
const start_pos: IVec2 = switch (offset_alignment) { const start_pos: IVec2 = switch (offset_alignment) {
DurOffsetAlignment.center => .{ center(buf_width) - center(movie_width), center(buf_height) - center(movie_height) }, DurOffsetAlignment.center => .{ center(buf_width) - center(movie_width), center(buf_height) - center(movie_height) },
@@ -353,20 +349,6 @@ fn calc_start_position(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat,
return start_pos + offset; return start_pos + offset;
} }
fn calc_frame_size(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat) UVec2 {
const buf_width: u32 = @intCast(terminal_buffer.width);
const buf_height: u32 = @intCast(terminal_buffer.height);
const movie_width: u32 = @intCast(dur_movie.columns.?);
const movie_height: u32 = @intCast(dur_movie.lines.?);
// Draw only the needed amount if movie smaller than screen. If movie is bigger, we will just draw entire screen
const frame_width = if (movie_width < buf_width) movie_width else buf_width;
const frame_height = if (movie_height < buf_height) movie_height else buf_height;
return .{ frame_width, frame_height };
}
pub fn init( pub fn init(
allocator: Allocator, allocator: Allocator,
io: std.Io, io: std.Io,
@@ -405,7 +387,6 @@ pub fn init(
const offset: IVec2 = .{ x_offset, y_offset }; const offset: IVec2 = .{ x_offset, y_offset };
const start_pos = calc_start_position(terminal_buffer, &dur_movie, offset_alignment, offset); const start_pos = calc_start_position(terminal_buffer, &dur_movie, offset_alignment, offset);
const frame_size = calc_frame_size(terminal_buffer, &dur_movie);
// Convert dur fps to frames per ms // Convert dur fps to frames per ms
const frame_time: u32 = @trunc(1000 / dur_movie.framerate.?); const frame_time: u32 = @trunc(1000 / dur_movie.framerate.?);
@@ -418,7 +399,6 @@ pub fn init(
.terminal_buffer = terminal_buffer, .terminal_buffer = terminal_buffer,
.frames = 0, .frames = 0,
.time_previous = std.Io.Timestamp.now(io, .real).toMilliseconds(), .time_previous = std.Io.Timestamp.now(io, .real).toMilliseconds(),
.frame_size = frame_size,
.start_pos = start_pos, .start_pos = start_pos,
.full_color = full_color, .full_color = full_color,
.animate = animate, .animate = animate,
@@ -453,9 +433,8 @@ fn deinit(self: *DurFile) void {
} }
fn realloc(self: *DurFile) !void { fn realloc(self: *DurFile) !void {
// when terminal size changes, we need to recalculate the start_pos and frame_size based on the new size // when terminal size changes, we need to recalculate the start_pos based on the new size
self.start_pos = calc_start_position(self.terminal_buffer, &self.dur_movie, self.offset_alignment, self.offset); self.start_pos = calc_start_position(self.terminal_buffer, &self.dur_movie, self.offset_alignment, self.offset);
self.frame_size = calc_frame_size(self.terminal_buffer, &self.dur_movie);
} }
fn draw(self: *DurFile) void { fn draw(self: *DurFile) void {
@@ -463,24 +442,14 @@ fn draw(self: *DurFile) void {
const current_frame = self.dur_movie.frames.items[self.frames]; const current_frame = self.dur_movie.frames.items[self.frames];
const buf_width: u32 = @intCast(self.terminal_buffer.width);
const buf_height: u32 = @intCast(self.terminal_buffer.height);
// y is used as an iterator in the durformat, while cell_y gives us the correct placement for the cell (same for x) // y is used as an iterator in the durformat, while cell_y gives us the correct placement for the cell (same for x)
for (0..self.frame_size[VEC_Y]) |y| { for (0..@intCast(self.dur_movie.lines)) |y| {
const y_offset_i = @as(i32, @intCast(y)) + self.start_pos[VEC_Y]; const cell_y = @as(i32, @intCast(y)) + self.start_pos[VEC_Y];
// we skip the pass if it falls outside of the draw window (ensure no int underflow)
const cell_y: u32 = if (y_offset_i >= 0 and y_offset_i < buf_height) @intCast(y_offset_i) else continue;
var iter = std.unicode.Utf8View.initUnchecked(current_frame.contents[y]).iterator(); var iter = std.unicode.Utf8View.initUnchecked(current_frame.contents[y]).iterator();
for (0..self.frame_size[VEC_X]) |x| { for (0..@intCast(self.dur_movie.columns)) |x| {
const x_offset_i = @as(i32, @intCast(x)) + self.start_pos[VEC_X]; const cell_x = @as(i32, @intCast(x)) + self.start_pos[VEC_X];
// skip pass, same as y but also increment the codepoint iter to fetch correct values in later passes
const cell_x: u32 = if (x_offset_i >= 0 and x_offset_i < buf_width) @intCast(x_offset_i) else {
_ = iter.nextCodepoint().?;
continue;
};
const codepoint: u21 = iter.nextCodepoint().?; const codepoint: u21 = iter.nextCodepoint().?;
const color_map = current_frame.colorMap[x][y]; const color_map = current_frame.colorMap[x][y];
@@ -498,7 +467,7 @@ fn draw(self: *DurFile) void {
const cell = Cell{ .ch = @intCast(codepoint), .fg = fg_color, .bg = bg_color }; const cell = Cell{ .ch = @intCast(codepoint), .fg = fg_color, .bg = bg_color };
cell.put(cell_x, cell_y); self.terminal_buffer.setCellBoundsChecked(cell_x, cell_y, cell);
} }
} }