From 693095bffbb4db9b0dd802cfdacb150721a37ba6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 31 Oct 2019 00:50:45 +0100 Subject: [PATCH] - added access wrappers to the two fields of DICTNODE that are accessed from the outside. The idea here is to completely merge the resource management into the file system so that Blood's DICTNODE is merely an alias to the internal FResourceLump. A two-tiered resource system is not something I consider worthwile, it made sense to get around Builds crappy cache but in the long term this is not a good solution for a multi-game port to have a resource management system in the backend and another one put over it in the front end, both with their own caching logic that might interfere with each other. Better merge it into one that can handle everything. --- source/blood/src/asound.cpp | 6 +++--- source/blood/src/db.cpp | 16 ++++------------ source/blood/src/loadsave.cpp | 2 +- source/blood/src/resource.h | 3 +++ source/blood/src/screen.cpp | 4 ++-- source/blood/src/sfx.cpp | 6 +++--- source/blood/src/sound.cpp | 8 ++++---- source/blood/src/tile.cpp | 4 ++-- source/blood/src/trig.cpp | 4 ++-- source/common/filesystem/resourcefile.h | 11 ++++++++++- 10 files changed, 34 insertions(+), 30 deletions(-) diff --git a/source/blood/src/asound.cpp b/source/blood/src/asound.cpp index 8072e8884..0502732cb 100644 --- a/source/blood/src/asound.cpp +++ b/source/blood/src/asound.cpp @@ -150,11 +150,11 @@ void ambInit(void) continue; } - if (pRAWNode->size > 0) { - pChannel->at14 = pRAWNode->size; + if (pRAWNode->Size() > 0) { + pChannel->at14 = pRAWNode->Size(); pChannel->at8 = nSFX; pChannel->atc = pRAWNode; - pChannel->at14 = pRAWNode->size; + pChannel->at14 = pRAWNode->Size(); pChannel->at10 = (char*)gSoundRes.Lock(pRAWNode); pChannel->at18 = pSFX->format; nAmbChannels++; diff --git a/source/blood/src/db.cpp b/source/blood/src/db.cpp index 7ba34751f..636a7d133 100644 --- a/source/blood/src/db.cpp +++ b/source/blood/src/db.cpp @@ -650,11 +650,7 @@ unsigned int dbReadMapCRC(const char *pPath) Bstrncpy(name2, pPath, BMAX_PATH); Bstrupr(name2); - DICTNODE* pNode = *gSysRes.Probe(name2, "MAP"); - if (pNode && pNode->flags & DICT_EXTERNAL) - { - gSysRes.RemoveNode(pNode); - } + DICTNODE* pNode; pNode = gSysRes.Lookup(pPath, "MAP"); if (!pNode) { @@ -673,7 +669,7 @@ unsigned int dbReadMapCRC(const char *pPath) char *pData = (char*)gSysRes.Lock(pNode); pathsearchmode = bakpathsearchmode; - int nSize = pNode->size; + int nSize = pNode->Size(); MAPSIGNATURE header; IOBuffer(nSize, pData).Read(&header, 6); #if B_BIG_ENDIAN == 1 @@ -721,11 +717,7 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short Bstrncpy(name2, pPath, BMAX_PATH); Bstrupr(name2); - DICTNODE* pNode = *gSysRes.Probe(name2, "MAP"); - if (pNode && pNode->flags & DICT_EXTERNAL) - { - gSysRes.RemoveNode(pNode); - } + DICTNODE* pNode; pNode = gSysRes.Lookup(pPath, "MAP"); if (!pNode) @@ -744,7 +736,7 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short } char *pData = (char*)gSysRes.Lock(pNode); pathsearchmode = bakpathsearchmode; - int nSize = pNode->size; + int nSize = pNode->Size(); MAPSIGNATURE header; IOBuffer IOBuffer1 = IOBuffer(nSize, pData); IOBuffer1.Read(&header, 6); diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index cfa2ebe3f..d6b09a352 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -428,7 +428,7 @@ void LoadSavedInfo(void) int nCount = 0; for (auto pIterator = pList; pIterator != NULL && nCount < 10; pIterator = pIterator->next, nCount++) { - auto hFile = kopenFileReader(pIterator->name, 0); + auto hFile = fopenFileReader(pIterator->name, 0); if (!hFile.isOpen()) ThrowError("Error loading save file header."); int vc; diff --git a/source/blood/src/resource.h b/source/blood/src/resource.h index 23629eedf..ec58485e2 100644 --- a/source/blood/src/resource.h +++ b/source/blood/src/resource.h @@ -82,6 +82,9 @@ struct DICTNODE : CACHENODE char *path; char *buffer; unsigned int id; + + unsigned int Size() const { return size; } + int LockCount() const { return lockCount; } }; class Resource diff --git a/source/blood/src/screen.cpp b/source/blood/src/screen.cpp index 864361402..f1aff5eb1 100644 --- a/source/blood/src/screen.cpp +++ b/source/blood/src/screen.cpp @@ -108,7 +108,7 @@ void scrLoadPLUs(void) DICTNODE *pPlu = gSysRes.Lookup(PLU[i].name, "PLU"); if (!pPlu) ThrowError("%s.PLU not found", PLU[i].name); - if (pPlu->size / 256 != 64) + if (pPlu->Size() / 256 != 64) ThrowError("Incorrect PLU size"); palookup[PLU[i].id] = (char*)gSysRes.Lock(pPlu); } @@ -227,7 +227,7 @@ void scrInit(void) DICTNODE *pGamma = gSysRes.Lookup("gamma", "DAT"); if (!pGamma) ThrowError("Gamma table not found"); - gGammaLevels = pGamma->size / 256; + gGammaLevels = pGamma->Size() / 256; gammaTable = (char(*)[256])gSysRes.Lock(pGamma); } diff --git a/source/blood/src/sfx.cpp b/source/blood/src/sfx.cpp index 2c7c34492..a904b79cf 100644 --- a/source/blood/src/sfx.cpp +++ b/source/blood/src/sfx.cpp @@ -145,7 +145,7 @@ void sfxPlay3DSound(int x, int y, int z, int soundId, int nSector) pBonkle->at1c = pEffect->relVol; pBonkle->at18 = v18; pBonkle->at3c = pEffect->format; - int size = hRes->size; + int size = hRes->Size(); char *pData = (char*)gSoundRes.Lock(hRes); Calc3DValues(pBonkle); int priority = 1; @@ -183,7 +183,7 @@ void sfxPlay3DSound(spritetype *pSprite, int soundId, int a3, int a4) hRes = gSoundRes.Lookup(pEffect->rawName, "RAW"); if (!hRes) return; - int size = hRes->size; + int size = hRes->Size(); if (size <= 0) return; int v14; @@ -290,7 +290,7 @@ void sfxPlay3DSoundCP(spritetype* pSprite, int soundId, int a3, int a4, int pitc SFX* pEffect = (SFX*)gSoundRes.Load(hRes); hRes = gSoundRes.Lookup(pEffect->rawName, "RAW"); if (!hRes) return; - int size = hRes->size; + int size = hRes->Size(); if (size <= 0) return; if (pitch <= 0) pitch = pEffect->pitch; diff --git a/source/blood/src/sound.cpp b/source/blood/src/sound.cpp index d11a394f3..6ae783013 100644 --- a/source/blood/src/sound.cpp +++ b/source/blood/src/sound.cpp @@ -95,7 +95,7 @@ int sndPlaySong(const char *songName, bool bLoop) OSD_Printf(OSD_ERROR "sndPlaySong(): error: can't open \"%s\" for playback!\n", songName); return 2; } - int nNewSongSize = hSong->size; + int nNewSongSize = hSong->Size(); char *pNewSongPtr = (char *)Xaligned_alloc(16, nNewSongSize); gSoundRes.Load(hSong, pNewSongPtr); MUSIC_SetVolume(mus_volume); @@ -260,7 +260,7 @@ void sndStartSample(const char *pzSound, int nVolume, int nChannel) pChannel->at5 = gSoundRes.Lookup(pzSound, "RAW"); if (!pChannel->at5) return; - int nSize = pChannel->at5->size; + int nSize = pChannel->at5->Size(); char *pData = (char*)gSoundRes.Lock(pChannel->at5); pChannel->at0 = FX_PlayRaw(pData, nSize, sndGetRate(1), 0, nVolume, nVolume, nVolume, nVolume, 1.f, (intptr_t)&pChannel->at0); } @@ -287,7 +287,7 @@ void sndStartSample(unsigned int nSound, int nVolume, int nChannel, bool bLoop) return; if (nVolume < 0) nVolume = pEffect->relVol; - int nSize = pChannel->at5->size; + int nSize = pChannel->at5->Size(); int nLoopEnd = nSize - 1; if (nLoopEnd < 0) nLoopEnd = 0; @@ -325,7 +325,7 @@ void sndStartWavID(unsigned int nSound, int nVolume, int nChannel) if (!pChannel->at5) return; char *pData = (char*)gSoundRes.Lock(pChannel->at5); - pChannel->at0 = FX_Play(pData, pChannel->at5->size, 0, -1, 0, nVolume, nVolume, nVolume, nVolume, 1.f, (intptr_t)&pChannel->at0); + pChannel->at0 = FX_Play(pData, pChannel->at5->Size(), 0, -1, 0, nVolume, nVolume, nVolume, nVolume, 1.f, (intptr_t)&pChannel->at0); } void sndKillSound(SAMPLE2D *pChannel) diff --git a/source/blood/src/tile.cpp b/source/blood/src/tile.cpp index 0ccb10607..c580cd83b 100644 --- a/source/blood/src/tile.cpp +++ b/source/blood/src/tile.cpp @@ -48,7 +48,7 @@ void qloadvoxel(int32_t nVoxel) return; } - if (!hVox->lockCount) + if (!hVox->LockCount()) voxoff[nLastVoxel][0] = 0; nLastVoxel = nVoxel; char *pVox = (char*)gSysRes.Lock(hVox); @@ -135,7 +135,7 @@ void tileProcessGLVoxels(void) if (!hVox) continue; char *pVox = (char*)gSysRes.Load(hVox); - voxmodels[i] = loadkvxfrombuf(pVox, hVox->size); + voxmodels[i] = loadkvxfrombuf(pVox, hVox->Size()); } } #endif diff --git a/source/blood/src/trig.cpp b/source/blood/src/trig.cpp index 0e5d6829e..dba977224 100644 --- a/source/blood/src/trig.cpp +++ b/source/blood/src/trig.cpp @@ -64,9 +64,9 @@ void trigInit(Resource &Res) DICTNODE *pTable = Res.Lookup("cosine","dat"); if (!pTable) ThrowError("Cosine table not found"); - if (pTable->size != 2048) + if (pTable->Size() != 2048) ThrowError("Cosine table incorrect size"); - memcpy(costable, Res.Load(pTable), pTable->size); + memcpy(costable, Res.Load(pTable), pTable->Size()); #if B_BIG_ENDIAN == 1 for (int i = 0; i < 512; i++) { diff --git a/source/common/filesystem/resourcefile.h b/source/common/filesystem/resourcefile.h index 19be3da91..d131c9608 100644 --- a/source/common/filesystem/resourcefile.h +++ b/source/common/filesystem/resourcefile.h @@ -46,11 +46,12 @@ struct FResourceLump { friend class FResourceFile; - int LumpSize = 0; + unsigned LumpSize = 0; int RefCount = 0; int Flags = 0; int PathLen = 0; int ExtStart = -1; + int ResourceId = -1; FString FullName; // Name with extension and path FResourceFile * Owner = nullptr; TArray Cache; @@ -67,12 +68,20 @@ struct FResourceLump void *CacheLump(); int ReleaseCache(); + + unsigned Size() const{ return LumpSize; } + int LockCount() const { return RefCount; } + FString BaseName(); // don't know if these will be needed + FString Type(); protected: virtual int FillCache() { return -1; } }; +// Map NBlood's resource system to our own. +using DICTNODE = FResourceLump; + class FResourceFile { public: