summaryrefslogtreecommitdiff
path: root/dev/glide.zig
diff options
context:
space:
mode:
Diffstat (limited to 'dev/glide.zig')
-rw-r--r--dev/glide.zig51
1 files changed, 45 insertions, 6 deletions
diff --git a/dev/glide.zig b/dev/glide.zig
index 711acb22..62e44bb7 100644
--- a/dev/glide.zig
+++ b/dev/glide.zig
@@ -39,9 +39,13 @@ pub const Glide = struct {
dir: i8 = 0,
before: []pardes.Cell = &.{},
/// The rows past the body's top (`above`) and bottom (`below`), nearest
- /// first, `bw` cells each: what the gap shows while the picture lags.
+ /// first, `bw` cells each, and a change's lanes on each (Surface.lanes,
+ /// a pixel shell's strips in the gutter, not cells): what the gap shows
+ /// while the picture lags.
above: []pardes.Cell = &.{},
below: []pardes.Cell = &.{},
+ above_lanes: []RowLanes = &.{},
+ below_lanes: []RowLanes = &.{},
nabove: u16 = 0,
nbelow: u16 = 0,
/// The core's lines a scroll moved, not yet measured; and what the
@@ -64,8 +68,10 @@ pub const Glide = struct {
/// not move, so a move is measured, and the rows that left are kept,
/// below them.
held: [pardes.MAX_PANES]u16 = @splat(0),
- /// The last frame's cells, which a move is measured against.
+ /// The last frame's cells, which a move is measured against, and its
+ /// lanes, which the rows that left take with them.
last: []pardes.Cell = &.{},
+ last_lanes: std.ArrayList(pardes.Lane) = .empty,
last_cols: u16 = 0,
last_rows: u16 = 0,
@@ -97,7 +103,10 @@ pub const Glide = struct {
gpa.free(glide.before);
gpa.free(glide.above);
gpa.free(glide.below);
+ gpa.free(glide.above_lanes);
+ gpa.free(glide.below_lanes);
gpa.free(glide.last);
+ glide.last_lanes.deinit(gpa);
}
pub fn bw(glide: *const Glide) u16 {
@@ -188,6 +197,8 @@ pub const Glide = struct {
glide.last_cols = surface.cols;
glide.last_rows = surface.rows;
glide.caret_row = if (surface.cursor) |c| c.y else null;
+ glide.last_lanes.clearRetainingCapacity();
+ glide.last_lanes.appendSlice(gpa, surface.lanes.items) catch {};
}
/// Finds how far the pane's body rows moved, `dir` rows at a time, by
@@ -261,28 +272,56 @@ pub const Glide = struct {
const src_row: usize = top + if (glide.dir > 0) shift - 1 - i else h - shift + i;
@memcpy(keep.*[i * w ..][0..w], glide.before[src_row * w ..][0..w]);
}
+ // Their lanes go with them, from the frame they left.
+ const keep_lanes = if (glide.dir > 0) glide.above_lanes else glide.below_lanes;
+ std.mem.copyBackwards(RowLanes, keep_lanes[shift..][0..kept], keep_lanes[0..kept]);
+ @memset(keep_lanes[0..shift], .{});
+ for (glide.last_lanes.items) |lane| {
+ if (lane.x < x0 or lane.x >= x0 + w or lane.y < glide.body_y + top or lane.y >= glide.body_y + glide.body_h) continue;
+ const row = lane.y - glide.body_y - top;
+ if (glide.dir > 0 and row < shift) keep_lanes[shift - 1 - row].add(lane);
+ if (glide.dir < 0 and row >= h - shift) keep_lanes[row - (h - shift)].add(lane);
+ }
count.* = kept + shift;
// What came into view is no longer past the other edge.
const other = if (glide.dir > 0) &glide.below else &glide.above;
+ const other_lanes = if (glide.dir > 0) glide.below_lanes else glide.above_lanes;
const other_n = if (glide.dir > 0) &glide.nbelow else &glide.nabove;
// ...and after a jump, the rows past it are another place's.
const dropped = if (far) other_n.* else @min(other_n.*, shift);
std.mem.copyForwards(pardes.Cell, other.*[0 .. @as(usize, other_n.* - dropped) * w], other.*[@as(usize, dropped) * w ..][0 .. @as(usize, other_n.* - dropped) * w]);
+ std.mem.copyForwards(RowLanes, other_lanes[0 .. other_n.* - dropped], other_lanes[dropped..][0 .. other_n.* - dropped]);
other_n.* -= dropped;
// An input: the core's rows moved by as many (down positive).
glide.follow.kick(@as(f32, @floatFromInt(shift)) * @as(f32, @floatFromInt(glide.dir)), glide.now_ns, glide.pace());
}
pub fn ensure(glide: *Glide, gpa: std.mem.Allocator) bool {
- const n = @as(usize, glide.bw()) * glide.body_h * reach;
- inline for (.{ &glide.above, &glide.below }) |buffer| if (buffer.len < n) {
- const grown = gpa.realloc(buffer.*, n) catch return false;
- buffer.* = grown;
+ const rows = @as(usize, glide.body_h) * reach;
+ inline for (.{ .{ &glide.above, rows * glide.bw() }, .{ &glide.below, rows * glide.bw() }, .{ &glide.above_lanes, rows }, .{ &glide.below_lanes, rows } }) |kept| if (kept[0].len < kept[1]) {
+ kept[0].* = gpa.realloc(kept[0].*, kept[1]) catch return false;
};
return true;
}
};
+/// A kept row's lanes, as the frame it left drew them: a row has a level
+/// each at most.
+pub const RowLanes = struct {
+ n: u8 = 0,
+ lane: [pardes.Lane.levels]pardes.Lane = undefined,
+
+ pub fn add(row: *RowLanes, lane: pardes.Lane) void {
+ if (row.n == row.lane.len) return;
+ row.lane[row.n] = lane;
+ row.n += 1;
+ }
+
+ pub fn items(row: *const RowLanes) []const pardes.Lane {
+ return row.lane[0..row.n];
+ }
+};
+
pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool {
for (a, b) |x, y| {
if (x.default != y.default) return false;