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

Commit 654dc5f

Browse files
committed
Added reader error if SoundContainer priority is outside limits, and added safety to priority setter to keep it within limits
Made sure music priority is always high
1 parent f97ca8f commit 654dc5f

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Entities/SoundContainer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ namespace RTE {
5050
reader >> m_Loops;
5151
} else if (propName == "Priority") {
5252
reader >> m_Priority;
53+
if (m_Priority < 0 || m_Priority > 256) {
54+
reader.ReportError("SoundContainer priority must be between 256 (lowest priority) and 0 (highest priority).");
55+
}
5356
} else if (propName == "AffectedByGlobalPitch") {
5457
reader >> m_AffectedByGlobalPitch;
5558
} else {

Entities/SoundContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace RTE {
191191
/// Sets the current playback priority. Higher value will make this more likely to make it into mixing on playback.
192192
/// </summary>
193193
/// <param name="priority">The new priority. See AudioMan::PRIORITY_* enumeration.</param>
194-
void SetPriority(int priority) { m_Priority = priority; }
194+
void SetPriority(int priority) { m_Priority = Limit(priority, 255, 0); }
195195

196196
/// <summary>
197197
/// Gets whether the sounds in this SoundContainer are affected by global pitch changes or not.

Managers/AudioMan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace RTE {
288288
g_ConsoleMan.PrintString("ERROR: Could not open music file " + std::string(filePath) + ": " + std::string(FMOD_ErrorString(result)));
289289
return;
290290
}
291-
291+
292292
result = musicStream->setLoopCount(loops);
293293
if (result != FMOD_OK && (loops != 0 && loops != 1)) {
294294
g_ConsoleMan.PrintString("ERROR: Failed to set looping for music file: " + std::string(filePath) + ". This means it will only play 1 time, instead of " + (loops == 0 ? "looping endlessly." : loops + " times.") + std::string(FMOD_ErrorString(result)));
@@ -300,6 +300,7 @@ namespace RTE {
300300
g_ConsoleMan.PrintString("ERROR: Could not play music file: " + std::string(filePath));
301301
return;
302302
}
303+
result = musicChannel->setPriority(PRIORITY_HIGH);
303304

304305
if (volumeOverrideIfNotMuted >= 0 && m_MusicVolume > 0) {
305306
result = musicChannel->setVolume(volumeOverrideIfNotMuted);

0 commit comments

Comments
 (0)