frontend: add CLI frame/audio dump flags and expand raylib input mapping

This commit is contained in:
2026-08-27 07:16:29 +02:00
parent 9ba71b7b62
commit 20c1106a9a
2 changed files with 180 additions and 6 deletions
+52 -3
View File
@@ -16,9 +16,10 @@ pub const Driver = struct {
audio_ring_head: usize = 0,
audio_ring_tail: usize = 0,
event_queue: [16]platform.Event = undefined,
event_queue: [64]platform.Event = undefined,
event_head: usize = 0,
event_tail: usize = 0,
polled_this_frame: bool = false,
pub fn init(title: [*:0]const u8, width: i32, height: i32, scale: i32) Driver {
c.InitWindow(width * scale, height * scale, title);
@@ -63,10 +64,22 @@ pub const Driver = struct {
return ev;
}
if (self.polled_this_frame) {
return null;
}
self.polled_this_frame = true;
self.event_head = 0;
self.event_tail = 0;
// Poll Raylib Key Events
const key_mappings = [_]struct { c_key: c_int, key: platform.Key }{
.{ .c_key = c.KEY_Z, .key = .z },
.{ .c_key = c.KEY_X, .key = .x },
.{ .c_key = c.KEY_C, .key = .c },
.{ .c_key = c.KEY_V, .key = .v },
.{ .c_key = c.KEY_J, .key = .j },
.{ .c_key = c.KEY_K, .key = .k },
.{ .c_key = c.KEY_SPACE, .key = .space },
.{ .c_key = c.KEY_RIGHT_SHIFT, .key = .right_shift },
.{ .c_key = c.KEY_LEFT_SHIFT, .key = .left_shift },
.{ .c_key = c.KEY_ENTER, .key = .enter },
@@ -74,6 +87,10 @@ pub const Driver = struct {
.{ .c_key = c.KEY_DOWN, .key = .down },
.{ .c_key = c.KEY_LEFT, .key = .left },
.{ .c_key = c.KEY_RIGHT, .key = .right },
.{ .c_key = c.KEY_W, .key = .w },
.{ .c_key = c.KEY_S, .key = .s },
.{ .c_key = c.KEY_A, .key = .a },
.{ .c_key = c.KEY_D, .key = .d },
.{ .c_key = c.KEY_F5, .key = .f5 },
.{ .c_key = c.KEY_F8, .key = .f8 },
.{ .c_key = c.KEY_P, .key = .p },
@@ -81,13 +98,43 @@ pub const Driver = struct {
for (key_mappings) |mapping| {
if (c.IsKeyPressed(mapping.c_key)) {
return .{ .key_down = .{ .key = mapping.key } };
const next = (self.event_head + 1) % self.event_queue.len;
if (next != self.event_tail) {
self.event_queue[self.event_head] = .{ .key_down = .{ .key = mapping.key } };
self.event_head = next;
}
}
if (c.IsKeyReleased(mapping.c_key)) {
return .{ .key_up = .{ .key = mapping.key } };
const next = (self.event_head + 1) % self.event_queue.len;
if (next != self.event_tail) {
self.event_queue[self.event_head] = .{ .key_up = .{ .key = mapping.key } };
self.event_head = next;
}
}
}
// Support mouse left click as Start/Action button
if (c.IsMouseButtonPressed(c.MOUSE_BUTTON_LEFT)) {
const next = (self.event_head + 1) % self.event_queue.len;
if (next != self.event_tail) {
self.event_queue[self.event_head] = .{ .key_down = .{ .key = .enter } };
self.event_head = next;
}
}
if (c.IsMouseButtonReleased(c.MOUSE_BUTTON_LEFT)) {
const next = (self.event_head + 1) % self.event_queue.len;
if (next != self.event_tail) {
self.event_queue[self.event_head] = .{ .key_up = .{ .key = .enter } };
self.event_head = next;
}
}
if (self.event_head != self.event_tail) {
const ev = self.event_queue[self.event_tail];
self.event_tail = (self.event_tail + 1) % self.event_queue.len;
return ev;
}
return null;
}
@@ -116,6 +163,8 @@ pub const Driver = struct {
.height = @floatFromInt(self.height * self.scale),
};
c.DrawTexturePro(self.texture, src, dest, c.Vector2{ .x = 0, .y = 0 }, 0.0, c.WHITE);
self.polled_this_frame = false;
}
pub fn queueAudio(self: *Driver, output: usize, buffer: contract.AudioBuffer) void {