diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-21 18:16:58 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-21 18:16:58 +0200 |
commit | fc449a2f2c10e443472cda62e1044264a09fe051 (patch) | |
tree | efc14038308b38b9f8c641c5bf57e09858884999 | |
parent | 53580f3695f6f53f2fc0ecea169609bc9d853643 (diff) | |
download | gba-renderers-fc449a2f2c10e443472cda62e1044264a09fe051.tar.gz gba-renderers-fc449a2f2c10e443472cda62e1044264a09fe051.zip |
Add sprite bounce benchmark
-rw-r--r-- | src/main.c | 85 |
1 files changed, 83 insertions, 2 deletions
@@ -11,7 +11,7 @@ WITH REGARD TO THIS SOFTWARE. | |||
11 | 11 | ||
12 | #include "gba/gba.h" | 12 | #include "gba/gba.h" |
13 | 13 | ||
14 | #include "renderer_m4.c" | 14 | #include "renderer_m0.c" |
15 | 15 | ||
16 | // | 16 | // |
17 | // Config parameters. | 17 | // Config parameters. |
@@ -132,6 +132,86 @@ test_all_static(void) { | |||
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | void | ||
136 | test_sprites_bounce(void) { | ||
137 | u8 sprite_icn[8] = { | ||
138 | 0xf8, 0xf8, 0xf8, 0xf8 | 0x3e, 0xf8 | 0x3e, 0x3e, 0x3e, 0x00, | ||
139 | }; | ||
140 | u8 sprite_chr[16] = { | ||
141 | 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, | ||
142 | 0x00, 0x00, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x00, | ||
143 | }; | ||
144 | int x = 50; | ||
145 | int y = 50; | ||
146 | int inc_x = 1; | ||
147 | int inc_y = 1; | ||
148 | typedef struct Sprite { | ||
149 | int x; | ||
150 | int y; | ||
151 | int inc_x; | ||
152 | int inc_y; | ||
153 | int clr; | ||
154 | int flip_x; | ||
155 | int flip_y; | ||
156 | } Sprite; | ||
157 | Sprite sprites[] = { | ||
158 | {50, 50, 1, 1, 1, 0, 0}, | ||
159 | {20, 30, 2, 3, 2, 0, 1}, | ||
160 | {10, 100, -2, -1, 3, 1, 0}, | ||
161 | {200, 80, 1, -2, 4, 1, 1}, | ||
162 | {50, 50, 1, 1, 1, 0, 0}, | ||
163 | {20, 30, 2, 3, 2, 0, 1}, | ||
164 | {10, 100, -2, -1, 3, 1, 0}, | ||
165 | {200, 80, 1, -2, 4, 1, 1}, | ||
166 | }; | ||
167 | int should_move = 1; | ||
168 | while (true) { | ||
169 | poll_keys(); | ||
170 | if (key_tap(KEY_A)) { | ||
171 | break; | ||
172 | } | ||
173 | if (key_pressed(KEY_B)) { | ||
174 | should_move = 0; | ||
175 | } else { | ||
176 | should_move = 1; | ||
177 | } | ||
178 | bios_vblank_wait(); | ||
179 | FRAME_START(); | ||
180 | PROF(flip_buffer(), flip_cycles); | ||
181 | PROF(screen_fill(8), clear_cycles); | ||
182 | for (size_t i = 0; i < LEN(sprites); i++) { | ||
183 | Sprite *s = &sprites[i]; | ||
184 | PROF(draw_icn( | ||
185 | s->x, s->y, | ||
186 | sprite_icn, | ||
187 | s->clr, | ||
188 | s->flip_x, s->flip_y), icn_cycles); | ||
189 | PROF(draw_chr( | ||
190 | (240 - s->x - 8), (160 - s->y - 8), | ||
191 | sprite_chr, | ||
192 | s->flip_x, s->flip_y), chr_cycles); | ||
193 | s->x += s->inc_x * should_move; | ||
194 | s->y += s->inc_y * should_move; | ||
195 | if (s->x > (240 - 8) && s->inc_x > 0) { | ||
196 | s->x = (240 - 8); | ||
197 | s->inc_x *= -1; | ||
198 | } else if (s->x <= 0 && s->inc_x < 0){ | ||
199 | s->x = 0; | ||
200 | s->inc_x *= -1; | ||
201 | } | ||
202 | if (s->y > (160 - 8) && s->inc_y > 0) { | ||
203 | s->y = 160 - 8; | ||
204 | s->inc_y *= -1; | ||
205 | } else if (s->y <= 0 && s->inc_y < 0){ | ||
206 | s->y = 0; | ||
207 | s->inc_y *= -1; | ||
208 | } | ||
209 | } | ||
210 | FRAME_END(); | ||
211 | PROF_SHOW(); | ||
212 | } | ||
213 | } | ||
214 | |||
135 | int main(void) { | 215 | int main(void) { |
136 | // Adjust system wait times. | 216 | // Adjust system wait times. |
137 | SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE; | 217 | SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE; |
@@ -143,10 +223,11 @@ int main(void) { | |||
143 | irq_init(); | 223 | irq_init(); |
144 | irs_set(IRQ_VBLANK, irs_stub); | 224 | irs_set(IRQ_VBLANK, irs_stub); |
145 | 225 | ||
146 | // TODO: Test sprites in movement. | 226 | // TODO: Test for text rendering. |
147 | // TODO: Verify all works well, there were some modifications and | 227 | // TODO: Verify all works well, there were some modifications and |
148 | // bugfixes on the ppu of the uxngba branch. | 228 | // bugfixes on the ppu of the uxngba branch. |
149 | while (true) { | 229 | while (true) { |
230 | test_sprites_bounce(); | ||
150 | test_moving_line(); | 231 | test_moving_line(); |
151 | test_all_static(); | 232 | test_all_static(); |
152 | } | 233 | } |