From 01d0287ee2a135e8f337c75df4834f92da23093c Mon Sep 17 00:00:00 2001 From: michael coates Date: Wed, 15 Jul 2020 02:48:47 -0400 Subject: [PATCH] Close #12253: Refactor Vehicle sound to remove goto (#12267) * Refactor Vehicle Scream Sound goto * updated contributors --- contributors.md | 1 + src/openrct2/ride/Vehicle.cpp | 20 +++++++++++--------- src/openrct2/ride/Vehicle.h | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/contributors.md b/contributors.md index 86fa6002ad..c373c9c3ec 100644 --- a/contributors.md +++ b/contributors.md @@ -144,6 +144,7 @@ The following people are not part of the development team, but have been contrib * Tomáš Žilínek (TomasZilinek) * Mustapha Elghoul (mustaphaelghoul) * Tyler Leamon (tylerleamon) +* Michael Coates (outerwear) ## Toolchain * (Balletie) - macOS diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 374c4c8886..53c3a9caeb 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5560,10 +5560,6 @@ void Vehicle::UpdateSound() */ SoundId Vehicle::UpdateScreamSound() { - rct_ride_entry* rideEntry = GetRideEntry(); - - rct_ride_entry_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle_type]; - int32_t totalNumPeeps = NumPeepsUntilTrainTail(); if (totalNumPeeps == 0) return SoundId::Null; @@ -5585,11 +5581,11 @@ SoundId Vehicle::UpdateScreamSound() if (vehicle2->vehicle_sprite_type < 1) continue; if (vehicle2->vehicle_sprite_type <= 4) - goto produceScream; + return ProduceScreamSound(totalNumPeeps); if (vehicle2->vehicle_sprite_type < 9) continue; if (vehicle2->vehicle_sprite_type <= 15) - goto produceScream; + return ProduceScreamSound(totalNumPeeps); } return SoundId::Null; } @@ -5608,15 +5604,21 @@ SoundId Vehicle::UpdateScreamSound() if (vehicle2->vehicle_sprite_type < 5) continue; if (vehicle2->vehicle_sprite_type <= 8) - goto produceScream; + return ProduceScreamSound(totalNumPeeps); if (vehicle2->vehicle_sprite_type < 17) continue; if (vehicle2->vehicle_sprite_type <= 23) - goto produceScream; + return ProduceScreamSound(totalNumPeeps); } return SoundId::Null; +} + +SoundId Vehicle::ProduceScreamSound(const int32_t totalNumPeeps) +{ + rct_ride_entry* rideEntry = GetRideEntry(); + + rct_ride_entry_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle_type]; -produceScream: if (scream_sound_id == SoundId::Null) { auto r = scenario_rand(); diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 66c17ae9b8..f383e17d7a 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -401,6 +401,7 @@ private: void UpdateCrossings() const; void UpdateSound(); SoundId UpdateScreamSound(); + SoundId ProduceScreamSound(const int32_t totalNumPeeps); void UpdateCrashSetup(); void UpdateCollisionSetup(); int32_t UpdateMotionDodgems();