forked from rosebudai/OpenRCT2-Web
Minor cleanup
This commit is contained in:
6 files changed
+50
-53
No files matched your search
@@ -1421,7 +1421,7 @@ static void window_options_audio_dropdown(rct_window* w, rct_widgetindex widgetI
|
||||
const char* devicename = OpenRCT2::Audio::GetDeviceName(dropdownIndex).c_str();
|
||||
Mixer_Init(devicename);
|
||||
SafeFree(gConfigSound.device);
|
||||
gConfigSound.device = strndup(devicename, AUDIO_DEVICE_NAME_SIZE);
|
||||
gConfigSound.device = strndup(devicename, OpenRCT2::Audio::MaxDeviceNameSize);
|
||||
}
|
||||
config_save_default();
|
||||
OpenRCT2::Audio::PlayTitleMusic();
|
||||
|
||||
@@ -48,11 +48,10 @@ namespace OpenRCT2::Audio
|
||||
void* gTitleMusicChannel = nullptr;
|
||||
void* gWeatherSoundChannel = nullptr;
|
||||
|
||||
RideMusic gRideMusicList[AUDIO_MAX_RIDE_MUSIC];
|
||||
RideMusicParams gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
|
||||
RideMusic gRideMusicList[MaxRideMusic];
|
||||
RideMusicParams gRideMusicParamsList[MaxRideMusic];
|
||||
RideMusicParams* gRideMusicParamsListEnd;
|
||||
|
||||
VehicleSound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
VehicleSound gVehicleSoundList[MaxVehicleSounds];
|
||||
|
||||
// clang-format off
|
||||
static int32_t SoundVolumeAdjust[RCT2SoundCount] =
|
||||
@@ -123,7 +122,7 @@ namespace OpenRCT2::Audio
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
static AudioParams audio_get_params_from_location(SoundId soundId, const CoordsXYZ& location);
|
||||
static AudioParams GetParametersFromLocation(SoundId soundId, const CoordsXYZ& location);
|
||||
|
||||
bool IsAvailable()
|
||||
{
|
||||
@@ -188,7 +187,7 @@ namespace OpenRCT2::Audio
|
||||
if (!IsAvailable())
|
||||
return;
|
||||
|
||||
AudioParams params = audio_get_params_from_location(soundId, loc);
|
||||
AudioParams params = GetParametersFromLocation(soundId, loc);
|
||||
if (params.in_range)
|
||||
{
|
||||
Play(soundId, params.volume, params.pan);
|
||||
@@ -201,7 +200,7 @@ namespace OpenRCT2::Audio
|
||||
* @param location The location at which the sound effect is to be played.
|
||||
* @return The audio parameters to be used when playing this sound effect.
|
||||
*/
|
||||
static AudioParams audio_get_params_from_location(SoundId soundId, const CoordsXYZ& location)
|
||||
static AudioParams GetParametersFromLocation(SoundId soundId, const CoordsXYZ& location)
|
||||
{
|
||||
int32_t volumeDown = 0;
|
||||
AudioParams params;
|
||||
@@ -324,6 +323,11 @@ namespace OpenRCT2::Audio
|
||||
const std::string& GetDeviceName(int32_t index)
|
||||
{
|
||||
Guard::Assert(index >= 0 && index < GetDeviceCount());
|
||||
if (index < 0 || index >= GetDeviceCount())
|
||||
{
|
||||
static std::string InvalidDevice = "Invalid Device";
|
||||
return InvalidDevice;
|
||||
}
|
||||
return _audioDevices[index];
|
||||
}
|
||||
|
||||
@@ -386,7 +390,7 @@ namespace OpenRCT2::Audio
|
||||
Close();
|
||||
for (auto& vehicleSound : gVehicleSoundList)
|
||||
{
|
||||
vehicleSound.id = SOUND_ID_NULL;
|
||||
vehicleSound.id = SoundIdNull;
|
||||
}
|
||||
|
||||
_currentAudioDevice = device;
|
||||
@@ -443,9 +447,9 @@ namespace OpenRCT2::Audio
|
||||
|
||||
for (auto& vehicleSound : gVehicleSoundList)
|
||||
{
|
||||
if (vehicleSound.id != SOUND_ID_NULL)
|
||||
if (vehicleSound.id != SoundIdNull)
|
||||
{
|
||||
vehicleSound.id = SOUND_ID_NULL;
|
||||
vehicleSound.id = SoundIdNull;
|
||||
if (vehicleSound.TrackSound.Id != SoundId::Null)
|
||||
{
|
||||
Mixer_Stop_Channel(vehicleSound.TrackSound.Channel);
|
||||
|
||||
+10
-10
@@ -16,13 +16,13 @@ struct CoordsXYZ;
|
||||
|
||||
namespace OpenRCT2::Audio
|
||||
{
|
||||
#define AUDIO_DEVICE_NAME_SIZE 256
|
||||
#define AUDIO_MAX_RIDE_MUSIC 32
|
||||
#define AUDIO_MAX_VEHICLE_SOUNDS 14
|
||||
#define NUM_DEFAULT_MUSIC_TRACKS 46
|
||||
constexpr size_t MaxDeviceNameSize = 256;
|
||||
constexpr size_t MaxRideMusic = 32;
|
||||
constexpr size_t MaxVehicleSounds = 14;
|
||||
constexpr size_t MaxDefaultMusic = 46;
|
||||
constexpr uint16_t SoundIdNull = 0xFFFF;
|
||||
|
||||
#define AUDIO_PLAY_AT_CENTRE 0x8000
|
||||
#define AUDIO_PLAY_AT_LOCATION 0x8001
|
||||
#define SOUND_ID_NULL 0xFFFF
|
||||
|
||||
enum class SoundId : uint8_t;
|
||||
|
||||
@@ -157,12 +157,12 @@ namespace OpenRCT2::Audio
|
||||
extern void* gTitleMusicChannel;
|
||||
extern void* gWeatherSoundChannel;
|
||||
|
||||
extern RideMusic gRideMusicList[AUDIO_MAX_RIDE_MUSIC];
|
||||
extern RideMusicInfo gRideMusicInfoList[NUM_DEFAULT_MUSIC_TRACKS];
|
||||
extern RideMusicParams gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
|
||||
extern RideMusic gRideMusicList[MaxRideMusic];
|
||||
extern RideMusicInfo gRideMusicInfoList[MaxDefaultMusic];
|
||||
extern RideMusicParams gRideMusicParamsList[MaxRideMusic];
|
||||
extern RideMusicParams* gRideMusicParamsListEnd;
|
||||
|
||||
extern VehicleSound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
extern VehicleSound gVehicleSoundList[MaxVehicleSounds];
|
||||
|
||||
/**
|
||||
* Returns false when no audio device is available or when audio is turned off, otherwise true.
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenRCT2::Audio
|
||||
}
|
||||
|
||||
// 0x009AF1C8
|
||||
RideMusicInfo gRideMusicInfoList[NUM_DEFAULT_MUSIC_TRACKS] = {
|
||||
RideMusicInfo gRideMusicInfoList[MaxDefaultMusic] = {
|
||||
INIT_MUSIC_INFO(PATH_ID_CSS4, 1378),
|
||||
INIT_MUSIC_INFO(PATH_ID_CSS5, 1378),
|
||||
INIT_MUSIC_INFO(PATH_ID_CSS6, 1378),
|
||||
|
||||
@@ -3611,7 +3611,7 @@ int32_t ride_music_params_update(
|
||||
{
|
||||
ride_music++;
|
||||
channel++;
|
||||
if (channel >= AUDIO_MAX_RIDE_MUSIC)
|
||||
if (channel >= OpenRCT2::Audio::MaxRideMusic)
|
||||
{
|
||||
OpenRCT2::Audio::RideMusicInfo* ride_music_info = &OpenRCT2::Audio::gRideMusicInfoList[*tuneId];
|
||||
a1 = position + ride_music_info->offset;
|
||||
@@ -3691,7 +3691,7 @@ void ride_music_update_final()
|
||||
}
|
||||
rideMusic++;
|
||||
channelIndex++;
|
||||
if (channelIndex >= AUDIO_MAX_RIDE_MUSIC)
|
||||
if (channelIndex >= OpenRCT2::Audio::MaxRideMusic)
|
||||
{
|
||||
auto* ride_music_info = &OpenRCT2::Audio::gRideMusicInfoList[rideMusicParams->tune_id];
|
||||
auto* ride_music_3 = &OpenRCT2::Audio::gRideMusicList[freeChannelIndex];
|
||||
|
||||
@@ -963,20 +963,17 @@ bool Vehicle::SoundCanPlay() const
|
||||
uint16_t Vehicle::GetSoundPriority() const
|
||||
{
|
||||
int32_t result = Train(this).Mass() + (std::abs(velocity) >> 13);
|
||||
auto* vehicle_sound = &OpenRCT2::Audio::gVehicleSoundList[0];
|
||||
|
||||
while (vehicle_sound->id != sprite_index)
|
||||
for (const auto& vehicleSound : OpenRCT2::Audio::gVehicleSoundList)
|
||||
{
|
||||
vehicle_sound++;
|
||||
|
||||
if (vehicle_sound >= &OpenRCT2::Audio::gVehicleSoundList[std::size(OpenRCT2::Audio::gVehicleSoundList)])
|
||||
if (vehicleSound.id == sprite_index)
|
||||
{
|
||||
return result;
|
||||
// Vehicle sounds will get higher priority if they are already playing
|
||||
return result + 300;
|
||||
}
|
||||
}
|
||||
|
||||
// Vehicle sounds will get higher priority if they are already playing
|
||||
return result + 300;
|
||||
return result;
|
||||
}
|
||||
|
||||
OpenRCT2::Audio::VehicleSoundParams Vehicle::CreateSoundParam(uint16_t priority) const
|
||||
@@ -1057,14 +1054,14 @@ void Vehicle::UpdateSoundParams(std::vector<OpenRCT2::Audio::VehicleSoundParams>
|
||||
|
||||
if (soundParamIter == std::end(vehicleSoundParamsList))
|
||||
{
|
||||
if (vehicleSoundParamsList.size() < AUDIO_MAX_VEHICLE_SOUNDS)
|
||||
if (vehicleSoundParamsList.size() < OpenRCT2::Audio::MaxVehicleSounds)
|
||||
{
|
||||
vehicleSoundParamsList.push_back(CreateSoundParam(soundPriority));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vehicleSoundParamsList.size() < AUDIO_MAX_VEHICLE_SOUNDS)
|
||||
if (vehicleSoundParamsList.size() < OpenRCT2::Audio::MaxVehicleSounds)
|
||||
{
|
||||
// Shift all sound params down one if using a free space
|
||||
vehicleSoundParamsList.insert(soundParamIter, CreateSoundParam(soundPriority));
|
||||
@@ -1155,30 +1152,26 @@ static uint8_t vehicle_sounds_update_get_pan_volume(OpenRCT2::Audio::VehicleSoun
|
||||
static OpenRCT2::Audio::VehicleSound* vehicle_sounds_update_get_vehicle_sound(OpenRCT2::Audio::VehicleSoundParams* sound_params)
|
||||
{
|
||||
// Search for already playing vehicle sound
|
||||
auto* vehicleSound = &OpenRCT2::Audio::gVehicleSoundList[0];
|
||||
for (; vehicleSound < &OpenRCT2::Audio::gVehicleSoundList[std::size(OpenRCT2::Audio::gVehicleSoundList)]; vehicleSound++)
|
||||
for (auto& vehicleSound : OpenRCT2::Audio::gVehicleSoundList)
|
||||
{
|
||||
if (vehicleSound->id == sound_params->id)
|
||||
return vehicleSound;
|
||||
if (vehicleSound.id == sound_params->id)
|
||||
return &vehicleSound;
|
||||
}
|
||||
|
||||
// No sound already playing
|
||||
if (vehicleSound >= &OpenRCT2::Audio::gVehicleSoundList[std::size(OpenRCT2::Audio::gVehicleSoundList)])
|
||||
for (auto& vehicleSound : OpenRCT2::Audio::gVehicleSoundList)
|
||||
{
|
||||
for (vehicleSound = &OpenRCT2::Audio::gVehicleSoundList[0];
|
||||
vehicleSound < &OpenRCT2::Audio::gVehicleSoundList[std::size(OpenRCT2::Audio::gVehicleSoundList)]; vehicleSound++)
|
||||
// Use free slot
|
||||
if (vehicleSound.id == OpenRCT2::Audio::SoundIdNull)
|
||||
{
|
||||
// Use free slot
|
||||
if (vehicleSound->id == SOUND_ID_NULL)
|
||||
{
|
||||
vehicleSound->id = sound_params->id;
|
||||
vehicleSound->TrackSound.Id = OpenRCT2::Audio::SoundId::Null;
|
||||
vehicleSound->OtherSound.Id = OpenRCT2::Audio::SoundId::Null;
|
||||
vehicleSound->volume = 0x30;
|
||||
return vehicleSound;
|
||||
}
|
||||
vehicleSound.id = sound_params->id;
|
||||
vehicleSound.TrackSound.Id = OpenRCT2::Audio::SoundId::Null;
|
||||
vehicleSound.OtherSound.Id = OpenRCT2::Audio::SoundId::Null;
|
||||
vehicleSound.volume = 0x30;
|
||||
return &vehicleSound;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1282,7 +1275,7 @@ void vehicle_sounds_update()
|
||||
return;
|
||||
|
||||
std::vector<OpenRCT2::Audio::VehicleSoundParams> vehicleSoundParamsList;
|
||||
vehicleSoundParamsList.reserve(AUDIO_MAX_VEHICLE_SOUNDS);
|
||||
vehicleSoundParamsList.reserve(OpenRCT2::Audio::MaxVehicleSounds);
|
||||
|
||||
vehicle_sounds_update_window_setup();
|
||||
|
||||
@@ -1294,7 +1287,7 @@ void vehicle_sounds_update()
|
||||
// Stop all playing sounds that no longer have priority to play after vehicle_update_sound_params
|
||||
for (auto& vehicle_sound : OpenRCT2::Audio::gVehicleSoundList)
|
||||
{
|
||||
if (vehicle_sound.id != SOUND_ID_NULL)
|
||||
if (vehicle_sound.id != OpenRCT2::Audio::SoundIdNull)
|
||||
{
|
||||
bool keepPlaying = false;
|
||||
for (auto vehicleSoundParams : vehicleSoundParamsList)
|
||||
@@ -1317,7 +1310,7 @@ void vehicle_sounds_update()
|
||||
{
|
||||
Mixer_Stop_Channel(vehicle_sound.OtherSound.Channel);
|
||||
}
|
||||
vehicle_sound.id = SOUND_ID_NULL;
|
||||
vehicle_sound.id = OpenRCT2::Audio::SoundIdNull;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user