Skip to content

Commit

Permalink
Replaced magic numbers with defines in dlls/nodes*
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
FOTMarut authored and a1batross committed Apr 11, 2019
1 parent 2b61380 commit 8ef6cb2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
18 changes: 9 additions & 9 deletions dlls/nodes.cpp
Expand Up @@ -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
//
Expand All @@ -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<CGraph_32*>(pMemFile) -> copyOverTo(this);
pMemFile += sizeof(CGraph_32);
reinterpret_cast<CGraph_Retail*>(pMemFile) -> copyOverTo(this);
pMemFile += sizeof(CGraph_Retail);
}
#endif

Expand Down Expand Up @@ -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<CLink_32*>(pMemFile) -> copyOverTo(m_pLinkPool);
pMemFile += sizeof(CLink_32) * m_cLinks;
reinterpret_cast<CLink_Retail*>(pMemFile) -> copyOverTo(m_pLinkPool);
pMemFile += sizeof(CLink_Retail) * m_cLinks;
}
#endif

Expand Down
4 changes: 3 additions & 1 deletion dlls/nodes.h
Expand Up @@ -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
{
Expand Down
12 changes: 7 additions & 5 deletions dlls/nodes_compat.h
Expand Up @@ -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:

Expand Down Expand Up @@ -62,10 +62,11 @@ class CGraph_32
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];
Expand Down Expand Up @@ -102,6 +103,7 @@ class CGraph_32
other->m_HashPrimes[i] = m_HashPrimes[i];
// m_HashPrimes[16]
#endif

other->m_pHashLinks = NULL;
other->m_nHashLinks = m_nHashLinks;

Expand All @@ -114,7 +116,7 @@ class CGraph_32
};


class CLink_32
class CLink_Retail
{

public:
Expand Down

0 comments on commit 8ef6cb2

Please sign in to comment.