Refactor MxPtrList to use p_ownership (#344)

* Refactor MxPtrList to use p_ownership

* Remove class names
This commit is contained in:
Christian Semmler 2023-12-20 20:09:05 -05:00 committed by GitHub
parent db60467ba3
commit afadca953b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 148 additions and 217 deletions

View file

@ -84,7 +84,6 @@ add_library(lego1 SHARED
LEGO1/legopartpresenter.cpp
LEGO1/legopathactor.cpp
LEGO1/legopathcontroller.cpp
LEGO1/legopathcontrollerlist.cpp
LEGO1/legopathpresenter.cpp
LEGO1/legophonemepresenter.cpp
LEGO1/legoplantmanager.cpp
@ -99,7 +98,6 @@ add_library(lego1 SHARED
LEGO1/legovehiclebuildstate.cpp
LEGO1/legovideomanager.cpp
LEGO1/legoworld.cpp
LEGO1/legoworldlist.cpp
LEGO1/legoworldpresenter.cpp
LEGO1/motorcycle.cpp
LEGO1/mxactionnotificationparam.cpp
@ -121,7 +119,6 @@ add_library(lego1 SHARED
LEGO1/mxdiskstreamprovider.cpp
LEGO1/mxdisplaysurface.cpp
LEGO1/mxdsaction.cpp
LEGO1/mxdsactionlist.cpp
LEGO1/mxdsanim.cpp
LEGO1/mxdsbuffer.cpp
LEGO1/mxdschunk.cpp
@ -161,11 +158,9 @@ add_library(lego1 SHARED
LEGO1/mxpalette.cpp
LEGO1/mxparam.cpp
LEGO1/mxpresenter.cpp
LEGO1/mxpresenterlist.cpp
LEGO1/mxramstreamcontroller.cpp
LEGO1/mxramstreamprovider.cpp
LEGO1/mxregion.cpp
LEGO1/mxregionlist.cpp
LEGO1/mxscheduler.cpp
LEGO1/mxsemaphore.cpp
LEGO1/mxsmack.cpp
@ -174,13 +169,11 @@ add_library(lego1 SHARED
LEGO1/mxsoundpresenter.cpp
LEGO1/mxstillpresenter.cpp
LEGO1/mxstreamchunk.cpp
LEGO1/mxstreamchunklist.cpp
LEGO1/mxstreamcontroller.cpp
LEGO1/mxstreamer.cpp
LEGO1/mxstreamlist.cpp
LEGO1/mxstreamprovider.cpp
LEGO1/mxstring.cpp
LEGO1/mxstringlist.cpp
LEGO1/mxthread.cpp
LEGO1/mxticklemanager.cpp
LEGO1/mxtimer.cpp

View file

@ -22,6 +22,8 @@
#include "mxticklemanager.h"
#include "mxtransitionmanager.h"
DECOMP_SIZE_ASSERT(LegoWorldList, 0x18);
// GLOBAL: LEGO1 0x100f451c
MxAtomId* g_copterScript = NULL;
@ -527,7 +529,7 @@ MxResult LegoOmni::Create(MxOmniCreateParam& p_param)
m_animationManager = new LegoAnimationManager();
m_buildingManager = new LegoBuildingManager();
m_gameState = new LegoGameState();
m_worldList = new LegoWorldList();
m_worldList = new LegoWorldList(TRUE);
if (m_unk0x6c && m_gifManager && m_worldList && m_plantManager && m_animationManager && m_buildingManager) {
// TODO: initialize a bunch of MxVariables

View file

@ -1,18 +0,0 @@
#include "legopathcontrollerlist.h"
#include "decomp.h"
#include "legopathcontroller.h"
DECOMP_SIZE_ASSERT(LegoPathControllerList, 0x18);
// FUNCTION: LEGO1 0x1001d210
MxS8 LegoPathControllerList::Compare(LegoPathController* p_a, LegoPathController* p_b)
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}
// FUNCTION: LEGO1 0x1001d3c0
void LegoPathControllerList::Destroy(LegoPathController* p_controller)
{
delete p_controller;
}

View file

@ -12,9 +12,13 @@
// SIZE 0x18
class LegoPathControllerList : public MxPtrList<LegoPathController> {
public:
LegoPathControllerList() : MxPtrList<LegoPathController>(Destroy) {}
virtual MxS8 Compare(LegoPathController*, LegoPathController*) override; // vtable+0x14
static void Destroy(LegoPathController*);
LegoPathControllerList(MxBool p_ownership = FALSE) : MxPtrList<LegoPathController>(p_ownership) {}
// FUNCTION: LEGO1 0x1001d210
virtual MxS8 Compare(LegoPathController* p_a, LegoPathController* p_b) override
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
} // vtable+0x14
};
// VTABLE: LEGO1 0x100d6380
@ -38,6 +42,9 @@ class LegoPathControllerList : public MxPtrList<LegoPathController> {
// TEMPLATE: LEGO1 0x1001d330
// MxList<LegoPathController *>::~MxList<LegoPathController *>
// TEMPLATE: LEGO1 0x1001d3c0
// MxPtrList<LegoPathController>::Destroy
// SYNTHETIC: LEGO1 0x1001d490
// MxCollection<LegoPathController *>::`scalar deleting destructor'

View file

@ -10,7 +10,7 @@
DECOMP_SIZE_ASSERT(LegoWorld, 0xf8);
// STUB: LEGO1 0x1001ca40
LegoWorld::LegoWorld()
LegoWorld::LegoWorld() : m_list0x68(TRUE)
{
// TODO
}

View file

@ -1,15 +0,0 @@
#include "legoworldlist.h"
#include "legoworld.h"
// FUNCTION: LEGO1 0x100598d0
MxS8 LegoWorldList::Compare(LegoWorld* p_a, LegoWorld* p_b)
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}
// FUNCTION: LEGO1 0x100599f0
void LegoWorldList::Destroy(LegoWorld* p_world)
{
delete p_world;
}

View file

@ -19,9 +19,13 @@ class LegoWorld;
// SIZE 0x18
class LegoWorldList : public MxPtrList<LegoWorld> {
public:
LegoWorldList() : MxPtrList<LegoWorld>(Destroy) {}
virtual MxS8 Compare(LegoWorld*, LegoWorld*) override; // vtable+0x14
static void Destroy(LegoWorld*);
LegoWorldList(MxBool p_ownership = FALSE) : MxPtrList<LegoWorld>(p_ownership) {}
// FUNCTION: LEGO1 0x100598d0
virtual MxS8 Compare(LegoWorld* p_a, LegoWorld* p_b) override
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}; // vtable+0x14
};
// TEMPLATE: LEGO1 0x100598f0
@ -36,6 +40,9 @@ class LegoWorldList : public MxPtrList<LegoWorld> {
// TEMPLATE: LEGO1 0x10059960
// MxList<LegoWorld *>::~MxList<LegoWorld *>
// TEMPLATE: LEGO1 0x100599f0
// MxPtrList<LegoWorld>::Destroy
// SYNTHETIC: LEGO1 0x10059ac0
// MxCollection<LegoWorld *>::`scalar deleting destructor'

View file

@ -9,12 +9,14 @@ class MxCollection : public MxCore {
MxCollection()
{
m_count = 0;
m_customDestructor = Destroy;
SetDestroy(Destroy);
}
virtual ~MxCollection() {}
static void Destroy(T){};
void SetDestroy(void (*p_customDestructor)(T)) { this->m_customDestructor = p_customDestructor; }
virtual ~MxCollection() {}
virtual MxS8 Compare(T, T) { return 0; }
protected:

View file

@ -1,19 +0,0 @@
#include "mxdsactionlist.h"
#include "mxdsaction.h"
DECOMP_SIZE_ASSERT(MxDSActionList, 0x1c);
DECOMP_SIZE_ASSERT(MxDSActionListCursor, 0x10);
// FUNCTION: LEGO1 0x100c9c90
MxS8 MxDSActionList::Compare(MxDSAction* p_a, MxDSAction* p_b)
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}
// FUNCTION: LEGO1 0x100c9cb0
void MxDSActionList::Destroy(MxDSAction* p_action)
{
if (p_action)
delete p_action;
}

View file

@ -18,9 +18,14 @@ class MxDSActionList : public MxList<MxDSAction*> {
public:
MxDSActionList() { this->m_unk0x18 = 0; }
virtual MxS8 Compare(MxDSAction*, MxDSAction*) override; // vtable+0x14
// FUNCTION: LEGO1 0x100c9c90
virtual MxS8 Compare(MxDSAction* p_a, MxDSAction* p_b) override
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
} // vtable+0x14
static void Destroy(MxDSAction* p_action);
// FUNCTION: LEGO1 0x100c9cb0
static void Destroy(MxDSAction* p_action) { delete p_action; }
private:
undefined m_unk0x18;

View file

@ -1,6 +1,8 @@
#include "mxdsmultiaction.h"
DECOMP_SIZE_ASSERT(MxDSMultiAction, 0x9c)
DECOMP_SIZE_ASSERT(MxDSActionList, 0x1c);
DECOMP_SIZE_ASSERT(MxDSActionListCursor, 0x10);
// FUNCTION: LEGO1 0x100c9b90
MxDSMultiAction::MxDSMultiAction()

View file

@ -5,6 +5,7 @@
#include "mxvariabletable.h"
DECOMP_SIZE_ASSERT(MxDSSelectAction, 0xb0)
DECOMP_SIZE_ASSERT(MxListEntry<MxString>, 0x18)
// FUNCTION: LEGO1 0x100cb2b0
MxDSSelectAction::MxDSSelectAction()

View file

@ -10,12 +10,6 @@ class MxList;
template <class T>
class MxListCursor;
template <class T>
class MxPtrList : public MxList<T*> {
public:
MxPtrList(void (*p_destroy)(T*) = Destroy) { m_customDestructor = p_destroy; }
};
template <class T>
class MxListEntry {
public:
@ -62,9 +56,9 @@ class MxList : protected MxCollection<T> {
void Append(T p_obj) { InsertEntry(p_obj, this->m_last, NULL); };
void DeleteAll(MxBool p_destroy = TRUE);
MxU32 GetCount() { return this->m_count; }
void SetDestroy(void (*p_customDestructor)(T)) { this->m_customDestructor = p_customDestructor; }
friend class MxListCursor<T>;
using MxCollection<T>::SetDestroy;
protected:
MxListEntry<T>* m_first; // 0x10
@ -74,6 +68,16 @@ class MxList : protected MxCollection<T> {
MxListEntry<T>* InsertEntry(T, MxListEntry<T>*, MxListEntry<T>*);
};
template <class T>
class MxPtrList : public MxList<T*> {
public:
MxPtrList(MxBool p_ownership) { SetOwnership(p_ownership); }
static void Destroy(T* p_obj) { delete p_obj; };
void SetOwnership(MxBool p_ownership) { SetDestroy(p_ownership ? Destroy : MxCollection<T*>::Destroy); }
};
template <class T>
class MxListCursor : public MxCore {
public:

View file

@ -7,6 +7,8 @@
#include "mxticklemanager.h"
DECOMP_SIZE_ASSERT(MxMediaManager, 0x2c);
DECOMP_SIZE_ASSERT(MxPresenterList, 0x18);
DECOMP_SIZE_ASSERT(MxPresenterListCursor, 0x10);
// FUNCTION: LEGO1 0x100b84c0
MxMediaManager::MxMediaManager()

View file

@ -8,6 +8,8 @@
#include "mxtimer.h"
DECOMP_SIZE_ASSERT(MxMediaPresenter, 0x50);
DECOMP_SIZE_ASSERT(MxStreamChunkList, 0x18);
DECOMP_SIZE_ASSERT(MxStreamChunkListCursor, 0x10);
// FUNCTION: LEGO1 0x1000c550
MxMediaPresenter::~MxMediaPresenter()

View file

@ -10,7 +10,6 @@
class MxCompositePresenter;
class MxStreamController;
class MxPresenter;
// VTABLE: LEGO1 0x100d4d38
// SIZE 0x40

View file

@ -1,12 +0,0 @@
#include "mxpresenterlist.h"
#include "mxpresenter.h"
DECOMP_SIZE_ASSERT(MxPresenterList, 0x18);
DECOMP_SIZE_ASSERT(MxPresenterListCursor, 0x10);
// FUNCTION: LEGO1 0x1001cd00
MxS8 MxPresenterList::Compare(MxPresenter* p_a, MxPresenter* p_b)
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}

View file

@ -2,8 +2,7 @@
#define MXPRESENTERLIST_H
#include "mxlist.h"
class MxPresenter;
#include "mxpresenter.h"
// VTABLE: LEGO1 0x100d62f0
// class MxPtrList<MxPresenter>
@ -12,7 +11,13 @@ class MxPresenter;
// SIZE 0x18
class MxPresenterList : public MxPtrList<MxPresenter> {
public:
virtual MxS8 Compare(MxPresenter*, MxPresenter*) override; // vtable+0x14
MxPresenterList(MxBool p_ownership = FALSE) : MxPtrList<MxPresenter>(p_ownership) {}
// FUNCTION: LEGO1 0x1001cd00
virtual MxS8 Compare(MxPresenter* p_a, MxPresenter* p_b) override
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}; // vtable+0x14
};
// VTABLE: LEGO1 0x100d6488

View file

@ -6,50 +6,6 @@
#include "mxrect32.h"
#include "mxregionlist.h"
// SIZE 0x0c
struct MxRegionTopBottom {
MxRegionTopBottom(MxRect32& p_rect);
MxRegionTopBottom(MxS32 p_top, MxS32 p_bottom);
MxRegionTopBottom* Clone();
void FUN_100c5280(MxS32 p_left, MxS32 p_right);
MxBool FUN_100c57b0(MxRect32& p_rect);
inline MxS32 GetTop() { return m_top; }
inline MxS32 GetBottom() { return m_bottom; }
inline void SetTop(MxS32 p_top) { m_top = p_top; }
inline void SetBottom(MxS32 p_bottom) { m_bottom = p_bottom; }
friend class MxRegionList;
private:
MxS32 m_top;
MxS32 m_bottom;
MxRegionLeftRightList* m_leftRightList;
};
// SIZE 0x08
struct MxRegionLeftRight {
MxRegionLeftRight(MxS32 p_left, MxS32 p_right)
{
m_left = p_left;
m_right = p_right;
}
MxRegionLeftRight* Clone() { return new MxRegionLeftRight(m_left, m_right); }
inline MxS32 GetLeft() { return m_left; }
inline MxS32 GetRight() { return m_right; }
inline void SetLeft(MxS32 p_left) { m_left = p_left; }
inline void SetRight(MxS32 p_right) { m_right = p_right; }
private:
MxS32 m_left;
MxS32 m_right;
};
// VTABLE: LEGO1 0x100dcae8
// SIZE 0x1c
class MxRegion : public MxCore {

View file

@ -1,19 +0,0 @@
#include "mxregionlist.h"
#include "mxregion.h"
// FUNCTION: LEGO1 0x100c33e0
void MxRegionList::Destroy(MxRegionTopBottom* p_topBottom)
{
if (p_topBottom) {
if (p_topBottom->m_leftRightList)
delete p_topBottom->m_leftRightList;
delete p_topBottom;
}
}
// FUNCTION: LEGO1 0x100c4e80
void MxRegionLeftRightList::Destroy(MxRegionLeftRight* p_leftRight)
{
delete p_leftRight;
}

View file

@ -3,8 +3,78 @@
#include "mxlist.h"
struct MxRegionTopBottom;
struct MxRegionLeftRight;
// SIZE 0x08
struct MxRegionLeftRight {
MxRegionLeftRight(MxS32 p_left, MxS32 p_right)
{
m_left = p_left;
m_right = p_right;
}
MxRegionLeftRight* Clone() { return new MxRegionLeftRight(m_left, m_right); }
inline MxS32 GetLeft() { return m_left; }
inline MxS32 GetRight() { return m_right; }
inline void SetLeft(MxS32 p_left) { m_left = p_left; }
inline void SetRight(MxS32 p_right) { m_right = p_right; }
private:
MxS32 m_left;
MxS32 m_right;
};
// VTABLE: LEGO1 0x100dcc40
// class MxCollection<MxRegionLeftRight *>
// VTABLE: LEGO1 0x100dcc58
// class MxList<MxRegionLeftRight *>
// VTABLE: LEGO1 0x100dcc70
// class MxPtrList<MxRegionLeftRight>
// VTABLE: LEGO1 0x100dcc88
// SIZE 0x18
class MxRegionLeftRightList : public MxPtrList<MxRegionLeftRight> {
public:
MxRegionLeftRightList() : MxPtrList<MxRegionLeftRight>(TRUE) {}
};
// VTABLE: LEGO1 0x100dcbf8
// class MxPtrListCursor<MxRegionLeftRight>
// VTABLE: LEGO1 0x100dcc28
// class MxListCursor<MxRegionLeftRight *>
// VTABLE: LEGO1 0x100dcc10
class MxRegionLeftRightListCursor : public MxPtrListCursor<MxRegionLeftRight> {
public:
MxRegionLeftRightListCursor(MxRegionLeftRightList* p_list) : MxPtrListCursor<MxRegionLeftRight>(p_list){};
};
// SIZE 0x0c
struct MxRegionTopBottom {
MxRegionTopBottom(MxRect32& p_rect);
MxRegionTopBottom(MxS32 p_top, MxS32 p_bottom);
~MxRegionTopBottom() { delete m_leftRightList; }
MxRegionTopBottom* Clone();
void FUN_100c5280(MxS32 p_left, MxS32 p_right);
MxBool FUN_100c57b0(MxRect32& p_rect);
inline MxS32 GetTop() { return m_top; }
inline MxS32 GetBottom() { return m_bottom; }
inline void SetTop(MxS32 p_top) { m_top = p_top; }
inline void SetBottom(MxS32 p_bottom) { m_bottom = p_bottom; }
friend class MxRegionList;
private:
MxS32 m_top;
MxS32 m_bottom;
MxRegionLeftRightList* m_leftRightList;
};
// VTABLE: LEGO1 0x100dcb10
// class MxCollection<MxRegionTopBottom *>
@ -19,8 +89,7 @@ struct MxRegionLeftRight;
// SIZE 0x18
class MxRegionList : public MxPtrList<MxRegionTopBottom> {
public:
MxRegionList() : MxPtrList<MxRegionTopBottom>(Destroy) {}
static void Destroy(MxRegionTopBottom*);
MxRegionList() : MxPtrList<MxRegionTopBottom>(TRUE) {}
};
// VTABLE: LEGO1 0x100dcb70
@ -39,41 +108,15 @@ class MxRegionListCursor : public MxPtrListCursor<MxRegionTopBottom> {
MxRegionListCursor(MxPtrList<MxRegionTopBottom>* p_list) : MxPtrListCursor<MxRegionTopBottom>(p_list){};
};
// VTABLE: LEGO1 0x100dcc40
// class MxCollection<MxRegionLeftRight *>
// VTABLE: LEGO1 0x100dcc58
// class MxList<MxRegionLeftRight *>
// VTABLE: LEGO1 0x100dcc70
// class MxPtrList<MxRegionLeftRight>
// VTABLE: LEGO1 0x100dcc88
// SIZE 0x18
class MxRegionLeftRightList : public MxPtrList<MxRegionLeftRight> {
public:
MxRegionLeftRightList() : MxPtrList<MxRegionLeftRight>(Destroy) {}
static void Destroy(MxRegionLeftRight*);
};
// VTABLE: LEGO1 0x100dcbf8
// class MxPtrListCursor<MxRegionLeftRight>
// VTABLE: LEGO1 0x100dcc28
// class MxListCursor<MxRegionLeftRight *>
// VTABLE: LEGO1 0x100dcc10
class MxRegionLeftRightListCursor : public MxPtrListCursor<MxRegionLeftRight> {
public:
MxRegionLeftRightListCursor(MxRegionLeftRightList* p_list) : MxPtrListCursor<MxRegionLeftRight>(p_list){};
};
// TEMPLATE: LEGO1 0x100c32e0
// MxCollection<MxRegionTopBottom *>::Compare
// TEMPLATE: LEGO1 0x100c3340
// MxCollection<MxRegionTopBottom *>::Destroy
// TEMPLATE: LEGO1 0x100c33e0
// MxPtrList<MxRegionTopBottom>::Destroy
// SYNTHETIC: LEGO1 0x100c34d0
// MxCollection<MxRegionTopBottom *>::`scalar deleting destructor'
@ -125,6 +168,9 @@ class MxRegionLeftRightListCursor : public MxPtrListCursor<MxRegionLeftRight> {
// SYNTHETIC: LEGO1 0x100c4f50
// MxCollection<MxRegionLeftRight *>::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x100c4e80
// MxPtrList<MxRegionLeftRight>::Destroy
// SYNTHETIC: LEGO1 0x100c4fc0
// MxList<MxRegionLeftRight *>::`scalar deleting destructor'

View file

@ -1,19 +0,0 @@
#include "mxstreamchunklist.h"
#include "mxstreamchunk.h"
DECOMP_SIZE_ASSERT(MxStreamChunkList, 0x18);
DECOMP_SIZE_ASSERT(MxStreamChunkListCursor, 0x10);
// FUNCTION: LEGO1 0x100b5900
MxS8 MxStreamChunkList::Compare(MxStreamChunk* p_a, MxStreamChunk* p_b)
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
}
// FUNCTION: LEGO1 0x100b5920
void MxStreamChunkList::Destroy(MxStreamChunk* p_chunk)
{
if (p_chunk)
delete p_chunk;
}

View file

@ -18,9 +18,14 @@ class MxStreamChunkList : public MxList<MxStreamChunk*> {
public:
MxStreamChunkList() { m_customDestructor = Destroy; }
virtual MxS8 Compare(MxStreamChunk*, MxStreamChunk*) override; // vtable+0x14
// FUNCTION: LEGO1 0x100b5900
virtual MxS8 Compare(MxStreamChunk* p_a, MxStreamChunk* p_b) override
{
return p_a == p_b ? 0 : p_a < p_b ? -1 : 1;
} // vtable+0x14
static void Destroy(MxStreamChunk* p_chunk);
// FUNCTION: LEGO1 0x100b5920
static void Destroy(MxStreamChunk* p_chunk) { delete p_chunk; }
};
// VTABLE: LEGO1 0x100dc510

View file

@ -1,5 +0,0 @@
#include "mxstringlist.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(MxListEntry<MxString>, 0x18)