From 8ef6cb2427ee16a763103bd3f315f38e2f01cfe2 Mon Sep 17 00:00:00 2001 From: FOTMarut Date: Sat, 16 Feb 2019 17:32:45 +0100 Subject: [PATCH] Replaced magic numbers with defines in dlls/nodes* - Changed some symbols to be platform-independent - Now the CGraph_Retail::copyOverTo method doesn't automatically fall back to manual copy (instead of memcpy) on GRAPH_VERSION increments --- dlls/nodes.cpp | 18 +++++++++--------- dlls/nodes.h | 4 +++- dlls/nodes_compat.h | 12 +++++++----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/dlls/nodes.cpp b/dlls/nodes.cpp index 5e5b6acf..e81f3252 100644 --- a/dlls/nodes.cpp +++ b/dlls/nodes.cpp @@ -2397,7 +2397,7 @@ int CGraph::FLoadGraph( const char *szMapName ) iVersion = *(int *) pMemFile; pMemFile += sizeof(int); - if( iVersion == GRAPH_VERSION || iVersion == 16 ) + if( iVersion == GRAPH_VERSION || iVersion == GRAPH_VERSION_RETAIL ) { // Read the graph class // @@ -2417,15 +2417,15 @@ int CGraph::FLoadGraph( const char *szMapName ) m_pRouteInfo = NULL; m_pHashLinks = NULL; } -#if _GRAPH_VERSION != 16 +#if _GRAPH_VERSION != _GRAPH_VERSION_RETAIL else { ALERT( at_aiconsole, "Loading CGraph in GRAPH_VERSION 16 compatibility mode\n" ); - length -= sizeof(CGraph_32); + length -= sizeof(CGraph_Retail); if( length < 0 ) goto ShortFile; - reinterpret_cast(pMemFile) -> copyOverTo(this); - pMemFile += sizeof(CGraph_32); + reinterpret_cast(pMemFile) -> copyOverTo(this); + pMemFile += sizeof(CGraph_Retail); } #endif @@ -2467,15 +2467,15 @@ int CGraph::FLoadGraph( const char *szMapName ) memcpy( m_pLinkPool, pMemFile, sizeof(CLink) * m_cLinks ); pMemFile += sizeof(CLink) * m_cLinks; } -#if _GRAPH_VERSION != 16 +#if _GRAPH_VERSION != _GRAPH_VERSION_RETAIL else { ALERT( at_aiconsole, "Loading CLink array in GRAPH_VERSION 16 compatibility mode\n" ); - length -= sizeof(CLink_32) * m_cLinks; + length -= sizeof(CLink_Retail) * m_cLinks; if( length < 0 ) goto ShortFile; - reinterpret_cast(pMemFile) -> copyOverTo(m_pLinkPool); - pMemFile += sizeof(CLink_32) * m_cLinks; + reinterpret_cast(pMemFile) -> copyOverTo(m_pLinkPool); + pMemFile += sizeof(CLink_Retail) * m_cLinks; } #endif diff --git a/dlls/nodes.h b/dlls/nodes.h index f43684c8..4bc1ec1b 100644 --- a/dlls/nodes.h +++ b/dlls/nodes.h @@ -105,12 +105,14 @@ typedef struct //========================================================= // CGraph //========================================================= +#define _GRAPH_VERSION_RETAIL 16 // Retail Half-Life graph version. Don't increment this #ifdef XASH_64BIT #define _GRAPH_VERSION (16 * 10) #else -#define _GRAPH_VERSION (16)// !!!increment this whever graph/node/link classes change, to obsolesce older disk files. +#define _GRAPH_VERSION (16) // !!!increment this whenever graph/node/link classes change, to obsolesce older disk files. #endif #define GRAPH_VERSION (int)_GRAPH_VERSION +#define GRAPH_VERSION_RETAIL (int)_GRAPH_VERSION_RETAIL class CGraph { diff --git a/dlls/nodes_compat.h b/dlls/nodes_compat.h index da91a5b8..d73567e9 100644 --- a/dlls/nodes_compat.h +++ b/dlls/nodes_compat.h @@ -5,13 +5,13 @@ //#include "nodes.h" -#if _GRAPH_VERSION != 16 +#if _GRAPH_VERSION != _GRAPH_VERSION_RETAIL #include "stdint.h" typedef int32_t PTR32; -class CGraph_32 +class CGraph_Retail { public: @@ -62,10 +62,11 @@ public: other->m_nRouteInfo = m_nRouteInfo; other->m_di = NULL; -#if _GRAPH_VERSION == 160 + memcpy( (void *) &other->m_RangeStart, (void *) m_RangeStart, offsetof(class CGraph, m_pHashLinks) - offsetof(class CGraph, m_RangeStart) ); -#else // fallback routine if the graph version changes + +#if 0 // replacement routine in case a change in CGraph breaks the above memcpy for (int i = 0; i < 3; ++i) for (int j = 0; j < NUM_RANGES; ++j) other->m_RangeStart[i][j] = m_RangeStart[i][j]; @@ -102,6 +103,7 @@ public: other->m_HashPrimes[i] = m_HashPrimes[i]; // m_HashPrimes[16] #endif + other->m_pHashLinks = NULL; other->m_nHashLinks = m_nHashLinks; @@ -114,7 +116,7 @@ public: }; -class CLink_32 +class CLink_Retail { public: