Implement/Match JukeboxEntity (#562)

* Implement/Match JukeboxEntity

* Style/naming

* Style/naming

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
Nathan M Gilbert
2024-02-14 11:48:39 -05:00
committed by GitHub
parent 1b696e4bd8
commit 271df035fd
8 changed files with 149 additions and 21 deletions

View File

@@ -21,7 +21,7 @@ MxBackgroundAudioManager::MxBackgroundAudioManager()
m_unk0x140 = 0;
m_targetVolume = 0;
m_unk0x148 = 0;
m_musicEnabled = FALSE;
m_enabled = FALSE;
}
// FUNCTION: LEGO1 0x1007ec20
@@ -39,7 +39,7 @@ MxResult MxBackgroundAudioManager::Create(MxAtomId& p_script, MxU32 p_frequencyM
if (result == SUCCESS) {
TickleManager()->RegisterClient(this, p_frequencyMS);
m_musicEnabled = TRUE;
m_enabled = TRUE;
}
return result;
@@ -71,7 +71,7 @@ void MxBackgroundAudioManager::DestroyMusic()
ds.SetUnknown24(-2);
DeleteObject(ds);
Streamer()->Close(m_script.GetInternal());
m_musicEnabled = FALSE;
m_enabled = FALSE;
}
}
@@ -237,9 +237,10 @@ void MxBackgroundAudioManager::StopAction(MxParam& p_param)
// FUNCTION: LEGO1 0x1007f2f0
MxResult MxBackgroundAudioManager::PlayMusic(MxDSAction& p_action, undefined4 p_unk0x140, undefined4 p_unk0x13c)
{
if (!m_musicEnabled) {
if (!m_enabled) {
return SUCCESS;
}
if (m_action2.GetObjectId() == -1 && m_action1.GetObjectId() != p_action.GetObjectId()) {
MxDSAction action;
action.SetAtomId(GetCurrentAction().GetAtomId());
@@ -261,8 +262,10 @@ MxResult MxBackgroundAudioManager::PlayMusic(MxDSAction& p_action, undefined4 p_
m_unk0x13c = p_unk0x13c;
m_unk0x140 = p_unk0x140;
}
return result;
}
return FAILURE;
}
@@ -317,8 +320,9 @@ void MxBackgroundAudioManager::RaiseVolume()
// FUNCTION: LEGO1 0x1007f5f0
void MxBackgroundAudioManager::Enable(MxBool p_enable)
{
if (this->m_musicEnabled != p_enable) {
this->m_musicEnabled = p_enable;
if (this->m_enabled != p_enable) {
this->m_enabled = p_enable;
if (!p_enable) {
Stop();
}

View File

@@ -1,20 +1,125 @@
#include "jukeboxentity.h"
// STUB: LEGO1 0x10085bc0
#include "isle.h"
#include "islepathactor.h"
#include "jukeboxstate.h"
#include "legogamestate.h"
#include "legoutil.h"
#include "mxbackgroundaudiomanager.h"
#include "mxnotificationmanager.h"
#include "mxtransitionmanager.h"
// FUNCTION: LEGO1 0x10085bc0
JukeBoxEntity::JukeBoxEntity()
{
// TODO
NotificationManager()->Register(this);
}
// STUB: LEGO1 0x10085dd0
// FUNCTION: LEGO1 0x10085dd0
JukeBoxEntity::~JukeBoxEntity()
{
// TODO
NotificationManager()->Unregister(this);
}
// STUB: LEGO1 0x10085e40
// FUNCTION: LEGO1 0x10085e40
MxLong JukeBoxEntity::Notify(MxParam& p_param)
{
// TODO
if (((MxNotificationParam&) p_param).GetType() == c_notificationType11) {
if (!FUN_1003ef60()) {
return 1;
}
if (CurrentVehicle()->VTable0x60() != GameState()->GetUnknownC()) {
CurrentVehicle()->VTable0xe4();
}
((Isle*) FindWorld(*g_isleScript, 0))->SetUnknown13c(0x35);
TransitionManager()->StartTransition(MxTransitionManager::e_pixelation, 50, FALSE, FALSE);
return 1;
}
return 0;
}
// FUNCTION: LEGO1 0x10085ed0
void JukeBoxEntity::StartAction()
{
MxDSAction action;
BackgroundAudioManager()->Stop();
JukeBoxState* state = (JukeBoxState*) GameState()->GetState("JukeBoxState");
state->SetActive(TRUE);
switch (state->GetState()) {
case 0:
InvokeAction(Extra::e_start, *g_isleScript, 0x319, NULL);
GameState()->SetUnknown0x41c(0x37);
break;
case 1:
InvokeAction(Extra::e_start, *g_isleScript, 0x31e, NULL);
GameState()->SetUnknown0x41c(0x38);
break;
case 2:
InvokeAction(Extra::e_start, *g_isleScript, 0x31b, NULL);
GameState()->SetUnknown0x41c(0x39);
break;
case 3:
InvokeAction(Extra::e_start, *g_isleScript, 0x31a, NULL);
GameState()->SetUnknown0x41c(0x3a);
break;
case 4:
InvokeAction(Extra::e_start, *g_isleScript, 0x31f, NULL);
GameState()->SetUnknown0x41c(0x3b);
break;
case 5:
InvokeAction(Extra::e_start, *g_isleScript, 0x31c, NULL);
GameState()->SetUnknown0x41c(0x3c);
break;
}
action.SetAtomId(*g_jukeboxScript);
action.SetObjectId(GameState()->GetUnknown0x41c());
m_audioEnabled = BackgroundAudioManager()->GetEnabled();
if (!m_audioEnabled) {
BackgroundAudioManager()->Enable(TRUE);
}
BackgroundAudioManager()->PlayMusic(action, 5, 4);
}
// FUNCTION: LEGO1 0x100860f0
void JukeBoxEntity::StopAction(MxU32 p_state)
{
JukeBoxState* state = (JukeBoxState*) GameState()->GetState("JukeBoxState");
if (state && state->IsActive()) {
switch (p_state) {
case 0x37:
state->SetActive(FALSE);
InvokeAction(Extra::e_stop, *g_isleScript, 0x319, NULL);
break;
case 0x38:
state->SetActive(FALSE);
InvokeAction(Extra::e_stop, *g_isleScript, 0x31e, NULL);
break;
case 0x39:
state->SetActive(FALSE);
InvokeAction(Extra::e_stop, *g_isleScript, 0x31b, NULL);
break;
case 0x3a:
state->SetActive(FALSE);
InvokeAction(Extra::e_stop, *g_isleScript, 0x31a, NULL);
break;
case 0x3b:
state->SetActive(FALSE);
InvokeAction(Extra::e_stop, *g_isleScript, 0x31f, NULL);
break;
case 0x3c:
state->SetActive(FALSE);
InvokeAction(Extra::e_stop, *g_isleScript, 0x31c, NULL);
break;
}
BackgroundAudioManager()->Enable(IsBackgroundAudioEnabled());
}
}

View File

@@ -61,8 +61,8 @@ void Radio::Play()
action.SetAtomId(*g_jukeboxScript);
action.SetLoopCount(1);
m_bgAudioPreviouslyEnabled = BackgroundAudioManager()->GetMusicEnabled();
if (!m_bgAudioPreviouslyEnabled) {
m_audioEnabled = BackgroundAudioManager()->GetEnabled();
if (!m_audioEnabled) {
BackgroundAudioManager()->Enable(TRUE);
}
@@ -84,7 +84,7 @@ void Radio::Stop()
}
BackgroundAudioManager()->Stop();
BackgroundAudioManager()->Enable(m_bgAudioPreviouslyEnabled);
BackgroundAudioManager()->Enable(m_audioEnabled);
m_state->SetActive(FALSE);
}
}