1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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);
}
|