1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 15:20:00 +00:00
re3/src/rw/TxdStore.cpp

261 lines
4.9 KiB
C++
Raw Normal View History

2019-05-15 14:52:37 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2021-01-23 18:23:26 +00:00
#include "main.h"
#include "smallHeap.h"
2019-05-15 14:52:37 +00:00
#include "templates.h"
#include "General.h"
2019-05-15 14:52:37 +00:00
#include "Streaming.h"
2019-06-13 09:57:43 +00:00
#include "RwHelper.h"
2019-05-15 14:52:37 +00:00
#include "TxdStore.h"
2020-04-17 05:54:14 +00:00
CPool<TxdDef,TxdDef> *CTxdStore::ms_pTxdPool;
RwTexDictionary *CTxdStore::ms_pStoredTxd;
2019-05-15 14:52:37 +00:00
2021-01-23 18:23:26 +00:00
// LCS: file done except unused:
// CTexListStore::RemoveTexListChunk(int)
// CTexListStore::validateRefs(void)
// CTexListStore::Write(base::cRelocatableChunkWriter &)
2019-05-15 14:52:37 +00:00
void
CTxdStore::Initialise(void)
2019-05-15 14:52:37 +00:00
{
2021-01-23 18:23:26 +00:00
if(gMakeResources && ms_pTxdPool == nil)
2020-08-20 10:53:17 +00:00
ms_pTxdPool = new CPool<TxdDef,TxdDef>(TXDSTORESIZE, "TexDictionary");
2019-05-15 14:52:37 +00:00
}
2021-01-23 18:23:26 +00:00
// removed in LCS but we should probably keep it
2019-05-15 14:52:37 +00:00
void
CTxdStore::Shutdown(void)
{
if(ms_pTxdPool)
delete ms_pTxdPool;
}
2021-01-23 18:23:26 +00:00
// removed in LCS but we should probably keep it
2019-06-13 10:25:55 +00:00
void
CTxdStore::GameShutdown(void)
{
int i;
for(i = 0; i < TXDSTORESIZE; i++){
TxdDef *def = GetSlot(i);
2019-06-15 09:41:27 +00:00
if(def && GetNumRefs(i) == 0)
2019-06-13 10:25:55 +00:00
RemoveTxdSlot(i);
}
}
2019-05-15 14:52:37 +00:00
int
CTxdStore::AddTxdSlot(const char *name)
{
TxdDef *def = ms_pTxdPool->New();
assert(def);
def->texDict = nil;
def->refCount = 0;
2021-01-23 18:23:26 +00:00
def->refCountGu = 0;
2019-05-15 14:52:37 +00:00
strcpy(def->name, name);
return ms_pTxdPool->GetJustIndex(def);
}
2019-05-22 18:28:53 +00:00
void
CTxdStore::RemoveTxdSlot(int slot)
{
TxdDef *def = GetSlot(slot);
if(def->texDict)
RwTexDictionaryDestroy(def->texDict);
ms_pTxdPool->Delete(def);
}
2019-05-15 14:52:37 +00:00
int
CTxdStore::FindTxdSlot(const char *name)
{
int size = ms_pTxdPool->GetSize();
for(int i = 0; i < size; i++){
2020-08-20 10:53:17 +00:00
TxdDef *def = GetSlot(i);
if(def && !CGeneral::faststricmp(def->name, name))
2019-05-15 14:52:37 +00:00
return i;
}
return -1;
}
char*
CTxdStore::GetTxdName(int slot)
{
2020-08-20 10:53:17 +00:00
return GetSlot(slot)->name;
2019-05-15 14:52:37 +00:00
}
void
CTxdStore::PushCurrentTxd(void)
{
ms_pStoredTxd = RwTexDictionaryGetCurrent();
}
void
CTxdStore::PopCurrentTxd(void)
{
RwTexDictionarySetCurrent(ms_pStoredTxd);
ms_pStoredTxd = nil;
}
void
CTxdStore::SetCurrentTxd(int slot)
{
2020-08-20 10:53:17 +00:00
RwTexDictionarySetCurrent(GetSlot(slot)->texDict);
2019-05-15 14:52:37 +00:00
}
void
CTxdStore::Create(int slot)
{
2021-01-23 18:23:26 +00:00
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;
2019-05-15 14:52:37 +00:00
}
2019-06-13 10:25:55 +00:00
int
CTxdStore::GetNumRefs(int slot)
{
return GetSlot(slot)->refCount;
}
2019-05-15 14:52:37 +00:00
void
CTxdStore::AddRef(int slot)
{
GetSlot(slot)->refCount++;
}
2021-01-23 18:23:26 +00:00
void
CTxdStore::AddRefEvenIfNotInMemory(int slot)
{
GetSlot(slot)->refCount++;
}
void
CTxdStore::AddRefGu(int slot)
{
TxdDef *def = GetSlot(slot);
def->refCount++;
def->refCountGu++;
}
2019-05-15 14:52:37 +00:00
void
CTxdStore::RemoveRef(int slot)
{
if(--GetSlot(slot)->refCount <= 0)
2020-08-20 10:53:17 +00:00
CStreaming::RemoveTxd(slot);
2019-05-15 14:52:37 +00:00
}
2021-01-23 18:23:26 +00:00
void
CTxdStore::RemoveRefGu(int slot)
{
TxdDef *def = GetSlot(slot);
def->refCount--;
if(gUseChunkFiles)
def->refCountGu--;
}
2019-05-15 14:52:37 +00:00
void
CTxdStore::RemoveRefWithoutDelete(int slot)
{
GetSlot(slot)->refCount--;
}
bool
CTxdStore::LoadTxd(int slot, RwStream *stream)
{
TxdDef *def = GetSlot(slot);
2019-05-22 18:28:53 +00:00
2021-01-23 18:23:26 +00:00
if(stream){
if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){
def->texDict = RwTexDictionaryGtaStreamRead(stream);
return def->texDict != nil;
}
}else{
// TODO(LCS)? fall back reading from file
2019-05-15 14:52:37 +00:00
}
2019-05-22 18:28:53 +00:00
printf("Failed to load TXD\n");
return false;
2019-05-15 14:52:37 +00:00
}
2021-01-23 18:23:26 +00:00
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;
}
2019-05-15 14:52:37 +00:00
bool
CTxdStore::LoadTxd(int slot, const char *filename)
{
2019-05-22 18:28:53 +00:00
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;
2019-05-15 14:52:37 +00:00
}
2021-01-23 18:23:26 +00:00
// removed in LCS but we should probably keep it
2019-06-13 10:25:55 +00:00
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");
2019-06-30 10:53:39 +00:00
return false;
2019-06-13 10:25:55 +00:00
}
}
2021-01-23 18:23:26 +00:00
// removed in LCS but we should probably keep it
2019-06-13 10:25:55 +00:00
bool
CTxdStore::FinishLoadTxd(int slot, RwStream *stream)
{
TxdDef *def = GetSlot(slot);
def->texDict = RwTexDictionaryGtaStreamRead2(stream, def->texDict);
return def->texDict != nil;
}
2019-05-15 14:52:37 +00:00
void
2021-01-23 18:23:26 +00:00
CTxdStore::RemoveTxd(int slot, bool notChunk)
2019-05-15 14:52:37 +00:00
{
TxdDef *def = GetSlot(slot);
2021-01-23 18:23:26 +00:00
if(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);
}
}
2019-05-15 14:52:37 +00:00
def->texDict = nil;
2021-01-23 18:23:26 +00:00
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;
}
2019-05-15 14:52:37 +00:00
}