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

Commit a21ee3c

Browse files
committed
Added proper support for splitscreen using FMOD's splitscreen handling. Added necessary supporting property and removed related TODO.
1 parent 8cf5f09 commit a21ee3c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

Managers/AudioMan.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ConsoleMan.h"
33
#include "SettingsMan.h"
44
#include "SceneMan.h"
5+
#include "ActivityMan.h"
56
#include "SoundContainer.h"
67
#include "GUISound.h"
78

@@ -73,12 +74,35 @@ namespace RTE {
7374
void AudioMan::Update() {
7475
if (m_AudioEnabled) {
7576

76-
//TODO handle splitscreen - do m_AudioSystem->set3DNumListeners(numPlayers); and set each player's position
77-
//TODO allow setting vel for AEmitter and PEmitter
78-
m_AudioSystem->set3DListenerAttributes(0, &GetAsFMODVector(g_SceneMan.GetScrollTarget()), NULL, &c_FMODForward, &c_FMODUp);
79-
m_AudioSystem->update();
77+
//TODO allow setting vel for AEmitter and PEmitter. Also maybe consider setting vel on listener when sceneman target scrolling is happening.
78+
79+
FMOD_RESULT status = FMOD_OK;
80+
81+
if (g_ActivityMan.ActivityRunning()) {
82+
Activity const *currentActivity = g_ActivityMan.GetActivity();
83+
84+
if (m_CurrentActivityHumanCount != (m_IsInMultiplayerMode ? 1 : currentActivity->GetHumanCount())) {
85+
m_CurrentActivityHumanCount = m_IsInMultiplayerMode ? 1 : currentActivity->GetHumanCount();
86+
status = m_AudioSystem->set3DNumListeners(m_CurrentActivityHumanCount);
87+
}
88+
89+
int audioSystemPlayerNumber = 0;
90+
for (int player = 0; player < currentActivity->GetPlayerCount() && audioSystemPlayerNumber < m_CurrentActivityHumanCount; player++) {
91+
if (currentActivity->PlayerHuman(player)) {
92+
status = m_AudioSystem->set3DListenerAttributes(audioSystemPlayerNumber, &GetAsFMODVector(g_SceneMan.GetScrollTarget(currentActivity->ScreenOfPlayer(player))), NULL, &c_FMODForward, &c_FMODUp);
93+
audioSystemPlayerNumber++;
94+
}
95+
}
96+
} else {
97+
if (m_CurrentActivityHumanCount != 1) {
98+
m_CurrentActivityHumanCount = 1;
99+
status = m_AudioSystem->set3DNumListeners(1);
100+
}
101+
status = m_AudioSystem->set3DListenerAttributes(0, &GetAsFMODVector(g_SceneMan.GetScrollTarget()), NULL, &c_FMODForward, &c_FMODUp);
102+
}
103+
104+
status = m_AudioSystem->update();
80105

81-
// Done waiting for silence
82106
if (!IsMusicPlaying() && m_SilenceTimer.IsPastRealTimeLimit()) { PlayNextStream(); }
83107
}
84108
}

Managers/AudioMan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ namespace RTE {
406406
FMOD::ChannelGroup *m_SoundChannelGroup; //!< The FMOD ChannelGroup for sounds.
407407

408408
bool m_AudioEnabled; //!< Bool to tell whether audio is enabled or not.
409+
int m_CurrentActivityHumanCount; //!< The stored number of humans in the current activity, used for audio splitscreen handling. Only updated when there's an activity running.
409410

410411
double m_SoundsVolume; //!< Global sounds effects volume.
411412
double m_MusicVolume; //!< Global music volume.

0 commit comments

Comments
 (0)