Skip to content

Commit

Permalink
[Maintenance] [th01] Shootout lasers: Add a safe subscript wrapper
Browse files Browse the repository at this point in the history
Part of P0193, funded by Ember2528.
  • Loading branch information
nmlgc committed May 31, 2022
1 parent e1f3f9f commit 365d8ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 1 addition & 4 deletions th01/main/boss/b20j.cpp
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions th01/main/boss/b20m.cpp
Expand Up @@ -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
);
Expand Down
4 changes: 4 additions & 0 deletions th01/main/bullet/laser_s.hpp
Expand Up @@ -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(); \
Expand Down

0 comments on commit 365d8ea

Please sign in to comment.