summaryrefslogtreecommitdiff
path: root/src/rw/TxdStore.cpp
diff options
context:
space:
mode:
authorclaude-bot <[email protected]>2026-07-13 12:27:07 +0000
committerclaude-bot <[email protected]>2026-07-13 12:27:07 +0000
commit9f61c9e6ac6b1ac5692cf6352d2ebbd47a31a686 (patch)
treea84756b82513739a2672db3a1f0ec579db6d18ff /src/rw/TxdStore.cpp
downloadre3-miami.tar.gz
re3-miami.zip
Import Cai1Hsu/re3 @ miami (reVC / GTA:VC decompilation)HEADmiami
Snapshot import (no upstream history) into git.ancap.in.ua/claude, per @lzcnt. Source: https://github.com/Cai1Hsu/re3 branch miami.
Diffstat (limited to 'src/rw/TxdStore.cpp')
-rw-r--r--src/rw/TxdStore.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/src/rw/TxdStore.cpp b/src/rw/TxdStore.cpp
new file mode 100644
index 0000000..0bd2971
--- /dev/null
+++ b/src/rw/TxdStore.cpp
@@ -0,0 +1,183 @@
+#include "common.h"
+
+#include "templates.h"
+#include "General.h"
+#include "Streaming.h"
+#include "RwHelper.h"
+#include "TxdStore.h"
+
+CPool<TxdDef,TxdDef> *CTxdStore::ms_pTxdPool;
+RwTexDictionary *CTxdStore::ms_pStoredTxd;
+
+void
+CTxdStore::Initialise(void)
+{
+ if(ms_pTxdPool == nil)
+ ms_pTxdPool = new CPool<TxdDef,TxdDef>(TXDSTORESIZE, "TexDictionary");
+}
+
+void
+CTxdStore::Shutdown(void)
+{
+ if(ms_pTxdPool)
+ delete ms_pTxdPool;
+}
+
+void
+CTxdStore::GameShutdown(void)
+{
+ int i;
+
+ for(i = 0; i < TXDSTORESIZE; i++){
+ TxdDef *def = GetSlot(i);
+ if(def && GetNumRefs(i) == 0)
+ RemoveTxdSlot(i);
+ }
+}
+
+int
+CTxdStore::AddTxdSlot(const char *name)
+{
+ TxdDef *def = ms_pTxdPool->New();
+ assert(def);
+ def->texDict = nil;
+ def->refCount = 0;
+ strcpy(def->name, name);
+ return ms_pTxdPool->GetJustIndex(def);
+}
+
+void
+CTxdStore::RemoveTxdSlot(int slot)
+{
+ TxdDef *def = GetSlot(slot);
+ if(def->texDict)
+ RwTexDictionaryDestroy(def->texDict);
+ ms_pTxdPool->Delete(def);
+}
+
+int
+CTxdStore::FindTxdSlot(const char *name)
+{
+ int size = ms_pTxdPool->GetSize();
+ for(int i = 0; i < size; i++){
+ TxdDef *def = GetSlot(i);
+ if(def && !CGeneral::faststricmp(def->name, name))
+ return i;
+ }
+ return -1;
+}
+
+char*
+CTxdStore::GetTxdName(int slot)
+{
+ return GetSlot(slot)->name;
+}
+
+void
+CTxdStore::PushCurrentTxd(void)
+{
+ ms_pStoredTxd = RwTexDictionaryGetCurrent();
+}
+
+void
+CTxdStore::PopCurrentTxd(void)
+{
+ RwTexDictionarySetCurrent(ms_pStoredTxd);
+ ms_pStoredTxd = nil;
+}
+
+void
+CTxdStore::SetCurrentTxd(int slot)
+{
+ RwTexDictionarySetCurrent(GetSlot(slot)->texDict);
+}
+
+void
+CTxdStore::Create(int slot)
+{
+ GetSlot(slot)->texDict = RwTexDictionaryCreate();
+}
+
+int
+CTxdStore::GetNumRefs(int slot)
+{
+ return GetSlot(slot)->refCount;
+}
+
+void
+CTxdStore::AddRef(int slot)
+{
+ GetSlot(slot)->refCount++;
+}
+
+void
+CTxdStore::RemoveRef(int slot)
+{
+ if(--GetSlot(slot)->refCount <= 0)
+ CStreaming::RemoveTxd(slot);
+}
+
+void
+CTxdStore::RemoveRefWithoutDelete(int slot)
+{
+ GetSlot(slot)->refCount--;
+}
+
+bool
+CTxdStore::LoadTxd(int slot, RwStream *stream)
+{
+ TxdDef *def = GetSlot(slot);
+
+ if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){
+ def->texDict = RwTexDictionaryGtaStreamRead(stream);
+ return def->texDict != nil;
+ }
+ printf("Failed to load TXD\n");
+ return false;
+}
+
+bool
+CTxdStore::LoadTxd(int slot, const char *filename)
+{
+ RwStream *stream;
+ bool ret;
+
+ ret = false;
+ _rwD3D8TexDictionaryEnableRasterFormatConversion(true);
+ do
+ stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, filename);
+ while(stream == nil);
+ ret = LoadTxd(slot, stream);
+ RwStreamClose(stream, nil);
+ return ret;
+}
+
+bool
+CTxdStore::StartLoadTxd(int slot, RwStream *stream)
+{
+ TxdDef *def = GetSlot(slot);
+ if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){
+ def->texDict = RwTexDictionaryGtaStreamRead1(stream);
+ return def->texDict != nil;
+ }else{
+ printf("Failed to load TXD\n");
+ return false;
+ }
+}
+
+bool
+CTxdStore::FinishLoadTxd(int slot, RwStream *stream)
+{
+ TxdDef *def = GetSlot(slot);
+ def->texDict = RwTexDictionaryGtaStreamRead2(stream, def->texDict);
+ return def->texDict != nil;
+}
+
+void
+CTxdStore::RemoveTxd(int slot)
+{
+ TxdDef *def = GetSlot(slot);
+ if(def->texDict)
+ RwTexDictionaryDestroy(def->texDict);
+ def->texDict = nil;
+}