[Maintenance] [th01] Shootout lasers: Add a safe subscript wrapper

Part of P0193, funded by Ember2528.
This commit is contained in:
nmlgc 2022-05-04 21:09:33 +02:00
parent e1f3f9fe0b
commit 365d8ea346
3 changed files with 6 additions and 7 deletions

View File

@ -1355,10 +1355,7 @@ void pattern_lasers_and_3_spread(void)
}
target_y = PLAYFIELD_BOTTOM;
// Quite a roundabout way of preventing a buffer overflow, but fine.
shootout_lasers[
(boss_phase_frame / INTERVAL) % SHOOTOUT_LASER_COUNT
].spawn(
shootout_laser_safe(boss_phase_frame / INTERVAL).spawn(
SWORD_CENTER_X, SWORD_CENTER_Y,
target_left, target_y,
(to_sp(8.5f) / 2), V_WHITE, 30, 5

View File

@ -1846,9 +1846,7 @@ void near pattern_radial_stacks_and_lasers(void)
target_y = polar_y(CENTER_Y, 600, angle);
mdrv2_se_play(7);
if((boss_phase_frame % 15) == 0) {
shootout_lasers[
((boss_phase_frame - 215) / 15) % SHOOTOUT_LASER_COUNT
].spawn(
shootout_laser_safe((boss_phase_frame - 215) / 15).spawn(
CENTER_X, CENTER_Y, target_x, target_y,
pattern_state.speed_multiplied_by_8, V_WHITE, 20, 4
);

View File

@ -126,6 +126,10 @@ extern CShootoutLaser shootout_lasers[SHOOTOUT_LASER_COUNT];
} \
}
// Quite a roundabout way of preventing buffer overflows, but fine.
#define shootout_laser_safe(i) \
shootout_lasers[(i) % SHOOTOUT_LASER_COUNT]
#define shootout_lasers_unput_and_reset_broken(i) { \
for(i = 0; i < SHOOTOUT_LASER_COUNT; i++) { \
shootout_lasers[i].unput_and_reset(); \