2023-06-29 04:10:08 -04:00
|
|
|
#include "mxmediapresenter.h"
|
|
|
|
|
2023-11-13 05:22:58 -05:00
|
|
|
#include "mxactionnotificationparam.h"
|
2023-11-12 07:47:01 -05:00
|
|
|
#include "mxautolocker.h"
|
2023-11-13 05:22:58 -05:00
|
|
|
#include "mxcompositepresenter.h"
|
|
|
|
#include "mxnotificationmanager.h"
|
2023-11-12 07:47:01 -05:00
|
|
|
#include "mxstreamchunk.h"
|
2023-11-13 06:25:27 -05:00
|
|
|
#include "mxtimer.h"
|
2023-11-12 07:47:01 -05:00
|
|
|
|
2023-07-02 03:00:28 -04:00
|
|
|
DECOMP_SIZE_ASSERT(MxMediaPresenter, 0x50);
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000c550
|
2023-10-08 09:46:09 -04:00
|
|
|
MxMediaPresenter::~MxMediaPresenter()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
Destroy(TRUE);
|
2023-10-08 09:46:09 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1000c5b0
|
2023-11-12 07:47:01 -05:00
|
|
|
void MxMediaPresenter::Destroy()
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-11-12 07:47:01 -05:00
|
|
|
Destroy(FALSE);
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-07 14:14:49 -05:00
|
|
|
// TODO: These probably belong in another class
|
|
|
|
// SYNTHETIC: LEGO1 0x100b46e0
|
|
|
|
// MxStreamChunkListCursor::`scalar deleting destructor'
|
|
|
|
|
|
|
|
// TEMPLATE: LEGO1 0x100b4750
|
|
|
|
// MxListCursor<MxStreamChunk *>::~MxListCursor<MxStreamChunk *>
|
|
|
|
|
|
|
|
// SYNTHETIC: LEGO1 0x100b47a0
|
|
|
|
// MxListCursor<MxStreamChunk *>::`scalar deleting destructor'
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x100b4810
|
|
|
|
// MxStreamChunkListCursor::~MxStreamChunkListCursor
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b54e0
|
2023-06-29 04:10:08 -04:00
|
|
|
void MxMediaPresenter::Init()
|
|
|
|
{
|
2023-11-12 07:47:01 -05:00
|
|
|
this->m_subscriber = NULL;
|
|
|
|
this->m_chunks = NULL;
|
|
|
|
this->m_cursor = NULL;
|
|
|
|
this->m_currentChunk = NULL;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
2023-10-05 06:31:20 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b54f0
|
2023-10-13 12:43:45 -04:00
|
|
|
void MxMediaPresenter::Destroy(MxBool p_fromDestructor)
|
2023-11-12 07:47:01 -05:00
|
|
|
{
|
|
|
|
{
|
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
|
|
|
|
|
|
|
if (m_currentChunk && m_subscriber)
|
|
|
|
m_subscriber->FUN_100b8390(m_currentChunk);
|
|
|
|
|
|
|
|
if (m_subscriber)
|
|
|
|
delete m_subscriber;
|
|
|
|
|
|
|
|
if (m_cursor)
|
|
|
|
delete m_cursor;
|
|
|
|
|
|
|
|
if (m_chunks) {
|
|
|
|
MxStreamChunkListCursor cursor(m_chunks);
|
|
|
|
MxStreamChunk* chunk;
|
|
|
|
|
|
|
|
while (cursor.Next(chunk))
|
2023-11-13 06:25:27 -05:00
|
|
|
chunk->Release();
|
2023-11-12 07:47:01 -05:00
|
|
|
|
|
|
|
delete m_chunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_fromDestructor)
|
|
|
|
MxPresenter::Destroy();
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5650
|
2023-11-13 06:25:27 -05:00
|
|
|
MxStreamChunk* MxMediaPresenter::FUN_100b5650()
|
|
|
|
{
|
|
|
|
MxStreamChunk* result = NULL;
|
|
|
|
|
|
|
|
if (m_subscriber) {
|
|
|
|
result = m_subscriber->FUN_100b8360();
|
|
|
|
|
|
|
|
if (result && result->GetFlags() & MxDSChunk::Flag_Bit3) {
|
|
|
|
m_action->SetFlags(m_action->GetFlags() | MxDSAction::Flag_Bit7);
|
|
|
|
m_subscriber->FUN_100b8250();
|
|
|
|
m_subscriber->FUN_100b8390(result);
|
|
|
|
result = NULL;
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b56b0
|
2023-11-13 06:25:27 -05:00
|
|
|
MxStreamChunk* MxMediaPresenter::NextChunk()
|
|
|
|
{
|
|
|
|
MxStreamChunk* result = NULL;
|
|
|
|
|
|
|
|
if (m_subscriber) {
|
|
|
|
result = m_subscriber->FUN_100b8250();
|
|
|
|
|
|
|
|
if (result && result->GetFlags() & MxDSChunk::Flag_Bit3) {
|
|
|
|
m_action->SetFlags(m_action->GetFlags() | MxDSAction::Flag_Bit7);
|
|
|
|
m_subscriber->FUN_100b8390(result);
|
|
|
|
result = NULL;
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5700
|
2023-11-21 03:44:45 -05:00
|
|
|
MxResult MxMediaPresenter::StartAction(MxStreamController* p_controller, MxDSAction* p_action)
|
|
|
|
{
|
|
|
|
MxResult result = FAILURE;
|
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
|
|
|
|
|
|
|
if (MxPresenter::StartAction(p_controller, p_action) == SUCCESS) {
|
|
|
|
if (m_action->GetFlags() & MxDSAction::Flag_Looping) {
|
|
|
|
m_chunks = new MxStreamChunkList;
|
|
|
|
m_cursor = new MxStreamChunkListCursor(m_chunks);
|
|
|
|
|
|
|
|
if (!m_chunks && !m_cursor)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_controller) {
|
|
|
|
m_subscriber = new MxDSSubscriber;
|
|
|
|
|
|
|
|
if (!m_subscriber ||
|
|
|
|
m_subscriber->FUN_100b7ed0(p_controller, p_action->GetObjectId(), p_action->GetUnknown24()) != SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5bc0
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxMediaPresenter::EndAction()
|
|
|
|
{
|
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
|
|
|
|
|
|
|
if (!m_action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentChunk = NULL;
|
|
|
|
|
|
|
|
if (m_action->GetFlags() & MxDSAction::Flag_World &&
|
|
|
|
(!m_compositePresenter || !m_compositePresenter->VTable0x64(2))) {
|
|
|
|
MxPresenter::Enable(FALSE);
|
|
|
|
SetTickleState(TickleState_Idle);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MxDSAction* action = m_action;
|
|
|
|
MxPresenter::EndAction();
|
|
|
|
|
|
|
|
if (m_subscriber) {
|
|
|
|
delete m_subscriber;
|
|
|
|
m_subscriber = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action && action->GetUnknown8c()) {
|
|
|
|
NotificationManager()->Send(
|
|
|
|
action->GetUnknown8c(),
|
|
|
|
&MxEndActionNotificationParam(c_notificationEndAction, this, action, FALSE)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5d10
|
2023-11-12 07:47:01 -05:00
|
|
|
MxResult MxMediaPresenter::Tickle()
|
2023-10-08 09:46:09 -04:00
|
|
|
{
|
2023-11-13 06:25:27 -05:00
|
|
|
MxAutoLocker lock(&m_criticalSection);
|
|
|
|
|
|
|
|
FUN_100b5650();
|
|
|
|
|
|
|
|
return MxPresenter::Tickle();
|
2023-10-08 09:46:09 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5d90
|
2023-10-08 09:46:09 -04:00
|
|
|
void MxMediaPresenter::StreamingTickle()
|
|
|
|
{
|
2023-11-13 06:25:27 -05:00
|
|
|
if (!m_currentChunk) {
|
|
|
|
m_currentChunk = NextChunk();
|
|
|
|
|
|
|
|
if (m_currentChunk) {
|
|
|
|
if (m_currentChunk->GetFlags() & MxDSChunk::Flag_Bit2) {
|
|
|
|
m_subscriber->FUN_100b8390(m_currentChunk);
|
|
|
|
m_currentChunk = NULL;
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Repeating;
|
|
|
|
}
|
|
|
|
else if (m_action->GetFlags() & MxDSAction::Flag_Looping) {
|
|
|
|
AppendChunk(m_currentChunk);
|
|
|
|
|
2023-11-14 15:25:14 -05:00
|
|
|
if (!IsEnabled()) {
|
2023-11-13 06:25:27 -05:00
|
|
|
m_subscriber->FUN_100b8390(m_currentChunk);
|
|
|
|
m_currentChunk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 09:46:09 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5e10
|
2023-10-08 09:46:09 -04:00
|
|
|
void MxMediaPresenter::RepeatingTickle()
|
|
|
|
{
|
2023-11-14 15:25:14 -05:00
|
|
|
if (IsEnabled() && !m_currentChunk) {
|
2023-11-13 06:25:27 -05:00
|
|
|
if (m_cursor)
|
|
|
|
if (!m_cursor->Next(m_currentChunk))
|
|
|
|
m_cursor->Next(m_currentChunk);
|
|
|
|
|
|
|
|
if (m_currentChunk) {
|
|
|
|
MxLong time = m_currentChunk->GetTime();
|
|
|
|
if (time <= m_action->GetElapsedTime() % m_action->GetLoopCount()) {
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_unk5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (m_action->GetElapsedTime() <= m_action->GetStartTime() + m_action->GetDuration()) {
|
|
|
|
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_unk5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 09:46:09 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5ef0
|
2023-10-08 09:46:09 -04:00
|
|
|
void MxMediaPresenter::DoneTickle()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_previousTickleStates |= 1 << m_currentTickleState;
|
|
|
|
m_currentTickleState = TickleState_Idle;
|
|
|
|
EndAction();
|
2023-10-08 09:46:09 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b5f10
|
2023-11-21 03:44:45 -05:00
|
|
|
void MxMediaPresenter::AppendChunk(MxStreamChunk* p_chunk)
|
|
|
|
{
|
|
|
|
MxStreamChunk* chunk = new MxStreamChunk;
|
|
|
|
|
|
|
|
MxU32 length = p_chunk->GetLength();
|
|
|
|
chunk->SetLength(length);
|
|
|
|
chunk->SetData(new MxU8[length]);
|
|
|
|
chunk->SetTime(p_chunk->GetTime());
|
|
|
|
|
|
|
|
memcpy(chunk->GetData(), p_chunk->GetData(), chunk->GetLength());
|
|
|
|
m_chunks->Append(chunk);
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100b6030
|
2023-10-08 09:46:09 -04:00
|
|
|
void MxMediaPresenter::Enable(MxBool p_enable)
|
|
|
|
{
|
2023-11-14 15:25:14 -05:00
|
|
|
if (IsEnabled() != p_enable) {
|
2023-11-13 06:25:27 -05:00
|
|
|
MxPresenter::Enable(p_enable);
|
|
|
|
|
|
|
|
if (p_enable) {
|
|
|
|
MxLong time = Timer()->GetTime();
|
|
|
|
m_action->SetUnkTimingField(time);
|
|
|
|
SetTickleState(TickleState_Repeating);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (m_cursor)
|
|
|
|
m_cursor->Reset();
|
|
|
|
m_currentChunk = NULL;
|
|
|
|
SetTickleState(TickleState_Done);
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 09:46:09 -04:00
|
|
|
}
|