Refactor LegoContainer

This commit is contained in:
Christian Semmler 2024-02-23 09:22:43 -05:00
parent 9d8820ee06
commit 3ffa5885f0
10 changed files with 232 additions and 211 deletions

View File

@ -156,6 +156,7 @@ target_include_directories(anim PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1/omni/include"
target_link_libraries(anim PRIVATE)
add_library(misc STATIC
LEGO1/lego/sources/misc/legocontainer.cpp
LEGO1/lego/sources/misc/legoimage.cpp
LEGO1/lego/sources/misc/legostorage.cpp
LEGO1/lego/sources/misc/legotexture.cpp
@ -293,12 +294,12 @@ add_library(lego1 SHARED
LEGO1/lego/legoomni/src/common/animstate.cpp
LEGO1/lego/legoomni/src/common/legoactioncontrolpresenter.cpp
LEGO1/lego/legoomni/src/common/legobackgroundcolor.cpp
LEGO1/lego/legoomni/src/common/legocontainer.cpp
LEGO1/lego/legoomni/src/common/legofullscreenmovie.cpp
LEGO1/lego/legoomni/src/common/legogamestate.cpp
LEGO1/lego/legoomni/src/common/legoobjectfactory.cpp
LEGO1/lego/legoomni/src/common/legoplantmanager.cpp
LEGO1/lego/legoomni/src/common/legostate.cpp
LEGO1/lego/legoomni/src/common/legotextureinfo.cpp
LEGO1/lego/legoomni/src/common/legounksavedatawriter.cpp
LEGO1/lego/legoomni/src/common/legoutil.cpp
LEGO1/lego/legoomni/src/common/legovariables.cpp

View File

@ -1,161 +0,0 @@
#ifndef LEGOTEXTURECONTAINER_H
#define LEGOTEXTURECONTAINER_H
#include "compat.h"
#include "decomp.h"
#include "mxstl/stlcompat.h"
#include "mxtypes.h"
#include <d3drmobj.h>
#include <ddraw.h>
#pragma warning(disable : 4237)
class LegoTexture;
// SIZE 0x10
struct TextureData {
public:
TextureData();
~TextureData();
static TextureData* Create(const char* p_name, LegoTexture* p_texture);
char* m_name; // 0x00
LPDIRECTDRAWSURFACE m_surface; // 0x04
LPDIRECTDRAWPALETTE m_palette; // 0x08
LPDIRECT3DRMTEXTURE2 m_texture; // 0x0c
};
struct LegoContainerInfoComparator {
bool operator()(const char* const& p_key0, const char* const& p_key1) const { return strcmp(p_key0, p_key1) > 0; }
};
// SIZE 0x10
template <class T>
class LegoContainerInfo : public map<const char*, T*, LegoContainerInfoComparator> {};
// SIZE 0x18
template <class T>
class LegoContainer {
public:
virtual ~LegoContainer()
{
#ifdef COMPAT_MODE
typename LegoContainerInfo<T>::iterator it;
#else
LegoContainerInfo<T>::iterator it;
#endif
for (it = m_map.begin(); it != m_map.end(); it++) {
// DECOMP: Use of const_cast here matches ~ViewLODListManager from 96 source.
const char* const& key = (*it).first;
delete[] const_cast<char*>(key);
if (m_ownership) {
delete (*it).second;
}
}
}
inline T* Get(const char* p_name)
{
#ifdef COMPAT_MODE
typename LegoContainerInfo<T>::iterator it = m_map.find(p_name);
#else
LegoContainerInfo<T>::iterator it = m_map.find(p_name);
#endif
if (it != m_map.end()) {
return (*it).second;
}
return NULL;
}
inline void SetOwnership(MxBool p_ownership) { m_ownership = p_ownership; }
protected:
MxBool m_ownership; // 0x04
LegoContainerInfo<T> m_map; // 0x08
};
// VTABLE: LEGO1 0x100d86d4
// class LegoContainer<TextureData>
typedef list<TextureData*> TextureList;
// VTABLE: LEGO1 0x100d86fc
// SIZE 0x24
class LegoTextureContainer : public LegoContainer<TextureData> {
public:
LegoTextureContainer() { m_ownership = TRUE; }
~LegoTextureContainer() override;
void FUN_10099cc0(TextureData* p_data);
protected:
TextureList m_list; // 0x18
};
// TEMPLATE: LEGO1 0x10059c50
// allocator<TextureData *>::_Charalloc
// clang-format off
// TEMPLATE: LEGO1 0x10001cc0
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Lbound
// TEMPLATE: LEGO1 0x1004f9b0
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Insert
// TEMPLATE: LEGO1 0x10059c70
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Color
// TEMPLATE: LEGO1 0x10059c80
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Left
// TEMPLATE: LEGO1 0x10059c90
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Parent
// TEMPLATE: LEGO1 0x10059ca0
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Right
// TEMPLATE: LEGO1 0x10059cb0
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::~_Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >
// TEMPLATE: LEGO1 0x10059d80
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::iterator::_Inc
// TEMPLATE: LEGO1 0x10059dc0
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::erase
// TEMPLATE: LEGO1 0x1005a210
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Erase
// TEMPLATE: LEGO1 0x1005a250
// list<TextureData *,allocator<TextureData *> >::~list<TextureData *,allocator<TextureData *> >
// TEMPLATE: LEGO1 0x1005a2c0
// map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::~map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >
// TEMPLATE: LEGO1 0x1005a310
// LegoContainer<TextureData>::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x1005a400
// LegoContainerInfo<TextureData>::~LegoContainerInfo<TextureData>
// TEMPLATE: LEGO1 0x1005a450
// Map<char const *,TextureData *,LegoContainerInfoComparator>::~Map<char const *,TextureData *,LegoContainerInfoComparator>
// SYNTHETIC: LEGO1 0x1005a580
// LegoTextureContainer::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x1005a5a0
// List<TextureData *>::~List<TextureData *>
// TEMPLATE: LEGO1 0x1005b660
// LegoContainer<TextureData>::~LegoContainer<TextureData>
// GLOBAL: LEGO1 0x100f0100
// _Tree<char const *,pair<char const * const,TextureData *>,map<char const *,TextureData *,LegoContainerInfoComparator,allocator<TextureData *> >::_Kfn,LegoContainerInfoComparator,allocator<TextureData *> >::_Nil
// clang-format on
#endif // LEGOTEXTURECONTAINER_H

View File

@ -275,7 +275,7 @@ ViewManager* GetViewManager();
LegoPlantManager* PlantManager();
LegoWorld* CurrentWorld();
LegoUnkSaveDataWriter* UnkSaveDataWriter();
LegoTextureContainer* GetTextureContainer();
LegoTextureContainer* TextureContainer();
void FUN_10015820(MxBool p_disable, MxU16 p_flags);
void SetROIUnknown0x0c(const char* p_name, undefined p_unk0x0c);
LegoWorld* FindWorld(const MxAtomId& p_atom, MxS32 p_entityid);

View File

@ -30,11 +30,12 @@ class LegoPhonemePresenter : public MxFlcPresenter {
private:
void Init();
int m_unk0x68;
int m_unk0x6c;
undefined m_unk0x70;
MxString m_string; // 0x74
undefined m_unk0x84;
undefined4 m_unk0x68; // 0x68
undefined4 m_unk0x6c; // 0x6c
undefined m_unk0x70; // 0x70
MxString m_string; // 0x74
undefined m_unk0x84; // 0x84
};
#endif // LEGOPHONEMEPRESENTER_H

View File

@ -0,0 +1,23 @@
#ifndef LEGOTEXTUREINFO_H
#define LEGOTEXTUREINFO_H
#include <d3drmobj.h>
#include <ddraw.h>
class LegoTexture;
// SIZE 0x10
struct LegoTextureInfo {
public:
LegoTextureInfo();
~LegoTextureInfo();
static LegoTextureInfo* Create(const char* p_name, LegoTexture* p_texture);
char* m_name; // 0x00
LPDIRECTDRAWSURFACE m_surface; // 0x04
LPDIRECTDRAWPALETTE m_palette; // 0x08
LPDIRECT3DRMTEXTURE2 m_texture; // 0x0c
};
#endif // LEGOTEXTUREINFO_H

View File

@ -1,4 +1,4 @@
#include "legocontainer.h"
#include "legotextureinfo.h"
#include "lego/sources/misc/legoimage.h"
#include "lego/sources/misc/legotexture.h"
@ -6,13 +6,10 @@
#include "legovideomanager.h"
#include "tgl/d3drm/impl.h"
DECOMP_SIZE_ASSERT(TextureData, 0x10);
DECOMP_SIZE_ASSERT(LegoContainerInfo<LegoTexture>, 0x10);
// DECOMP_SIZE_ASSERT(LegoContainer<LegoTexture>, 0x18);
DECOMP_SIZE_ASSERT(LegoTextureContainer, 0x24);
DECOMP_SIZE_ASSERT(LegoTextureInfo, 0x10);
// FUNCTION: LEGO1 0x10065bf0
TextureData::TextureData()
LegoTextureInfo::LegoTextureInfo()
{
m_name = NULL;
m_surface = NULL;
@ -21,7 +18,7 @@ TextureData::TextureData()
}
// FUNCTION: LEGO1 0x10065c00
TextureData::~TextureData()
LegoTextureInfo::~LegoTextureInfo()
{
if (m_name) {
delete[] m_name;
@ -45,9 +42,9 @@ TextureData::~TextureData()
}
// FUNCTION: LEGO1 0x10065c60
TextureData* TextureData::Create(const char* p_name, LegoTexture* p_texture)
LegoTextureInfo* LegoTextureInfo::Create(const char* p_name, LegoTexture* p_texture)
{
TextureData* texture = new TextureData();
LegoTextureInfo* texture = new LegoTextureInfo();
if (p_name == NULL || p_texture == NULL) {
return NULL;
@ -154,35 +151,3 @@ TextureData* TextureData::Create(const char* p_name, LegoTexture* p_texture)
return NULL;
}
// FUNCTION: LEGO1 0x10099870
LegoTextureContainer::~LegoTextureContainer()
{
}
// FUNCTION: LEGO1 0x10099cc0
void LegoTextureContainer::FUN_10099cc0(TextureData* p_data)
{
if (p_data == NULL) {
return;
}
#ifdef COMPAT_MODE
TextureList::iterator it;
for (it = m_list.begin(); it != m_list.end(); it++) {
#else
for (TextureList::iterator it = m_list.begin(); it != m_list.end(); it++) {
#endif
if (*it == p_data) {
// TODO: This is wrong, but what is at +0x0c on the iterator?
*it = NULL;
if (p_data->m_texture->Release() == TRUE) {
delete p_data;
m_list.erase(it);
}
return;
}
}
}

View File

@ -233,7 +233,7 @@ void Score::Enable(MxBool p_enable)
// FUNCTION: LEGO1 0x100019d0
void Score::Paint()
{
TextureData* gd = GetTextureContainer()->Get("bigcube.gif");
LegoTextureInfo* gd = TextureContainer()->Get("bigcube.gif");
if (gd) {
RaceState* l78 = (RaceState*) GameState()->GetState("JetskiRaceState");

View File

@ -215,7 +215,7 @@ LegoBuildingManager* BuildingManager()
}
// FUNCTION: LEGO1 0x10015800
LegoTextureContainer* GetTextureContainer()
LegoTextureContainer* TextureContainer()
{
return LegoOmni::GetInstance()->GetTextureContainer();
}

View File

@ -0,0 +1,43 @@
#include "legocontainer.h"
DECOMP_SIZE_ASSERT(LegoContainerInfo<LegoTexture>, 0x10);
// DECOMP_SIZE_ASSERT(LegoContainer<LegoTexture>, 0x18);
DECOMP_SIZE_ASSERT(LegoTextureContainer, 0x24);
// FUNCTION: LEGO1 0x10099870
LegoTextureContainer::~LegoTextureContainer()
{
}
// STUB: LEGO1 0x100998e0
LegoTextureInfo* LegoTextureContainer::Create(undefined* p_und)
{
return NULL;
}
// FUNCTION: LEGO1 0x10099cc0
void LegoTextureContainer::Destroy(LegoTextureInfo* p_data)
{
if (p_data == NULL) {
return;
}
#ifdef COMPAT_MODE
LegoTextureList::iterator it;
for (it = m_list.begin(); it != m_list.end(); it++) {
#else
for (LegoTextureList::iterator it = m_list.begin(); it != m_list.end(); it++) {
#endif
if (((*it).first) == p_data) {
// TODO: Element type
(*it).second = 0;
if (p_data->m_texture->Release() == TRUE) {
delete p_data;
m_list.erase(it);
}
return;
}
}
}

View File

@ -0,0 +1,149 @@
#ifndef LEGOCONTAINER_H
#define LEGOCONTAINER_H
#include "compat.h"
#include "decomp.h"
#include "legotexture.h"
#include "legotypes.h"
#include "mxstl/stlcompat.h"
// Note: dependency on LegoOmni
#include "lego/legoomni/include/legotextureinfo.h"
#pragma warning(disable : 4237)
struct LegoContainerInfoComparator {
bool operator()(const char* const& p_key0, const char* const& p_key1) const { return strcmp(p_key0, p_key1) > 0; }
};
// SIZE 0x10
template <class T>
class LegoContainerInfo : public map<const char*, T*, LegoContainerInfoComparator> {};
// SIZE 0x18
template <class T>
class LegoContainer {
public:
virtual ~LegoContainer()
{
#ifdef COMPAT_MODE
typename LegoContainerInfo<T>::iterator it;
#else
LegoContainerInfo<T>::iterator it;
#endif
for (it = m_map.begin(); it != m_map.end(); it++) {
// DECOMP: Use of const_cast here matches ~ViewLODListManager from 96 source.
const char* const& key = (*it).first;
delete[] const_cast<char*>(key);
if (m_ownership) {
delete (*it).second;
}
}
}
inline T* Get(const char* p_name)
{
#ifdef COMPAT_MODE
typename LegoContainerInfo<T>::iterator it = m_map.find(p_name);
#else
LegoContainerInfo<T>::iterator it = m_map.find(p_name);
#endif
if (it != m_map.end()) {
return (*it).second;
}
return NULL;
}
inline void SetOwnership(LegoBool p_ownership) { m_ownership = p_ownership; }
protected:
LegoBool m_ownership; // 0x04
LegoContainerInfo<T> m_map; // 0x08
};
// VTABLE: LEGO1 0x100d86d4
// class LegoContainer<LegoTextureInfo>
// TODO: Element type
typedef pair<LegoTextureInfo*, undefined4> LegoTextureListElement;
typedef list<LegoTextureListElement> LegoTextureList;
// VTABLE: LEGO1 0x100d86fc
// SIZE 0x24
class LegoTextureContainer : public LegoContainer<LegoTextureInfo> {
public:
LegoTextureContainer() { m_ownership = TRUE; }
~LegoTextureContainer() override;
LegoTextureInfo* Create(undefined* p_und);
void Destroy(LegoTextureInfo* p_data);
protected:
LegoTextureList m_list; // 0x18
};
// TEMPLATE: LEGO1 0x10059c50
// allocator<LegoTextureInfo *>::_Charalloc
// clang-format off
// TEMPLATE: LEGO1 0x10001cc0
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Lbound
// TEMPLATE: LEGO1 0x1004f9b0
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Insert
// TEMPLATE: LEGO1 0x10059c70
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Color
// TEMPLATE: LEGO1 0x10059c80
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Left
// TEMPLATE: LEGO1 0x10059c90
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Parent
// TEMPLATE: LEGO1 0x10059ca0
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Right
// TEMPLATE: LEGO1 0x10059cb0
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::~_Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >
// TEMPLATE: LEGO1 0x10059d80
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::iterator::_Inc
// TEMPLATE: LEGO1 0x10059dc0
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::erase
// TEMPLATE: LEGO1 0x1005a210
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Erase
// TEMPLATE: LEGO1 0x1005a250
// list<LegoTextureInfo *,allocator<LegoTextureInfo *> >::~list<LegoTextureInfo *,allocator<LegoTextureInfo *> >
// TEMPLATE: LEGO1 0x1005a2c0
// map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::~map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >
// TEMPLATE: LEGO1 0x1005a310
// LegoContainer<LegoTextureInfo>::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x1005a400
// LegoContainerInfo<LegoTextureInfo>::~LegoContainerInfo<LegoTextureInfo>
// TEMPLATE: LEGO1 0x1005a450
// Map<char const *,LegoTextureInfo *,LegoContainerInfoComparator>::~Map<char const *,LegoTextureInfo *,LegoContainerInfoComparator>
// SYNTHETIC: LEGO1 0x1005a580
// LegoTextureContainer::`scalar deleting destructor'
// TEMPLATE: LEGO1 0x1005a5a0
// List<LegoTextureInfo *>::~List<LegoTextureInfo *>
// TEMPLATE: LEGO1 0x1005b660
// LegoContainer<LegoTextureInfo>::~LegoContainer<LegoTextureInfo>
// GLOBAL: LEGO1 0x100f0100
// _Tree<char const *,pair<char const * const,LegoTextureInfo *>,map<char const *,LegoTextureInfo *,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Kfn,LegoContainerInfoComparator,allocator<LegoTextureInfo *> >::_Nil
// clang-format on
#endif // LEGOCONTAINER_H