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

Commit f8f58ae

Browse files
committed
Cleanup and some minor changes
1 parent f7a7036 commit f8f58ae

File tree

8 files changed

+156
-197
lines changed

8 files changed

+156
-197
lines changed

Entities/SoundContainer.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace RTE {
2828
for (std::vector<std::pair<ContentFile, FMOD::Sound *>>::const_iterator itr = reference.m_Sounds.begin(); itr != reference.m_Sounds.end(); ++itr) {
2929
m_Sounds.push_back(*itr);
3030
}
31-
3231
m_SelectedSounds = reference.m_SelectedSounds;
3332
m_PlayingChannels.clear();
3433

@@ -48,19 +47,15 @@ namespace RTE {
4847
ContentFile newFile;
4948
reader >> newFile;
5049
FMOD::Sound *pNewSample = newFile.GetAsSample();
51-
if (!pNewSample) {
52-
reader.ReportError(std::string("Failed to load the sample from the file"));
53-
}
50+
if (!pNewSample) { reader.ReportError(std::string("Failed to load the sample from the file")); }
5451
m_Sounds.push_back(std::pair<ContentFile, FMOD::Sound *>(newFile, pNewSample));
5552
} else if (propName == "AttenuationStartDistance") {
5653
reader >> m_AttenuationStartDistance;
5754
} else if (propName == "LoopSetting") {
5855
reader >> m_Loops;
5956
} else if (propName == "Priority") {
6057
reader >> m_Priority;
61-
if (m_Priority < 0 || m_Priority > 256) {
62-
reader.ReportError("SoundContainer priority must be between 256 (lowest priority) and 0 (highest priority).");
63-
}
58+
if (m_Priority < 0 || m_Priority > 256) { reader.ReportError("SoundContainer priority must be between 256 (lowest priority) and 0 (highest priority)."); }
6459
} else if (propName == "AffectedByGlobalPitch") {
6560
reader >> m_AffectedByGlobalPitch;
6661
} else if (propName == "Immobile") {
@@ -80,17 +75,17 @@ namespace RTE {
8075

8176
FMOD::Sound *newSample = newFile.GetAsSample(abortGameForInvalidSound);
8277
if (newSample) {
83-
FMOD_RESULT result = newSample->setMode(m_Loops == 0 ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL);
84-
result = result == FMOD_OK ? newSample->setLoopCount(m_Loops) : result;
78+
FMOD_RESULT result = newSample->setMode((m_Loops == 0) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL);
79+
result = (result == FMOD_OK) ? newSample->setLoopCount(m_Loops) : result;
8580
m_Sounds.push_back(std::pair<ContentFile, FMOD::Sound *>(newFile, newSample));
8681
}
8782
}
8883

8984
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9085

91-
std::vector<std::size_t> SoundContainer::GetSelectedSoundHashes() {
92-
std::vector<std::size_t> soundHashes;
93-
for (std::size_t selectedSoundIndex : m_SelectedSounds) {
86+
std::vector<size_t> SoundContainer::GetSelectedSoundHashes() {
87+
std::vector<size_t> soundHashes;
88+
for (size_t selectedSoundIndex : m_SelectedSounds) {
9489
soundHashes.push_back(m_Sounds[selectedSoundIndex].first.GetHash());
9590
}
9691
return soundHashes;
@@ -100,7 +95,7 @@ namespace RTE {
10095

10196
std::vector<FMOD::Sound *> SoundContainer::GetSelectedSoundObjects() {
10297
std::vector<FMOD::Sound *> soundObjects;
103-
for (std::size_t selectedSoundIndex : m_SelectedSounds) {
98+
for (size_t selectedSoundIndex : m_SelectedSounds) {
10499
soundObjects.push_back(m_Sounds[selectedSoundIndex].second);
105100
}
106101
return soundObjects;
@@ -113,8 +108,7 @@ namespace RTE {
113108
if (soundCount == 0) {
114109
return false;
115110
}
116-
117-
std::size_t previouslySelectedSound = m_SelectedSounds.size() > 0 ? m_SelectedSounds[0] : 0;
111+
size_t previouslySelectedSound = (m_SelectedSounds.size() > 0) ? m_SelectedSounds[0] : 0;
118112

119113
if (m_SelectedSounds.empty() || soundCount == 1) {
120114
m_SelectedSounds.clear();
@@ -124,16 +118,16 @@ namespace RTE {
124118
if (soundCount == 2) {
125119
m_SelectedSounds.push_back((previouslySelectedSound + 1) % soundCount);
126120
} else if (soundCount > 2) {
127-
size_t soundToSelect = floorf((float)soundCount * PosRand());
121+
size_t soundToSelect = floorf(static_cast<float>(soundCount) * PosRand());
128122
// Mix it up again if we got the same sound twice
129123
while (soundToSelect == previouslySelectedSound) {
130-
soundToSelect = floorf((float)soundCount * PosRand());
124+
soundToSelect = floorf(static_cast<float>(soundCount) * PosRand());
131125
}
132126
m_SelectedSounds.push_back(soundToSelect);
133127
}
134128
}
135129
RTEAssert(m_SelectedSounds.size() > 0 && m_SelectedSounds[0] >= 0 && m_SelectedSounds[0] < soundCount, "Failed to select next sound, either none was selected or the selected sound was invalid.");
136-
130+
137131
return true;
138132
}
139133

@@ -143,12 +137,12 @@ namespace RTE {
143137
FMOD_RESULT result = FMOD_OK;
144138

145139
for (std::vector<std::pair<ContentFile, FMOD::Sound * >>::const_iterator itr = m_Sounds.begin(); itr != m_Sounds.end() && result == FMOD_OK; ++itr) {
146-
FMOD_MODE soundMode = m_Loops == 0 ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL;
147-
soundMode |= m_Immobile ? FMOD_3D_HEADRELATIVE : FMOD_3D_WORLDRELATIVE;
140+
FMOD_MODE soundMode = (m_Loops == 0) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL;
141+
(soundMode |= m_Immobile) ? FMOD_3D_HEADRELATIVE : FMOD_3D_WORLDRELATIVE;
148142

149-
result = result == FMOD_OK ? itr->second->setMode(soundMode) : result;
150-
result = result == FMOD_OK ? itr->second->setLoopCount(m_Loops) : result;
151-
result = result == FMOD_OK ? itr->second->set3DMinMaxDistance(m_AttenuationStartDistance, 100000) : result;
143+
result = (result == FMOD_OK) ? itr->second->setMode(soundMode) : result;
144+
result = (result == FMOD_OK) ? itr->second->setLoopCount(m_Loops) : result;
145+
result = (result == FMOD_OK) ? itr->second->set3DMinMaxDistance(m_AttenuationStartDistance, 100000) : result;
152146
}
153147
m_AllSoundPropertiesUpToDate = result == FMOD_OK;
154148

Entities/SoundContainer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace RTE {
140140
/// Gets a vector of hashes of the sounds selected to be played next in this SoundContainer.
141141
/// </summary>
142142
/// <returns>The currently playing sounds hashes.</returns>
143-
std::vector<std::size_t> GetSelectedSoundHashes();
143+
std::vector<size_t> GetSelectedSoundHashes();
144144

145145
/// <summary>
146146
/// Gets a vector of the sounds objects selected to be played next in this SoundContainer.
@@ -152,19 +152,19 @@ namespace RTE {
152152
/// Gets the channels playing sounds from this SoundContainer.
153153
/// </summary>
154154
/// <returns>The channels currently being used.</returns>
155-
std::unordered_set<unsigned short int> *GetPlayingChannels() { return &m_PlayingChannels; }
155+
std::unordered_set<unsigned short> *GetPlayingChannels() { return &m_PlayingChannels; }
156156

157157
/// <summary>
158158
/// Adds a channel index to the SoundContainer's collection of playing channels.
159159
/// </summary>
160160
/// <param name="channel">The channel index to add.</param>
161-
void AddPlayingChannel(unsigned short int channel) { m_PlayingChannels.insert(channel); RTEAssert(m_PlayingChannels.size() <= c_MaxPlayingSoundsPerContainer, "Tried to play more than " + std::to_string(c_MaxPlayingSoundsPerContainer) + " sounds in SoundContainer " + GetPresetName()); }
161+
void AddPlayingChannel(unsigned short channel) { m_PlayingChannels.insert(channel); RTEAssert(m_PlayingChannels.size() <= c_MaxPlayingSoundsPerContainer, "Tried to play more than " + std::to_string(c_MaxPlayingSoundsPerContainer) + " sounds in SoundContainer " + GetPresetName()); }
162162

163163
/// <summary>
164164
/// Removes a channel index from the SoundContainer's collection of playing channels.
165165
/// </summary>
166166
/// <param name="channel">The channel index to remove.</param>
167-
void RemovePlayingChannel(unsigned short int channel) { m_PlayingChannels.erase(channel); }
167+
void RemovePlayingChannel(unsigned short channel) { m_PlayingChannels.erase(channel); }
168168
#pragma endregion
169169

170170
#pragma region Sound Property Getters and Setters
@@ -313,9 +313,9 @@ namespace RTE {
313313
std::vector<std::pair<ContentFile, FMOD::Sound *>> m_Sounds; // All the FMOD Sound objects in this SoundContainer, paired with their appropriate ContentFile. The sound objects within are owned by the ContentFile static maps
314314
std::vector<size_t> m_SelectedSounds; //!< Vector of the indices of all selected sounds
315315

316-
std::unordered_set<unsigned short int> m_PlayingChannels; //!< The channels this SoundContainer is currently using
316+
std::unordered_set<unsigned short> m_PlayingChannels; //!< The channels this SoundContainer is currently using
317317

318-
float m_AttenuationStartDistance; //!< The distance away from the AudioSystem listenter to start attenuating this sound. Attenuation follows FMOD 3D Inverse Rolloff model.
318+
float m_AttenuationStartDistance; //!< The distance away from the AudioSystem listener to start attenuating this sound. Attenuation follows FMOD 3D Inverse roll-off model.
319319
int m_Loops; //!< Number of loops (repeats) the SoundContainer's sounds should play when played. 0 means it plays once, -1 means it plays until stopped
320320
int m_Priority; //!< The mixing priority of this SoundContainer's sounds. Higher values are more likely to be heard
321321
bool m_AffectedByGlobalPitch; //!< Whether this SoundContainer's sounds should be able to be altered by global pitch changes

GUI/GUISound.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace RTE {
5656

5757
m_BackButtonPressSound.Create("Base.rte/Sounds/GUIs/BackButtonPress.wav", 0, false, 0, true);
5858

59-
m_ConfirmSound.Create("Base.rte/Sounds/GUIs/MenuExit2.wav", 0, false, 0, true);
59+
m_ConfirmSound.Create("Base.rte/Sounds/GUIs/MenuExit1.wav", 0, false, 0, true);
6060

6161
m_UserErrorSound.Create("Base.rte/Sounds/GUIs/UserError.wav", 0, false, 0, true);
6262

@@ -93,13 +93,13 @@ namespace RTE {
9393
m_CameraTravelSound.AddSound("Base.rte/Sounds/GUIs/CameraTravel3.wav");
9494

9595
// m_AreaPickedSound.Create("Base.rte/Sounds/GUIs/MenuEnter.wav", 0, false, 0, true);
96-
m_AreaPickedSound = m_EnterMenuSound;
96+
m_AreaPickedSound = m_ConfirmSound;
9797

9898
// m_ObjectPickedSound.Create("Base.rte/Sounds/GUIs/MenuEnter.wav", 0, false, 0, true);
99-
m_ObjectPickedSound = m_EnterMenuSound;
99+
m_ObjectPickedSound = m_ConfirmSound;
100100

101101
// m_PurchaseMadeSound.Create("Base.rte/Sounds/GUIs/MenuEnter.wav", 0, false, 0, true);
102-
m_PurchaseMadeSound = m_EnterMenuSound;
102+
m_PurchaseMadeSound = m_ConfirmSound;
103103

104104
m_PlacementBlip.Create("Base.rte/Sounds/GUIs/PlacementBlip.wav", 0, false, 0, true);
105105

0 commit comments

Comments
 (0)