isle-portable/LEGO1/mxstreamer.cpp
MattKC 574a9dc6f1
Implement some MxStreamer functions (#130)
* Implement some MxStreamer stuff

* Implement/match MxVideoManager::Tickle (#128)

* Implement/match MxPresenter::StartAction

* Update mxpoint32.h

* Implement/match MxVideoManager::Tickle

* Update mxlist.h

* Update mxpresenter.cpp

* MxFlcPresenter ctor/dtor (#132)

* MxFlcPresenter ctor/dtor

* Match constructor

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>

* LegoOmni::CreateStreamObject and related (#129)

* LegoOmni::CreateStreamObject and related

* Revert change to MxDSSource/MxDSFile Read export

* Bootstrap MxDSMultiAction (#133)

* Bootstrap MxDSMultiAction

* Move destroy function to list class

* Fix unk14 call

* Quick patch for EqualsDataProduct (#134)

* MxLong Tickle() -> MxResult Tickle() (#135)

* MxLong Tickle() -> MxResult Tickle()

* Remove garbage

* Fix implementations

* PresenterNameDispatch (#137)

* PresenterNameDispatch

* Use reference for PresenterNameDispatch param
- fix or add const markers so we can use a const reference

* Implement/match remaining MxDSMultiAction functions (#136)

* Implement/match MxDSMultiAction::Deserialize

* Implement remaining functions of MxDSMultiAction

* Remove space

* Implement/match MxDSParallelAction (#138)

* Implement/match MxDSParallelAction

* Fix type

* Remove space

* Add neccessary MxDSMultiAction functions

* Implement/match MxDSSerialAction (#139)

* Implement/match MxDSSerialAction

* Add neccessary MxDSMultiAction functions

* Fix LegoOmni vtable (#140)

* matched GetOpenStream

* matched MakeSourceName

* add MxDSBuffer stub

* add MxRAMStreamController stub

* add stubbed functions for MxStreamController used by MxStreamer

* implement AddStreamControllerToOpenList

* implement most of MxStreamer::Open

* add note for MxStreamerSubclass1

* fix compiler issue

* implement MxStreamer::Notify

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
Co-authored-by: Joshua Peisach <itzswirlz2020@outlook.com>
Co-authored-by: MS <disinvite@users.noreply.github.com>
2023-09-25 19:30:56 -07:00

166 lines
3.4 KiB
C++

#include "mxstreamer.h"
#include <algorithm>
#include "legoomni.h"
#include "mxdiskstreamcontroller.h"
#include "mxramstreamcontroller.h"
DECOMP_SIZE_ASSERT(MxStreamer, 0x2c);
#define MXSTREAMER_DELETE_NOTIFY 6
// OFFSET: LEGO1 0x100b8f00
MxStreamer::MxStreamer()
{
NotificationManager()->Register(this);
}
// OFFSET: LEGO1 0x100b9190
MxResult MxStreamer::Init()
{
undefined *b = new undefined[m_subclass1.GetSize() * 0x5800];
m_subclass1.SetBuffer(b);
if (b) {
b = new undefined[m_subclass2.GetSize() * 0x800];
m_subclass2.SetBuffer(b);
if (b) {
return SUCCESS;
}
}
return FAILURE;
}
// OFFSET: LEGO1 0x100b91d0
MxStreamer::~MxStreamer()
{
while (!m_openStreams.empty()) {
MxStreamController *c = m_openStreams.front();
m_openStreams.pop_front();
delete c;
}
NotificationManager()->Unregister(this);
}
// OFFSET: LEGO1 0x100b92c0
MxStreamController *MxStreamer::Open(const char *p_name, MxU16 p_lookupType)
{
// TODO
MxStreamController *stream = NULL;
if (!GetOpenStream(p_name)) {
switch (p_lookupType) {
case e_DiskStream:
stream = new MxDiskStreamController();
break;
case e_RAMStream:
stream = new MxRAMStreamController();
break;
}
if (!stream
|| stream->Open(p_name) != SUCCESS
|| AddStreamControllerToOpenList(stream) != SUCCESS) {
delete stream;
stream = NULL;
}
}
return stream;
}
// OFFSET: LEGO1 0x100b9570
MxLong MxStreamer::Close(const char *p)
{
MxDSAction ds;
ds.SetUnknown24(-2);
for (list<MxStreamController *>::iterator it = m_openStreams.begin(); it != m_openStreams.end(); it++) {
MxStreamController *c = *it;
if (!p || !strcmp(p, c->atom.GetInternal())) {
m_openStreams.erase(it);
if (!c->FUN_100c20d0(ds)) {
MxStreamerNotification notif(MXSTREAMER_DELETE_NOTIFY, NULL, c);
NotificationManager()->Send(this, &notif);
} else {
delete c;
}
return SUCCESS;
}
}
return FAILURE;
}
// OFFSET: LEGO1 0x100b9700
MxParam *MxStreamerNotification::Clone()
{
return new MxStreamerNotification(m_type, m_sender, m_controller);
}
// OFFSET: LEGO1 0x100b9870
MxStreamController *MxStreamer::GetOpenStream(const char *p_name)
{
for (list<MxStreamController *>::iterator it = m_openStreams.begin(); it != m_openStreams.end(); it++) {
MxStreamController *c = *it;
MxAtomId &atom = c->atom;
if (p_name) {
if (!strcmp(atom.GetInternal(), p_name)) {
return *it;
}
}
}
return NULL;
}
// OFFSET: LEGO1 0x100b9930
MxResult MxStreamer::AddStreamControllerToOpenList(MxStreamController *stream)
{
if (find(m_openStreams.begin(), m_openStreams.end(), stream) == m_openStreams.end()) {
m_openStreams.push_back(stream);
return SUCCESS;
}
return FAILURE;
}
// OFFSET: LEGO1 0x100b9b60
MxLong MxStreamer::Notify(MxParam &p)
{
if (p.GetType() == MXSTREAMER_DELETE_NOTIFY) {
MxDSAction ds;
ds.SetUnknown24(-2);
MxStreamController *c = static_cast<MxStreamerNotification&>(p).GetController();
if (!c->FUN_100c20d0(ds)) {
MxStreamerNotification notif(MXSTREAMER_DELETE_NOTIFY, NULL, c);
NotificationManager()->Send(this, &notif);
} else {
delete c;
}
}
return 0;
}
// No offset, function is always inlined
MxStreamerSubClass1::MxStreamerSubClass1(undefined4 size)
{
m_buffer = NULL;
m_size = size;
undefined4 *ptr = &m_unk08;
for (int i = 0; i >= 0; i--) {
ptr[i] = 0;
}
}