1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-06 05:55:55 +00:00

txd store

This commit is contained in:
aap 2021-01-23 19:23:26 +01:00
parent 13507d422b
commit a1d6833bac
2 changed files with 94 additions and 10 deletions

View file

@ -1,5 +1,7 @@
#include "common.h" #include "common.h"
#include "main.h"
#include "smallHeap.h"
#include "templates.h" #include "templates.h"
#include "General.h" #include "General.h"
#include "Streaming.h" #include "Streaming.h"
@ -9,13 +11,19 @@
CPool<TxdDef,TxdDef> *CTxdStore::ms_pTxdPool; CPool<TxdDef,TxdDef> *CTxdStore::ms_pTxdPool;
RwTexDictionary *CTxdStore::ms_pStoredTxd; RwTexDictionary *CTxdStore::ms_pStoredTxd;
// LCS: file done except unused:
// CTexListStore::RemoveTexListChunk(int)
// CTexListStore::validateRefs(void)
// CTexListStore::Write(base::cRelocatableChunkWriter &)
void void
CTxdStore::Initialise(void) CTxdStore::Initialise(void)
{ {
if(ms_pTxdPool == nil) if(gMakeResources && ms_pTxdPool == nil)
ms_pTxdPool = new CPool<TxdDef,TxdDef>(TXDSTORESIZE, "TexDictionary"); ms_pTxdPool = new CPool<TxdDef,TxdDef>(TXDSTORESIZE, "TexDictionary");
} }
// removed in LCS but we should probably keep it
void void
CTxdStore::Shutdown(void) CTxdStore::Shutdown(void)
{ {
@ -23,6 +31,7 @@ CTxdStore::Shutdown(void)
delete ms_pTxdPool; delete ms_pTxdPool;
} }
// removed in LCS but we should probably keep it
void void
CTxdStore::GameShutdown(void) CTxdStore::GameShutdown(void)
{ {
@ -42,6 +51,7 @@ CTxdStore::AddTxdSlot(const char *name)
assert(def); assert(def);
def->texDict = nil; def->texDict = nil;
def->refCount = 0; def->refCount = 0;
def->refCountGu = 0;
strcpy(def->name, name); strcpy(def->name, name);
return ms_pTxdPool->GetJustIndex(def); return ms_pTxdPool->GetJustIndex(def);
} }
@ -95,7 +105,11 @@ CTxdStore::SetCurrentTxd(int slot)
void void
CTxdStore::Create(int slot) CTxdStore::Create(int slot)
{ {
GetSlot(slot)->texDict = RwTexDictionaryCreate(); TxdDef *def = GetSlot(slot);
def->texDict = RwTexDictionaryCreate();
// LCS: mobile sets the txd name here, but txds don't really have names
def->refCount = 0;
def->refCountGu = 0;
} }
int int
@ -110,6 +124,20 @@ CTxdStore::AddRef(int slot)
GetSlot(slot)->refCount++; GetSlot(slot)->refCount++;
} }
void
CTxdStore::AddRefEvenIfNotInMemory(int slot)
{
GetSlot(slot)->refCount++;
}
void
CTxdStore::AddRefGu(int slot)
{
TxdDef *def = GetSlot(slot);
def->refCount++;
def->refCountGu++;
}
void void
CTxdStore::RemoveRef(int slot) CTxdStore::RemoveRef(int slot)
{ {
@ -117,6 +145,15 @@ CTxdStore::RemoveRef(int slot)
CStreaming::RemoveTxd(slot); CStreaming::RemoveTxd(slot);
} }
void
CTxdStore::RemoveRefGu(int slot)
{
TxdDef *def = GetSlot(slot);
def->refCount--;
if(gUseChunkFiles)
def->refCountGu--;
}
void void
CTxdStore::RemoveRefWithoutDelete(int slot) CTxdStore::RemoveRefWithoutDelete(int slot)
{ {
@ -128,14 +165,31 @@ CTxdStore::LoadTxd(int slot, RwStream *stream)
{ {
TxdDef *def = GetSlot(slot); TxdDef *def = GetSlot(slot);
if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){ if(stream){
def->texDict = RwTexDictionaryGtaStreamRead(stream); if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){
return def->texDict != nil; def->texDict = RwTexDictionaryGtaStreamRead(stream);
return def->texDict != nil;
}
}else{
// TODO(LCS)? fall back reading from file
} }
printf("Failed to load TXD\n"); printf("Failed to load TXD\n");
return false; return false;
} }
bool
CTxdStore::LoadTxd(int slot, void *data, void *chunk)
{
TxdDef *def = GetSlot(slot);
def->texDict = (RwTexDictionary*)data;
if(strncasecmp(def->name, "radar", 5) == 0){
def->refCount = 0;
def->refCountGu = 0;
}
CStreaming::RegisterPointer(&def->texDict, 3, true);
return def->texDict != nil;
}
bool bool
CTxdStore::LoadTxd(int slot, const char *filename) CTxdStore::LoadTxd(int slot, const char *filename)
{ {
@ -152,6 +206,7 @@ CTxdStore::LoadTxd(int slot, const char *filename)
return ret; return ret;
} }
// removed in LCS but we should probably keep it
bool bool
CTxdStore::StartLoadTxd(int slot, RwStream *stream) CTxdStore::StartLoadTxd(int slot, RwStream *stream)
{ {
@ -165,6 +220,7 @@ CTxdStore::StartLoadTxd(int slot, RwStream *stream)
} }
} }
// removed in LCS but we should probably keep it
bool bool
CTxdStore::FinishLoadTxd(int slot, RwStream *stream) CTxdStore::FinishLoadTxd(int slot, RwStream *stream)
{ {
@ -174,10 +230,31 @@ CTxdStore::FinishLoadTxd(int slot, RwStream *stream)
} }
void void
CTxdStore::RemoveTxd(int slot) CTxdStore::RemoveTxd(int slot, bool notChunk)
{ {
TxdDef *def = GetSlot(slot); TxdDef *def = GetSlot(slot);
if(def->texDict) if(def->texDict){
RwTexDictionaryDestroy(def->texDict); if(!gUseChunkFiles || notChunk)
RwTexDictionaryDestroy(def->texDict);
else{
// TODO? Rsl3D specific: RslTextureDestroyDispList for all textures
CStreaming::UnregisterPointer(&def->texDict, 3);
cSmallHeap::msInstance.Free(def->texDict);
}
}
def->texDict = nil; def->texDict = nil;
def->refCount = 0;
def->refCountGu = 0;
}
void
CTxdStore::Load(RwTexDictionary *stored, CPool<TxdDef> *pool)
{
ms_pTxdPool = pool;
ms_pStoredTxd = stored;
for(int i = 0; i < TXDSTORESIZE; i++){
TxdDef *def = GetSlot(i);
if(def)
def->refCount = def->texDict != nil;
}
} }

