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

Commit daedacb

Browse files
committed
Moved GUISound initialization and construction since it can be done safely outside of AudioMan now
Added comment to SoundContainer lambda, fixed non-referenced based range for loop, added constnesses to GetSoundDataForSound method. Fixed Vector to FMOD_VECTOR conversion trying to use scene dimensions if the scene isn't loaded, since the assert makes this unsafe. Fixed bad typing on sound max audible distance that would cut it off (it was a u short instead of a u int) Removed junk member variable from GUISound (poopsound)
1 parent adb104b commit daedacb

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

Entities/SoundContainer.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ namespace RTE {
113113
std::string propValue = reader.ReadPropValue();
114114
SoundData soundData;
115115

116+
/// <summary>
117+
/// This lambda exists to have some easy, private reused code.
118+
/// It loads an audio file by path in as a ContentFile, which in turn loads it into FMOD, then returns SoundData for it in the outParam outSoundData.
119+
/// </summary>
120+
/// <param name="soundPath">The path to the sound file.</param>
121+
/// <param name="parentReader">The reader being used when calling this. Used to report errors if loading the sound fails.</param>
122+
/// <param name="outSoundData">The outParam for the SoundData struct produced by reading the given sound.</param>
116123
auto readSound = [](const std::string &soundPath, Reader &parentReader, SoundData *outSoundData) {
117124
ContentFile soundFile(soundPath.c_str());
118125
FMOD::Sound *soundObject = soundFile.GetAsSample();
@@ -174,9 +181,9 @@ namespace RTE {
174181

175182
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
176183

177-
SoundContainer::SoundData *SoundContainer::GetSoundDataForSound(FMOD::Sound *sound) {
178-
for (std::vector<SoundData> soundSet : m_SoundSets) {
179-
for (SoundData soundData : soundSet) {
184+
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) {
180187
if (sound == soundData.SoundObject) {
181188
return &soundData;
182189
}

Entities/SoundContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace RTE {
230230
/// </summary>
231231
/// <param name="sound">The FMOD::Sound to search for.</param>
232232
/// <returns>A pointer to the corresponding SoundData or a null pointer.</returns>
233-
SoundData *GetSoundDataForSound(FMOD::Sound *sound);
233+
const SoundData *GetSoundDataForSound(const FMOD::Sound *sound) const;
234234
#pragma endregion
235235

236236
#pragma region Sound Property Getters and Setters

GUI/GUISound.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ namespace RTE {
205205
#pragma endregion
206206

207207
protected:
208-
SoundContainer m_PoopSound;
209208
SoundContainer m_SplashSound; //! Juicy logo signature jingle sound.
210209

211210
SoundContainer m_EnterMenuSound; //! SoundContainer for enabling menu.

Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,7 @@ int main(int argc, char *argv[]) {
18801880
new PresetMan();
18811881
new FrameMan();
18821882
new AudioMan();
1883+
new GUISound();
18831884
new UInputMan();
18841885
new ActivityMan();
18851886
new MovableMan();
@@ -1907,7 +1908,6 @@ int main(int argc, char *argv[]) {
19071908
g_TimerMan.Create();
19081909
g_PresetMan.Create();
19091910
g_FrameMan.Create();
1910-
//NOTE: By necessity of when things can be instantiated, this internally does: new GUISound()
19111911
if (g_AudioMan.Create() >= 0) {
19121912
g_GUISound.Create();
19131913
}

Managers/AudioMan.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ namespace RTE {
5353

5454
m_AudioEnabled = audioSystemSetupResult == FMOD_OK;
5555

56-
// NOTE: Anything that instantiates SoundContainers needs to wait until the Audio System is up and running before they start doing that. It'll fail safely even if Audio is not enabled.
57-
new GUISound();
58-
5956
if (!m_AudioEnabled) {
6057
g_ConsoleMan.PrintString("ERROR: Failed to enable audio: " + std::string(FMOD_ErrorString(audioSystemSetupResult)));
6158
return -1;
@@ -749,14 +746,14 @@ namespace RTE {
749746
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
750747

751748
FMOD_VECTOR AudioMan::GetAsFMODVector(const Vector &vector, float zValue) {
752-
Vector sceneDimensions = g_SceneMan.GetSceneDim();
749+
Vector sceneDimensions = g_SceneMan.GetScene() ? g_SceneMan.GetSceneDim() : Vector();
753750
return sceneDimensions.IsZero() ? FMOD_VECTOR{0, 0, zValue} : FMOD_VECTOR{vector.m_X, sceneDimensions.m_Y - vector.m_Y, zValue};
754751
}
755752

756753
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
757754

758755
Vector AudioMan::GetAsVector(FMOD_VECTOR fmodVector) {
759-
Vector sceneDimensions = g_SceneMan.GetSceneDim();
756+
Vector sceneDimensions = g_SceneMan.GetScene() ? g_SceneMan.GetSceneDim() : Vector();
760757
return sceneDimensions.IsZero() ? Vector() : Vector(fmodVector.x, sceneDimensions.m_Y - fmodVector.y);
761758
}
762759
}

System/Constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace RTE {
4242
static constexpr unsigned short c_MinimumDistanceForPanning = 50; //!< The minimum distance before which sound panning should not occur. Not relevant for immobile sounds or in splitscreen.
4343
*/
4444
static constexpr unsigned short c_DefaultAttenuationStartDistance = 100; //!< The default start distance for attenuating sounds. Individual sounds can have different values for this.
45-
static constexpr unsigned short c_SoundMaxAudibleDistance = 100000; //!< The maximum distance at which any sound can possibly be heard, after which point it will have 0 volume. Arbitrary default suggested by FMOD.
45+
static constexpr unsigned int c_SoundMaxAudibleDistance = 100000; //!< The maximum distance at which any sound can possibly be heard, after which point it will have 0 volume. Arbitrary default suggested by FMOD.
4646
#pragma endregion
4747

4848
#pragma region Network Constants

0 commit comments

Comments
 (0)