summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 16:30:57 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commit1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54 (patch)
treeeddcf21a1e5b35f7871b521c747e851b1134f512 /src
parentbe09d1ec7abd71f4e52f05942a941d76b6d420f2 (diff)
downloadpardes-1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54.tar.gz
pardes-1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54.zip
Crt, Ripple and Glitch take a level, 0 to 3, tunable at run time
Coordinator's request: `Crt 0..3` (likewise Ripple, Glitch), 0 off, `on` the default level 2 (the polished rewrite), `off` and a bare word as before. The level is one uniform (pardesLevel, beside pardesOpaque in the prefix's own block); each pass picks its constants by it. Level 3 is at least as strong as the old effects, measured as pixels changed by more than 8 in a channel against a plain frame: Crt 18.3% (old 17.4%), Ripple 11.1% (9.5%), Glitch 9.3% a frame (8.1%); Glitch's level raises how often it bursts as well as how hard. Config and ctl report `Crt 2` / `Crt off`. Shared files touched: ninep/ctl.zig (the report line). Not touched: pardes.zig, Messages.zig, mouse.zig, gui.zig, detached/*.
Diffstat (limited to 'src')
-rw-r--r--src/config.zig75
-rw-r--r--src/gui/Post.zig6
-rw-r--r--src/ninep/ctl.zig2
3 files changed, 72 insertions, 11 deletions
diff --git a/src/config.zig b/src/config.zig
index 1d4043ab..e8c5a705 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -628,7 +628,12 @@ pub const Runtime = struct {
pub const Entry = struct {
scene: ?Scene = null,
path: Text(limits.host_path_cap) = .{},
+ /// A bundled pass's strength, 1 to `max_level`; 0 for a file.
+ level: u8 = 0,
};
+ pub const max_level = 3;
+ /// What `on` and a bare word turn a bundled pass on at.
+ pub const default_level = 2;
entries: [max]Entry = @splat(.{}),
len: u8 = 0,
/// Bumped on every change: a shell compiles the chain again when it
@@ -640,8 +645,28 @@ pub const Runtime = struct {
}
pub fn has(post: *const Post, scene: Scene) bool {
- for (post.list()) |entry| if (entry.scene == scene) return true;
- return false;
+ return post.level(scene) != 0;
+ }
+
+ /// A bundled pass's level; 0 when it is not in the chain.
+ pub fn level(post: *const Post, scene: Scene) u8 {
+ for (post.list()) |entry| if (entry.scene == scene) return entry.level;
+ return 0;
+ }
+
+ /// Sets a bundled pass's level: 0 takes it out, anything else puts it
+ /// in at the end or changes it where it is.
+ pub fn setLevel(post: *Post, scene: Scene, to: u8) bool {
+ std.debug.assert(to <= max_level);
+ if (to == 0) return post.set(scene, "", false);
+ for (post.entries[0..post.len]) |*entry| if (entry.scene == scene) {
+ if (entry.level != to) post.generation +%= 1;
+ entry.level = to;
+ return true;
+ };
+ if (!post.set(scene, "", true)) return false;
+ post.entries[post.len - 1].level = to;
+ return true;
}
/// Puts the pass in the chain, at its end, or takes it out; `want`
@@ -949,8 +974,19 @@ pub const Runtime = struct {
}
},
.scene => |effect| {
- const want = switchedTo(argument) catch return false;
- return state.post.set(effect, "", want);
+ // A level, 0 (off) to 3; `on` is the default level, `off` 0,
+ // and bare flips between the two.
+ const text = std.mem.trim(u8, argument orelse "", " \t\r\n");
+ const to: u8 = if (text.len == 0)
+ (if (state.post.has(effect)) 0 else Post.default_level)
+ else if (std.mem.eql(u8, text, "on"))
+ Post.default_level
+ else if (std.mem.eql(u8, text, "off"))
+ 0
+ else
+ std.fmt.parseInt(u8, text, 10) catch return false;
+ if (to > Post.max_level) return false;
+ return state.post.setLevel(effect, to);
},
.shader => {
const path = std.mem.trim(u8, argument orelse return false, " \t\r\n");
@@ -1119,7 +1155,8 @@ pub const Runtime = struct {
try out.print("{s} unsupported\n", .{setting.word});
continue;
}
- try out.print("{s} {s}\n", .{ setting.word, onOff(state.post.has(effect)) });
+ const level = state.post.level(effect);
+ if (level == 0) try out.print("{s} off\n", .{setting.word}) else try out.print("{s} {d}\n", .{ setting.word, level });
},
.shader => {
if (!setting.enabled(context.capabilities)) {
@@ -1246,6 +1283,28 @@ pub const Runtime = struct {
try std.testing.expect(!apply(&state, find("ShaderAnimation").?, "sometimes"));
}
+ test "a bundled pass takes a level: on is the default, 0 and off take it out, and the old words still flip" {
+ var state: Runtime = .{};
+ const crt = find("Crt").?;
+ try std.testing.expect(apply(&state, crt, "on"));
+ try std.testing.expectEqual(@as(u8, Post.default_level), state.post.level(.crt));
+ try std.testing.expect(apply(&state, find("Glitch").?, "1"));
+ const moved = state.post.generation;
+ try std.testing.expect(apply(&state, crt, "3"));
+ try std.testing.expectEqual(@as(u8, 3), state.post.level(.crt));
+ // A new level keeps its place in the chain.
+ try std.testing.expectEqual(Scene.crt, state.post.list()[0].scene.?);
+ try std.testing.expect(state.post.generation != moved);
+ try std.testing.expect(!apply(&state, crt, "4"));
+ try std.testing.expect(!apply(&state, crt, "loud"));
+ try std.testing.expect(apply(&state, crt, "0"));
+ try std.testing.expect(!state.post.has(.crt));
+ try std.testing.expect(apply(&state, crt, null));
+ try std.testing.expectEqual(@as(u8, Post.default_level), state.post.level(.crt));
+ try std.testing.expect(apply(&state, crt, "off"));
+ try std.testing.expectEqual(@as(u8, 0), state.post.level(.crt));
+ }
+
test "tagline size validates before mutating live state" {
const setting = find("TaglineSize").?;
var state: Runtime = .{};
@@ -1412,9 +1471,9 @@ pub const Runtime = struct {
.typewriter => "Panel transition PanelType\n",
},
.scene => |effect| switch (effect) {
- .crt => "Crt on\n",
- .ripple => "Ripple on\n",
- .glitch => "Glitch on\n",
+ .crt => "Crt 2\n",
+ .ripple => "Ripple 2\n",
+ .glitch => "Glitch 2\n",
},
.shader => "Shader ~/crt.glsl\n",
.shader_animation => "ShaderAnimation always\n",
diff --git a/src/gui/Post.zig b/src/gui/Post.zig
index c529efc0..d9d3d53e 100644
--- a/src/gui/Post.zig
+++ b/src/gui/Post.zig
@@ -69,6 +69,8 @@ pub const Uniforms = extern struct {
pub const Pass = struct {
scene: ?Scene = null,
+ /// A bundled pass's strength (pardesLevel); 0 for a file.
+ level: u8 = 0,
/// A user's file, owned; empty for a bundled pass.
path: []u8 = &.{},
pipeline: ?*Pipeline = null,
@@ -117,7 +119,7 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, io: std.Io, device: *c.SDL_GPUD
for (chain.list(), 0..) |entry, i| {
if (entry.scene) |scene| {
if (post.bundled.get(scene) == null) post.bundled.set(scene, makePipeline(device, format, bundled_spv.get(scene)) catch null);
- next[i] = .{ .scene = scene, .pipeline = post.bundled.get(scene) };
+ next[i] = .{ .scene = scene, .level = entry.level, .pipeline = post.bundled.get(scene) };
continue;
}
// A file already in the chain keeps its pipeline and its path.
@@ -405,7 +407,6 @@ pub fn draw(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer,
const day = epoch.getEpochDay().calculateYearDay();
const month = day.calculateMonthDay();
u.date = .{ @floatFromInt(day.year), @floatFromInt(month.month.numeric() - 1), @floatFromInt(month.day_index + 1), @floatFromInt(epoch.getDaySeconds().secs) };
- const own: [4]f32 = .{ @floatFromInt(@intFromBool(opaque_window)), 0, 0, 0 };
var input = source;
var index: usize = 0;
@@ -423,6 +424,7 @@ pub fn draw(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer,
const binding = c.SDL_GPUTextureSamplerBinding{ .texture = input, .sampler = sampler };
c.SDL_BindGPUFragmentSamplers(pass_rp, 0, &binding, 1);
c.SDL_PushGPUFragmentUniformData(cmd, 0, u, @sizeOf(Uniforms));
+ const own: [4]f32 = .{ @floatFromInt(@intFromBool(opaque_window)), @floatFromInt(pass.level), 0, 0 };
c.SDL_PushGPUFragmentUniformData(cmd, 1, &own, @sizeOf(@TypeOf(own)));
c.SDL_DrawGPUPrimitives(pass_rp, 3, 1, 0, 0);
c.SDL_EndGPURenderPass(pass_rp);
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index ed10dd70..cd327d03 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -263,7 +263,7 @@ fn writeSettings(p: *Pardes, w: *std.Io.Writer) !void {
// Bare, it names the default directory.
.dump_dir => if (s.dump_dir.len > 0) try w.print("{s} {s}\n", .{ word, s.dump_dir.get() }) else try w.print("{s}\n", .{word}),
.transition => |effect| try w.print("{s} {s}\n", .{ word, if (s.panel_transition == effect) "on" else "off" }),
- .scene => |effect| try w.print("{s} {s}\n", .{ word, if (s.post.has(effect)) "on" else "off" }),
+ .scene => |effect| if (s.post.level(effect) == 0) try w.print("{s} off\n", .{word}) else try w.print("{s} {d}\n", .{ word, s.post.level(effect) }),
.shader => for (s.post.list()) |entry| if (entry.scene == null) try w.print("{s} {s}\n", .{ word, entry.path.get() }),
.shader_animation => try w.print("{s} {s}\n", .{ word, @tagName(s.shader_animation) }),
}