mirror of https://github.com/AxioDL/metaforce.git
CSfxManager: Make use of std::array where applicable
Same behavior, but with stronger typing.
This commit is contained in:
parent
d677d2ac1d
commit
2ab59eec52
|
@ -26,7 +26,7 @@ CFactoryFnReturn FAudioTranslationTableFactory(const SObjectTag& tag, CInputStre
|
||||||
return TToken<std::vector<u16>>::GetIObjObjectFor(std::move(obj));
|
return TToken<std::vector<u16>>::GetIObjObjectFor(std::move(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSfxManager::CSfxChannel CSfxManager::m_channels[4];
|
std::array<CSfxManager::CSfxChannel, 4> CSfxManager::m_channels;
|
||||||
CSfxManager::ESfxChannels CSfxManager::m_currentChannel = CSfxManager::ESfxChannels::Default;
|
CSfxManager::ESfxChannels CSfxManager::m_currentChannel = CSfxManager::ESfxChannels::Default;
|
||||||
bool CSfxManager::m_doUpdate;
|
bool CSfxManager::m_doUpdate;
|
||||||
void* CSfxManager::m_usedSounds;
|
void* CSfxManager::m_usedSounds;
|
||||||
|
@ -186,7 +186,7 @@ void CSfxManager::SetChannel(ESfxChannels chan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::KillAll(ESfxChannels chan) {
|
void CSfxManager::KillAll(ESfxChannels chan) {
|
||||||
CSfxChannel& chanObj = m_channels[int(chan)];
|
CSfxChannel& chanObj = m_channels[size_t(chan)];
|
||||||
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
||||||
const CSfxHandle& handle = *it;
|
const CSfxHandle& handle = *it;
|
||||||
handle->Stop();
|
handle->Stop();
|
||||||
|
@ -197,7 +197,7 @@ void CSfxManager::KillAll(ESfxChannels chan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::TurnOnChannel(ESfxChannels chan) {
|
void CSfxManager::TurnOnChannel(ESfxChannels chan) {
|
||||||
CSfxChannel& chanObj = m_channels[int(chan)];
|
CSfxChannel& chanObj = m_channels[size_t(chan)];
|
||||||
m_currentChannel = chan;
|
m_currentChannel = chan;
|
||||||
m_doUpdate = true;
|
m_doUpdate = true;
|
||||||
if (chanObj.x44_listenerActive) {
|
if (chanObj.x44_listenerActive) {
|
||||||
|
@ -208,7 +208,7 @@ void CSfxManager::TurnOnChannel(ESfxChannels chan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::TurnOffChannel(ESfxChannels chan) {
|
void CSfxManager::TurnOffChannel(ESfxChannels chan) {
|
||||||
CSfxChannel& chanObj = m_channels[int(chan)];
|
CSfxChannel& chanObj = m_channels[size_t(chan)];
|
||||||
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
||||||
const CSfxHandle& handle = *it;
|
const CSfxHandle& handle = *it;
|
||||||
if (handle->IsLooped()) {
|
if (handle->IsLooped()) {
|
||||||
|
@ -260,24 +260,29 @@ void CSfxManager::UpdateListener(const zeus::CVector3f& pos, const zeus::CVector
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 CSfxManager::GetRank(CBaseSfxWrapper* sfx) {
|
s16 CSfxManager::GetRank(CBaseSfxWrapper* sfx) {
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
const CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
if (!sfx->IsInArea())
|
if (!sfx->IsInArea()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
s16 rank = sfx->GetPriority() / 4;
|
s16 rank = sfx->GetPriority() / 4;
|
||||||
if (sfx->IsPlaying())
|
if (sfx->IsPlaying()) {
|
||||||
++rank;
|
++rank;
|
||||||
|
}
|
||||||
|
|
||||||
if (sfx->IsLooped())
|
if (sfx->IsLooped()) {
|
||||||
rank -= 2;
|
rank -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (sfx->Ready() && !sfx->IsPlaying())
|
if (sfx->Ready() && !sfx->IsPlaying()) {
|
||||||
rank += 3;
|
rank += 3;
|
||||||
|
}
|
||||||
|
|
||||||
if (chanObj.x44_listenerActive) {
|
if (chanObj.x44_listenerActive) {
|
||||||
ESfxAudibility aud = sfx->GetAudible(chanObj.x0_pos);
|
const ESfxAudibility aud = sfx->GetAudible(chanObj.x0_pos);
|
||||||
if (aud == ESfxAudibility::Aud0)
|
if (aud == ESfxAudibility::Aud0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
rank += int(aud) / 2;
|
rank += int(aud) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +290,7 @@ s16 CSfxManager::GetRank(CBaseSfxWrapper* sfx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::ApplyReverb() {
|
void CSfxManager::ApplyReverb() {
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
const CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
for (const CSfxHandle& handle : chanObj.x48_handles) {
|
for (const CSfxHandle& handle : chanObj.x48_handles) {
|
||||||
handle->SetReverb(m_reverbAmount);
|
handle->SetReverb(m_reverbAmount);
|
||||||
}
|
}
|
||||||
|
@ -344,7 +349,7 @@ void CSfxManager::StopSound(const CSfxHandle& handle) {
|
||||||
m_doUpdate = true;
|
m_doUpdate = true;
|
||||||
handle->Stop();
|
handle->Stop();
|
||||||
handle->Release();
|
handle->Release();
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
handle->Close();
|
handle->Close();
|
||||||
chanObj.x48_handles.erase(handle);
|
chanObj.x48_handles.erase(handle);
|
||||||
}
|
}
|
||||||
|
@ -357,7 +362,7 @@ CSfxHandle CSfxManager::SfxStart(u16 id, float vol, float pan, bool useAcoustics
|
||||||
|
|
||||||
m_doUpdate = true;
|
m_doUpdate = true;
|
||||||
CSfxHandle wrapper = std::make_shared<CSfxWrapper>(looped, prio, id, vol, pan, useAcoustics, areaId);
|
CSfxHandle wrapper = std::make_shared<CSfxWrapper>(looped, prio, id, vol, pan, useAcoustics, areaId);
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
chanObj.x48_handles.insert(wrapper);
|
chanObj.x48_handles.insert(wrapper);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
@ -428,14 +433,13 @@ CSfxHandle CSfxManager::AddEmitter(const CAudioSys::C3DEmitterParmData& parmData
|
||||||
data.x20_flags |= 0x6; // Pausable/restartable when inaudible
|
data.x20_flags |= 0x6; // Pausable/restartable when inaudible
|
||||||
m_doUpdate = true;
|
m_doUpdate = true;
|
||||||
CSfxHandle wrapper = std::make_shared<CSfxEmitterWrapper>(looped, prio, data, useAcoustics, areaId);
|
CSfxHandle wrapper = std::make_shared<CSfxEmitterWrapper>(looped, prio, data, useAcoustics, areaId);
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
chanObj.x48_handles.insert(wrapper);
|
chanObj.x48_handles.insert(wrapper);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::StopAndRemoveAllEmitters() {
|
void CSfxManager::StopAndRemoveAllEmitters() {
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (auto& chanObj : m_channels) {
|
||||||
CSfxChannel& chanObj = m_channels[i];
|
|
||||||
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
||||||
const CSfxHandle& handle = *it;
|
const CSfxHandle& handle = *it;
|
||||||
handle->Stop();
|
handle->Stop();
|
||||||
|
@ -538,15 +542,15 @@ void CSfxManager::DisableAuxProcessing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::SetActiveAreas(const rstl::reserved_vector<TAreaId, 10>& areas) {
|
void CSfxManager::SetActiveAreas(const rstl::reserved_vector<TAreaId, 10>& areas) {
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
const CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
|
|
||||||
for (const CSfxHandle& hnd : chanObj.x48_handles) {
|
for (const CSfxHandle& hnd : chanObj.x48_handles) {
|
||||||
TAreaId sndArea = hnd->GetArea();
|
const TAreaId sndArea = hnd->GetArea();
|
||||||
if (sndArea == kInvalidAreaId) {
|
if (sndArea == kInvalidAreaId) {
|
||||||
hnd->SetInArea(true);
|
hnd->SetInArea(true);
|
||||||
} else {
|
} else {
|
||||||
bool inArea = false;
|
bool inArea = false;
|
||||||
for (TAreaId id : areas) {
|
for (const TAreaId id : areas) {
|
||||||
if (sndArea == id) {
|
if (sndArea == id) {
|
||||||
inArea = true;
|
inArea = true;
|
||||||
break;
|
break;
|
||||||
|
@ -559,7 +563,7 @@ void CSfxManager::SetActiveAreas(const rstl::reserved_vector<TAreaId, 10>& areas
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSfxManager::Update(float dt) {
|
void CSfxManager::Update(float dt) {
|
||||||
CSfxChannel& chanObj = m_channels[int(m_currentChannel)];
|
CSfxChannel& chanObj = m_channels[size_t(m_currentChannel)];
|
||||||
|
|
||||||
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
for (auto it = chanObj.x48_handles.begin(); it != chanObj.x48_handles.end();) {
|
||||||
const CSfxHandle& handle = *it;
|
const CSfxHandle& handle = *it;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -177,7 +178,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static CSfxChannel m_channels[4];
|
static std::array<CSfxChannel, 4> m_channels;
|
||||||
static ESfxChannels m_currentChannel;
|
static ESfxChannels m_currentChannel;
|
||||||
static bool m_doUpdate;
|
static bool m_doUpdate;
|
||||||
static void* m_usedSounds;
|
static void* m_usedSounds;
|
||||||
|
|
Loading…
Reference in New Issue