From 52aa9891b9564debd757ee203249ac443712e560 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 23 Jul 2022 20:58:10 +0000 Subject: [PATCH] Simplify passing weapon to do_missile_firing When the player fires a generic secondary, the choice of proximity bomb versus super-mine is never read. When the player specifically drops a bomb, only that choice needs to be read. Pass the chosen weapon as an argument, and avoid computing the choice on the path where it is never read. --- common/main/laser.h | 2 +- similar/main/gamecntl.cpp | 5 ++--- similar/main/laser.cpp | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/common/main/laser.h b/common/main/laser.h index 861fb1ce4..71faf98fa 100644 --- a/common/main/laser.h +++ b/common/main/laser.h @@ -89,7 +89,7 @@ void Flare_create(vmobjptridx_t obj); bool laser_are_related(vcobjptridx_t o1, vcobjptridx_t o2); void do_laser_firing_player(object &); -void do_missile_firing(int drop_bomb, const secondary_weapon_index_t bomb, const vmobjptridx_t plrobjidx); +void do_missile_firing(const secondary_weapon_index_t weapon, const vmobjptridx_t plrobjidx); // Fires a laser-type weapon (a Primary weapon) // Fires from object objnum, weapon type weapon_id. diff --git a/similar/main/gamecntl.cpp b/similar/main/gamecntl.cpp index 0060b466b..14ff75285 100644 --- a/similar/main/gamecntl.cpp +++ b/similar/main/gamecntl.cpp @@ -300,8 +300,7 @@ static void do_weapon_n_item_stuff(object_array &Objects, control_info &Controls if (Global_missile_firing_count) { --Global_missile_firing_count; - const auto bomb = which_bomb(player_info); - do_missile_firing(0, bomb, plrobjidx); + do_missile_firing(player_info.Secondary_weapon, plrobjidx); } if (Controls.state.cycle_primary > 0) @@ -339,7 +338,7 @@ static void do_weapon_n_item_stuff(object_array &Objects, control_info &Controls { const auto bomb = which_bomb(player_info); for (uint_fast32_t i = std::exchange(Controls.state.drop_bomb, 0); i--;) - do_missile_firing(1, bomb, plrobjidx); + do_missile_firing(bomb, plrobjidx); } #if defined(DXX_BUILD_DESCENT_II) if (Controls.state.toggle_bomb > 0) diff --git a/similar/main/laser.cpp b/similar/main/laser.cpp index 9ad86b444..a217e1dc8 100644 --- a/similar/main/laser.cpp +++ b/similar/main/laser.cpp @@ -2322,14 +2322,13 @@ void release_remote_guided_missile(d_level_unique_object_state &LevelUniqueObjec // ------------------------------------------------------------------------------------------- //changed on 31/3/10 by kreatordxx to distinguish between drop bomb and secondary fire -void do_missile_firing(int drop_bomb, const secondary_weapon_index_t bomb, const vmobjptridx_t plrobjidx) +void do_missile_firing(const secondary_weapon_index_t weapon, const vmobjptridx_t plrobjidx) { int gun_flag=0; fix fire_frame_overhead = 0; auto &plrobj = *plrobjidx; auto &player_info = plrobj.ctype.player_info; - const auto weapon = drop_bomb ? bomb : player_info.Secondary_weapon; assert(weapon < MAX_SECONDARY_WEAPONS); auto &Next_missile_fire_time = player_info.Next_missile_fire_time; if (GameTime64 - Next_missile_fire_time <= FrameTime) // if firing is prolonged by FrameTime overhead, let's try to fix that.