mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #10596 from tupaschoal/pr-10070-copy
Remove global variable for sound param list
This commit is contained in:
commit
22768ea915
|
@ -53,8 +53,6 @@ rct_ride_music_params gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
|
|||
rct_ride_music_params* gRideMusicParamsListEnd;
|
||||
|
||||
rct_vehicle_sound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
rct_vehicle_sound_params gVehicleSoundParamsList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
rct_vehicle_sound_params* gVehicleSoundParamsListEnd;
|
||||
|
||||
// clang-format off
|
||||
static int32_t SoundVolumeAdjust[RCT2SoundCount] =
|
||||
|
|
|
@ -168,8 +168,6 @@ extern rct_ride_music_params gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
|
|||
extern rct_ride_music_params* gRideMusicParamsListEnd;
|
||||
|
||||
extern rct_vehicle_sound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
extern rct_vehicle_sound_params gVehicleSoundParamsList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
extern rct_vehicle_sound_params* gVehicleSoundParamsListEnd;
|
||||
|
||||
/**
|
||||
* Deregisters the audio device.
|
||||
|
|
|
@ -998,34 +998,36 @@ rct_vehicle_sound_params Vehicle::CreateSoundParam(uint16_t priority) const
|
|||
*
|
||||
* rct2: 0x006BB9FF
|
||||
*/
|
||||
void Vehicle::UpdateSoundParams() const
|
||||
void Vehicle::UpdateSoundParams(std::vector<rct_vehicle_sound_params>& vehicleSoundParamsList) const
|
||||
{
|
||||
if (!SoundCanPlay())
|
||||
return;
|
||||
|
||||
uint16_t soundPriority = GetSoundPriority();
|
||||
rct_vehicle_sound_params* soundParam;
|
||||
// Find a sound param of lower priority to use
|
||||
for (soundParam = &gVehicleSoundParamsList[0];
|
||||
soundParam < gVehicleSoundParamsListEnd && soundPriority <= soundParam->priority; soundParam++)
|
||||
;
|
||||
auto soundParamIter = std::find_if(
|
||||
vehicleSoundParamsList.begin(), vehicleSoundParamsList.end(),
|
||||
[soundPriority](rct_vehicle_sound_params param) { return soundPriority > param.priority; });
|
||||
|
||||
if (soundParam >= &gVehicleSoundParamsList[std::size(gVehicleSoundParamsList)])
|
||||
return;
|
||||
|
||||
if (gVehicleSoundParamsListEnd < &gVehicleSoundParamsList[std::size(gVehicleSoundParamsList)])
|
||||
if (soundParamIter == std::end(vehicleSoundParamsList))
|
||||
{
|
||||
gVehicleSoundParamsListEnd++;
|
||||
if (vehicleSoundParamsList.size() < AUDIO_MAX_VEHICLE_SOUNDS)
|
||||
{
|
||||
vehicleSoundParamsList.push_back(CreateSoundParam(soundPriority));
|
||||
}
|
||||
}
|
||||
|
||||
// Shift all sound params down one if using a free space
|
||||
if (soundParam != gVehicleSoundParamsListEnd)
|
||||
else
|
||||
{
|
||||
std::memmove(
|
||||
soundParam + 1, soundParam, ((gVehicleSoundParamsListEnd - soundParam) - 1) * sizeof(rct_vehicle_sound_params));
|
||||
if (vehicleSoundParamsList.size() < AUDIO_MAX_VEHICLE_SOUNDS)
|
||||
{
|
||||
// Shift all sound params down one if using a free space
|
||||
vehicleSoundParamsList.insert(soundParamIter, CreateSoundParam(soundPriority));
|
||||
}
|
||||
else
|
||||
{
|
||||
*soundParamIter = CreateSoundParam(soundPriority);
|
||||
}
|
||||
}
|
||||
|
||||
*soundParam = CreateSoundParam(soundPriority);
|
||||
}
|
||||
|
||||
static void vehicle_sounds_update_window_setup()
|
||||
|
@ -1272,12 +1274,14 @@ void vehicle_sounds_update()
|
|||
if (gAudioCurrentDevice == -1 || gGameSoundsOff || !gConfigSound.sound_enabled || gOpenRCT2Headless)
|
||||
return;
|
||||
|
||||
std::vector<rct_vehicle_sound_params> vehicleSoundParamsList;
|
||||
vehicleSoundParamsList.reserve(AUDIO_MAX_VEHICLE_SOUNDS);
|
||||
|
||||
vehicle_sounds_update_window_setup();
|
||||
|
||||
gVehicleSoundParamsListEnd = &gVehicleSoundParamsList[0];
|
||||
for (uint16_t i = gSpriteListHead[SPRITE_LIST_VEHICLE_HEAD]; i != SPRITE_INDEX_NULL; i = get_sprite(i)->vehicle.next)
|
||||
{
|
||||
get_sprite(i)->vehicle.UpdateSoundParams();
|
||||
get_sprite(i)->vehicle.UpdateSoundParams(vehicleSoundParamsList);
|
||||
}
|
||||
|
||||
// Stop all playing sounds that no longer have priority to play after vehicle_update_sound_params
|
||||
|
@ -1286,10 +1290,9 @@ void vehicle_sounds_update()
|
|||
if (vehicle_sound.id != SOUND_ID_NULL)
|
||||
{
|
||||
bool keepPlaying = false;
|
||||
for (rct_vehicle_sound_params* vehicle_sound_params = &gVehicleSoundParamsList[0];
|
||||
vehicle_sound_params != gVehicleSoundParamsListEnd; vehicle_sound_params++)
|
||||
for (auto vehicleSoundParams : vehicleSoundParamsList)
|
||||
{
|
||||
if (vehicle_sound.id == vehicle_sound_params->id)
|
||||
if (vehicle_sound.id == vehicleSoundParams.id)
|
||||
{
|
||||
keepPlaying = true;
|
||||
break;
|
||||
|
@ -1311,21 +1314,20 @@ void vehicle_sounds_update()
|
|||
}
|
||||
}
|
||||
|
||||
for (rct_vehicle_sound_params* vehicleSoundParams = &gVehicleSoundParamsList[0];
|
||||
vehicleSoundParams < gVehicleSoundParamsListEnd; vehicleSoundParams++)
|
||||
for (auto& vehicleSoundParams : vehicleSoundParamsList)
|
||||
{
|
||||
uint8_t panVol = vehicle_sounds_update_get_pan_volume(vehicleSoundParams);
|
||||
uint8_t panVol = vehicle_sounds_update_get_pan_volume(&vehicleSoundParams);
|
||||
|
||||
rct_vehicle_sound* vehicleSound = vehicle_sounds_update_get_vehicle_sound(vehicleSoundParams);
|
||||
rct_vehicle_sound* vehicleSound = vehicle_sounds_update_get_vehicle_sound(&vehicleSoundParams);
|
||||
// No free vehicle sound slots (RCT2 corrupts the pointer here)
|
||||
if (vehicleSound == nullptr)
|
||||
continue;
|
||||
|
||||
// Move the Sound Volume towards the SoundsParam Volume
|
||||
int32_t tempvolume = vehicleSound->volume;
|
||||
if (tempvolume != vehicleSoundParams->volume)
|
||||
if (tempvolume != vehicleSoundParams.volume)
|
||||
{
|
||||
if (tempvolume < vehicleSoundParams->volume)
|
||||
if (tempvolume < vehicleSoundParams.volume)
|
||||
{
|
||||
tempvolume += 4;
|
||||
}
|
||||
|
@ -1337,9 +1339,9 @@ void vehicle_sounds_update()
|
|||
vehicleSound->volume = tempvolume;
|
||||
panVol = std::max(0, panVol - tempvolume);
|
||||
|
||||
Vehicle* vehicle = GET_VEHICLE(vehicleSoundParams->id);
|
||||
vehicle_sounds_update_sound_1(vehicle, vehicleSoundParams, vehicleSound, panVol);
|
||||
vehicle_sounds_update_sound_2(vehicle, vehicleSoundParams, vehicleSound, panVol);
|
||||
Vehicle* vehicle = GET_VEHICLE(vehicleSoundParams.id);
|
||||
vehicle_sounds_update_sound_1(vehicle, &vehicleSoundParams, vehicleSound, panVol);
|
||||
vehicle_sounds_update_sound_2(vehicle, &vehicleSoundParams, vehicleSound, panVol);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7901,7 +7903,8 @@ static void sub_6DBF3E(Vehicle* vehicle)
|
|||
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_GO_KART)
|
||||
{
|
||||
// Determine the stop positions for the karts. If in left lane it's further along the track than the right lane.
|
||||
// Since it's not possible to overtake when the race has ended, this does not check for overtake states (7 and 8).
|
||||
// Since it's not possible to overtake when the race has ended, this does not check for overtake states (7 and
|
||||
// 8).
|
||||
cx = vehicle->TrackSubposition == VEHICLE_TRACK_SUBPOSITION_GO_KARTS_RIGHT_LANE ? 18 : 20;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef _VEHICLE_H_
|
||||
#define _VEHICLE_H_
|
||||
|
||||
#include "../audio/audio.h"
|
||||
#include "../common.h"
|
||||
#include "../ride/RideTypes.h"
|
||||
#include "../world/Location.hpp"
|
||||
|
@ -299,7 +300,7 @@ struct Vehicle : SpriteBase
|
|||
void Invalidate();
|
||||
void SetState(VEHICLE_STATUS vehicleStatus, uint8_t subState = 0);
|
||||
bool IsGhost() const;
|
||||
void UpdateSoundParams() const;
|
||||
void UpdateSoundParams(std::vector<rct_vehicle_sound_params>& vehicleSoundParamsList) const;
|
||||
|
||||
private:
|
||||
bool SoundCanPlay() const;
|
||||
|
|
Loading…
Reference in New Issue