From d81220fce22a23da5b2363f0d4b8ee54b6b00220 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Sat, 24 Oct 2020 21:28:52 -0400 Subject: [PATCH 01/13] Refactor GoTo loc_6D7A97 Moved to another function; what would be a good name for it? --- src/openrct2/ride/Vehicle.cpp | 43 +++++++++++++++++++++++------------ src/openrct2/ride/Vehicle.h | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index bf6020ba2efb..f62d28af40b4 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5496,6 +5496,20 @@ void Vehicle::UpdateCrash() } } } + +void Vehicle::screamSubFunction(Ride* curRide, OpenRCT2::Audio::SoundId screamId, uint8_t screamVolume) +{ + scream_sound_id = OpenRCT2::Audio::SoundId::Null; + if (curRide->type < std::size(RideTypeDescriptors)) + { + // Get lift hill sound + screamId = RideTypeDescriptors[curRide->type].LiftData.sound_id; + screamVolume = 243; + if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) + screamId = OpenRCT2::Audio::SoundId::Null; + } +} + /** * * rct2: 0x006D7888 @@ -5534,7 +5548,10 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSubFunction(curRide, screamId, screamVolume); + break; + } if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5553,7 +5570,10 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSubFunction(curRide, screamId, screamVolume); + break; + } if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5574,21 +5594,16 @@ void Vehicle::UpdateSound() if (screamId == OpenRCT2::Audio::SoundId::NoScream) screamId = OpenRCT2::Audio::SoundId::Null; else if (screamId == OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSubFunction(curRide, screamId, screamVolume); + break; + } break; } - loc_6D7A97: - scream_sound_id = OpenRCT2::Audio::SoundId::Null; - if (curRide->type < std::size(RideTypeDescriptors)) - { - // Get lift hill sound - screamId = RideTypeDescriptors[curRide->type].LiftData.sound_id; - screamVolume = 243; - if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) - screamId = OpenRCT2::Audio::SoundId::Null; - } - } + screamSubFunction(curRide, screamId, screamVolume); + + } // end switch // Friction sound auto soundIdVolume = sub_6D7AC0(sound1_id, sound1_volume, frictionId, frictionVolume); diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index c1b9fdefb8fb..fc04ecb73a3b 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -395,6 +395,7 @@ struct Vehicle : SpriteBase void UpdateShowingFilm(); void UpdateDoingCircusShow(); void UpdateCrossings() const; + void screamSubFunction(Ride*, OpenRCT2::Audio::SoundId, uint8_t); void UpdateSound(); OpenRCT2::Audio::SoundId UpdateScreamSound(); OpenRCT2::Audio::SoundId ProduceScreamSound(const int32_t totalNumPeeps); From e731d2ee3c922072d144c435dee96dae9bbd511c Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Sat, 31 Oct 2020 20:47:23 -0400 Subject: [PATCH 02/13] Revert "Refactor GoTo loc_6D7A97" This reverts commit d81220fce22a23da5b2363f0d4b8ee54b6b00220. --- src/openrct2/ride/Vehicle.cpp | 43 ++++++++++++----------------------- src/openrct2/ride/Vehicle.h | 1 - 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f62d28af40b4..bf6020ba2efb 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5496,20 +5496,6 @@ void Vehicle::UpdateCrash() } } } - -void Vehicle::screamSubFunction(Ride* curRide, OpenRCT2::Audio::SoundId screamId, uint8_t screamVolume) -{ - scream_sound_id = OpenRCT2::Audio::SoundId::Null; - if (curRide->type < std::size(RideTypeDescriptors)) - { - // Get lift hill sound - screamId = RideTypeDescriptors[curRide->type].LiftData.sound_id; - screamVolume = 243; - if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) - screamId = OpenRCT2::Audio::SoundId::Null; - } -} - /** * * rct2: 0x006D7888 @@ -5548,10 +5534,7 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - { - screamSubFunction(curRide, screamId, screamVolume); - break; - } + goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5570,10 +5553,7 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - { - screamSubFunction(curRide, screamId, screamVolume); - break; - } + goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5594,16 +5574,21 @@ void Vehicle::UpdateSound() if (screamId == OpenRCT2::Audio::SoundId::NoScream) screamId = OpenRCT2::Audio::SoundId::Null; else if (screamId == OpenRCT2::Audio::SoundId::Null) - { - screamSubFunction(curRide, screamId, screamVolume); - break; - } + goto loc_6D7A97; break; } - screamSubFunction(curRide, screamId, screamVolume); - - } // end switch + loc_6D7A97: + scream_sound_id = OpenRCT2::Audio::SoundId::Null; + if (curRide->type < std::size(RideTypeDescriptors)) + { + // Get lift hill sound + screamId = RideTypeDescriptors[curRide->type].LiftData.sound_id; + screamVolume = 243; + if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) + screamId = OpenRCT2::Audio::SoundId::Null; + } + } // Friction sound auto soundIdVolume = sub_6D7AC0(sound1_id, sound1_volume, frictionId, frictionVolume); diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index fc04ecb73a3b..c1b9fdefb8fb 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -395,7 +395,6 @@ struct Vehicle : SpriteBase void UpdateShowingFilm(); void UpdateDoingCircusShow(); void UpdateCrossings() const; - void screamSubFunction(Ride*, OpenRCT2::Audio::SoundId, uint8_t); void UpdateSound(); OpenRCT2::Audio::SoundId UpdateScreamSound(); OpenRCT2::Audio::SoundId ProduceScreamSound(const int32_t totalNumPeeps); From 497253f64d4e80602923ac23c561a7dd3ee676da Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Sat, 31 Oct 2020 21:47:33 -0400 Subject: [PATCH 03/13] transition to function and struct using function for 6D7A97, using struct as return value --- src/openrct2/ride/Vehicle.cpp | 74 +++++++++++++++++++++++++---------- src/openrct2/ride/Vehicle.h | 3 ++ 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index bf6020ba2efb..a0013ab90b17 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1945,6 +1945,22 @@ static SoundIdVolume sub_6D7AC0( return { currentSoundId, currentVolume }; } +SoundIdVolume Vehicle::sub_6D7A97(Ride* curRide) +{ + SoundIdVolume resultSounds{}; + std::cout << " Call function"; + scream_sound_id = OpenRCT2::Audio::SoundId::Null; + if (curRide->type < std::size(RideTypeDescriptors)) + { + // Get lift hill sound + resultSounds.id = RideTypeDescriptors[curRide->type].LiftData.sound_id; + resultSounds.volume = 243; + if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) + resultSounds.id = OpenRCT2::Audio::SoundId::Null; + } + return resultSounds; +} + /** * * rct2: 0x006D77F2 @@ -5506,8 +5522,9 @@ void Vehicle::UpdateSound() uint8_t frictionVolume = 255; auto frictionId = OpenRCT2::Audio::SoundId::Null; // bh screamVolume should be set before hand - auto screamId = OpenRCT2::Audio::SoundId::Null; - uint8_t screamVolume = 255; + SoundIdVolume screamSound = { OpenRCT2::Audio::SoundId::Null, 255 }; + //auto screamId = OpenRCT2::Audio::SoundId::Null; + //uint8_t screamVolume = 255; auto curRide = GetRide(); if (curRide == nullptr) @@ -5527,58 +5544,73 @@ void Vehicle::UpdateSound() frictionVolume = std::min(208 + (ecx & 0xFF), 255); } + std::cout << "Begin sound switch: "; switch (vehicleEntry->sound_range) { case SOUND_RANGE_WHISTLE: - screamId = scream_sound_id; + std::cout << " whistle"; + screamSound.id = scream_sound_id; if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSound = sub_6D7A97(curRide); // goto loc_6D7A97; + break; + } if ((scenario_rand() & 0xFFFF) <= 0x5555) { scream_sound_id = OpenRCT2::Audio::SoundId::TrainWhistle; - screamVolume = 255; + screamSound.volume = 255; break; } } - if (screamId == OpenRCT2::Audio::SoundId::NoScream) - screamId = OpenRCT2::Audio::SoundId::Null; - screamVolume = 255; + if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + screamSound.id = OpenRCT2::Audio::SoundId::Null; + screamSound.volume = 255; break; case SOUND_RANGE_BELL: - screamId = scream_sound_id; + std::cout << " bell"; + screamSound.id = scream_sound_id; if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + sub_6D7A97(curRide); // goto loc_6D7A97; + break; + } if ((scenario_rand() & 0xFFFF) <= 0x5555) { scream_sound_id = OpenRCT2::Audio::SoundId::Tram; - screamVolume = 255; + screamSound.volume = 255; break; } } - if (screamId == OpenRCT2::Audio::SoundId::NoScream) - screamId = OpenRCT2::Audio::SoundId::Null; - screamVolume = 255; + if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + screamSound.id = OpenRCT2::Audio::SoundId::Null; + screamSound.volume = 255; break; default: + std::cout << " default"; if ((vehicleEntry->flags & VEHICLE_ENTRY_FLAG_RIDERS_SCREAM)) { - screamId = UpdateScreamSound(); - if (screamId == OpenRCT2::Audio::SoundId::NoScream) - screamId = OpenRCT2::Audio::SoundId::Null; - else if (screamId == OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + screamSound.id = UpdateScreamSound(); + if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + screamSound.id = OpenRCT2::Audio::SoundId::Null; + else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) + { + sub_6D7A97(curRide);//goto loc_6D7A97; + break; + } break; } + /* loc_6D7A97: + std::cout << " went to loc"; scream_sound_id = OpenRCT2::Audio::SoundId::Null; if (curRide->type < std::size(RideTypeDescriptors)) { @@ -5588,7 +5620,9 @@ void Vehicle::UpdateSound() if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) screamId = OpenRCT2::Audio::SoundId::Null; } + */ } + std::cout << " - end switch\n"; // Friction sound auto soundIdVolume = sub_6D7AC0(sound1_id, sound1_volume, frictionId, frictionVolume); @@ -5596,7 +5630,7 @@ void Vehicle::UpdateSound() sound1_volume = soundIdVolume.volume; // Scream sound - soundIdVolume = sub_6D7AC0(sound2_id, sound2_volume, screamId, screamVolume); + soundIdVolume = sub_6D7AC0(sound2_id, sound2_volume, screamSound.id, screamSound.volume); sound2_id = soundIdVolume.id; sound2_volume = soundIdVolume.volume; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index c1b9fdefb8fb..9f96fe02d4bd 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -153,6 +153,8 @@ struct rct_vehicle_info uint8_t bank_rotation; // 0x08 }; +struct SoundIdVolume; + struct Vehicle : SpriteBase { enum class Type : uint8_t @@ -396,6 +398,7 @@ struct Vehicle : SpriteBase void UpdateDoingCircusShow(); void UpdateCrossings() const; void UpdateSound(); + SoundIdVolume sub_6D7A97(Ride* curRide); OpenRCT2::Audio::SoundId UpdateScreamSound(); OpenRCT2::Audio::SoundId ProduceScreamSound(const int32_t totalNumPeeps); void UpdateCrashSetup(); From ad746cff6f1e72d61a1854dca6809a7e202845a9 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Sat, 31 Oct 2020 21:54:09 -0400 Subject: [PATCH 04/13] minor adjustments and clang formatting as usual --- src/openrct2/ride/Vehicle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index a0013ab90b17..cb568c4e670e 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5523,8 +5523,8 @@ void Vehicle::UpdateSound() auto frictionId = OpenRCT2::Audio::SoundId::Null; // bh screamVolume should be set before hand SoundIdVolume screamSound = { OpenRCT2::Audio::SoundId::Null, 255 }; - //auto screamId = OpenRCT2::Audio::SoundId::Null; - //uint8_t screamVolume = 255; + // auto screamId = OpenRCT2::Audio::SoundId::Null; + // uint8_t screamVolume = 255; auto curRide = GetRide(); if (curRide == nullptr) @@ -5577,7 +5577,7 @@ void Vehicle::UpdateSound() { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - sub_6D7A97(curRide); // goto loc_6D7A97; + screamSound = sub_6D7A97(curRide); // goto loc_6D7A97; break; } @@ -5602,7 +5602,7 @@ void Vehicle::UpdateSound() screamSound.id = OpenRCT2::Audio::SoundId::Null; else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) { - sub_6D7A97(curRide);//goto loc_6D7A97; + screamSound = sub_6D7A97(curRide); // goto loc_6D7A97; break; } break; From 31b5e9588744bd54689354cac610060c0ef04242 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:36:25 -0400 Subject: [PATCH 05/13] backtrack goto see if the problem is with my function or the goto refactor --- src/openrct2/ride/Vehicle.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index cb568c4e670e..3cc666290b1f 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5553,10 +5553,7 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - { - screamSound = sub_6D7A97(curRide); // goto loc_6D7A97; - break; - } + goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5576,10 +5573,7 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - { - screamSound = sub_6D7A97(curRide); // goto loc_6D7A97; - break; - } + goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5601,15 +5595,13 @@ void Vehicle::UpdateSound() if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) screamSound.id = OpenRCT2::Audio::SoundId::Null; else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) - { - screamSound = sub_6D7A97(curRide); // goto loc_6D7A97; - break; - } + goto loc_6D7A97; break; } - /* loc_6D7A97: + screamSound = sub_6D7A97(curRide); + /* std::cout << " went to loc"; scream_sound_id = OpenRCT2::Audio::SoundId::Null; if (curRide->type < std::size(RideTypeDescriptors)) From dc5e27b6a06829a5c59c166389e8ca173fbca865 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Wed, 4 Nov 2020 21:43:12 -0500 Subject: [PATCH 06/13] Remove GoTo part 1 Make sure this idea works --- src/openrct2/ride/Vehicle.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 3cc666290b1f..d9d5648d7eb0 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5553,7 +5553,10 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSound = sub_6D7A97(curRide); + break; + } if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5573,7 +5576,10 @@ void Vehicle::UpdateSound() if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSound = sub_6D7A97(curRide); + break; + } if ((scenario_rand() & 0xFFFF) <= 0x5555) { @@ -5595,11 +5601,14 @@ void Vehicle::UpdateSound() if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) screamSound.id = OpenRCT2::Audio::SoundId::Null; else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) - goto loc_6D7A97; + { + screamSound = sub_6D7A97(curRide); + break; + } break; } - loc_6D7A97: + // loc_6D7A97: screamSound = sub_6D7A97(curRide); /* std::cout << " went to loc"; From 52dbb69ab4997655cffa8aa91a6405a81520b8e1 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Wed, 4 Nov 2020 22:02:26 -0500 Subject: [PATCH 07/13] rename function to friendly name Now called GetLiftHillSound after the comment within the code --- src/openrct2/ride/Vehicle.cpp | 10 +++++----- src/openrct2/ride/Vehicle.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index d9d5648d7eb0..d9355bf8e074 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1945,7 +1945,7 @@ static SoundIdVolume sub_6D7AC0( return { currentSoundId, currentVolume }; } -SoundIdVolume Vehicle::sub_6D7A97(Ride* curRide) +SoundIdVolume Vehicle::GetLiftHillSound(Ride* curRide) { SoundIdVolume resultSounds{}; std::cout << " Call function"; @@ -5554,7 +5554,7 @@ void Vehicle::UpdateSound() { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - screamSound = sub_6D7A97(curRide); + screamSound = GetLiftHillSound(curRide); break; } @@ -5577,7 +5577,7 @@ void Vehicle::UpdateSound() { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - screamSound = sub_6D7A97(curRide); + screamSound = GetLiftHillSound(curRide); break; } @@ -5602,14 +5602,14 @@ void Vehicle::UpdateSound() screamSound.id = OpenRCT2::Audio::SoundId::Null; else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) { - screamSound = sub_6D7A97(curRide); + screamSound = GetLiftHillSound(curRide); break; } break; } // loc_6D7A97: - screamSound = sub_6D7A97(curRide); + screamSound = GetLiftHillSound(curRide); /* std::cout << " went to loc"; scream_sound_id = OpenRCT2::Audio::SoundId::Null; diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 9f96fe02d4bd..60f062003461 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -398,7 +398,7 @@ struct Vehicle : SpriteBase void UpdateDoingCircusShow(); void UpdateCrossings() const; void UpdateSound(); - SoundIdVolume sub_6D7A97(Ride* curRide); + SoundIdVolume GetLiftHillSound(Ride* curRide); OpenRCT2::Audio::SoundId UpdateScreamSound(); OpenRCT2::Audio::SoundId ProduceScreamSound(const int32_t totalNumPeeps); void UpdateCrashSetup(); From 740806609d85b4814a93784369042cb93a570903 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Wed, 4 Nov 2020 22:30:30 -0500 Subject: [PATCH 08/13] rename variable and clean up code currentSound seemed better, as it is not always a scream --- src/openrct2/ride/Vehicle.cpp | 59 ++++++++++++----------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index d9355bf8e074..092ebde4c252 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1948,7 +1948,6 @@ static SoundIdVolume sub_6D7AC0( SoundIdVolume Vehicle::GetLiftHillSound(Ride* curRide) { SoundIdVolume resultSounds{}; - std::cout << " Call function"; scream_sound_id = OpenRCT2::Audio::SoundId::Null; if (curRide->type < std::size(RideTypeDescriptors)) { @@ -5522,7 +5521,7 @@ void Vehicle::UpdateSound() uint8_t frictionVolume = 255; auto frictionId = OpenRCT2::Audio::SoundId::Null; // bh screamVolume should be set before hand - SoundIdVolume screamSound = { OpenRCT2::Audio::SoundId::Null, 255 }; + SoundIdVolume currentSound = { OpenRCT2::Audio::SoundId::Null, 255 }; // auto screamId = OpenRCT2::Audio::SoundId::Null; // uint8_t screamVolume = 255; @@ -5544,86 +5543,68 @@ void Vehicle::UpdateSound() frictionVolume = std::min(208 + (ecx & 0xFF), 255); } - std::cout << "Begin sound switch: "; switch (vehicleEntry->sound_range) { case SOUND_RANGE_WHISTLE: - std::cout << " whistle"; - screamSound.id = scream_sound_id; + currentSound.id = scream_sound_id; if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - screamSound = GetLiftHillSound(curRide); + currentSound = GetLiftHillSound(curRide); break; } if ((scenario_rand() & 0xFFFF) <= 0x5555) { scream_sound_id = OpenRCT2::Audio::SoundId::TrainWhistle; - screamSound.volume = 255; + currentSound.volume = 255; break; } } - if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) - screamSound.id = OpenRCT2::Audio::SoundId::Null; - screamSound.volume = 255; + if (currentSound.id == OpenRCT2::Audio::SoundId::NoScream) + currentSound.id = OpenRCT2::Audio::SoundId::Null; + currentSound.volume = 255; break; case SOUND_RANGE_BELL: - std::cout << " bell"; - screamSound.id = scream_sound_id; + currentSound.id = scream_sound_id; if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - screamSound = GetLiftHillSound(curRide); + currentSound = GetLiftHillSound(curRide); break; } if ((scenario_rand() & 0xFFFF) <= 0x5555) { scream_sound_id = OpenRCT2::Audio::SoundId::Tram; - screamSound.volume = 255; + currentSound.volume = 255; break; } } - if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) - screamSound.id = OpenRCT2::Audio::SoundId::Null; - screamSound.volume = 255; + if (currentSound.id == OpenRCT2::Audio::SoundId::NoScream) + currentSound.id = OpenRCT2::Audio::SoundId::Null; + currentSound.volume = 255; break; default: - std::cout << " default"; if ((vehicleEntry->flags & VEHICLE_ENTRY_FLAG_RIDERS_SCREAM)) { - screamSound.id = UpdateScreamSound(); - if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) - screamSound.id = OpenRCT2::Audio::SoundId::Null; - else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) + currentSound.id = UpdateScreamSound(); + if (currentSound.id == OpenRCT2::Audio::SoundId::NoScream) + currentSound.id = OpenRCT2::Audio::SoundId::Null; + else if (currentSound.id == OpenRCT2::Audio::SoundId::Null) { - screamSound = GetLiftHillSound(curRide); + currentSound = GetLiftHillSound(curRide); break; } break; } - // loc_6D7A97: - screamSound = GetLiftHillSound(curRide); - /* - std::cout << " went to loc"; - scream_sound_id = OpenRCT2::Audio::SoundId::Null; - if (curRide->type < std::size(RideTypeDescriptors)) - { - // Get lift hill sound - screamId = RideTypeDescriptors[curRide->type].LiftData.sound_id; - screamVolume = 243; - if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) - screamId = OpenRCT2::Audio::SoundId::Null; - } - */ + currentSound = GetLiftHillSound(curRide); } - std::cout << " - end switch\n"; // Friction sound auto soundIdVolume = sub_6D7AC0(sound1_id, sound1_volume, frictionId, frictionVolume); @@ -5631,7 +5612,7 @@ void Vehicle::UpdateSound() sound1_volume = soundIdVolume.volume; // Scream sound - soundIdVolume = sub_6D7AC0(sound2_id, sound2_volume, screamSound.id, screamSound.volume); + soundIdVolume = sub_6D7AC0(sound2_id, sound2_volume, currentSound.id, currentSound.volume); sound2_id = soundIdVolume.id; sound2_volume = soundIdVolume.volume; From 1f3499d74328141b35283baf045e68d0478eb0dd Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Wed, 4 Nov 2020 22:35:31 -0500 Subject: [PATCH 09/13] Remove unnecessary comments per best practice --- src/openrct2/ride/Vehicle.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 092ebde4c252..7f972aea4963 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5522,8 +5522,6 @@ void Vehicle::UpdateSound() auto frictionId = OpenRCT2::Audio::SoundId::Null; // bh screamVolume should be set before hand SoundIdVolume currentSound = { OpenRCT2::Audio::SoundId::Null, 255 }; - // auto screamId = OpenRCT2::Audio::SoundId::Null; - // uint8_t screamVolume = 255; auto curRide = GetRide(); if (curRide == nullptr) From deee0c6d50ecc8167b426bbd2b90d19a6e679b58 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Mon, 9 Nov 2020 20:39:29 -0500 Subject: [PATCH 10/13] make currentSound a reference param That way, it won't wipe out the previous value, as it was doing before --- src/openrct2/ride/Vehicle.cpp | 18 ++++++++---------- src/openrct2/ride/Vehicle.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7f972aea4963..b8c180f63782 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1945,19 +1945,17 @@ static SoundIdVolume sub_6D7AC0( return { currentSoundId, currentVolume }; } -SoundIdVolume Vehicle::GetLiftHillSound(Ride* curRide) +void Vehicle::GetLiftHillSound(Ride* curRide, SoundIdVolume& curSound) { - SoundIdVolume resultSounds{}; scream_sound_id = OpenRCT2::Audio::SoundId::Null; if (curRide->type < std::size(RideTypeDescriptors)) { // Get lift hill sound - resultSounds.id = RideTypeDescriptors[curRide->type].LiftData.sound_id; - resultSounds.volume = 243; + curSound.id = RideTypeDescriptors[curRide->type].LiftData.sound_id; + curSound.volume = 243; if (!(sound2_flags & VEHICLE_SOUND2_FLAGS_LIFT_HILL)) - resultSounds.id = OpenRCT2::Audio::SoundId::Null; + curSound.id = OpenRCT2::Audio::SoundId::Null; } - return resultSounds; } /** @@ -5549,7 +5547,7 @@ void Vehicle::UpdateSound() { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - currentSound = GetLiftHillSound(curRide); + GetLiftHillSound(curRide, currentSound); break; } @@ -5571,7 +5569,7 @@ void Vehicle::UpdateSound() { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - currentSound = GetLiftHillSound(curRide); + GetLiftHillSound(curRide, currentSound); break; } @@ -5595,13 +5593,13 @@ void Vehicle::UpdateSound() currentSound.id = OpenRCT2::Audio::SoundId::Null; else if (currentSound.id == OpenRCT2::Audio::SoundId::Null) { - currentSound = GetLiftHillSound(curRide); + GetLiftHillSound(curRide, currentSound); break; } break; } - currentSound = GetLiftHillSound(curRide); + GetLiftHillSound(curRide, currentSound); } // Friction sound diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 60f062003461..6274d9f752b9 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -398,7 +398,7 @@ struct Vehicle : SpriteBase void UpdateDoingCircusShow(); void UpdateCrossings() const; void UpdateSound(); - SoundIdVolume GetLiftHillSound(Ride* curRide); + void GetLiftHillSound(Ride* curRide, SoundIdVolume &curSound); OpenRCT2::Audio::SoundId UpdateScreamSound(); OpenRCT2::Audio::SoundId ProduceScreamSound(const int32_t totalNumPeeps); void UpdateCrashSetup(); From 59b3f0a2883c764fb53a16a2447fbd78bb55f71f Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Mon, 9 Nov 2020 20:42:06 -0500 Subject: [PATCH 11/13] update clang formatting --- src/openrct2/ride/Vehicle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 6274d9f752b9..582f1ef017cd 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -398,7 +398,7 @@ struct Vehicle : SpriteBase void UpdateDoingCircusShow(); void UpdateCrossings() const; void UpdateSound(); - void GetLiftHillSound(Ride* curRide, SoundIdVolume &curSound); + void GetLiftHillSound(Ride* curRide, SoundIdVolume& curSound); OpenRCT2::Audio::SoundId UpdateScreamSound(); OpenRCT2::Audio::SoundId ProduceScreamSound(const int32_t totalNumPeeps); void UpdateCrashSetup(); From 67cc220904a6071be0a3032f05bb4bbd3cb43080 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Fri, 13 Nov 2020 16:55:28 -0500 Subject: [PATCH 12/13] refactor two sound variables to match frictionSound and screamSound are now consistent, since they're used in the same way --- src/openrct2/ride/Vehicle.cpp | 49 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index b8c180f63782..7cb737a7053e 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5516,10 +5516,9 @@ void Vehicle::UpdateCrash() void Vehicle::UpdateSound() { // frictionVolume (bl) should be set before hand - uint8_t frictionVolume = 255; - auto frictionId = OpenRCT2::Audio::SoundId::Null; + SoundIdVolume frictionSound = { OpenRCT2::Audio::SoundId::Null, 255 }; // bh screamVolume should be set before hand - SoundIdVolume currentSound = { OpenRCT2::Audio::SoundId::Null, 255 }; + SoundIdVolume screamSound = { OpenRCT2::Audio::SoundId::Null, 255 }; auto curRide = GetRide(); if (curRide == nullptr) @@ -5534,81 +5533,81 @@ void Vehicle::UpdateSound() int32_t ecx = abs(velocity) - 0x10000; if (ecx >= 0) { - frictionId = vehicleEntry->friction_sound_id; + frictionSound.id = vehicleEntry->friction_sound_id; ecx >>= 15; - frictionVolume = std::min(208 + (ecx & 0xFF), 255); + frictionSound.volume = std::min(208 + (ecx & 0xFF), 255); } switch (vehicleEntry->sound_range) { case SOUND_RANGE_WHISTLE: - currentSound.id = scream_sound_id; + screamSound.id = scream_sound_id; if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - GetLiftHillSound(curRide, currentSound); + GetLiftHillSound(curRide, screamSound); break; } if ((scenario_rand() & 0xFFFF) <= 0x5555) { scream_sound_id = OpenRCT2::Audio::SoundId::TrainWhistle; - currentSound.volume = 255; + screamSound.volume = 255; break; } } - if (currentSound.id == OpenRCT2::Audio::SoundId::NoScream) - currentSound.id = OpenRCT2::Audio::SoundId::Null; - currentSound.volume = 255; + if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + screamSound.id = OpenRCT2::Audio::SoundId::Null; + screamSound.volume = 255; break; case SOUND_RANGE_BELL: - currentSound.id = scream_sound_id; + screamSound.id = scream_sound_id; if (!(gCurrentTicks & 0x7F)) { if (velocity < 0x40000 || scream_sound_id != OpenRCT2::Audio::SoundId::Null) { - GetLiftHillSound(curRide, currentSound); + GetLiftHillSound(curRide, screamSound); break; } if ((scenario_rand() & 0xFFFF) <= 0x5555) { scream_sound_id = OpenRCT2::Audio::SoundId::Tram; - currentSound.volume = 255; + screamSound.volume = 255; break; } } - if (currentSound.id == OpenRCT2::Audio::SoundId::NoScream) - currentSound.id = OpenRCT2::Audio::SoundId::Null; - currentSound.volume = 255; + if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + screamSound.id = OpenRCT2::Audio::SoundId::Null; + screamSound.volume = 255; break; default: if ((vehicleEntry->flags & VEHICLE_ENTRY_FLAG_RIDERS_SCREAM)) { - currentSound.id = UpdateScreamSound(); - if (currentSound.id == OpenRCT2::Audio::SoundId::NoScream) - currentSound.id = OpenRCT2::Audio::SoundId::Null; - else if (currentSound.id == OpenRCT2::Audio::SoundId::Null) + screamSound.id = UpdateScreamSound(); + if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + screamSound.id = OpenRCT2::Audio::SoundId::Null; + else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) { - GetLiftHillSound(curRide, currentSound); + GetLiftHillSound(curRide, screamSound); break; } break; } - GetLiftHillSound(curRide, currentSound); + GetLiftHillSound(curRide, screamSound); } // Friction sound - auto soundIdVolume = sub_6D7AC0(sound1_id, sound1_volume, frictionId, frictionVolume); + auto soundIdVolume = sub_6D7AC0(sound1_id, sound1_volume, frictionSound.id, frictionSound.volume); sound1_id = soundIdVolume.id; sound1_volume = soundIdVolume.volume; // Scream sound - soundIdVolume = sub_6D7AC0(sound2_id, sound2_volume, currentSound.id, currentSound.volume); + soundIdVolume = sub_6D7AC0(sound2_id, sound2_volume, screamSound.id, screamSound.volume); sound2_id = soundIdVolume.id; sound2_volume = soundIdVolume.volume; From 87f09517f1b3e5c1ccd9e47dfb068e385641dc55 Mon Sep 17 00:00:00 2001 From: rpstester <32249806+rpstester@users.noreply.github.com> Date: Sat, 14 Nov 2020 18:59:20 -0500 Subject: [PATCH 13/13] rework breaks on default scream Per duncanspumpkin; I hope this is what you're looking for --- src/openrct2/ride/Vehicle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7cb737a7053e..c6efe897ab11 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5589,15 +5589,15 @@ void Vehicle::UpdateSound() { screamSound.id = UpdateScreamSound(); if (screamSound.id == OpenRCT2::Audio::SoundId::NoScream) + { screamSound.id = OpenRCT2::Audio::SoundId::Null; - else if (screamSound.id == OpenRCT2::Audio::SoundId::Null) + break; + } + if (screamSound.id != OpenRCT2::Audio::SoundId::Null) { - GetLiftHillSound(curRide, screamSound); break; } - break; } - GetLiftHillSound(curRide, screamSound); }