isle-portable/LEGO1/omni/src/common/mxmediapresenter.cpp
Anonymous Maarten e4690a57b8
Some checks are pending
CI / clang-format (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain /usr/local/vitasdk/share/vita.toolchain.cmake, false, false, Ninja, Vita, ubuntu-latest, true, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0, false, false, Visual Studio 17 2022, true, Xbox One, windows-latest, amd64, false, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake, false, devkitpro/devkitarm:latest, false, Ninja, true, Nintendo 3DS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake, false, devkitpro/devkita64:latest, false, Ninja, Nintendo Switch, true, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, emcmake, false, false, true, Ninja, Emscripten, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, false, Ninja, true, MSVC (arm64), windows-latest, amd64_arm64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, true, Ninja, true, MSVC (x86), windows-latest, amd64_x86, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, false, Ninja, true, MSVC (x64), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, true, false, Ninja, true, MSVC (x64 Debug), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, -DCMAKE_SYSTEM_NAME=iOS, false, false, Xcode, true, iOS, macos-15, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, Ninja, true, mingw-w64-i686, mingw32, msys2 mingw32, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, false, Ninja, Android, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, true, false, Ninja, macOS, macos-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, false, Ninja, true, mingw-w64-x86_64, mingw64, msys2 mingw64, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux (Debug), ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux, ubuntu-latest, true) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (x86_64, ubuntu-latest) (push) Waiting to run
CI / C++ (push) Waiting to run
CI / Release (push) Blocked by required conditions
Docker / Publish web port (push) Waiting to run
Plug leaks until Information Center, detected by the LeakSanitizer (#764)
2026-01-04 03:35:42 +01:00

282 lines
5.9 KiB
C++

#include "mxmediapresenter.h"
#include "mxactionnotificationparam.h"
#include "mxautolock.h"
#include "mxcompositepresenter.h"
#include "mxdssubscriber.h"
#include "mxmisc.h"
#include "mxnotificationmanager.h"
#include "mxstreamchunk.h"
#include "mxtimer.h"
DECOMP_SIZE_ASSERT(MxMediaPresenter, 0x50);
DECOMP_SIZE_ASSERT(MxStreamChunkList, 0x18);
DECOMP_SIZE_ASSERT(MxStreamChunkListCursor, 0x10);
// FUNCTION: LEGO1 0x100b54e0
void MxMediaPresenter::Init()
{
if (this->m_loopingChunks) {
delete m_loopingChunks;
}
if (this->m_loopingChunkCursor) {
delete this->m_loopingChunkCursor;
}
this->m_subscriber = NULL;
this->m_loopingChunks = NULL;
this->m_loopingChunkCursor = NULL;
this->m_currentChunk = NULL;
}
// FUNCTION: LEGO1 0x100b54f0
void MxMediaPresenter::Destroy(MxBool p_fromDestructor)
{
{
AUTOLOCK(m_criticalSection);
if (m_currentChunk && m_subscriber) {
m_subscriber->FreeDataChunk(m_currentChunk);
}
if (m_subscriber) {
delete m_subscriber;
}
if (m_loopingChunkCursor) {
delete m_loopingChunkCursor;
m_loopingChunkCursor = NULL;
}
if (m_loopingChunks) {
MxStreamChunkListCursor cursor(m_loopingChunks);
MxStreamChunk* chunk;
while (cursor.Next(chunk)) {
chunk->Release();
}
delete m_loopingChunks;
m_loopingChunks = NULL;
}
Init();
}
if (!p_fromDestructor) {
MxPresenter::Destroy();
}
}
// FUNCTION: LEGO1 0x100b5650
MxStreamChunk* MxMediaPresenter::CurrentChunk()
{
MxStreamChunk* chunk = NULL;
if (m_subscriber) {
chunk = m_subscriber->PeekData();
if (chunk && chunk->GetChunkFlags() & DS_CHUNK_BIT3) {
m_action->SetFlags(m_action->GetFlags() | MxDSAction::c_bit7);
m_subscriber->PopData();
m_subscriber->FreeDataChunk(chunk);
chunk = NULL;
ProgressTickleState(e_done);
}
}
return chunk;
}
// FUNCTION: LEGO1 0x100b56b0
MxStreamChunk* MxMediaPresenter::NextChunk()
{
MxStreamChunk* chunk = NULL;
if (m_subscriber) {
chunk = m_subscriber->PopData();
if (chunk && chunk->GetChunkFlags() & DS_CHUNK_BIT3) {
m_action->SetFlags(m_action->GetFlags() | MxDSAction::c_bit7);
m_subscriber->FreeDataChunk(chunk);
chunk = NULL;
ProgressTickleState(e_done);
}
}
return chunk;
}
// FUNCTION: LEGO1 0x100b5700
MxResult MxMediaPresenter::StartAction(MxStreamController* p_controller, MxDSAction* p_action)
{
MxResult result = FAILURE;
AUTOLOCK(m_criticalSection);
if (MxPresenter::StartAction(p_controller, p_action) == SUCCESS) {
if (m_action->GetFlags() & MxDSAction::c_looping) {
if (m_loopingChunks) {
delete m_loopingChunks;
}
if (m_loopingChunkCursor) {
delete m_loopingChunkCursor;
}
m_loopingChunks = new MxStreamChunkList;
m_loopingChunkCursor = new MxStreamChunkListCursor(m_loopingChunks);
if (!m_loopingChunks && !m_loopingChunkCursor) {
goto done;
}
}
if (p_controller) {
m_subscriber = new MxDSSubscriber;
if (!m_subscriber ||
m_subscriber->Create(p_controller, p_action->GetObjectId(), p_action->GetUnknown24()) != SUCCESS) {
goto done;
}
}
result = SUCCESS;
}
done:
return result;
}
// FUNCTION: LEGO1 0x100b5bc0
// STUB: BETA10 0x1013623c
void MxMediaPresenter::EndAction()
{
AUTOLOCK(m_criticalSection);
if (!m_action) {
return;
}
m_currentChunk = NULL;
if (m_action->GetFlags() & MxDSAction::c_world && (!m_compositePresenter || !m_compositePresenter->VTable0x64(2))) {
MxPresenter::Enable(FALSE);
SetTickleState(e_idle);
}
else {
MxDSAction* action = m_action;
MxPresenter::EndAction();
if (m_subscriber) {
delete m_subscriber;
m_subscriber = NULL;
}
if (action && action->GetOrigin()) {
NotificationManager()->Send(
action->GetOrigin(),
MxEndActionNotificationParam(c_notificationEndAction, this, action, FALSE)
);
}
}
}
// FUNCTION: LEGO1 0x100b5d10
MxResult MxMediaPresenter::Tickle()
{
AUTOLOCK(m_criticalSection);
CurrentChunk();
return MxPresenter::Tickle();
}
// FUNCTION: LEGO1 0x100b5d90
void MxMediaPresenter::StreamingTickle()
{
if (!m_currentChunk) {
m_currentChunk = NextChunk();
if (m_currentChunk) {
if (m_currentChunk->GetChunkFlags() & DS_CHUNK_END_OF_STREAM) {
m_subscriber->FreeDataChunk(m_currentChunk);
m_currentChunk = NULL;
ProgressTickleState(e_repeating);
}
else if (m_action->GetFlags() & MxDSAction::c_looping) {
LoopChunk(m_currentChunk);
if (!IsEnabled()) {
m_subscriber->FreeDataChunk(m_currentChunk);
m_currentChunk = NULL;
}
}
}
}
}
// FUNCTION: LEGO1 0x100b5e10
void MxMediaPresenter::RepeatingTickle()
{
if (IsEnabled() && !m_currentChunk) {
if (m_loopingChunkCursor) {
if (!m_loopingChunkCursor->Next(m_currentChunk)) {
m_loopingChunkCursor->Next(m_currentChunk);
}
}
if (m_currentChunk) {
MxLong time = m_currentChunk->GetTime();
if (time <= m_action->GetElapsedTime() % m_action->GetLoopCount()) {
ProgressTickleState(e_freezing);
}
}
else {
if (m_action->GetElapsedTime() >= m_action->GetStartTime() + m_action->GetDuration()) {
ProgressTickleState(e_freezing);
}
}
}
}
// FUNCTION: LEGO1 0x100b5ef0
void MxMediaPresenter::DoneTickle()
{
ProgressTickleState(e_idle);
EndAction();
}
// FUNCTION: LEGO1 0x100b5f10
// FUNCTION: BETA10 0x101366e9
void MxMediaPresenter::LoopChunk(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_loopingChunks->Append(chunk);
}
// FUNCTION: LEGO1 0x100b6030
// FUNCTION: BETA10 0x10136814
void MxMediaPresenter::Enable(MxBool p_enable)
{
if (IsEnabled() != p_enable) {
MxPresenter::Enable(p_enable);
if (p_enable) {
MxLong time = Timer()->GetTime();
m_action->SetTimeStarted(time);
SetTickleState(e_repeating);
}
else {
if (m_loopingChunkCursor) {
m_loopingChunkCursor->Reset();
}
m_currentChunk = NULL;
SetTickleState(e_done);
}
}
}