CBaseModelInfo

This commit is contained in:
aap 2021-01-24 00:07:45 +01:00
parent 8cdc6b5d7c
commit c1a7ded1e4
2 changed files with 66 additions and 9 deletions

View file

@ -7,6 +7,10 @@
#include "BaseModelInfo.h" #include "BaseModelInfo.h"
#include "ModelInfo.h" #include "ModelInfo.h"
#include "KeyGen.h" #include "KeyGen.h"
#include "Streaming.h"
#include "smallHeap.h"
// LCS: file done except for TODO
CBaseModelInfo::CBaseModelInfo(ModelInfoType type) CBaseModelInfo::CBaseModelInfo(ModelInfoType type)
{ {
@ -18,7 +22,11 @@ CBaseModelInfo::CBaseModelInfo(ModelInfoType type)
m_type = type; m_type = type;
m_num2dEffects = 0; m_num2dEffects = 0;
m_bOwnsColModel = false; m_bOwnsColModel = false;
m_nameKey = 0;
m_unk1 = 0;
m_unk2 = 0;
m_name = new char[MAX_MODEL_NAME]; m_name = new char[MAX_MODEL_NAME];
*(int32*)m_name = 0;
} }
void void
@ -26,6 +34,7 @@ CBaseModelInfo::Shutdown(void)
{ {
DeleteCollisionModel(); DeleteCollisionModel();
DeleteRwObject(); DeleteRwObject();
DeleteChunk();
m_2dEffectsID = -1; m_2dEffectsID = -1;
m_num2dEffects = 0; m_num2dEffects = 0;
m_txdSlot = -1; m_txdSlot = -1;
@ -34,11 +43,11 @@ CBaseModelInfo::Shutdown(void)
void void
CBaseModelInfo::DeleteCollisionModel(void) CBaseModelInfo::DeleteCollisionModel(void)
{ {
if(m_colModel && m_bOwnsColModel){ if(!gUseChunkFiles && m_colModel && m_bOwnsColModel){
if(m_colModel) if(m_colModel)
delete m_colModel; delete m_colModel;
m_colModel = nil;
} }
m_colModel = nil;
} }
void void
@ -51,15 +60,17 @@ CBaseModelInfo::AddRef(void)
void void
CBaseModelInfo::RemoveRef(void) CBaseModelInfo::RemoveRef(void)
{ {
m_refCount--; if(m_refCount > 0){
RemoveTexDictionaryRef(); m_refCount--;
RemoveTexDictionaryRef();
}
} }
void void
CBaseModelInfo::SetTexDictionary(const char *name) CBaseModelInfo::SetTexDictionary(const char *name)
{ {
int slot = CTxdStore::FindTxdSlot(name); int slot = CTxdStore::FindTxdSlot(name);
if(slot < 0) if(slot == -1)
slot = CTxdStore::AddTxdSlot(name); slot = CTxdStore::AddTxdSlot(name);
m_txdSlot = slot; m_txdSlot = slot;
} }
@ -70,12 +81,24 @@ CBaseModelInfo::AddTexDictionaryRef(void)
CTxdStore::AddRef(m_txdSlot); CTxdStore::AddRef(m_txdSlot);
} }
void
CBaseModelInfo::AddTexDictionaryRefGu(void)
{
CTxdStore::AddRefGu(m_txdSlot);
}
void void
CBaseModelInfo::RemoveTexDictionaryRef(void) CBaseModelInfo::RemoveTexDictionaryRef(void)
{ {
CTxdStore::RemoveRef(m_txdSlot); CTxdStore::RemoveRef(m_txdSlot);
} }
void
CBaseModelInfo::RemoveTexDictionaryRefGu(void)
{
CTxdStore::RemoveRefGu(m_txdSlot);
}
void void
CBaseModelInfo::Init2dEffects(void) CBaseModelInfo::Init2dEffects(void)
{ {
@ -111,3 +134,24 @@ CBaseModelInfo::SetModelName(const char *name)
if (!gUseChunkFiles) if (!gUseChunkFiles)
strcpy(m_name, name); strcpy(m_name, name);
} }
void
CBaseModelInfo::DeleteChunk(void)
{
// BUG? what if we're not using chunks?
if(m_chunk){
CStreaming::UnregisterPointer(&m_chunk, 2);
cSmallHeap::msInstance.Free(m_chunk);
m_chunk = nil;
}
}
void
CBaseModelInfo::Write(base::cRelocatableChunkWriter &writer)
{
m_chunk = nil;
RcWriteThis(writer);
if(m_colModel){
assert(0 && "TODO");
}
}

View file

@ -2,7 +2,7 @@
struct CColModel; struct CColModel;
#define MAX_MODEL_NAME (21) #define MAX_MODEL_NAME (24)
enum ModelInfoType enum ModelInfoType
{ {
@ -23,9 +23,13 @@ class C2dEffect;
class CBaseModelInfo class CBaseModelInfo
{ {
protected: protected:
char *m_name; uint32 m_unk1;
uint32 m_unk2;
uint32 m_nameKey; uint32 m_nameKey;
RwObject *m_object; union {
char *m_name; // if not using chunks
void *m_chunk; // else
};
uint8 m_type; uint8 m_type;
uint8 m_num2dEffects; uint8 m_num2dEffects;
bool m_bOwnsColModel; bool m_bOwnsColModel;
@ -53,6 +57,13 @@ public:
virtual void ConvertAnimFileIndex(void) {} virtual void ConvertAnimFileIndex(void) {}
virtual int GetAnimFileIndex(void) { return -1; } virtual int GetAnimFileIndex(void) { return -1; }
virtual void LoadModel(void *,void const*) {}; // = 0;
virtual void DeleteChunk(void);
virtual void Write(base::cRelocatableChunkWriter &writer);
virtual void WriteModel(base::cRelocatableChunkWriter &writer) {} // = 0;
virtual void RcWriteThis(base::cRelocatableChunkWriter &writer) {} // = 0;
virtual void RcWriteEmpty(base::cRelocatableChunkWriter &writer) {} // = 0;
// one day it becomes virtual // one day it becomes virtual
uint8 GetModelType() const { return m_type; } uint8 GetModelType() const { return m_type; }
bool IsBuilding(void) { return m_type == MITYPE_SIMPLE || m_type == MITYPE_TIME; } bool IsBuilding(void) { return m_type == MITYPE_SIMPLE || m_type == MITYPE_TIME; }
@ -74,7 +85,9 @@ public:
void RemoveRef(void); void RemoveRef(void);
void SetTexDictionary(const char *name); void SetTexDictionary(const char *name);
void AddTexDictionaryRef(void); void AddTexDictionaryRef(void);
void AddTexDictionaryRefGu(void);
void RemoveTexDictionaryRef(void); void RemoveTexDictionaryRef(void);
void RemoveTexDictionaryRefGu(void);
void Init2dEffects(void); void Init2dEffects(void);
void Add2dEffect(C2dEffect *fx); void Add2dEffect(C2dEffect *fx);
C2dEffect *Get2dEffect(int n); C2dEffect *Get2dEffect(int n);