Finish MxBackgroundAudioManager (#263)

* MxBackgroundAudioManager additional functions

* fix code style

* MxBackgroundAudioManager::PlayMusic

* match MxBackgroundAudioManager::Notify

* MxBackgroundAudioManager::Notify

* rename functions

* Fixes

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
Misha
2023-11-05 10:07:28 -05:00
committed by GitHub
parent 22ac0b9296
commit 4c4dce1302
13 changed files with 272 additions and 18 deletions

View File

@@ -1,6 +1,10 @@
#include "mxbackgroundaudiomanager.h"
#include "legoomni.h"
#include "mxcompositepresenter.h"
#include "mxdssound.h"
#include "mxomni.h"
#include "mxpresenter.h"
#include "mxstreamer.h"
#include "mxticklemanager.h"
@@ -14,7 +18,7 @@ MxBackgroundAudioManager::MxBackgroundAudioManager()
m_unk138 = 0;
m_unk13c = 0;
m_unk140 = 0;
m_unk144 = 0;
m_targetVolume = 0;
m_unk148 = 0;
m_musicEnabled = FALSE;
}
@@ -47,6 +51,32 @@ void MxBackgroundAudioManager::Stop()
m_unk13c = 0;
}
// OFFSET: LEGO1 0x1007f570
void MxBackgroundAudioManager::LowerVolume()
{
if (m_unk148 == 0) {
if (m_unk13c == 0) {
m_unk13c = 2;
}
m_unk140 = 20;
}
m_unk148++;
}
// OFFSET: LEGO1 0x1007f5b0
void MxBackgroundAudioManager::RaiseVolume()
{
if (m_unk148 != 0) {
m_unk148--;
if (m_unk148 == 0) {
if (m_unk13c == 0) {
m_unk13c = 2;
}
m_unk140 = 10;
}
}
}
// OFFSET: LEGO1 0x1007f5f0
void MxBackgroundAudioManager::Enable(MxBool p)
{
@@ -106,3 +136,191 @@ void MxBackgroundAudioManager::DestroyMusic()
m_musicEnabled = FALSE;
}
}
// OFFSET: LEGO1 0x1007f170
MxLong MxBackgroundAudioManager::Notify(MxParam& p)
{
switch (((MxNotificationParam&) p).GetNotification()) {
case c_notificationStartAction:
StartAction(p);
return 1;
case c_notificationEndAction:
StopAction(p);
return 1;
}
return 0;
}
// OFFSET: LEGO1 0x1007f1b0
void MxBackgroundAudioManager::StartAction(MxParam& p)
{
// TODO: the sender is most likely a MxAudioPresenter?
m_unk138 = (MxAudioPresenter*) ((MxNotificationParam&) p).GetSender();
m_action2.SetAtomId(m_unk138->GetAction()->GetAtomId());
m_action2.SetObjectId(m_unk138->GetAction()->GetObjectId());
m_targetVolume = ((MxDSSound*) (m_unk138->GetAction()))->GetVolume();
m_unk138->vtable60(0);
}
// OFFSET: LEGO1 0x1007f200
void MxBackgroundAudioManager::StopAction(MxParam& p)
{
if (((MxNotificationParam&) p).GetSender() == m_unka0) {
m_unka0 = NULL;
m_action1.SetAtomId(MxAtomId());
m_action1.SetObjectId(-1);
}
else if (((MxNotificationParam&) p).GetSender() == m_unk138) {
m_unk138 = NULL;
m_action2.SetAtomId(MxAtomId());
m_action2.SetObjectId(-1);
}
Lego()->HandleNotificationType2(p);
}
// OFFSET: LEGO1 0x1007f2f0
MxResult MxBackgroundAudioManager::PlayMusic(MxDSAction& p_action, undefined4 p_unknown, undefined4 p_unknown2)
{
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);
m_action2.SetUnknown8c(this);
MxResult result = Start(&m_action2);
GetCurrentAction().SetAtomId(action.GetAtomId());
GetCurrentAction().SetObjectId(action.GetObjectId());
GetCurrentAction().SetUnknown24(action.GetUnknown24());
if (result == SUCCESS) {
m_unk13c = p_unknown2;
m_unk140 = p_unknown;
}
return result;
}
return FAILURE;
}
// OFFSET: LEGO1 0x1007ee40
MxResult MxBackgroundAudioManager::Tickle()
{
switch (m_unk13c) {
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;
}
}
// OFFSET: LEGO1 0x1007ee70
void MxBackgroundAudioManager::FUN_1007ee70()
{
if (m_unka0 && m_unka0->GetAction()) {
DeleteObject(*m_unk138->GetAction());
}
if (m_unk138) {
m_unka0 = m_unk138;
m_action1 = m_action2;
m_unk138 = NULL;
m_action2.SetObjectId(-1);
m_action2.SetAtomId(MxAtomId());
m_unk13c = NULL;
}
}
// OFFSET: LEGO1 0x1007ef40
void MxBackgroundAudioManager::FUN_1007ef40()
{
MxU32 compare;
MxU32 volume;
if (m_unka0 == NULL) {
if (m_unk138) {
compare = 30;
if (m_unk148 == 0) {
compare = m_unk148;
}
volume = m_unk138->vtable5c();
if (volume < compare) {
if (m_unk140 + m_unk138->vtable5c() <= compare) {
compare = m_unk140 + compare;
}
m_unk138->vtable60(compare);
}
else {
m_unk138->vtable60(compare);
m_unka0 = m_unk138;
m_action1 = m_action2;
m_unk138 = NULL;
m_action2.SetObjectId(-1);
m_action2.SetAtomId(MxAtomId());
m_unk13c = NULL;
}
}
}
else if (m_unka0->GetAction() != NULL) {
if (m_unka0->vtable5c() == 0) {
DeleteObject(*m_unka0->GetAction());
}
else {
compare = m_unka0->vtable5c();
volume = 0;
if (compare != m_unk140 && -1 < compare - m_unk140) {
volume = m_unka0->vtable5c() - m_unk140;
}
m_unk138->vtable60(volume);
}
}
}
// OFFSET: LEGO1 0x1007f0e0
void MxBackgroundAudioManager::FadeInOrFadeOut()
{
// This function probably is the fade in/out routine
if (m_unka0 != NULL) {
undefined4 volume = m_unka0->vtable5c();
MxU32 compare = 30;
if (m_unk148 == 0) {
compare = m_targetVolume;
}
if (volume < compare) {
volume = m_unk140 + volume;
if (compare <= volume) {
volume = compare;
}
m_unka0->vtable60(volume);
}
else if (compare < volume) {
volume = volume - m_unk140;
if (volume <= compare) {
volume = compare;
}
m_unka0->vtable60(volume);
}
else {
m_unka0->vtable60(volume);
m_unk13c = 0;
}
}
else {
m_unk13c = 0;
}
}