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

Commit 42d2b2c

Browse files
committed
Added sound channel group for menu sounds and used it when an activity isn't running, so immobile sounds in game are separated and can thus be paused separately
1 parent d4689ae commit 42d2b2c

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

Entities/Activity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void Activity::Clear() {
333333
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
334334

335335
void Activity::End() {
336-
g_AudioMan.FinishAllLoopingSounds();
336+
g_AudioMan.FinishIngameLoopingSounds();
337337
// Actor control is automatically disabled when players are set to observation mode, so no need to do anything directly.
338338
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
339339
m_ViewState[player] = ViewState::Observe;

Managers/ActivityMan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ namespace RTE {
328328

329329
m_LastMusicPath = "";
330330
m_LastMusicPos = 0;
331-
g_AudioMan.PauseAllSounds(false);
331+
g_AudioMan.PauseIngameSounds(false);
332332

333333
return error;
334334
}
@@ -378,7 +378,7 @@ namespace RTE {
378378

379379
m_Activity->SetPaused(pause);
380380
m_InActivity = !pause;
381-
g_AudioMan.PauseAllSounds(pause);
381+
g_AudioMan.PauseIngameSounds(pause);
382382
g_ConsoleMan.PrintString("SYSTEM: Activity \"" + m_Activity->GetPresetName() + "\" was " + (pause ? "paused" : "resumed"));
383383
} else {
384384
g_ConsoleMan.PrintString("ERROR: No Activity to pause!");

Managers/AudioMan.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ namespace RTE {
6969
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_AudioSystem->createChannelGroup("Sounds", &m_SoundChannelGroup) : audioSystemSetupResult;
7070
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_AudioSystem->createChannelGroup("MobileSounds", &m_MobileSoundChannelGroup) : audioSystemSetupResult;
7171
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_AudioSystem->createChannelGroup("ImmobileSounds", &m_ImmobileSoundChannelGroup) : audioSystemSetupResult;
72+
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_AudioSystem->createChannelGroup("MenuSounds", &m_MenuSoundChannelGroup) : audioSystemSetupResult;
7273
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_MasterChannelGroup->addGroup(m_MusicChannelGroup) : audioSystemSetupResult;
7374
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_MasterChannelGroup->addGroup(m_SoundChannelGroup) : audioSystemSetupResult;
7475
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_SoundChannelGroup->addGroup(m_MobileSoundChannelGroup) : audioSystemSetupResult;
7576
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_SoundChannelGroup->addGroup(m_ImmobileSoundChannelGroup) : audioSystemSetupResult;
77+
audioSystemSetupResult = (audioSystemSetupResult == FMOD_OK) ? m_SoundChannelGroup->addGroup(m_MenuSoundChannelGroup) : audioSystemSetupResult;
7678

7779
m_AudioEnabled = audioSystemSetupResult == FMOD_OK;
7880

@@ -244,7 +246,7 @@ namespace RTE {
244246

245247
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
246248

247-
void AudioMan::FinishAllLoopingSounds() {
249+
void AudioMan::FinishIngameLoopingSounds() {
248250
if (m_AudioEnabled) {
249251
int numberOfPlayingChannels;
250252
FMOD::Channel *soundChannel;
@@ -575,7 +577,14 @@ namespace RTE {
575577
g_ConsoleMan.PrintString("Unable to select new sounds to play for SoundContainer " + soundContainer->GetPresetName());
576578
return false;
577579
}
578-
FMOD::ChannelGroup *channelGroupToPlayIn = soundContainer->IsImmobile() ? m_ImmobileSoundChannelGroup : m_MobileSoundChannelGroup;
580+
581+
FMOD::ChannelGroup *channelGroupToPlayIn;
582+
if (g_ActivityMan.ActivityRunning()) {
583+
channelGroupToPlayIn = soundContainer->IsImmobile() ? m_ImmobileSoundChannelGroup : m_MobileSoundChannelGroup;
584+
} else {
585+
channelGroupToPlayIn = m_MenuSoundChannelGroup;
586+
}
587+
579588
FMOD::Channel *channel;
580589
int channelIndex;
581590
std::vector<const SoundSet::SoundData *> selectedSoundData;

Managers/AudioMan.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,13 @@ namespace RTE {
295295
/// <summary>
296296
/// Makes all sounds that are looping stop looping, allowing them to play once more then be finished.
297297
/// </summary>
298-
void FinishAllLoopingSounds();
298+
void FinishIngameLoopingSounds();
299+
300+
/// <summary>
301+
/// Pauses all ingame sounds.
302+
/// <param name="pause">Whether to pause sounds or resume them.</param>
303+
/// </summary>
304+
void PauseIngameSounds(bool pause = true) { if (m_AudioEnabled) { m_MobileSoundChannelGroup->setPaused(pause); m_ImmobileSoundChannelGroup->setPaused(pause); } }
299305
#pragma endregion
300306

301307
#pragma region Music Playback and Handling
@@ -336,14 +342,6 @@ namespace RTE {
336342
void ClearMusicQueue() { m_MusicPlayList.clear(); }
337343
#pragma endregion
338344

339-
#pragma region Mobile Sound Playback and Handling
340-
/// <summary>
341-
/// Pauses all sound playback.
342-
/// <param name="pause">Whether to pause sounds or resume them.</param>
343-
/// </summary>
344-
void PauseAllSounds(bool pause = true) { if (m_AudioEnabled) { m_MobileSoundChannelGroup->setPaused(pause); m_ImmobileSoundChannelGroup->setPaused(pause); } }
345-
#pragma endregion
346-
347345
#pragma region Lua Sound File Playing
348346
/// <summary>
349347
/// Starts playing a certain sound file.
@@ -440,6 +438,7 @@ namespace RTE {
440438
FMOD::ChannelGroup *m_SoundChannelGroup; //!< The FMOD ChannelGroup for sounds.
441439
FMOD::ChannelGroup *m_MobileSoundChannelGroup; //!< The FMOD ChannelGroup for mobile sounds.
442440
FMOD::ChannelGroup *m_ImmobileSoundChannelGroup; //!< The FMOD ChannelGroup for immobile sounds.
441+
FMOD::ChannelGroup *m_MenuSoundChannelGroup; //!< The FMOD ChannelGroup for immobile sounds.
443442

444443
bool m_AudioEnabled; //!< Bool to tell whether audio is enabled or not.
445444
std::vector<std::unique_ptr<const Vector>> m_CurrentActivityHumanPlayerPositions; //!< The stored positions of each human player in the current activity. Only filled when there's an activity running.

0 commit comments

Comments
 (0)