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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
pub use std::time::Duration;
#[derive(Debug)]
#[allow(missing_docs)]
pub struct Bitmap {
pub memory: *mut u8,
pub width: i32,
pub height: i32,
pub pitch: isize,
}
#[derive(Debug)]
#[allow(missing_docs)]
pub struct SoundBuffer {
pub samples_per_second: i32,
pub sample_count: i32,
pub samples: *mut i16,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct ControllerButton {
pub transition_count: u8,
pub pressed: bool,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub struct XBoxController {
pub packet_number: u32,
pub top_button: ControllerButton,
pub left_button: ControllerButton,
pub right_button: ControllerButton,
pub bottom_button: ControllerButton,
pub start_button: ControllerButton,
pub back_button: ControllerButton,
pub left_shoulder: ControllerButton,
pub right_shoulder: ControllerButton,
pub left_stick: ControllerButton,
pub right_stick: ControllerButton,
pub dpad_up: ControllerButton,
pub dpad_down: ControllerButton,
pub dpad_left: ControllerButton,
pub dpad_right: ControllerButton,
pub left_trigger: u8,
pub right_trigger: u8,
pub left_thumb_x: i16,
pub left_thumb_y: i16,
pub right_thumb_x: i16,
pub right_thumb_y: i16,
pub controller_id: u8,
pub trigger_threshold: u8,
pub left_thumb_deadzone: i16,
pub right_thumb_deadzone: i16,
}
#[derive(Debug, Clone)]
pub struct GameInput {
pub xbox_controllers: [Option<XBoxController>; 4],
}
#[derive(Debug, Clone)]
#[allow(missing_docs)]
pub struct GameMemory {
pub x_offset: i32,
pub y_offset: i32,
pub tone_hz: i32,
}
pub type GameUpdateAndRenderFn =
fn(&mut GameMemory, Duration, &GameInput, &mut Bitmap, &mut SoundBuffer);
#[macro_export]
macro_rules! dump {
($($n:expr),*) => (if cfg!(debug_assertions) {
$(println!(concat!("{}:{}> ",stringify!($n),": {:?}"),file!(),line!(),$n);)*
})
}
#[macro_export]
macro_rules! debugln {
($($arg:tt)*) => (if cfg!(debug_assertions) {
print!("{}:{}> ",file!(),line!());
println!($($arg)*);
})
}
#[macro_export]
macro_rules! tlc_read {
($cell_name:ident) => {
$cell_name.with(Cell::get)
};
}
#[macro_export]
macro_rules! tlc_write {
($cell_name:ident, $new_value:expr) => {
$cell_name.with(|cell| cell.set($new_value));
};
}
#[macro_export]
macro_rules! tlc_modify {
($cell_name:ident, $modify_func:expr) => {
$cell_name.with(|cell| cell.set($modify_func(cell.get())));
};
}