2023-06-29 04:10:08 -04:00
|
|
|
#include "mxpresenter.h"
|
2023-10-07 11:30:04 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
#include "decomp.h"
|
|
|
|
#include "define.h"
|
2023-12-26 17:42:29 -05:00
|
|
|
#include "legoobjectfactory.h"
|
2023-10-07 11:30:04 -04:00
|
|
|
#include "legoomni.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
#include "mxactionnotificationparam.h"
|
2023-09-04 18:33:38 -04:00
|
|
|
#include "mxautolocker.h"
|
2023-11-13 05:22:58 -05:00
|
|
|
#include "mxcompositepresenter.h"
|
2023-09-22 17:42:23 -04:00
|
|
|
#include "mxdsanim.h"
|
|
|
|
#include "mxdssound.h"
|
2023-12-26 17:42:29 -05:00
|
|
|
#include "mxentity.h"
|
2023-10-07 11:30:04 -04:00
|
|
|
#include "mxnotificationmanager.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
#include "mxparam.h"
|
2023-10-10 13:05:04 -04:00
|
|
|
#include "mxstreamer.h"
|
2023-07-02 03:00:28 -04:00
|
|
|
|
2023-10-07 11:30:04 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2023-07-02 03:00:28 -04:00
|
|
|
DECOMP_SIZE_ASSERT(MxPresenter, 0x40);
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000be30
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::VTable0x14()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000be40
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::ReadyTickle()
|
|
|
|
{
|
|
|
|
ParseExtra();
|
|
|
|
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Starting;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000be60
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::StartingTickle()
|
|
|
|
{
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Streaming;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000be80
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::StreamingTickle()
|
|
|
|
{
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Repeating;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bea0
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::RepeatingTickle()
|
|
|
|
{
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_unk5;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bec0
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::Unk5Tickle()
|
|
|
|
{
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Done;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bee0
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::DoneTickle()
|
|
|
|
{
|
|
|
|
m_previousTickleStates |= 1 << m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Idle;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bf00
|
2023-11-21 03:44:45 -05:00
|
|
|
MxPresenter::~MxPresenter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bf70
|
2023-11-21 03:44:45 -05:00
|
|
|
MxResult MxPresenter::AddToManager()
|
|
|
|
{
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bf80
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::Destroy()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bf90
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::SetTickleState(TickleState p_tickleState)
|
|
|
|
{
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = p_tickleState;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bfb0
|
2023-11-21 03:44:45 -05:00
|
|
|
MxBool MxPresenter::HasTickleStatePassed(TickleState p_tickleState)
|
|
|
|
{
|
|
|
|
return m_previousTickleStates & (1 << (unsigned char) p_tickleState);
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bfc0
|
2023-11-26 09:03:40 -05:00
|
|
|
MxResult MxPresenter::PutData()
|
2023-11-21 03:44:45 -05:00
|
|
|
{
|
2023-11-26 09:03:40 -05:00
|
|
|
return SUCCESS;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000bfd0
|
2023-11-21 03:44:45 -05:00
|
|
|
MxBool MxPresenter::IsHit(MxS32 p_x, MxS32 p_y)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b4d50
|
2023-06-29 04:10:08 -04:00
|
|
|
void MxPresenter::Init()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_currentTickleState = TickleState_Idle;
|
|
|
|
m_action = NULL;
|
|
|
|
m_location = MxPoint32(0, 0);
|
|
|
|
m_displayZ = 0;
|
2023-11-13 05:22:58 -05:00
|
|
|
m_compositePresenter = NULL;
|
2023-10-24 19:38:27 -04:00
|
|
|
m_previousTickleStates = 0;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b4d80
|
2023-11-21 03:44:45 -05:00
|
|
|
MxResult MxPresenter::StartAction(MxStreamController*, MxDSAction* p_action)
|
|
|
|
{
|
|
|
|
MxAutoLocker lock(&this->m_criticalSection);
|
|
|
|
|
|
|
|
this->m_action = p_action;
|
|
|
|
|
|
|
|
const Vector3Data& location = this->m_action->GetLocation();
|
|
|
|
MxS32 previousTickleState = this->m_currentTickleState;
|
|
|
|
|
|
|
|
this->m_location = MxPoint32(this->m_action->GetLocation()[0], this->m_action->GetLocation()[1]);
|
|
|
|
this->m_displayZ = this->m_action->GetLocation()[2];
|
|
|
|
this->m_previousTickleStates |= 1 << (unsigned char) previousTickleState;
|
|
|
|
this->m_currentTickleState = TickleState_Ready;
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b4e40
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxPresenter::EndAction()
|
|
|
|
{
|
2023-11-25 07:22:23 -05:00
|
|
|
if (this->m_action == NULL)
|
2023-11-21 03:44:45 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
MxAutoLocker lock(&this->m_criticalSection);
|
|
|
|
|
|
|
|
if (!this->m_compositePresenter) {
|
|
|
|
MxOmni::GetInstance()->NotifyCurrentEntity(
|
|
|
|
&MxEndActionNotificationParam(c_notificationEndAction, NULL, this->m_action, TRUE)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-25 07:22:23 -05:00
|
|
|
this->m_action = NULL;
|
2023-11-21 03:44:45 -05:00
|
|
|
MxS32 previousTickleState = 1 << m_currentTickleState;
|
|
|
|
this->m_previousTickleStates |= previousTickleState;
|
|
|
|
this->m_currentTickleState = TickleState_Idle;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b4fc0
|
2023-06-29 04:10:08 -04:00
|
|
|
void MxPresenter::ParseExtra()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
2023-10-25 16:51:59 -04:00
|
|
|
MxU16 len = m_action->GetExtraLength();
|
2023-10-24 19:38:27 -04:00
|
|
|
char* extraData = m_action->GetExtraData();
|
|
|
|
|
|
|
|
if (len) {
|
2023-10-25 16:51:59 -04:00
|
|
|
// len &= MAXWORD;
|
2023-10-24 19:38:27 -04:00
|
|
|
char extraCopy[512];
|
|
|
|
memcpy(extraCopy, extraData, len);
|
|
|
|
extraCopy[len] = '\0';
|
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
char worldValue[512];
|
|
|
|
if (KeyValueStringParse(worldValue, g_strWORLD, extraCopy)) {
|
|
|
|
char* token = strtok(worldValue, g_parseExtraTokens);
|
|
|
|
char buf[256];
|
|
|
|
strcpy(buf, token);
|
2023-10-24 19:38:27 -04:00
|
|
|
|
|
|
|
token = strtok(NULL, g_parseExtraTokens);
|
|
|
|
MxS32 val = token ? atoi(token) : 0;
|
2023-12-13 05:48:14 -05:00
|
|
|
MxEntity* result = MxOmni::GetInstance()->FindWorld(buf, val, this);
|
2023-10-24 19:38:27 -04:00
|
|
|
|
2023-11-13 05:22:58 -05:00
|
|
|
m_action->SetFlags(m_action->GetFlags() | MxDSAction::Flag_World);
|
2023-10-24 19:38:27 -04:00
|
|
|
|
|
|
|
if (result)
|
2023-11-13 05:22:58 -05:00
|
|
|
SendToCompositePresenter(MxOmni::GetInstance());
|
2023-10-24 19:38:27 -04:00
|
|
|
}
|
|
|
|
}
|
2023-09-13 03:44:03 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5120
|
2023-11-13 05:22:58 -05:00
|
|
|
void MxPresenter::SendToCompositePresenter(MxOmni* p_omni)
|
2023-09-13 03:44:03 -04:00
|
|
|
{
|
2023-11-13 05:22:58 -05:00
|
|
|
if (m_compositePresenter) {
|
2023-10-24 19:38:27 -04:00
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
2023-09-13 03:44:03 -04:00
|
|
|
|
2023-11-13 05:22:58 -05:00
|
|
|
NotificationManager()->Send(m_compositePresenter, &MxNotificationParam(MXPRESENTER_NOTIFICATION, this));
|
2023-09-13 03:44:03 -04:00
|
|
|
|
2023-12-11 16:35:50 -05:00
|
|
|
m_action->SetOrigin(p_omni ? p_omni : MxOmni::GetInstance());
|
2023-11-13 05:22:58 -05:00
|
|
|
m_compositePresenter = NULL;
|
2023-10-24 19:38:27 -04:00
|
|
|
}
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5200
|
2023-09-21 14:51:24 -04:00
|
|
|
MxResult MxPresenter::Tickle()
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxAutoLocker lock(&this->m_criticalSection);
|
|
|
|
|
|
|
|
switch (this->m_currentTickleState) {
|
|
|
|
case TickleState_Ready:
|
|
|
|
this->ReadyTickle();
|
|
|
|
|
|
|
|
if (m_currentTickleState != TickleState_Starting)
|
|
|
|
break;
|
|
|
|
case TickleState_Starting:
|
|
|
|
this->StartingTickle();
|
|
|
|
|
|
|
|
if (m_currentTickleState != TickleState_Streaming)
|
|
|
|
break;
|
|
|
|
case TickleState_Streaming:
|
|
|
|
this->StreamingTickle();
|
|
|
|
|
|
|
|
if (m_currentTickleState != TickleState_Repeating)
|
|
|
|
break;
|
|
|
|
case TickleState_Repeating:
|
|
|
|
this->RepeatingTickle();
|
|
|
|
|
|
|
|
if (m_currentTickleState != TickleState_unk5)
|
|
|
|
break;
|
|
|
|
case TickleState_unk5:
|
|
|
|
this->Unk5Tickle();
|
|
|
|
|
|
|
|
if (m_currentTickleState != TickleState_Done)
|
|
|
|
break;
|
|
|
|
case TickleState_Done:
|
|
|
|
this->DoneTickle();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b52d0
|
2023-09-04 18:33:38 -04:00
|
|
|
void MxPresenter::Enable(MxBool p_enable)
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (this->m_action && this->IsEnabled() != p_enable) {
|
|
|
|
MxU32 flags = this->m_action->GetFlags();
|
|
|
|
|
|
|
|
if (p_enable)
|
|
|
|
this->m_action->SetFlags(flags | MxDSAction::Flag_Enabled);
|
|
|
|
else
|
|
|
|
this->m_action->SetFlags(flags & ~MxDSAction::Flag_Enabled);
|
|
|
|
}
|
2023-09-04 18:33:38 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5310
|
2023-10-24 19:38:27 -04:00
|
|
|
const char* PresenterNameDispatch(const MxDSAction& p_action)
|
2023-09-22 17:42:23 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
const char* name = p_action.GetSourceName();
|
|
|
|
MxS32 format;
|
|
|
|
|
|
|
|
if (!name || strlen(name) == 0) {
|
|
|
|
switch (p_action.GetType()) {
|
|
|
|
case MxDSType_Anim:
|
|
|
|
format = ((MxDSAnim&) p_action).GetMediaFormat();
|
|
|
|
switch (format) {
|
|
|
|
case FOURCC(' ', 'F', 'L', 'C'):
|
|
|
|
name = !p_action.IsLooping() ? "MxFlcPresenter" : "MxLoopingFlcPresenter";
|
|
|
|
break;
|
|
|
|
case FOURCC(' ', 'S', 'M', 'K'):
|
|
|
|
name = !p_action.IsLooping() ? "MxSmkPresenter" : "MxLoopingSmkPresenter";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MxDSType_Sound:
|
|
|
|
format = ((MxDSSound&) p_action).GetMediaFormat();
|
|
|
|
switch (format) {
|
|
|
|
case FOURCC(' ', 'M', 'I', 'D'):
|
|
|
|
name = !p_action.IsLooping() ? "MxMIDIPresenter" : "MxLoopingMIDIPresenter";
|
|
|
|
break;
|
|
|
|
case FOURCC(' ', 'W', 'A', 'V'):
|
|
|
|
name = "MxWavePresenter";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MxDSType_SerialAction:
|
|
|
|
case MxDSType_ParallelAction:
|
|
|
|
case MxDSType_SelectAction:
|
|
|
|
name = "MxCompositePresenter";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MxDSType_Event:
|
|
|
|
name = "MxEventPresenter";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MxDSType_Still:
|
|
|
|
name = "MxStillPresenter";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
2023-09-22 17:42:23 -04:00
|
|
|
}
|
|
|
|
|
2023-12-26 17:42:29 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5410
|
|
|
|
MxEntity* MxPresenter::CreateEntityBackend(const char* p_name)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
char buffer2[512];
|
|
|
|
strcpy(buffer, p_name);
|
|
|
|
|
|
|
|
MxU16 extraLen = m_action->GetExtraLength();
|
|
|
|
|
|
|
|
buffer[0] = extraLen;
|
|
|
|
buffer[1] = extraLen >> 8;
|
|
|
|
if (extraLen) {
|
|
|
|
extraLen &= MAXWORD;
|
|
|
|
memcpy(buffer2 + 2, m_action->GetExtraData(), extraLen);
|
|
|
|
buffer2[extraLen + 2] = 0;
|
|
|
|
KeyValueStringParse(buffer, g_strOBJECT, buffer2 + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (MxEntity*) ObjectFactory()->Create(buffer);
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b54c0
|
2023-09-04 18:33:38 -04:00
|
|
|
MxBool MxPresenter::IsEnabled()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return this->m_action && this->m_action->GetFlags() & MxDSAction::Flag_Enabled;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|