Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit ee99a37

Browse files
committed
Misc changes, cleanup and rearrangements
1 parent e50c888 commit ee99a37

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

Entities/SoundContainer.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ namespace RTE {
3333
int SoundContainer::Create(const SoundContainer &reference) {
3434
Entity::Create(reference);
3535

36-
for (std::vector<SoundData> referenceSoundSet : reference.m_SoundSets) {
36+
for (const std::vector<SoundData> &referenceSoundSet : reference.m_SoundSets) {
3737
std::vector<SoundData> soundSet;
38-
for (SoundData referenceData : referenceSoundSet) {
38+
for (const SoundData &referenceData : referenceSoundSet) {
3939
soundSet.push_back(SoundData {referenceData.SoundFile, referenceData.SoundObject, referenceData.Offset, referenceData.MinimumAudibleDistance, referenceData.AttenuationStartDistance});
4040
}
4141
m_SoundSets.push_back(soundSet);
@@ -152,8 +152,8 @@ namespace RTE {
152152

153153
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154154

155-
void SoundContainer::AddSound(std::string const &soundFilePath, unsigned int soundSetIndex, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance, bool abortGameForInvalidSound) {
156-
vector<SoundData> soundSet;
155+
void SoundContainer::AddSound(const std::string &soundFilePath, unsigned int soundSetIndex, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance, bool abortGameForInvalidSound) {
156+
std::vector<SoundData> soundSet;
157157
if (soundSetIndex < m_SoundSets.size()) { soundSet = m_SoundSets[soundSetIndex]; }
158158

159159
ContentFile soundFile(soundFilePath.c_str());
@@ -162,7 +162,7 @@ namespace RTE {
162162
return;
163163
}
164164

165-
attenuationStartDistance = attenuationStartDistance < 0 ? c_DefaultAttenuationStartDistance : attenuationStartDistance;
165+
attenuationStartDistance = (attenuationStartDistance < 0) ? c_DefaultAttenuationStartDistance : attenuationStartDistance;
166166
soundSet.push_back({soundFile, soundObject, offset, minimumAudibleDistance, attenuationStartDistance});
167167
if (soundSetIndex >= m_SoundSets.size()) { m_SoundSets.push_back(soundSet); }
168168

@@ -173,7 +173,7 @@ namespace RTE {
173173

174174
std::vector<size_t> SoundContainer::GetSelectedSoundHashes() const {
175175
std::vector<size_t> soundHashes;
176-
for (SoundData selectedSoundData : m_SoundSets[m_SelectedSoundSet]) {
176+
for (const SoundData &selectedSoundData : m_SoundSets[m_SelectedSoundSet]) {
177177
soundHashes.push_back(selectedSoundData.SoundFile.GetHash());
178178
}
179179
return soundHashes;
@@ -182,8 +182,8 @@ namespace RTE {
182182
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
183183

184184
const SoundContainer::SoundData *SoundContainer::GetSoundDataForSound(const FMOD::Sound *sound) const {
185-
for (std::vector<SoundData> const &soundSet : m_SoundSets) {
186-
for (SoundData const &soundData : soundSet) {
185+
for (const std::vector<SoundData> &soundSet : m_SoundSets) {
186+
for (const SoundData &soundData : soundSet) {
187187
if (sound == soundData.SoundObject) {
188188
return &soundData;
189189
}
@@ -206,9 +206,9 @@ namespace RTE {
206206
break;
207207
default:
208208
auto selectRandomSound = [](int soundSetSize, size_t *outSelectedSoundSet) {
209-
size_t soundToSelect = floorf(static_cast<float>(soundSetSize) * PosRand());
209+
size_t soundToSelect = std::floorf(static_cast<float>(soundSetSize) * PosRand());
210210
while (soundToSelect == *outSelectedSoundSet) {
211-
soundToSelect = floorf(static_cast<float>(soundSetSize) * PosRand());
211+
soundToSelect = std::floorf(static_cast<float>(soundSetSize) * PosRand());
212212
}
213213
*outSelectedSoundSet = soundToSelect;
214214
};
@@ -254,7 +254,7 @@ namespace RTE {
254254

255255
//TODO Consider replacing this with normal min and max distance (but keep custom rolloff mode) so we can save some pointing issues. Might need to store min audible distance in audioman if fmod is strict about min and max distance sizes wrt each other.
256256
soundData.CustomRolloffPoints[0] = FMOD_VECTOR{soundData.MinimumAudibleDistance, 0, 0};
257-
soundData.CustomRolloffPoints[1] = FMOD_VECTOR{soundData.AttenuationStartDistance < 0 ? m_AttenuationStartDistance : soundData.AttenuationStartDistance, 1, 0};
257+
soundData.CustomRolloffPoints[1] = FMOD_VECTOR{(soundData.AttenuationStartDistance < 0) ? m_AttenuationStartDistance : soundData.AttenuationStartDistance, 1, 0};
258258
result = (result == FMOD_OK) ? soundData.SoundObject->set3DCustomRolloff(soundData.CustomRolloffPoints, 2) : result;
259259
}
260260
}
@@ -268,7 +268,7 @@ namespace RTE {
268268

269269
//TODO this needs to be used or be deleted
270270
void SoundContainer::CalculateCustomRolloffPoints(const SoundData &soundDataToCalculateFor, FMOD_VECTOR *rolloffPoints, int numRolloffPoints) {
271-
int attenuationStartDistance = soundDataToCalculateFor.AttenuationStartDistance < 0 ? m_AttenuationStartDistance : soundDataToCalculateFor.AttenuationStartDistance;
271+
int attenuationStartDistance = (soundDataToCalculateFor.AttenuationStartDistance < 0) ? m_AttenuationStartDistance : soundDataToCalculateFor.AttenuationStartDistance;
272272
float currentDistance = attenuationStartDistance;
273273
float currentVolumeLevel = 1;
274274

@@ -280,10 +280,10 @@ namespace RTE {
280280
rolloffPoints[1] = FMOD_VECTOR{soundDataToCalculateFor.MinimumAudibleDistance - 0.1F, 0, 0};
281281
}
282282

283-
for (i = (soundDataToCalculateFor.MinimumAudibleDistance > 0 ? 2 : 0); i < numRolloffPoints - 1; i++) {
283+
for (i = ((soundDataToCalculateFor.MinimumAudibleDistance > 0) ? 2 : 0); i < numRolloffPoints - 1; i++) {
284284
rolloffPoints[i] = FMOD_VECTOR{currentDistance, currentVolumeLevel, 0};
285285
currentDistance += attenuationStartDistance;
286-
currentVolumeLevel = currentDistance < c_SoundMaxAudibleDistance ? currentVolumeLevel * 0.5 : 0;
286+
currentVolumeLevel = (currentDistance < c_SoundMaxAudibleDistance) ? currentVolumeLevel * 0.5F : 0;
287287
}
288288
rolloffPoints[numRolloffPoints - 1] = FMOD_VECTOR{currentDistance, 0, 0};
289289
}

Entities/SoundContainer.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ namespace RTE {
6969
/// <param name="attenuationStartDistance">The distance at which this SoundContainer's sounds should start attenuating away.</param>
7070
/// <param name="immobile">Whether this SoundContainer's sounds will be treated as immobile, i.e. they won't be affected by 3D sound manipulation.</param>
7171
/// <returns>An error return value signaling success or any particular failure. Anything below 0 is an error signal.</returns>
72-
int Create(std::string const soundFilePath, int loops = 0, bool affectedByGlobalPitch = true, float attenuationStartDistance = -1, bool immobile = false) { int result = Create(loops, affectedByGlobalPitch, attenuationStartDistance, immobile); AddSound(soundFilePath); return result; }
72+
int Create(const std::string soundFilePath, int loops = 0, bool affectedByGlobalPitch = true, float attenuationStartDistance = -1, bool immobile = false) { int result = Create(loops, affectedByGlobalPitch, attenuationStartDistance, immobile); AddSound(soundFilePath); return result; }
7373

7474
/// <summary>
7575
/// Adds a new sound to this SoundContainer, spitting out a lua error if it fails.
7676
/// The Sound will have default configuration and be added to a new SoundSet.
7777
/// </summary>
7878
/// <param name="soundFilePath">A path to the new sound to add. This will be handled through PresetMan.</param>
79-
void AddSound(std::string const &soundFilePath) { return AddSound(soundFilePath, false); }
79+
void AddSound(const std::string &soundFilePath) { return AddSound(soundFilePath, false); }
8080

8181
/// <summary>
8282
/// Adds a new sound to this SoundContainer, either spitting out a lua error or aborting if it fails.
8383
/// The sound will have default configuration and be added to a new SoundSet.
8484
/// </summary>
8585
/// <param name="soundFilePath">A path to the new sound to add. This will be handled through PresetMan.</param>
8686
/// <param name="abortGameForInvalidSound">Whether to abort the game if the sound couldn't be added, or just show a console error.</param>
87-
void AddSound(std::string const &soundFilePath, bool abortGameForInvalidSound) { return AddSound(soundFilePath, Vector(), c_DefaultAttenuationStartDistance, abortGameForInvalidSound); }
87+
void AddSound(const std::string &soundFilePath, bool abortGameForInvalidSound) { return AddSound(soundFilePath, Vector(), c_DefaultAttenuationStartDistance, abortGameForInvalidSound); }
8888

8989
/// <summary>
9090
/// Adds a new sound to this SoundContainer, either spitting out a lua error or aborting if it fails.
@@ -94,7 +94,7 @@ namespace RTE {
9494
/// <param name="offset">The offset position to play this sound at, where (0, 0) is no offset.</param>
9595
/// <param name="attenuationStartDistance">The attenuation start distance for this sound, -1 is default.</param>
9696
/// <param name="abortGameForInvalidSound">Whether to abort the game if the sound couldn't be added, or just show a console error.</param>
97-
void AddSound(std::string const &soundFilePath, const Vector &offset, float attenuationStartDistance, bool abortGameForInvalidSound) { return AddSound(soundFilePath, m_SoundSets.size() + 1, Vector(), 0, c_DefaultAttenuationStartDistance, abortGameForInvalidSound); }
97+
void AddSound(const std::string &soundFilePath, const Vector &offset, float attenuationStartDistance, bool abortGameForInvalidSound) { return AddSound(soundFilePath, m_SoundSets.size() + 1, Vector(), 0, c_DefaultAttenuationStartDistance, abortGameForInvalidSound); }
9898

9999
/// <summary>
100100
/// Adds a new sound to this SoundContainer, either spitting out a lua error or aborting if it fails.
@@ -106,7 +106,7 @@ namespace RTE {
106106
/// <param name="minimumAudibleDistance">The minimum distance at which this sound will be audible. 0 means there is none, which is normally the case.</param>
107107
/// <param name="attenuationStartDistance">The attenuation start distance for this sound, -1 sets it to default.</param>
108108
/// <param name="abortGameForInvalidSound">Whether to abort the game if the sound couldn't be added, or just show a console error.</param>
109-
void AddSound(std::string const &soundFilePath, unsigned int soundSetIndex, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance, bool abortGameForInvalidSound);
109+
void AddSound(const std::string &soundFilePath, unsigned int soundSetIndex, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance, bool abortGameForInvalidSound);
110110
#pragma endregion
111111

112112
#pragma region Destruction
@@ -251,7 +251,7 @@ namespace RTE {
251251
/// Sets the attenuation start distance of this SoundContainer. Values < 0 set it to default. Does not affect currently playing sounds.
252252
/// </summary>
253253
/// <param name="attenuationStartDistance">The new attenuation start distance.</param>
254-
void SetAttenuationStartDistance(float attenuationStartDistance) { m_AttenuationStartDistance = attenuationStartDistance < 0 ? c_DefaultAttenuationStartDistance : attenuationStartDistance; m_AllSoundPropertiesUpToDate = false; }
254+
void SetAttenuationStartDistance(float attenuationStartDistance) { m_AttenuationStartDistance = (attenuationStartDistance < 0) ? c_DefaultAttenuationStartDistance : attenuationStartDistance; m_AllSoundPropertiesUpToDate = false; }
255255

256256
/// <summary>
257257
/// Gets the looping setting of this SoundContainer.
@@ -392,18 +392,19 @@ namespace RTE {
392392
bool m_AllSoundPropertiesUpToDate = false; //!< Whether this SoundContainer's sounds' modes and properties are up to date. Used primarily to handle discrepancies that can occur when loading from ini if the line ordering isn't ideal.
393393

394394
private:
395-
/// <summary>
396-
/// Clears all the member variables of this SoundContainer, effectively resetting the members of this abstraction level only.
397-
/// </summary>
398-
void Clear();
399395

400396
/// <summary>
401-
/// TODO This is currently not used in favour of a simpler 2-point method but is kept in case it should be changed back. Examine this and remove or use it in future.
397+
/// TODO This is currently not used in favor of a simpler 2-point method but is kept in case it should be changed back. Examine this and remove or use it in future.
402398
/// </summary>
403399
/// <param name="soundDataToCalculateFor"></param>
404400
/// <param name="rolloffPoints"></param>
405401
/// <param name="numRolloffPoints"></param>
406402
void CalculateCustomRolloffPoints(const SoundData &soundDataToCalculateFor, FMOD_VECTOR *rolloffPoints, int numRolloffPoints);
403+
404+
/// <summary>
405+
/// Clears all the member variables of this SoundContainer, effectively resetting the members of this abstraction level only.
406+
/// </summary>
407+
void Clear();
407408
};
408409
}
409410
#endif

Managers/AudioMan.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ namespace RTE {
8080
void AudioMan::Update() {
8181
if (m_AudioEnabled) {
8282

83-
//TODO allow setting vel for AEmitter and PEmitter. Also maybe consider setting vel on listener when sceneman target scrolling is happening.
83+
//TODO allow setting vel for AEmitter and PEmitter. Also maybe consider setting vel on listener when SceneMan target scrolling is happening.
8484

8585
FMOD_RESULT status = FMOD_OK;
8686

8787
if (g_ActivityMan.ActivityRunning()) {
88-
Activity const *currentActivity = g_ActivityMan.GetActivity();
88+
const Activity *currentActivity = g_ActivityMan.GetActivity();
8989

9090
if (m_CurrentActivityHumanCount != (m_IsInMultiplayerMode ? 1 : currentActivity->GetHumanCount())) {
9191
m_CurrentActivityHumanCount = m_IsInMultiplayerMode ? 1 : currentActivity->GetHumanCount();
@@ -100,9 +100,7 @@ namespace RTE {
100100
}
101101
}
102102

103-
if (g_SettingsMan.SoundPanningEffectStrength() < 1) {
104-
UpdateCalculated3DEffectsForMobileSoundChannels();
105-
}
103+
if (g_SettingsMan.SoundPanningEffectStrength() < 1) { UpdateCalculated3DEffectsForMobileSoundChannels(); }
106104
} else {
107105
if (m_CurrentActivityHumanCount != 1) {
108106
m_CurrentActivityHumanCount = 1;
@@ -147,7 +145,7 @@ namespace RTE {
147145
if (result == FMOD_OK && isPlaying) {
148146
void *userData;
149147
result == FMOD_OK ? soundChannel->getUserData(&userData) : result;
150-
SoundContainer const *channelSoundContainer = (SoundContainer *)userData;
148+
const SoundContainer *channelSoundContainer = (SoundContainer *)userData;
151149

152150
if (channelSoundContainer->IsAffectedByGlobalPitch()) { soundChannel->setPitch(pitch); }
153151
}
@@ -233,13 +231,13 @@ namespace RTE {
233231
FMOD::Channel *soundChannel;
234232
FMOD::Sound *sound;
235233

236-
std::unordered_set<unsigned short> const *playingChannels = soundContainer->GetPlayingChannels();
234+
const std::unordered_set<unsigned short> *playingChannels = soundContainer->GetPlayingChannels();
237235
for (unsigned short channelIndex : *playingChannels) {
238236
result = m_AudioSystem->getChannel(channelIndex, &soundChannel);
239237
result = (result == FMOD_OK) ? soundChannel->getCurrentSound(&sound) : result;
240-
SoundContainer::SoundData const *soundData = soundContainer->GetSoundDataForSound(sound);
241-
242-
result = (result == FMOD_OK) ? soundChannel->set3DAttributes(&GetAsFMODVector(position + (soundData == NULL ? Vector() : soundData->Offset)), NULL) : result;
238+
const SoundContainer::SoundData *soundData = soundContainer->GetSoundDataForSound(sound);
239+
240+
result = (result == FMOD_OK) ? soundChannel->set3DAttributes(&GetAsFMODVector(position + ((soundData == NULL) ? Vector() : soundData->Offset)), NULL) : result;
243241
if (result != FMOD_OK) {
244242
g_ConsoleMan.PrintString("ERROR: Could not set sound position for the sound being played on channel " + std::to_string(channelIndex) + " for SoundContainer " + soundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
245243
}
@@ -265,7 +263,7 @@ namespace RTE {
265263
FMOD_RESULT result;
266264
FMOD::Channel *soundChannel;
267265

268-
std::unordered_set<unsigned short> const *channels = soundContainer->GetPlayingChannels();
266+
const std::unordered_set<unsigned short> *channels = soundContainer->GetPlayingChannels();
269267
for (std::unordered_set<unsigned short>::iterator channelIterator = channels->begin(); channelIterator != channels->end(); ++channelIterator) {
270268
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
271269
if (result == FMOD_OK) { soundChannel->setPitch(pitch); }
@@ -500,7 +498,7 @@ namespace RTE {
500498
bool anySoundsPlaying = soundContainer->IsBeingPlayed();
501499

502500
if (anySoundsPlaying) {
503-
std::unordered_set<unsigned short> const *channels = soundContainer->GetPlayingChannels();
501+
const std::unordered_set<unsigned short> *channels = soundContainer->GetPlayingChannels();
504502
for (std::unordered_set<unsigned short>::iterator channelIterator = channels->begin(); channelIterator != channels->end();) {
505503
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
506504
++channelIterator; // NOTE - stopping the sound will remove the channel, screwing things up if we don't move to the next iterator preemptively
@@ -528,7 +526,7 @@ namespace RTE {
528526
unsigned long long parentClock;
529527
float currentVolume;
530528

531-
std::unordered_set<unsigned short> const *channels = soundContainer->GetPlayingChannels();
529+
const std::unordered_set<unsigned short> *channels = soundContainer->GetPlayingChannels();
532530
for (std::unordered_set<unsigned short>::iterator channelIterator = channels->begin(); channelIterator != channels->end(); ++channelIterator) {
533531
result = m_AudioSystem->getChannel((*channelIterator), &soundChannel);
534532
result = (result == FMOD_OK) ? soundChannel->getDSPClock(nullptr, &parentClock) : result;
@@ -570,9 +568,9 @@ namespace RTE {
570568
musicData.Pitch = pitch;
571569
musicData.Position = position;
572570
if (filepath) {
573-
strncpy(musicData.Path, filepath, 255);
571+
std::strncpy(musicData.Path, filepath, 255);
574572
} else {
575-
memset(musicData.Path, 0, 255);
573+
std::memset(musicData.Path, 0, 255);
576574
}
577575
g_SoundEventsListMutex[player].lock();
578576
m_MusicEvents[player].push_back(musicData);
@@ -598,7 +596,7 @@ namespace RTE {
598596

599597
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
600598

601-
void AudioMan::RegisterSoundEvent(int player, NetworkSoundState state, std::unordered_set<unsigned short> const *channels, std::vector<size_t> const *soundFileHashes, const Vector &position, short loops, float pitch, bool affectedByGlobalPitch, float attenuationStartDistance, bool immobile, short fadeOutTime) {
599+
void AudioMan::RegisterSoundEvent(int player, NetworkSoundState state, const std::unordered_set<unsigned short> *channels, const std::vector<size_t> *soundFileHashes, const Vector &position, short loops, float pitch, bool affectedByGlobalPitch, float attenuationStartDistance, bool immobile, short fadeOutTime) {
602600
if (player == -1) {
603601
for (int i = 0; i < c_MaxClients; i++) {
604602
RegisterSoundEvent(i, state, channels, soundFileHashes, position, loops, pitch, affectedByGlobalPitch, fadeOutTime);
@@ -701,7 +699,7 @@ namespace RTE {
701699
return result;
702700
}
703701

704-
Activity const *currentActivity = g_ActivityMan.GetActivity();
702+
const Activity *currentActivity = g_ActivityMan.GetActivity();
705703
float shortestDistance = g_SceneMan.GetSceneDim().GetMagnitude();
706704
float longestDistance = 0;
707705
for (int player = 0; player < currentActivity->GetPlayerCount(); player++) {

0 commit comments

Comments
 (0)