isle/LEGO1/mxbackgroundaudiomanager.cpp

109 lines
2.1 KiB
C++
Raw Normal View History

#include "mxbackgroundaudiomanager.h"
2023-09-25 16:28:25 -04:00
#include "mxomni.h"
#include "mxstreamer.h"
#include "mxticklemanager.h"
2023-09-25 16:28:25 -04:00
DECOMP_SIZE_ASSERT(MxBackgroundAudioManager, 0x150)
// OFFSET: LEGO1 0x1007ea90
MxBackgroundAudioManager::MxBackgroundAudioManager()
{
2023-10-24 19:38:27 -04:00
NotificationManager()->Register(this);
m_unka0 = 0;
m_unk138 = 0;
m_unk13c = 0;
m_unk140 = 0;
m_unk144 = 0;
m_unk148 = 0;
m_musicEnabled = FALSE;
}
// OFFSET: LEGO1 0x1007ec20
MxBackgroundAudioManager::~MxBackgroundAudioManager()
{
2023-10-24 19:38:27 -04:00
TickleManager()->UnregisterClient(this);
NotificationManager()->Unregister(this);
DestroyMusic();
}
// OFFSET: LEGO1 0x1007f470
void MxBackgroundAudioManager::Stop()
{
2023-10-24 19:38:27 -04:00
if (m_action2.GetObjectId() != -1)
DeleteObject(m_action2);
2023-10-24 19:38:27 -04:00
m_unk138 = 0;
m_action2.SetAtomId(MxAtomId());
m_action2.SetObjectId(-1);
2023-10-24 19:38:27 -04:00
if (m_action1.GetObjectId() != -1)
DeleteObject(m_action1);
2023-10-24 19:38:27 -04:00
m_unka0 = 0;
m_action1.SetAtomId(MxAtomId());
m_unk148 = 0;
m_action1.SetObjectId(-1);
m_unk13c = 0;
}
// OFFSET: LEGO1 0x1007f5f0
void MxBackgroundAudioManager::Enable(MxBool p)
{
2023-10-24 19:38:27 -04:00
if (this->m_musicEnabled != p) {
this->m_musicEnabled = p;
if (!p) {
Stop();
}
}
}
// OFFSET: LEGO1 0x1007f650
void MxBackgroundAudioManager::Init()
{
2023-10-24 19:38:27 -04:00
this->m_unka0 = 0;
this->m_unk13c = 0;
}
// OFFSET: LEGO1 0x1007ece0
2023-10-24 19:38:27 -04:00
MxResult MxBackgroundAudioManager::Create(MxAtomId& p_script, MxU32 p_frequencyMS)
{
2023-10-24 19:38:27 -04:00
MxResult result = OpenMusic(p_script);
2023-10-24 19:38:27 -04:00
if (result == SUCCESS) {
TickleManager()->RegisterClient(this, p_frequencyMS);
m_musicEnabled = TRUE;
}
2023-10-24 19:38:27 -04:00
return result;
}
// OFFSET: LEGO1 0x1007ed20
2023-10-24 19:38:27 -04:00
MxResult MxBackgroundAudioManager::OpenMusic(MxAtomId& p_script)
{
2023-10-24 19:38:27 -04:00
if (m_script.GetInternal())
DestroyMusic();
2023-10-24 19:38:27 -04:00
MxResult result = FAILURE;
2023-10-24 19:38:27 -04:00
if (Streamer()->Open(p_script.GetInternal(), 0)) {
m_script = p_script;
result = SUCCESS;
}
2023-10-24 19:38:27 -04:00
return result;
}
// OFFSET: LEGO1 0x1007ed70
void MxBackgroundAudioManager::DestroyMusic()
{
2023-10-24 19:38:27 -04:00
if (m_script.GetInternal()) {
MxDSAction ds;
ds.SetAtomId(m_script);
ds.SetUnknown24(-2);
DeleteObject(ds);
Streamer()->Close(m_script.GetInternal());
m_musicEnabled = FALSE;
}
}