diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 10:56:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | f2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch) | |
| tree | c344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /src/Kind.zig | |
| parent | fc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff) | |
| download | pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip | |
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py.
Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open.
The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home.
The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so.
The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'src/Kind.zig')
| -rw-r--r-- | src/Kind.zig | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Kind.zig b/src/Kind.zig index 6d4caec6..250e1144 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -37,10 +37,10 @@ pub const abi: u32 = c.PA_ABI; // records the core reads are the ones addons are built to. comptime { if (@sizeOf(usize) == 8) for (.{ - .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, - .{ c.pa_placement, 80 }, .{ c.pa_paint, 32 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 }, - .{ c.pa_api, 112 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, - .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 }, + .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, + .{ c.pa_placement, 80 }, .{ c.pa_paint, 48 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 }, + .{ c.pa_api, 112 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, + .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 }, }) |r| if (@sizeOf(r[0]) != r[1]) @compileError(std.fmt.comptimePrint("{s} is {d} bytes, the header says {d}", .{ @typeName(r[0]), @sizeOf(r[0]), r[1] })); } @@ -119,7 +119,6 @@ pub const Registry = struct { pub const take = Addon.take; pub const collides = Addon.collides; pub const drop = Addon.drop; - }; // ---- a pane of a kind ---- @@ -389,7 +388,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa var frame: Frame = .{ .cols = cols, .rows = rows }; if (slot.ops == null and slot.live) { const sh = slot.shadow orelse return; - frame = .{ .cells = sh.cells, .cols = sh.cols, .rows = sh.rows, .places = sh.places.items, .n = @intCast(sh.places.items.len) }; + frame = .{ .cells = sh.cells, .cols = sh.cols, .rows = sh.rows, .places = sh.places.items, .n = @intCast(sh.places.items.len), .gpu = sh.gpu }; } else if (slot.ops == null) { var line: [160]u8 = undefined; const why = if (slot.refused.len > 0) slot.refused.slice() else "Addon load <path>"; @@ -398,6 +397,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa _ = s.print(x, y, cols, text, .{ .fg = fg, .bg = bg }); return; } else frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return); + if (frame.gpu.len != 0) s.gpu_frames[id] = .{ .bytes = frame.gpu, .serial = pane.serial, .dst = .{ .x = x, .y = y, .w = cols, .h = rows } }; for (0..@min(rows, frame.rows)) |r| for (0..@min(cols, frame.cols)) |col| { const cell = &frame.cells[r * frame.cols + col]; if (cell.flags & c.PA_PAINTED == 0) continue; @@ -423,6 +423,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa /// A frame of a kind's pane: its cells, `cols` a row, and its placements. pub const Frame = struct { + gpu: []const u8 = &.{}, cells: []c.pa_cell = &.{}, cols: u16, rows: u16, @@ -438,7 +439,8 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, const ops = slot.ops orelse return null; const cells = arena.alloc(c.pa_cell, @as(usize, cols) * rows) catch return null; @memset(std.mem.sliceAsBytes(cells), 0); - var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len }); + var gpu: GpuPaint = .{ .arena = arena, .frame = frame }; + var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len, .gpu = GpuPaint.emit, .gpu_ctx = &gpu }); const px = p.view().cell_pixels; const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images) }); var cl: Call = .{ .p = null, .id = 0, .slot = slot, .quiet = true }; @@ -1206,3 +1208,14 @@ test "a kind's head is checked before a core takes it, and a core's kinds are it a.drop(a.byName("zzzab").?); try std.testing.expect(a.byName("zzzab") == null); } + +const GpuPaint = struct { + arena: std.mem.Allocator, + frame: *Frame, + fn emit(ctx: ?*anyopaque, bytes: [*c]const u8, n: u32) callconv(.c) c_int { + const self: *GpuPaint = @ptrCast(@alignCast(ctx orelse return 1)); + if (bytes == null or n > 4 << 20) return 1; + self.frame.gpu = self.arena.dupe(u8, bytes[0..n]) catch return 1; + return 0; + } +}; |
