diff options
Diffstat (limited to 'test/deck/schema.zig')
| -rw-r--r-- | test/deck/schema.zig | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/deck/schema.zig b/test/deck/schema.zig new file mode 100644 index 00000000..782c829a --- /dev/null +++ b/test/deck/schema.zig @@ -0,0 +1,70 @@ +//! deckcap's capture format (schema.zig v1), trimmed to the types + parse +//! the replay test needs. The .zon slices beside this file are windows cut +//! from real Steam Deck recordings made with deckcap. + +const std = @import("std"); + +pub const Recording = struct { + version: u32 = 1, + events: []const Event = &.{}, +}; + +pub const Event = struct { + /// Nanoseconds since SDL init (SDL_Event.common.timestamp). + t: u64, + /// SDL joystick instance id the event came from. + pad: u32, + ev: Payload, + + pub const Payload = union(enum) { + added: Added, + removed: void, + button: Button, + axis: Axis, + gyro: Imu, + accel: Imu, + touch: Touch, + }; + + pub const Added = struct { + name: []const u8, + vendor: u16, + product: u16, + gyro_hz: f32, + accel_hz: f32, + touchpads: u8, + }; + pub const Button = struct { + /// SDL_GamepadButton index. + idx: u8, + down: bool, + }; + pub const Axis = struct { + /// SDL_GamepadAxis index (sticks + triggers). + idx: u8, + value: i16, + }; + pub const Imu = struct { + x: f32, + y: f32, + z: f32, + st: u64, + }; + pub const Touch = struct { + touchpad: u8, + finger: u8, + phase: enum { down, motion, up }, + /// Normalized 0..1. + x: f32, + y: f32, + pressure: f32, + }; +}; + +pub fn parse(gpa: std.mem.Allocator, src: [:0]const u8) error{ OutOfMemory, ParseZon }!Recording { + return std.zon.parse.fromSliceAlloc(Recording, gpa, src, null, .{}); +} + +pub fn free(gpa: std.mem.Allocator, rec: Recording) void { + std.zon.parse.free(gpa, rec); +} |
