2023-06-29 04:10:08 -04:00
|
|
|
#include "mxbackgroundaudiomanager.h"
|
|
|
|
|
2023-11-05 10:07:28 -05:00
|
|
|
#include "legoomni.h"
|
|
|
|
#include "mxcompositepresenter.h"
|
|
|
|
#include "mxdssound.h"
|
2023-09-25 16:28:25 -04:00
|
|
|
#include "mxomni.h"
|
2023-11-05 10:07:28 -05:00
|
|
|
#include "mxpresenter.h"
|
2023-10-22 10:11:46 -04:00
|
|
|
#include "mxstreamer.h"
|
|
|
|
#include "mxticklemanager.h"
|
2023-09-25 16:28:25 -04:00
|
|
|
|
2023-08-03 14:42:12 -04:00
|
|
|
DECOMP_SIZE_ASSERT(MxBackgroundAudioManager, 0x150)
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ea90
|
2023-06-29 04:10:08 -04:00
|
|
|
MxBackgroundAudioManager::MxBackgroundAudioManager()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
NotificationManager()->Register(this);
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0xa0 = 0;
|
|
|
|
m_unk0x138 = 0;
|
|
|
|
m_unk0x13c = 0;
|
|
|
|
m_unk0x140 = 0;
|
2023-11-05 10:07:28 -05:00
|
|
|
m_targetVolume = 0;
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x148 = 0;
|
2023-10-24 19:38:27 -04:00
|
|
|
m_musicEnabled = FALSE;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ec20
|
2023-06-29 04:10:08 -04:00
|
|
|
MxBackgroundAudioManager::~MxBackgroundAudioManager()
|
2023-08-03 14:42:12 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
TickleManager()->UnregisterClient(this);
|
|
|
|
NotificationManager()->Unregister(this);
|
|
|
|
DestroyMusic();
|
2023-08-03 14:42:12 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ece0
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult MxBackgroundAudioManager::Create(MxAtomId& p_script, MxU32 p_frequencyMS)
|
2023-10-22 10:11:46 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult result = OpenMusic(p_script);
|
2023-10-22 10:11:46 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (result == SUCCESS) {
|
|
|
|
TickleManager()->RegisterClient(this, p_frequencyMS);
|
|
|
|
m_musicEnabled = TRUE;
|
|
|
|
}
|
2023-10-22 10:11:46 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return result;
|
2023-10-22 10:11:46 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ed20
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult MxBackgroundAudioManager::OpenMusic(MxAtomId& p_script)
|
2023-10-22 10:11:46 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_script.GetInternal())
|
|
|
|
DestroyMusic();
|
2023-10-22 10:11:46 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult result = FAILURE;
|
2023-10-22 10:11:46 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (Streamer()->Open(p_script.GetInternal(), 0)) {
|
|
|
|
m_script = p_script;
|
|
|
|
result = SUCCESS;
|
|
|
|
}
|
2023-10-22 10:11:46 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return result;
|
2023-10-22 10:11:46 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ed70
|
2023-10-22 10:11:46 -04:00
|
|
|
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;
|
|
|
|
}
|
2023-10-25 14:51:59 -04:00
|
|
|
}
|
2023-11-05 10:07:28 -05:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ee40
|
2023-11-05 10:07:28 -05:00
|
|
|
MxResult MxBackgroundAudioManager::Tickle()
|
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
switch (m_unk0x13c) {
|
2023-11-05 10:07:28 -05:00
|
|
|
case MxPresenter::TickleState_Starting:
|
|
|
|
FadeInOrFadeOut();
|
|
|
|
return SUCCESS;
|
|
|
|
case MxPresenter::TickleState_Streaming:
|
|
|
|
FUN_1007ee70();
|
|
|
|
return SUCCESS;
|
|
|
|
case MxPresenter::TickleState_Repeating:
|
|
|
|
FUN_1007ef40();
|
|
|
|
return SUCCESS;
|
|
|
|
default:
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ee70
|
2023-11-05 10:07:28 -05:00
|
|
|
void MxBackgroundAudioManager::FUN_1007ee70()
|
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0xa0 && m_unk0xa0->GetAction()) {
|
|
|
|
DeleteObject(*m_unk0x138->GetAction());
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x138) {
|
|
|
|
m_unk0xa0 = m_unk0x138;
|
2023-11-05 10:07:28 -05:00
|
|
|
m_action1 = m_action2;
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138 = NULL;
|
2023-11-05 10:07:28 -05:00
|
|
|
m_action2.SetObjectId(-1);
|
|
|
|
m_action2.SetAtomId(MxAtomId());
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x13c = NULL;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007ef40
|
2023-11-05 10:07:28 -05:00
|
|
|
void MxBackgroundAudioManager::FUN_1007ef40()
|
|
|
|
{
|
|
|
|
MxU32 compare;
|
|
|
|
MxU32 volume;
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0xa0 == NULL) {
|
|
|
|
if (m_unk0x138) {
|
2023-11-05 10:07:28 -05:00
|
|
|
compare = 30;
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x148 == 0) {
|
|
|
|
compare = m_unk0x148;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
volume = m_unk0x138->GetVolume();
|
2023-11-05 10:07:28 -05:00
|
|
|
if (volume < compare) {
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x140 + m_unk0x138->GetVolume() <= compare) {
|
|
|
|
compare = m_unk0x140 + compare;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138->SetVolume(compare);
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138->SetVolume(compare);
|
|
|
|
m_unk0xa0 = m_unk0x138;
|
2023-11-05 10:07:28 -05:00
|
|
|
m_action1 = m_action2;
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138 = NULL;
|
2023-11-05 10:07:28 -05:00
|
|
|
m_action2.SetObjectId(-1);
|
|
|
|
m_action2.SetAtomId(MxAtomId());
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x13c = NULL;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
else if (m_unk0xa0->GetAction() != NULL) {
|
|
|
|
if (m_unk0xa0->GetVolume() == 0) {
|
|
|
|
DeleteObject(*m_unk0xa0->GetAction());
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-13 05:48:14 -05:00
|
|
|
compare = m_unk0xa0->GetVolume();
|
2023-11-05 10:07:28 -05:00
|
|
|
volume = 0;
|
2023-12-13 05:48:14 -05:00
|
|
|
if (compare != m_unk0x140 && -1 < compare - m_unk0x140) {
|
|
|
|
volume = m_unk0xa0->GetVolume() - m_unk0x140;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138->SetVolume(volume);
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f0e0
|
2023-11-05 10:07:28 -05:00
|
|
|
void MxBackgroundAudioManager::FadeInOrFadeOut()
|
|
|
|
{
|
|
|
|
// This function probably is the fade in/out routine
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0xa0 != NULL) {
|
|
|
|
undefined4 volume = m_unk0xa0->GetVolume();
|
2023-11-05 10:07:28 -05:00
|
|
|
MxU32 compare = 30;
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x148 == 0) {
|
2023-11-05 10:07:28 -05:00
|
|
|
compare = m_targetVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (volume < compare) {
|
2023-12-13 05:48:14 -05:00
|
|
|
volume = m_unk0x140 + volume;
|
2023-11-05 10:07:28 -05:00
|
|
|
if (compare <= volume) {
|
|
|
|
volume = compare;
|
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0xa0->SetVolume(volume);
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
else if (compare < volume) {
|
2023-12-13 05:48:14 -05:00
|
|
|
volume = volume - m_unk0x140;
|
2023-11-05 10:07:28 -05:00
|
|
|
if (volume <= compare) {
|
|
|
|
volume = compare;
|
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0xa0->SetVolume(volume);
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0xa0->SetVolume(volume);
|
|
|
|
m_unk0x13c = 0;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x13c = 0;
|
2023-11-05 10:07:28 -05:00
|
|
|
}
|
|
|
|
}
|
2023-11-21 03:44:45 -05:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f170
|
2023-12-13 05:48:14 -05:00
|
|
|
MxLong MxBackgroundAudioManager::Notify(MxParam& p_param)
|
2023-11-21 03:44:45 -05:00
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
switch (((MxNotificationParam&) p_param).GetNotification()) {
|
2023-11-21 03:44:45 -05:00
|
|
|
case c_notificationStartAction:
|
2023-12-13 05:48:14 -05:00
|
|
|
StartAction(p_param);
|
2023-11-21 03:44:45 -05:00
|
|
|
return 1;
|
|
|
|
case c_notificationEndAction:
|
2023-12-13 05:48:14 -05:00
|
|
|
StopAction(p_param);
|
2023-11-21 03:44:45 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f1b0
|
2023-12-13 05:48:14 -05:00
|
|
|
void MxBackgroundAudioManager::StartAction(MxParam& p_param)
|
2023-11-21 03:44:45 -05:00
|
|
|
{
|
|
|
|
// TODO: the sender is most likely a MxAudioPresenter?
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138 = (MxAudioPresenter*) ((MxNotificationParam&) p_param).GetSender();
|
|
|
|
m_action2.SetAtomId(m_unk0x138->GetAction()->GetAtomId());
|
|
|
|
m_action2.SetObjectId(m_unk0x138->GetAction()->GetObjectId());
|
|
|
|
m_targetVolume = ((MxDSSound*) (m_unk0x138->GetAction()))->GetVolume();
|
|
|
|
m_unk0x138->SetVolume(0);
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f200
|
2023-12-13 05:48:14 -05:00
|
|
|
void MxBackgroundAudioManager::StopAction(MxParam& p_param)
|
2023-11-21 03:44:45 -05:00
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
if (((MxNotificationParam&) p_param).GetSender() == m_unk0xa0) {
|
|
|
|
m_unk0xa0 = NULL;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_action1.SetAtomId(MxAtomId());
|
|
|
|
m_action1.SetObjectId(-1);
|
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
else if (((MxNotificationParam&) p_param).GetSender() == m_unk0x138) {
|
|
|
|
m_unk0x138 = NULL;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_action2.SetAtomId(MxAtomId());
|
|
|
|
m_action2.SetObjectId(-1);
|
|
|
|
}
|
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
Lego()->HandleNotificationType2(p_param);
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f2f0
|
2023-12-13 05:48:14 -05:00
|
|
|
MxResult MxBackgroundAudioManager::PlayMusic(MxDSAction& p_action, undefined4 p_unk0x140, undefined4 p_unk0x13c)
|
2023-11-21 03:44:45 -05:00
|
|
|
{
|
|
|
|
if (!m_musicEnabled) {
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
if (m_action2.GetObjectId() == -1 && m_action1.GetObjectId() != p_action.GetObjectId()) {
|
|
|
|
MxDSAction action;
|
|
|
|
action.SetAtomId(GetCurrentAction().GetAtomId());
|
|
|
|
action.SetObjectId(GetCurrentAction().GetObjectId());
|
|
|
|
action.SetUnknown24(GetCurrentAction().GetUnknown24());
|
|
|
|
|
|
|
|
m_action2.SetAtomId(p_action.GetAtomId());
|
|
|
|
m_action2.SetObjectId(p_action.GetObjectId());
|
|
|
|
m_action2.SetUnknown84(this);
|
2023-12-11 16:35:50 -05:00
|
|
|
m_action2.SetOrigin(this);
|
2023-11-21 03:44:45 -05:00
|
|
|
|
|
|
|
MxResult result = Start(&m_action2);
|
|
|
|
|
|
|
|
GetCurrentAction().SetAtomId(action.GetAtomId());
|
|
|
|
GetCurrentAction().SetObjectId(action.GetObjectId());
|
|
|
|
GetCurrentAction().SetUnknown24(action.GetUnknown24());
|
|
|
|
|
|
|
|
if (result == SUCCESS) {
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x13c = p_unk0x13c;
|
|
|
|
m_unk0x140 = p_unk0x140;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f470
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxBackgroundAudioManager::Stop()
|
|
|
|
{
|
|
|
|
if (m_action2.GetObjectId() != -1)
|
|
|
|
DeleteObject(m_action2);
|
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x138 = 0;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_action2.SetAtomId(MxAtomId());
|
|
|
|
m_action2.SetObjectId(-1);
|
|
|
|
|
|
|
|
if (m_action1.GetObjectId() != -1)
|
|
|
|
DeleteObject(m_action1);
|
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0xa0 = 0;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_action1.SetAtomId(MxAtomId());
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x148 = 0;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_action1.SetObjectId(-1);
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x13c = 0;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f570
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxBackgroundAudioManager::LowerVolume()
|
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x148 == 0) {
|
|
|
|
if (m_unk0x13c == 0) {
|
|
|
|
m_unk0x13c = 2;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x140 = 20;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x148++;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f5b0
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxBackgroundAudioManager::RaiseVolume()
|
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
if (m_unk0x148 != 0) {
|
|
|
|
m_unk0x148--;
|
|
|
|
if (m_unk0x148 == 0) {
|
|
|
|
if (m_unk0x13c == 0) {
|
|
|
|
m_unk0x13c = 2;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
m_unk0x140 = 10;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f5f0
|
2023-12-13 05:48:14 -05:00
|
|
|
void MxBackgroundAudioManager::Enable(MxBool p_enable)
|
2023-11-21 03:44:45 -05:00
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
if (this->m_musicEnabled != p_enable) {
|
|
|
|
this->m_musicEnabled = p_enable;
|
|
|
|
if (!p_enable) {
|
2023-11-21 03:44:45 -05:00
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1007f650
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxBackgroundAudioManager::Init()
|
|
|
|
{
|
2023-12-13 05:48:14 -05:00
|
|
|
this->m_unk0xa0 = 0;
|
|
|
|
this->m_unk0x13c = 0;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|