View file

@ -4,7 +4,8 @@
struct TxdDef { struct TxdDef {
RwTexDictionary *texDict; RwTexDictionary *texDict;
int refCount; int16 refCount;
int16 refCountGu;
char name[20]; char name[20];
}; };
@ -26,13 +27,19 @@ public:
static void Create(int slot); static void Create(int slot);
static int GetNumRefs(int slot); static int GetNumRefs(int slot);
static void AddRef(int slot); static void AddRef(int slot);
static void AddRefEvenIfNotInMemory(int slot);
static void AddRefGu(int slot);
static void RemoveRef(int slot); static void RemoveRef(int slot);
static void RemoveRefGu(int slot);
static void RemoveRefWithoutDelete(int slot); static void RemoveRefWithoutDelete(int slot);
static bool LoadTxd(int slot, RwStream *stream); static bool LoadTxd(int slot, RwStream *stream);
static bool LoadTxd(int slot, void *data, void *chunk);
static bool LoadTxd(int slot, const char *filename); static bool LoadTxd(int slot, const char *filename);
static bool StartLoadTxd(int slot, RwStream *stream); static bool StartLoadTxd(int slot, RwStream *stream);
static bool FinishLoadTxd(int slot, RwStream *stream); static bool FinishLoadTxd(int slot, RwStream *stream);
static void RemoveTxd(int slot); static void RemoveTxd(int slot, bool notChunk = false);
static void Load(RwTexDictionary *stored, CPool<TxdDef> *pool);
static TxdDef *GetSlot(int slot) { static TxdDef *GetSlot(int slot) {
assert(slot >= 0); assert(slot >= 0);