diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/builtins.zig | 14 | ||||
| -rw-r--r-- | src/config.zig | 4 | ||||
| -rw-r--r-- | src/gui/gui.zig | 112 | ||||
| -rw-r--r-- | src/gui/pet.zig | 215 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 10 |
5 files changed, 11 insertions, 344 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index c7b427f5..39ad9d7b 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1632,20 +1632,6 @@ pub const Changelog = struct { } }; -/// An optional SDL workspace-tag companion; never consumes input or text cells. -pub const Pet = struct { - pub const scope: Scope = .session; - pub const takes_arg = true; - pub const requires_arg = true; - pub const enabled = desktop; - pub const gui_only = true; - pub const in_window = true; - pub fn run(c: Ctx) void { - const name = std.mem.trim(u8, c.arg orelse return, " \t\r\n"); - c.p.settings.pet = std.meta.stringToEnum(@TypeOf(c.p.settings.pet), name) orelse return; - } -}; - /// Open a minimap of the file in braille dots. pub const Mini = struct { pub const takes_arg = true; diff --git a/src/config.zig b/src/config.zig index 9394f912..c8ba76bd 100644 --- a/src/config.zig +++ b/src/config.zig @@ -158,7 +158,6 @@ pub const leader_path = paths: { table.set(.Font, null); table.set(.TaglineSize, null); } - if (builtins.Pet.enabled) table.set(.Pet, null); table.set(.MessageAnimation, null); table.set(.MessageLinger, null); table.set(.MessageFall, null); @@ -794,7 +793,6 @@ pub const Runtime = struct { window_opacity: u8 = 100, window_blur: u8 = 0, window_opacity_pending: bool = true, - pet: enum { off, cat, frog } = .off, // Effective values change only after a host acknowledges the request. shell: struct { @@ -1354,8 +1352,6 @@ pub const Runtime = struct { ); try out.print("# Look hover delay: {d} frames\n", .{context.hover_delay_frames}); try out.print("# Native images: {s}\n", .{onOff(context.native_images)}); - if (std.mem.eql(u8, context.platform, "gui")) - try out.print("# Pet: {s}\n", .{@tagName(state.pet)}); } test "panel effects flip bare and are set by on and off" { diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 2c2f53c4..ee565aeb 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -13,7 +13,6 @@ const look = @import("../look.zig"); const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const deck = @import("deck.zig"); -const pet = @import("pet.zig"); const fonts = @import("../fonts.zig"); // the fallback faces const selection_pipe = @import("../selection_pipe.zig"); const c_heap = @import("c_heap"); @@ -240,9 +239,9 @@ const LoadedFallback = struct { const max_touch_points: usize = 16; const touch_scroll_tick: f32 = 0.02; -// The triangle overlay holds only the pet and the cursor's glide quad: the -// chrome is decor. -const max_overlay_vertices: usize = pet.max_vertices + 6; +// The triangle overlay holds only the cursor's glide quad: the chrome is +// decor. +const max_overlay_vertices: usize = 6; const font_px_step: f32 = 2.0; const font_px_min: f32 = 8.0; @@ -1137,7 +1136,6 @@ const Gui = struct { words: Words = .{}, touch: Touch = .{}, - pet_state: pet.State = .{}, live_ctrl: bool = false, live_alt: bool = false, @@ -1434,7 +1432,7 @@ const Group = struct { /// standing still), a group for each track in paint order (tier 2 moving and /// opening, tier 3 closing), tier 4 (floating: the notices, then the guides /// and the debug box, which the core paints over them) and tier 5 (ink: the -/// bar cursors; the pet and the cursor's glide draw after it). Tier 1 is the +/// bar cursors; the cursor's glide draws after it). Tier 1 is the /// focus lift, which does not exist yet. const Groups = struct { items: [pardes.MAX_PANES * 2 + 4]Group = @splat(.{}), @@ -5862,7 +5860,7 @@ fn renderFrame( if (!pdf_focus) core.frames.scroll = g.glide.follow.offset; core.frames.caret = caretRow(g, surface) orelse 0; const cursors_shown = groups.tracks == 0 and !quad_mode; - var overlay_count = buildOverlay(g, core, surface, sw, sh); + var overlay_count = buildOverlay(g, surface, sw, sh); if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -9882,18 +9880,15 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, if (box.bar) try addDecor(g, gpa, box.x0, box.y0, box.x1, box.y1, box.rgb, 1, null, win_w, win_h); } -/// The triangle overlay: the workspace pet and the cursor's glide, over -/// everything. +/// The triangle overlay: the cursor's glide, over everything. fn buildOverlay( g: *Gui, - core: *const pardes.Pardes, surface: *const pardes.Surface, sw: u32, sh: u32, ) u32 { if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0; var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) }; - appendWorkspacePet(g, core, surface, &builder); appendCursorGlide(g, surface, &builder); return @intCast(builder.len); } @@ -9936,81 +9931,6 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB builder.addTri(px[0][0], px[0][1], px[2][0], px[2][1], px[3][0], px[3][1], color); } -fn appendWorkspacePet(g: *Gui, core: *const pardes.Pardes, surface: *const pardes.Surface, builder: *OverlayBuilder) void { - const kind: pet.Kind = @fromBackingInt(@intCast(@backingInt(core.settings.pet))); - if (kind == .off or surface.rows == 0 or surface.cols == 0) { - g.pet_state = .{}; - return; - } - // Read only the rendered global row. No pane/column tags, status text or - // mouse targets are changed; editing the workspace tag leaves it be. - var occupied: usize = 0; - for (surface.cells[0..surface.cols], 0..) |*cell, i| { - if (cellCodepoint(cell) != ' ') occupied = i + 1; - } - const band_top: f32 = @floatFromInt(taglineBandOffset(0, builder.win_h, g.cell_h, g.tagline_height)); - const region = if (occupied >= surface.cols) null else pet.lane( - occupied, - @floatFromInt(g.tagline_width), - builder.win_w, - band_top, - @floatFromInt(g.tagline_height), - ); - // SDL's regular pump already wakes at least every 16 ms. Quantization in - // sample keeps this independent of input, render rate and scene effects, - // without creating another timer or forcing core animation ticks. - const pose = g.pet_state.sample(kind, c.SDL_GetTicks(), region) orelse return; - const ink = overlayRgb(core.chromeTheme().tag_fg); - const eye = overlayRgb(core.chromeTheme().tag_bg); - // Behind the cursor: the overlay is over the cells, so the pixels a - // cursor covers are left out. - var boxes: [max_cursors]CursorBox = undefined; - const cursors = boxes[0..cursorBoxes(g, surface, fixedCellLayout(g), builder.win_h, &boxes)]; - for (0..pet.height) |y| for (0..pet.width) |x| { - const color = pet.pixel(kind, pose, x, y); - if (color == 0) continue; - const x0 = pose.x + @as(f32, @floatFromInt(x)) * pose.scale; - const y0 = pose.y + @as(f32, @floatFromInt(y)) * pose.scale; - const covered = for (cursors) |box| { - if (x0 < box.x1 and x0 + pose.scale > box.x0 and y0 < box.y1 and y0 + pose.scale > box.y0) break true; - } else false; - if (covered) continue; - builder.addRect(x0, y0, x0 + pose.scale, y0 + pose.scale, if (color == 2) eye else ink); - }; -} - -test "pet overlay stays beyond workspace text and keeps going while its tag is edited" { - std.testing.refAllDecls(pet); - const core = try pardes.Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); - defer core.deinit(); - core.settings.pet = .cat; - var cells: [80]pardes.Cell = @splat(.{}); - const surface: pardes.Surface = .{ .cols = 80, .rows = 1, .cells = &cells }; - for ("Workspace Commands", 0..) |ch, i| { - cells[i].text[0] = ch; - cells[i].len = 1; - cells[i].default = false; - } - var g = testGui(10, 20, 8, 16); - var vertices: [pet.max_vertices]OverlayVertex = undefined; - var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 800, .win_h = 480 }; - appendWorkspacePet(&g, core, &surface, &builder); - try std.testing.expect(builder.len > 0); - for (vertices[0..builder.len]) |v| { - const x = (v.x + 1) * 400; - const y = (1 - v.y) * 240; - try std.testing.expect(x >= 20 * 8 - 0.01); - try std.testing.expect(y >= 0 and y < 20); - } - const before = g.pet_state; - pardes.tagline.enterHeader(core, null); - builder.len = 0; - appendWorkspacePet(&g, core, &surface, &builder); - try std.testing.expect(builder.len > 0); - try std.testing.expectEqual(before.tick, g.pet_state.tick); - try std.testing.expectEqual(before.x, g.pet_state.x); -} - fn cursorColor(chrome: *const pardes.Chrome, cell: *const pardes.Cell, role: pardes.FontRole) [3]u8 { return if (role == .tagline) switch (cell.style.fg) { .rgb => |rgb| rgb, @@ -10018,15 +9938,6 @@ fn cursorColor(chrome: *const pardes.Chrome, cell: *const pardes.Cell, role: par } else chrome.fg orelse fg_default; } -fn overlayRgb(rgb: [3]u8) OverlayColor { - return .{ - .r = @as(f32, @floatFromInt(rgb[0])) / 255.0, - .g = @as(f32, @floatFromInt(rgb[1])) / 255.0, - .b = @as(f32, @floatFromInt(rgb[2])) / 255.0, - .a = 1, - }; -} - fn uploadOverlayGpu(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, vertex_count: u32) bool { const byte_len: u32 = vertex_count * @sizeOf(OverlayVertex); const ptr = c.SDL_MapGPUTransferBuffer(g.device, g.overlay_vxfer, false) orelse return false; @@ -10088,17 +9999,6 @@ const OverlayBuilder = struct { b.addVertex(x2, y2, color); } - fn addRect(b: *OverlayBuilder, x0_in: f32, y0_in: f32, x1_in: f32, y1_in: f32, color: OverlayColor) void { - if (b.len + 6 > b.vertices.len) return; - const x0 = std.math.clamp(@min(x0_in, x1_in), 0.0, b.win_w); - const x1 = std.math.clamp(@max(x0_in, x1_in), 0.0, b.win_w); - const y0 = std.math.clamp(@min(y0_in, y1_in), 0.0, b.win_h); - const y1 = std.math.clamp(@max(y0_in, y1_in), 0.0, b.win_h); - if (x1 <= x0 or y1 <= y0) return; - b.addTri(x0, y0, x1, y0, x1, y1, color); - b.addTri(x0, y0, x1, y1, x0, y1, color); - } - }; fn envU16(env: *std.process.Environ.Map, name: []const u8) ?u16 { diff --git a/src/gui/pet.zig b/src/gui/pet.zig deleted file mode 100644 index 7a13ca91..00000000 --- a/src/gui/pet.zig +++ /dev/null @@ -1,215 +0,0 @@ -//! Original code-native pixel companions. Pure, bounded geometry and a 10 Hz -//! animation clock: no textures, allocation, input handling or editor state. -const std = @import("std"); - -pub const Kind = enum { off, cat, frog }; -pub const width = 12; -pub const height = 9; -pub const max_vertices = width * height * 6; -pub const Lane = struct { left: f32, right: f32, top: f32, scale: f32 }; -pub const Pose = struct { x: f32, y: f32, scale: f32, left: bool, walking: bool, frame: u8 }; -/// The frog's hop: sits two ticks, takes off, peaks for two, comes down, lands. -const hop_ticks = 8; - -/// Only the trailing blank part of the global tag is eligible. The caller -/// supplies its last occupied cell, including any wide-grapheme continuation. -pub fn lane(occupied: usize, cell_w: f32, screen_w: f32, top: f32, band_h: f32) ?Lane { - if (cell_w <= 0 or band_h < height + 2) return null; - const scale = @min(3, @floor((band_h - 2) / height)); - const left = @as(f32, @floatFromInt(occupied + 2)) * cell_w; - const right = screen_w - 2 * cell_w - width * scale; - if (right - left < 4 * scale) return null; - return .{ .left = left, .right = right, .top = top + band_h - height * scale - 1, .scale = scale }; -} - -pub const State = struct { - kind: Kind = .off, - tick: ?u64 = null, - x: f32 = 0, - target: f32 = 0, - left: bool = false, - idle: u8 = 12, - frame: u8 = 0, - rng: std.Random.DefaultPrng = undefined, - - /// No lane (the tag's text has filled it) hides the pet but keeps - /// where it was and what it was doing. - pub fn sample(s: *State, kind: Kind, now_ms: u64, area: ?Lane) ?Pose { - const region = area orelse return null; - if (kind == .off) { - s.* = .{}; - return null; - } - const tick = now_ms / 100; - if (s.kind != kind or s.tick == null) { - s.* = .{ .kind = kind, .tick = tick, .x = region.left, .target = region.left, .rng = .init(now_ms) }; - } - s.x = std.math.clamp(s.x, region.left, region.right); - s.target = std.math.clamp(s.target, region.left, region.right); - // Coming back from suspension never launches the pet across the tag. - const steps = @min(tick -| s.tick.?, 2); - s.tick = tick; - for (0..steps) |_| { - s.frame +%= 1; - if (s.idle > 0) { - s.idle -= 1; - if (s.idle == 0) { - // Wander to a random spot of the lane; one too close - // would be a shuffle in place, so take the far end. - s.target = region.left + s.rng.random().float(f32) * (region.right - region.left); - if (@abs(s.target - s.x) < 8 * region.scale) - s.target = if (s.x - region.left > region.right - s.x) region.left else region.right; - s.left = s.target < s.x; - s.frame = 255; // the walk starts at frame 0 - } - continue; - } - // The cat walks steadily; the frog travels only while airborne. - const phase = s.frame % hop_ticks; - if (kind == .cat or (phase >= 2 and phase < 6)) { - const step = (if (kind == .cat) @as(f32, 1.8) else 2.6) * region.scale; - s.x = if (s.left) @max(s.target, s.x - step) else @min(s.target, s.x + step); - } - if (s.x == s.target and (kind == .cat or phase == hop_ticks - 1)) - s.idle = s.rng.random().intRangeAtMost(u8, 20, 60); - } - return .{ .x = @floor(s.x), .y = region.top, .scale = region.scale, .left = s.left, .walking = s.idle == 0, .frame = s.frame }; - } -}; - -const cat = [_][]const u8{ - " # # ", - " #####", - " ##o##", - " # ######", - " # ######## ", - " ######### ", - " ######## ", - " ## ## ", - " # # ", -}; -const frog = [_][]const u8{ - " ", - " ", - " ", - " ## ", - " #o## ", - " #########", - " ######### ", - " ##### ## ", - "###### ### ", -}; -const frog_leap = [_][]const u8{ - " ## ", - " #o## ", - " #######", - " ######## ", - " ####### ", - " ### ## ", - "## # ", - "# ", - " ", -}; - -/// 0 transparent, 1 theme ink, 2 eye cutout. Walk legs and idle blinks are -/// generated in this fixed 12x9 tile; neither can spill into an adjacent row. -pub fn pixel(kind: Kind, pose: Pose, x_in: usize, y: usize) u2 { - if (x_in >= width or y >= height or kind == .off) return 0; - const x = if (pose.left) width - 1 - x_in else x_in; - const alternate = (pose.frame / 2) % 2 == 1; - // An idle companion still looks alive during its first pause: a slow - // two-pixel tail-tip flick, or the frog's throat gently inflating. These - // remain inside the tile and mirror with the rest of the animal. - const breathing = (pose.frame / 4) % 2 == 1; - if (!pose.walking and breathing) { - if (kind == .cat and y == 3 and x <= 1) - return @intFromBool(x == 0); - if (kind == .frog and ((y == 6 and x == 11) or (y == 7 and x == 10))) return 1; - } - if (kind == .cat and pose.walking and alternate and y >= 7) - return @intFromBool((y == 7 and (x == 3 or x == 7)) or (y == 8 and (x == 2 or x == 8))); - // A hopping frog leaps two rows low at take-off and one on the way down. - const phase = pose.frame % hop_ticks; - const leaping = kind == .frog and pose.walking and phase >= 2 and phase < 6; - const sink: usize = if (!leaping) 0 else if (phase == 2) 2 else if (phase == 5) 1 else 0; - if (y < sink) return 0; - const ch = (if (kind == .cat) cat else if (leaping) frog_leap else frog)[y - sink][x]; - return switch (ch) { - '#' => 1, - 'o' => if (!pose.walking and pose.frame % 30 >= 27) 1 else 2, - else => 0, - }; -} - -test "pet stays in trailing workspace blanks, and a lost lane hides it without a reset" { - try std.testing.expect(lane(20, 8, 200, 0, 16) == null); - try std.testing.expect(lane(3, 8, 200, 0, 10) == null); - const region = lane(3, 8, 200, 2, 20).?; - try std.testing.expect(region.left >= 5 * 8); - var state: State = .{}; - var moved = false; - var reversed = false; - for (0..2000) |i| { - const pose = state.sample(.cat, i * 100, region).?; - try std.testing.expect(pose.x >= region.left and pose.x + width * pose.scale <= 200 - 16); - try std.testing.expect(pose.y >= 2 and pose.y + height * pose.scale < 22); - moved = moved or pose.walking; - reversed = reversed or pose.left; - } - try std.testing.expect(moved and reversed); - const kept = state; - try std.testing.expect(state.sample(.cat, 300000, null) == null); - try std.testing.expectEqual(kept.x, state.x); - try std.testing.expectEqual(kept.tick, state.tick); - try std.testing.expect(state.sample(.off, 300100, region) == null); -} - -test "pet clock is fixed rate and sprites bounded in both directions" { - const region = lane(1, 8, 400, 0, 16).?; - var state: State = .{}; - const start = state.sample(.frog, 1000, region).?; - try std.testing.expectEqualDeep(start, state.sample(.frog, 1099, region).?); - for ([_]Kind{ .cat, .frog }) |kind| for ([_]bool{ false, true }) |left| { - const pose: Pose = .{ .x = 0, .y = 0, .scale = 1, .left = left, .walking = true, .frame = 3 }; - var count: usize = 0; - for (0..height) |y| for (0..width) |x| { - count += @intFromBool(pixel(kind, pose, x, y) != 0); - }; - try std.testing.expect(count > 20 and count <= width * height); - try std.testing.expectEqual(@as(u2, 0), pixel(kind, pose, width, height)); - }; -} - -test "pet rests at random spots and the frog travels only in the air" { - const region = lane(1, 8, 800, 0, 16).?; - var state: State = .{}; - var last = state.sample(.frog, 0, region).?; - var rested_midway = false; - for (1..3000) |i| { - const pose = state.sample(.frog, i * 100, region).?; - const phase = pose.frame % hop_ticks; - if (pose.x != last.x) try std.testing.expect(pose.walking and phase >= 2 and phase < 6); - rested_midway = rested_midway or (last.walking and !pose.walking and pose.x > region.left and pose.x < @floor(region.right)); - last = pose; - } - try std.testing.expect(rested_midway); -} - -test "pet initial idle visibly animates without walking or leaving its tile" { - const region = lane(1, 8, 400, 0, 16).?; - for ([_]Kind{ .cat, .frog }) |kind| { - var state: State = .{}; - const initial = state.sample(kind, 0, region).?; - var later = initial; - for (1..5) |tick| later = state.sample(kind, tick * 100, region).?; - try std.testing.expect(!initial.walking and !later.walking); - try std.testing.expectEqual(initial.x, later.x); - try std.testing.expectEqual(initial.y, later.y); - var changes: usize = 0; - for (0..height) |y| for (0..width) |x| { - changes += @intFromBool(pixel(kind, initial, x, y) != pixel(kind, later, x, y)); - }; - try std.testing.expectEqual(@as(usize, 2), changes); - try std.testing.expectEqual(@as(u2, 0), pixel(kind, later, width, height)); - } -} diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 8a84e37f..2cfee904 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -612,18 +612,18 @@ const e_prompt = "control message needs its argument"; /// is /status's or the DumpConfig window's. fn writeSettings(p: *Pardes, w: *std.Io.Writer) !void { try writeSettingsFor(p, &p.settings, w, builtins.viewCapabilities(p)); - try w.writeAll("LocationsConfig "); - try p.locations_config.write(w); - try w.writeByte('\n'); - if (comptime builtins.Pet.enabled) if (builtins.registry.here(p, .Pet)) try w.print("Pet {s}\n", .{@tagName(p.settings.pet)}); } /// The setting words of `s`, one a line, those a frontend of `caps` takes -/// (the root ctl's: the live view's). +/// (the root ctl's: the live view's), and the session's LocationsConfig. fn writeSettingsFor(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer, caps: config.Runtime.Capabilities) !void { // DumpConfig's words: a `# Word unsupported` comment for what `caps` lacks. var dump_dir: [1024]u8 = undefined; + var located_buf: [256]u8 = undefined; + var located: std.Io.Writer = .fixed(&located_buf); + try p.locations_config.write(&located); try config.Runtime.writeSettings(w, .{ + .locations = located.buffered(), .theme_name = p.theme().name, .theme_file = pardes.colors.loadedThemeFile(p), .compiled_default_shell = config.defaultShell(), |
