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

Commit 3c2e779

Browse files
committed
Cleaned up SoundContainer
Trimmed down various creates and plays, fixed little bugs and cruft, reordered variables, renamed some stuff Added new properties for pitch and volume, and made position a variable of sound container Modified GUISound methods to match new SoundContainer Creates
1 parent d529e89 commit 3c2e779

File tree

3 files changed

+126
-91
lines changed

3 files changed

+126
-91
lines changed

Entities/SoundContainer.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ namespace RTE {
1919

2020
m_PlayingChannels.clear();
2121

22+
m_Immobile = false;
2223
m_AttenuationStartDistance = c_DefaultAttenuationStartDistance;
2324
m_Loops = 0;
25+
m_SoundPropertiesUpToDate = false;
26+
2427
m_Priority = AudioMan::PRIORITY_NORMAL;
2528
m_AffectedByGlobalPitch = true;
26-
m_Immobile = false;
2729

28-
m_AllSoundPropertiesUpToDate = false;
30+
m_Pos = Vector();
31+
m_Volume = 1.0F;
32+
m_Pitch = 1.0F;
2933
}
3034

3135
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -45,11 +49,16 @@ namespace RTE {
4549

4650
m_PlayingChannels.clear();
4751

52+
m_Immobile = reference.m_Immobile;
4853
m_AttenuationStartDistance = reference.m_AttenuationStartDistance;
4954
m_Loops = reference.m_Loops;
55+
5056
m_Priority = reference.m_Priority;
5157
m_AffectedByGlobalPitch = reference.m_AffectedByGlobalPitch;
52-
m_Immobile = reference.m_Immobile;
58+
59+
m_Pos = reference.m_Pos;
60+
m_Volume = reference.m_Volume;
61+
m_Pitch = reference.m_Pitch;
5362

5463
return 0;
5564
}
@@ -66,6 +75,8 @@ namespace RTE {
6675
} else {
6776
reader.ReportError("Cycle mode " + cycleModeString + " is invalid.");
6877
}
78+
} else if (propName == "Immobile") {
79+
reader >> m_Immobile;
6980
} else if (propName == "AttenuationStartDistance") {
7081
reader >> m_AttenuationStartDistance;
7182
} else if (propName == "LoopSetting") {
@@ -75,8 +86,12 @@ namespace RTE {
7586
if (m_Priority < 0 || m_Priority > 256) { reader.ReportError("SoundContainer priority must be between 256 (lowest priority) and 0 (highest priority)."); }
7687
} else if (propName == "AffectedByGlobalPitch") {
7788
reader >> m_AffectedByGlobalPitch;
78-
} else if (propName == "Immobile") {
79-
reader >> m_Immobile;
89+
} else if (propName == "Position") {
90+
reader >> m_Pos;
91+
} else if (propName == "Volume") {
92+
reader >> m_Volume;
93+
} else if (propName == "Pitch") {
94+
reader >> m_Pitch;
8095
} else {
8196
return Entity::ReadProperty(propName, reader);
8297
}
@@ -166,7 +181,7 @@ namespace RTE {
166181
soundSet.push_back({soundFile, soundObject, offset, minimumAudibleDistance, attenuationStartDistance});
167182
if (soundSetIndex >= m_SoundSets.size()) { m_SoundSets.push_back(soundSet); }
168183

169-
m_AllSoundPropertiesUpToDate = false;
184+
m_SoundPropertiesUpToDate = false;
170185
}
171186

172187
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -250,7 +265,7 @@ namespace RTE {
250265
result = (result == FMOD_OK) ? soundData.SoundObject->setMode(soundMode) : result;
251266
result = (result == FMOD_OK) ? soundData.SoundObject->setLoopCount(m_Loops) : result;
252267
if (m_Immobile) {
253-
result = (result == FMOD_OK) ? soundData.SoundObject->set3DMinMaxDistance(m_AttenuationStartDistance, c_SoundMaxAudibleDistance) : result;
268+
result = (result == FMOD_OK) ? soundData.SoundObject->set3DMinMaxDistance(std::max(0.0F, m_AttenuationStartDistance), c_SoundMaxAudibleDistance) : result;
254269
} else {
255270
//FMOD_VECTOR customRolloffPoints[10];
256271
//CalculateCustomRolloffPoints(soundData, customRolloffPoints, 10);
@@ -262,7 +277,7 @@ namespace RTE {
262277
}
263278
}
264279
}
265-
m_AllSoundPropertiesUpToDate = result == FMOD_OK;
280+
m_SoundPropertiesUpToDate = result == FMOD_OK;
266281

267282
return result;
268283
}
@@ -271,7 +286,7 @@ namespace RTE {
271286

272287
//TODO this needs to be used or be deleted
273288
void SoundContainer::CalculateCustomRolloffPoints(const SoundData &soundDataToCalculateFor, FMOD_VECTOR *rolloffPoints, int numRolloffPoints) {
274-
int attenuationStartDistance = (soundDataToCalculateFor.AttenuationStartDistance < 0) ? m_AttenuationStartDistance : soundDataToCalculateFor.AttenuationStartDistance;
289+
float attenuationStartDistance = (soundDataToCalculateFor.AttenuationStartDistance < 0) ? m_AttenuationStartDistance : soundDataToCalculateFor.AttenuationStartDistance;
275290
float currentDistance = attenuationStartDistance;
276291
float currentVolumeLevel = 1;
277292

0 commit comments

Comments
 (0)