summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 15:23:45 -0300
committerGabriel Schneider <[email protected]>2026-10-24 21:00:32 -0300
commita9e33e52d789c7433da1da17a8c82093c9114243 (patch)
tree0fb83bc2be369b5a36c86ce8173fb9114503528b /src/gui
parente28b0992e9cd8dcedea5ed435566277ee6a93d5b (diff)
downloadpardes-a9e33e52d789c7433da1da17a8c82093c9114243.tar.gz
pardes-a9e33e52d789c7433da1da17a8c82093c9114243.zip
anim 7: what the probe found: the paced wait spins (asleep, the CPU's clock fell and an input's frame took 2-5x as long), a glide measures the core's line count first and emits only the rows it shows, a far jump paints only its view, a long line 16 KB round the caret, the caret's sideways scroll measured from the view's edge, a paint never joined on the loop nor asked while the view stands still, rewritten generated panes do not glide, pictures decode off the loop
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig77
1 files changed, 52 insertions, 25 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 1a56ecd0..5d3cbafd 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -4126,8 +4126,8 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
// tick, skipping (never bunching) the ticks a slow frame missed.
tick = if (g.pace_ns != 0 and now -| g.pace_ns < 2 * period) g.pace_ns + period else now;
if (tick < now) tick += (now - tick) / period * period;
- const left: c_int = @intCast(@min(std.math.maxInt(c_int), (tick -| now) / std.time.ns_per_ms));
- ms = if (ms < 0) left else @min(ms, left);
+ // Waited out polling, below.
+ ms = 0;
}
g.input_seen = false;
// The wait is the 9P connections' turn with the core.
@@ -4177,16 +4177,25 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
// never adds a tick to an input's latency), and the ticks after it
// run from it.
if (paced and g.input_seen) tick = c.SDL_GetTicksNS();
+ // The tick is waited out polling, not asleep, as a game's frame
+ // limiter spins: asleep between 60 Hz frames, the CPU's clock fell
+ // (intel_pstate, 4.9 GHz down toward 0.8) and every frame, an
+ // input's first among them, took 2-5x as long: input-to-present p50
+ // 1.9 ms spinning against 7-8 ms asleep (docs/next-anim.md).
+ // ponytail: a core while something moves (~250 ms a scroll); a
+ // sleep to a millisecond short of the tick if the power matters more.
while (paced and !g.input_seen) {
- const left = tick -| c.SDL_GetTicksNS();
- if (left < std.time.ns_per_ms) break;
- const wait_ms: c_int = @intCast(@min(left / std.time.ns_per_ms, @as(u64, @intCast(demoDue(g) orelse std.math.maxInt(c_int)))));
+ if (tick -| c.SDL_GetTicksNS() < 50 * std.time.ns_per_us) break;
pardes.turn.rest();
- const more = c.SDL_WaitEventTimeout(&sev, wait_ms);
+ const more = c.SDL_PollEvent(&sev);
pardes.turn.wake();
if (more) {
dispatch(g, &in, &sev);
while (c.SDL_PollEvent(&sev)) dispatch(g, &in, &sev);
+ } else {
+ // The events asked for every 100 µs, the core busy between.
+ const until = c.SDL_GetTicksNS() + 100 * std.time.ns_per_us;
+ while (c.SDL_GetTicksNS() < @min(until, tick)) std.atomic.spinLoopHint();
}
runDemo(g, &in, core);
if (g.input_seen) tick = c.SDL_GetTicksNS();
@@ -5071,7 +5080,7 @@ const Glide = struct {
/// whatever moved it.
/// When the picture was last sampled (sample).
shown_ns: u64 = 0,
- seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0 } = @splat(.{}),
+ seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0, revision: u32 = 0 } = @splat(.{}),
/// How far the picture may lag, in bodies: the rows kept past each
/// edge, so a jump made while one glides carries on from where it is.
@@ -5152,23 +5161,31 @@ const Glide = struct {
}
};
// The least shift under which the rows agree, but for a few: the
- // cursor's line and its number's weight move with the scroll.
- var shift: u16 = found: for (1..h) |k| {
- const kk: u16 = @intCast(k);
- const allowed = @max(2, (h - kk) / 8);
- var misses: usize = 0;
- for (0..h - kk) |r| {
- const rr: u16 = @intCast(r);
- const old_row = glide.before[@as(usize, if (glide.dir > 0) rr + kk else rr) * w ..][0..w];
- const new_row = now.row(surface, x0, glide.body_y + if (glide.dir > 0) rr else rr + kk, w);
- if (!sameRow(old_row, new_row)) {
- misses += 1;
- if (misses > allowed) continue :found;
+ // cursor's line and its number's weight move with the scroll. The
+ // lines the core moved are tried first: unwrapped, they are the
+ // rows, and one pass over the body settles it (the search over
+ // every shift was 6 ms of the first frame of a page in Debug).
+ const agrees = struct {
+ fn at(gl: *const Glide, surf: *const pardes.Surface, x: u16, width: u16, height: u16, kk: u16) bool {
+ if (kk == 0 or kk + 3 > height) return false;
+ const allowed = @max(2, (height - kk) / 8);
+ var misses: usize = 0;
+ for (0..height - kk) |r| {
+ const rr: u16 = @intCast(r);
+ const old_row = gl.before[@as(usize, if (gl.dir > 0) rr + kk else rr) * width ..][0..width];
+ const new_row = now.row(surf, x, gl.body_y + if (gl.dir > 0) rr else rr + kk, width);
+ if (!sameRow(old_row, new_row)) {
+ misses += 1;
+ if (misses > allowed) return false;
+ }
}
+ return true;
}
- // Too few rows left to tell: none in common.
- if (h - kk < 3) break :found 0;
- break :found kk;
+ };
+ const guess: u16 = @intFromFloat(@min(glide.pending_lines, @as(f32, @floatFromInt(h))));
+ // A body's lines or more: every row moved off, none in common.
+ var shift: u16 = if (guess >= h) 0 else if (agrees.at(glide, surface, x0, w, h, guess)) guess else found: for (1..h) |k| {
+ if (agrees.at(glide, surface, x0, w, h, @intCast(k))) break :found @intCast(k);
} else 0;
// None in common: a body's move from the last frame's body, if the
// lines moved are that many (rows that merely changed, a small
@@ -5285,9 +5302,14 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
};
const line: i64 = if (pane.file) |f| @intCast(f.scroll) else if (pane.isTerminal()) pardes.panes.terminal.gridOffset(pane) else 0;
const file: u64 = if (pane.file) |f| std.hash.Wyhash.hash(0, f.path) else 0;
+ const revision: u32 = if (pane.file) |f| f.revision else 0;
const was = glide.seen[id];
- glide.seen[id] = .{ .serial = pane.serial, .line = line, .file = file };
+ glide.seen[id] = .{ .serial = pane.serial, .line = line, .file = file, .revision = revision };
if (was.serial != pane.serial or was.file != file or was.line == line or pane.collapsed or pane.hasPdf()) continue;
+ // Generated text rewritten as its view moved (a query pane's live
+ // rows, a +Search refilled, Callstack): the rows are another
+ // text's, not this one's moved; it lands.
+ if (pane.file) |f| if (f.output != null and revision != was.revision) continue;
if (pane.file == null and wheeled != id) continue;
if (g.scroll_pane == id and (g.scroll_lag != 0 or g.scroll_delta != 0)) continue;
const moved = line - was.line;
@@ -5350,8 +5372,13 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32);
const cursor_bar = if (surface.cursor) |cu| cu.bar else false;
var n: u32 = 0;
- var row = y0 + kept.rows;
- while (row < y0 + bh) : (row += 1) {
+ // Only the rows the scissor shows: lagging a body or more, every body
+ // row is past the edge, and drawing them all was twice the frame's
+ // instances for the length of a long glide.
+ const lag: u16 = @intFromFloat(@min(@floor(@abs(glide.offset)), @as(f32, @floatFromInt(bh))));
+ var row = y0 + kept.rows + if (glide.offset > 0) lag else 0;
+ const row_end = y0 + bh - if (glide.offset < 0) lag else 0;
+ while (row < row_end) : (row += 1) {
const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols];
const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null;
var col = x0;