summaryrefslogtreecommitdiff
path: root/src/host/Console.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/Console.zig')
-rw-r--r--src/host/Console.zig26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/host/Console.zig b/src/host/Console.zig
index b22facb..40845f7 100644
--- a/src/host/Console.zig
+++ b/src/host/Console.zig
@@ -133,7 +133,7 @@ pub fn execute(self: *Console, host: *Host, line: []const u8, now: u64) ![]const
const rest = words.rest();
if (eq(command, "help")) {
- self.log("save|load [1..7] snapshot N | record|play [0..15] recording N | stop | pause | step N | seek start|end|<ms>");
+ self.log("save|load [1..7] snapshot N | record|play [0..15] recording N | stop | pause | step N (frames) | seek start|end|<ms>");
self.log("diff [N] | reset | get <field> | set <field> <value> | overlay memory|sound | quit");
if (host.forward(self, line, now) == .unknown) self.log("Backtick hides the console. Tab completes.");
return &.{};
@@ -145,10 +145,12 @@ pub fn execute(self: *Console, host: *Host, line: []const u8, now: u64) ![]const
self.print("{s} overlay: {s}", .{ name, if (flag.*) "on" else "off" });
} else if (eq(command, "get")) {
const path = arg orelse return error.ExpectedField;
- const leaf = host.state.layout.find(path) orelse return error.UnknownField;
var buf: [160]u8 = undefined;
var w: std.Io.Writer = .fixed(&buf);
- fields.format(leaf, host.live(), &w) catch {};
+ fields.formatPath(host.state.layout, host.live(), path, &w) catch |err| switch (err) {
+ error.UnknownField => return error.UnknownField,
+ error.WriteFailed => {}, // shown cut off
+ };
self.print("{s} = {s}", .{ path, w.buffered() });
} else if (eq(command, "set")) {
const path = arg orelse return error.ExpectedField;
@@ -176,16 +178,17 @@ pub fn execute(self: *Console, host: *Host, line: []const u8, now: u64) ![]const
h.bank.save(index);
self.print("Saved snapshot {d}. Recordings from its old contents are invalidated.", .{index});
} else {
- try h.bank.restore(index);
+ try h.restore(index);
self.print("Loaded snapshot {d}.", .{index});
}
} else if (eq(command, "record") or eq(command, "play")) {
const index = if (arg) |a| try slot(a, 0, timeline.recording_count - 1) else self.recording;
if (eq(command, "play")) _ = try h.bank.get(index);
h.stop(now);
- if (eq(command, "record")) try h.startRecording(index, self.snapshot, now) else try h.play(index, now);
+ if (eq(command, "record")) try h.startRecording(index, self.snapshot, now, host.build) else try h.play(index, now);
self.recording = index;
self.print("{s} recording {d} from snapshot {d}.", .{ if (eq(command, "record")) "Started" else "Playing", index, h.bank.recording(index).snapshot });
+ if (eq(command, "play")) self.warnBuild(host, h.bank.recording(index));
} else if (eq(command, "stop")) {
h.stop(now);
} else if (eq(command, "pause")) {
@@ -197,6 +200,7 @@ pub fn execute(self: *Console, host: *Host, line: []const u8, now: u64) ![]const
if (h.mode == .recording) h.stop(now);
if (h.mode == .live) try h.play(self.recording, now);
const r = try h.bank.get(h.selected);
+ if (h.mode == .playing and h.cursor == 0) self.warnBuild(host, r);
if (eq(command, "step")) return h.step(std.fmt.parseInt(i64, value, 10) catch return error.InvalidPosition);
if (eq(value, "start")) return h.seekCount(0);
if (eq(value, "end")) return h.seekCount(r.count);
@@ -206,7 +210,12 @@ pub fn execute(self: *Console, host: *Host, line: []const u8, now: u64) ![]const
const index = if (arg) |a| try slot(a, 1, memory.slot_count - 1) else self.snapshot;
if (!h.bank.hasSnapshot(index)) return error.EmptySnapshot;
const diff = h.bank.compare(0, index);
- self.print("Live vs snapshot {d}: {d} differing bytes; first={any}, last={any}", .{ index, diff.count, diff.first, diff.last });
+ if (diff.first) |first| {
+ var buf: [96]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&buf);
+ first.leaf.name(first.offset, &w) catch {};
+ self.print("Live vs snapshot {d}: {d} differing values, first {s}", .{ index, diff.count, w.buffered() });
+ } else self.print("Live vs snapshot {d}: same", .{index});
} else {
// Sketch commands edit state outside the recorded input.
h.stop(now);
@@ -237,6 +246,11 @@ pub fn draw(self: *const Console, host: *Host, out: *std.ArrayList(abi.Command),
try out.append(arena, .{ .rect = .{ .dst = .{ .x = @floatFromInt(28 + self.cursor * 8), .y = top + 120, .w = 1, .h = 12 }, .color = hint } });
}
+/// A replay of a recording made by other code may diverge: say so.
+fn warnBuild(self: *Console, host: *const Host, r: *const timeline.Recording) void {
+ if (r.build() != 0 and host.build != 0 and r.build() != host.build) self.log("Warning: recorded by another build of the sketch; the replay may differ.");
+}
+
fn eq(a: []const u8, b: []const u8) bool {
return std.mem.eql(u8, a, b);
}