implement most of MxBackgroundAudioManager (#232)

* implement most of MxBackgroundAudioManager

* Match OpenMusic to 100%, style fixes

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
Misha
2023-10-22 10:11:46 -04:00
committed by GitHub
parent 50fe5f9c83
commit 681ab9c026
6 changed files with 85 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
#include "mxbackgroundaudiomanager.h"
#include "mxomni.h"
#include "mxstreamer.h"
#include "mxticklemanager.h"
DECOMP_SIZE_ASSERT(MxBackgroundAudioManager, 0x150)
@@ -20,14 +22,29 @@ MxBackgroundAudioManager::MxBackgroundAudioManager()
// OFFSET: LEGO1 0x1007ec20
MxBackgroundAudioManager::~MxBackgroundAudioManager()
{
// TODO
TickleManager()->UnregisterClient(this);
NotificationManager()->Unregister(this);
DestroyMusic();
}
// OFFSET: LEGO1 0x1007f470
void MxBackgroundAudioManager::Stop()
{
// TODO
if (m_action2.GetObjectId() != -1)
DeleteObject(m_action2);
m_unk138 = 0;
m_action2.SetAtomId(MxAtomId());
m_action2.SetObjectId(-1);
if (m_action1.GetObjectId() != -1)
DeleteObject(m_action1);
m_unka0 = 0;
m_action1.SetAtomId(MxAtomId());
m_unk148 = 0;
m_action1.SetObjectId(-1);
m_unk13c = 0;
}
// OFFSET: LEGO1 0x1007f5f0
@@ -47,3 +64,45 @@ void MxBackgroundAudioManager::Init()
this->m_unka0 = 0;
this->m_unk13c = 0;
}
// OFFSET: LEGO1 0x1007ece0
MxResult MxBackgroundAudioManager::Create(MxAtomId &p_script, MxU32 p_frequencyMS)
{
MxResult result = OpenMusic(p_script);
if (result == SUCCESS) {
TickleManager()->RegisterClient(this, p_frequencyMS);
m_musicEnabled = TRUE;
}
return result;
}
// OFFSET: LEGO1 0x1007ed20
MxResult MxBackgroundAudioManager::OpenMusic(MxAtomId &p_script)
{
if (m_script.GetInternal())
DestroyMusic();
MxResult result = FAILURE;
if (Streamer()->Open(p_script.GetInternal(), 0)) {
m_script = p_script;
result = SUCCESS;
}
return result;
}
// OFFSET: LEGO1 0x1007ed70
void MxBackgroundAudioManager::DestroyMusic()
{
if (m_script.GetInternal()) {
MxDSAction ds;
ds.SetAtomId(m_script);
ds.SetUnknown24(-2);
DeleteObject(ds);
Streamer()->Close(m_script.GetInternal());
m_musicEnabled = FALSE;
}
}