DataCache: only check on DC_INVALID_HANDLE in debug builds

In release we should only check if the handle is NULL for performance reasons (the release engine executable never sets DC_INVALID_HANDLE on invalid handles. In debug we also check on DC_INVALID_HANDLE as this is easier to cache in memory.
This commit is contained in:
Kawe Mazidjatari 2024-11-14 14:21:01 +01:00
parent abe5578557
commit ad741882ae
2 changed files with 26 additions and 9 deletions

View File

@ -16,7 +16,6 @@
#include "public/studio.h"
CStudioFallbackHandler g_StudioMdlFallbackHandler;
#define IS_VALID_DATACACHE_HANDLE(cacheHandle) (cacheHandle && cacheHandle != DC_INVALID_HANDLE)
//-----------------------------------------------------------------------------
// Purpose: finds an MDL
@ -47,7 +46,7 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* const cache, const MDLHandle_t handle
studiomodelcache_t* modelCache = studioData->GetModelCache();
// Store error and empty fallback models.
if (IS_VALID_DATACACHE_HANDLE(modelCache))
if (IsValidDataCacheHandle(modelCache))
{
studiohdr_t* const studioHdr = studioData->GetModelCache()->GetStudioHdr();
@ -67,7 +66,7 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* const cache, const MDLHandle_t handle
if ((studioData->flags & nFlags))
{
if (IS_VALID_DATACACHE_HANDLE(modelCache))
if (IsValidDataCacheHandle(modelCache))
{
if (a3)
{
@ -85,7 +84,7 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* const cache, const MDLHandle_t handle
studioanimcache_t* const animCache = studioData->GetAnimCache();
if (IS_VALID_DATACACHE_HANDLE(animCache))
if (IsValidDataCacheHandle(animCache))
{
studiohdr_t* const pStudioHdr = animCache->GetStudioHdr();
@ -158,7 +157,7 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* const cache, const MDLHandle_
studiomodelcache_t* const modelCache = pStudioData->GetModelCache();
if (IS_VALID_DATACACHE_HANDLE(modelCache))
if (IsValidDataCacheHandle(modelCache))
{
FindCachedMDL(cache, pStudioData, a4);
studioHdr = modelCache->GetStudioHdr();
@ -168,7 +167,7 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* const cache, const MDLHandle_
// Attempt to get studio header from anim cache.
studioanimcache_t* const animCache = pStudioData->GetAnimCache();
if (IS_VALID_DATACACHE_HANDLE(animCache))
if (IsValidDataCacheHandle(animCache))
{
studioHdr = animCache->GetStudioHdr();
}
@ -219,7 +218,7 @@ vcollide_t* CMDLCache::GetVCollide(CMDLCache* const cache, const MDLHandle_t han
{
studiomodelcache_t* const modelCache = cache->GetModelCache(handle);
if (!IS_VALID_DATACACHE_HANDLE(modelCache))
if (!IsValidDataCacheHandle(modelCache))
{
Warning(eDLL_T::ENGINE, "Attempted to load collision data on model \"%s\" with invalid studio data!\n", cache->GetModelName(handle));
return nullptr;
@ -248,7 +247,7 @@ void* CMDLCache::GetPhysicsGeometry(CMDLCache* const cache, const MDLHandle_t ha
{
studiomodelcache_t* const modelCache = cache->GetModelCache(handle);
if (!IS_VALID_DATACACHE_HANDLE(modelCache))
if (!IsValidDataCacheHandle(modelCache))
{
Warning(eDLL_T::ENGINE, "Attempted to load physics geometry on model \"%s\" with invalid studio data!\n", cache->GetModelName(handle));
return nullptr;
@ -278,7 +277,7 @@ studiohwdata_t* CMDLCache::GetHardwareData(CMDLCache* const cache, const MDLHand
const studiodata_t* studioData = nullptr; cache->GetStudioData(handle);
const studiomodelcache_t* modelCache = cache->GetModelCache(handle);
if (!IS_VALID_DATACACHE_HANDLE(modelCache))
if (!IsValidDataCacheHandle(modelCache))
{
if (!HasErrorModel())
{

View File

@ -6,6 +6,24 @@
//---------------------------------------------------------
FORWARD_DECLARE_HANDLE(memhandle_t);
typedef memhandle_t DataCacheHandle_t;
#define DC_INVALID_HANDLE ((void*)0xDEADFEEDDEADFEED)
//---------------------------------------------------------
// Check whether the data cache handle is valid
//---------------------------------------------------------
inline bool IsValidDataCacheHandle(const void* const handle)
{
if (!handle)
return false;
if (IsDebug())
{
if (handle == DC_INVALID_HANDLE)
return false;
}
return true;
}
#endif // IDATACACHE_H