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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
// TODO: Remove this
#![allow(unused_macros)]
macro_rules! impl_primitive {
($name:ident, $cmd:expr) => {
impl $name {
/// Resets a primitive's command.
///
/// This is useful when a primitive is a variant of an untagged union which
/// must be set to `Self` without modifying its other fields.
pub const fn reset_cmd(&mut self) -> &mut Self {
self.cmd = $cmd;
self
}
/// Creates a new primitive
pub const fn new() -> Self {
let buf = [0u8; size_of::<Self>()];
let mut primitive = unsafe { transmute::<_, Self>(buf) };
primitive.cmd = $cmd;
primitive
}
}
impl GP0Command for $name {}
};
($name:ident < N > , $cmd:expr) => {
impl<const N: usize> $name<N> {
/// Creates a new primitive
pub const fn new() -> Self {
let buf = [0u8; size_of::<Self>()];
let mut primitive = unsafe { transmute::<_, Self>(buf) };
primitive.cmd = $cmd;
primitive
}
}
impl<const N: usize> GP0Command for $name<N> {}
};
}
macro_rules! vertices_fn {
(3) => {
/// Gets the primitive's vertices.
pub fn get_vertices(&self) -> [Vertex; 3] {
[self.v0, self.v1, self.v2]
}
/// Gets mutable references to the primitive's vertices
pub fn get_vertices_mut(&mut self) -> [&mut Vertex; 3] {
[&mut self.v0, &mut self.v1, &mut self.v2]
}
/// Sets the primitive's vertices.
pub fn set_vertices(&mut self, vertices: [Vertex; 3]) -> &mut Self {
self.v0 = vertices[0];
self.v1 = vertices[1];
self.v2 = vertices[2];
self
}
};
(4) => {
/// Gets the primitive's vertices.
pub fn get_vertices(&self) -> [Vertex; 4] {
[self.v0, self.v1, self.v2, self.v3]
}
/// Gets mutable references to the primitive's vertices
pub fn get_vertices_mut(&mut self) -> [&mut Vertex; 4] {
[&mut self.v0, &mut self.v1, &mut self.v2, &mut self.v3]
}
/// Sets the primitive's vertices.
pub fn set_vertices(&mut self, vertices: [Vertex; 4]) -> &mut Self {
self.v0 = vertices[0];
self.v1 = vertices[1];
self.v2 = vertices[2];
self.v3 = vertices[3];
self
}
};
}
macro_rules! color_fn {
() => {
/// Gets the primitive's color.
pub fn get_color(&self) -> Color {
self.color
}
/// Sets the primitive's color.
pub fn set_color(&mut self, color: Color) -> &mut Self {
self.color = color;
self
}
};
(textured) => {
/// Gets the textured primitive's color.
pub fn get_color(&self) -> TexColor {
self.color
}
/// Gets a mutable reference to the textured primitive's color.
pub fn get_color_mut(&mut self) -> &mut TexColor {
&mut self.color
}
/// Sets the textured primitive's color.
pub fn set_color<T>(&mut self, color: T) -> &mut Self
where TexColor: From<T> {
self.color = TexColor::from(color);
self
}
};
}
macro_rules! gouraud_fn {
(3) => {
/// Gets the primitive's color.
pub fn get_colors(&self) -> [Color; 3] {
[self.color0, self.color1, self.color2]
}
/// Returns mutable references to the primitive's colors.
pub fn get_colors_mut(&mut self) -> [&mut Color; 3] {
[&mut self.color0, &mut self.color1, &mut self.color2]
}
/// Sets the primitive's color.
pub fn set_colors(&mut self, colors: [Color; 3]) -> &mut Self {
self.color0 = colors[0];
self.color1 = colors[1];
self.color2 = colors[2];
self
}
};
(4) => {
/// Gets the primitive's color.
pub fn get_colors(&self) -> [Color; 4] {
[self.color0, self.color1, self.color2, self.color3]
}
/// Returns mutable references to the primitive's colors.
pub fn get_colors_mut(&mut self) -> [&mut Color; 4] {
[
&mut self.color0,
&mut self.color1,
&mut self.color2,
&mut self.color3,
]
}
/// Sets the primitive's color.
pub fn set_colors(&mut self, colors: [Color; 4]) -> &mut Self {
self.color0 = colors[0];
self.color1 = colors[1];
self.color2 = colors[2];
self.color3 = colors[3];
self
}
};
(3,textured) => {
/// Gets the textured primitive's color.
pub fn get_colors(&self) -> [TexColor; 3] {
[self.color0, self.color1, self.color2]
}
/// Returns mutable references to the textured primitive's colors.
pub fn get_colors_mut(&mut self) -> [&mut TexColor; 3] {
[&mut self.color0, &mut self.color1, &mut self.color2]
}
/// Sets the textured primitive's color.
pub fn set_colors<T>(&mut self, colors: [T; 3]) -> &mut Self
where
TexColor: From<T>,
T: Copy, {
self.color0 = TexColor::from(colors[0]);
self.color1 = TexColor::from(colors[1]);
self.color2 = TexColor::from(colors[2]);
self
}
};
(4,textured) => {
/// Gets the textured primitive's color.
pub fn get_colors(&self) -> [TexColor; 4] {
[self.color0, self.color1, self.color2, self.color3]
}
/// Returns mutable references to the textured primitive's colors.
pub fn get_colors_mut(&mut self) -> [&mut TexColor; 4] {
[
&mut self.color0,
&mut self.color1,
&mut self.color2,
&mut self.color3,
]
}
/// Sets the textured primitive's color.
pub fn set_colors<T>(&mut self, colors: [T; 4]) -> &mut Self
where
TexColor: From<T>,
T: Copy, {
self.color0 = TexColor::from(colors[0]);
self.color1 = TexColor::from(colors[1]);
self.color2 = TexColor::from(colors[2]);
self.color3 = TexColor::from(colors[3]);
self
}
};
}
macro_rules! offset_fn {
() => {
/// Gets the primitive's offset.
pub fn get_offset(&self) -> Vertex {
self.offset
}
/// Sets the primitive's offset.
pub fn set_offset(&mut self, offset: Vertex) -> &mut Self {
self.offset = offset;
self
}
};
}
macro_rules! size_fn {
() => {
/// Gets the primitive's offset.
pub fn get_size(&self) -> Vertex {
self.size
}
/// Sets the primitive's offset.
pub fn set_size(&mut self, size: Vertex) -> &mut Self {
self.size = size;
self
}
};
}
macro_rules! clut_fn {
() => {
/// Gets the color lookup table.
pub fn get_clut(&self) -> Clut {
self.clut
}
/// Sets the color lookup table.
pub fn set_clut(&mut self, clut: Clut) -> &mut Self {
self.clut = clut;
self
}
};
}
macro_rules! tex_coord_fn {
(1) => {
/// Gets the primitive's texcoord.
pub fn get_tex_coord(&self) -> TexCoord {
self.t0
}
/// Sets the primitive's texcoord.
pub fn set_tex_coord(&mut self, t0: TexCoord) -> &mut Self {
self.t0 = t0;
self
}
};
(3) => {
/// Gets the primitive's texcoords.
pub fn get_tex_coords(&self) -> [TexCoord; 3] {
[self.t0, self.t1, self.t2]
}
/// Returns mutable references to the primitive's texcoord.
pub fn get_tex_coords_mut(&mut self) -> [&mut TexCoord; 3] {
[&mut self.t0, &mut self.t1, &mut self.t2]
}
/// Sets the primitive's texcoords.
pub fn set_tex_coords<T>(&mut self, tex_coords: [T; 3]) -> &mut Self
where TexCoord: From<T> {
let tex_coords = tex_coords.map(|t| TexCoord::from(t));
self.t0 = tex_coords[0];
self.t1 = tex_coords[1];
self.t2 = tex_coords[2];
self
}
};
(4) => {
/// Gets the primitive's texcoords.
pub fn get_tex_coords(&self) -> [TexCoord; 4] {
[self.t0, self.t1, self.t2, self.t3]
}
/// Returns mutable references to the primitive's texcoord.
pub fn get_tex_coords_mut(&mut self) -> [&mut TexCoord; 4] {
[&mut self.t0, &mut self.t1, &mut self.t2, &mut self.t3]
}
/// Sets the primitive's texcoords.
pub fn set_tex_coords<T>(&mut self, tex_coords: [T; 4]) -> &mut Self
where TexCoord: From<T> {
let tex_coords = tex_coords.map(|t| TexCoord::from(t));
self.t0 = tex_coords[0];
self.t1 = tex_coords[1];
self.t2 = tex_coords[2];
self.t3 = tex_coords[3];
self
}
};
}
macro_rules! tex_page_fn {
() => {
/// Gets the primitive's texture page.
pub fn get_tex_page(&self) -> TexPage {
self.tpage
}
/// Sets the primitive's texture page.
pub fn set_tex_page<T>(&mut self, tpage: T) -> &mut Self
where TexPage: From<T> {
self.tpage = tpage.into();
self
}
};
}