2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-24 18:59:50 +01:00

engine: cleanup XASH_64BIT usage. Always use it from build.h

This commit is contained in:
Alibek Omarov 2024-10-24 16:33:54 +03:00
parent 40ffde0439
commit 128a1f59a9
6 changed files with 40 additions and 35 deletions

3
.gitignore vendored
View File

@ -342,3 +342,6 @@ enc_temp_folder/
# KDevelop4 # KDevelop4
*.kdev4 *.kdev4
# ccls langauge server
.ccls-*

View File

@ -26,7 +26,8 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#if defined __ANDROID__ && !defined XASH_64BIT #include "build.h"
#if XASH_ANDROID && !XASH_64BIT
#include <string.h> #include <string.h>
#include <android/log.h> #include <android/log.h>
#include "linker.h" #include "linker.h"
@ -102,4 +103,4 @@ void *dlsym_weak( void *handle, const char *symbol )
__android_log_print( ANDROID_LOG_ERROR, "dlsym-weak", "Failed when looking up %s\n", symbol ); __android_log_print( ANDROID_LOG_ERROR, "dlsym-weak", "Failed when looking up %s\n", symbol );
return NULL; return NULL;
} }
#endif #endif // XASH_ANDROID && !XASH_64BIT

View File

@ -674,7 +674,7 @@ static void VID_SetWindowIcon( SDL_Window *hWnd )
if( ico && WIN_SetWindowIcon( ico )) if( ico && WIN_SetWindowIcon( ico ))
return; return;
} }
#endif // _WIN32 && !XASH_64BIT #endif // XASH_WIN32
Q_strncpy( iconpath, GI->iconpath, sizeof( iconpath )); Q_strncpy( iconpath, GI->iconpath, sizeof( iconpath ));
COM_ReplaceExtension( iconpath, ".tga", sizeof( iconpath )); COM_ReplaceExtension( iconpath, ".tga", sizeof( iconpath ));

View File

@ -2985,24 +2985,22 @@ static void *GAME_EXPORT pfnPvEntPrivateData( edict_t *pEdict )
} }
#ifdef XASH_64BIT
static struct str64_s static struct str64_s
{ {
size_t maxstringarray; size_t maxstringarray;
qboolean allowdup; qboolean allowdup;
qboolean dynamic;
char *staticstringarray; char *staticstringarray;
char *pstringarray; char *pstringarray;
char *pstringarraystatic; char *pstringarraystatic;
char *pstringbase; char *pstringbase;
char *poldstringbase; char *poldstringbase;
char *plast; char *plast;
qboolean dynamic;
size_t maxalloc; size_t maxalloc;
size_t numdups; size_t numdups;
size_t numoverflows; size_t numoverflows;
size_t totalalloc; size_t totalalloc;
} str64; } str64;
#endif
/* /*
================== ==================
@ -3013,7 +3011,7 @@ Free strings on server stop. Reset string pointer on 64 bits
*/ */
void SV_EmptyStringPool( void ) void SV_EmptyStringPool( void )
{ {
#ifdef XASH_64BIT #if XASH_64BIT
if( str64.dynamic ) // switch only after array fill (more space for multiplayer games) if( str64.dynamic ) // switch only after array fill (more space for multiplayer games)
str64.pstringbase = str64.pstringarray; str64.pstringbase = str64.pstringarray;
else else
@ -3021,9 +3019,9 @@ void SV_EmptyStringPool( void )
str64.pstringbase = str64.poldstringbase = str64.pstringarraystatic; str64.pstringbase = str64.poldstringbase = str64.pstringarraystatic;
str64.plast = str64.pstringbase + 1; str64.plast = str64.pstringbase + 1;
} }
#else #else // !XASH_64BIT
Mem_EmptyPool( svgame.stringspool ); Mem_EmptyPool( svgame.stringspool );
#endif #endif // !XASH_64BIT
} }
/* /*
@ -3037,7 +3035,7 @@ this helps not to lose strings that belongs to static game part
*/ */
void SV_SetStringArrayMode( qboolean dynamic ) void SV_SetStringArrayMode( qboolean dynamic )
{ {
#ifdef XASH_64BIT #if XASH_64BIT
Con_Reportf( "%s(%d) %d\n", __func__, dynamic, str64.dynamic ); Con_Reportf( "%s(%d) %d\n", __func__, dynamic, str64.dynamic );
if( dynamic == str64.dynamic ) if( dynamic == str64.dynamic )
@ -3046,11 +3044,11 @@ void SV_SetStringArrayMode( qboolean dynamic )
str64.dynamic = dynamic; str64.dynamic = dynamic;
SV_EmptyStringPool(); SV_EmptyStringPool();
#endif #endif // !XASH_64BIT
} }
#if XASH_AMD64 && XASH_LINUX && !XASH_ANDROID #if XASH_AMD64 && XASH_LINUX && !XASH_ANDROID
#define USE_MMAP #define USE_MMAP 1
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
@ -3066,7 +3064,7 @@ this case need patched game dll with MAKE_STRING checking ptrdiff size
*/ */
static void SV_AllocStringPool( void ) static void SV_AllocStringPool( void )
{ {
#ifdef XASH_64BIT #if XASH_64BIT
void *ptr = NULL; void *ptr = NULL;
string lenstr; string lenstr;
@ -3081,7 +3079,7 @@ static void SV_AllocStringPool( void )
if( Sys_CheckParm( "-str64dup" ) ) if( Sys_CheckParm( "-str64dup" ) )
str64.allowdup = true; str64.allowdup = true;
#ifdef USE_MMAP #if USE_MMAP
{ {
uint flags; uint flags;
size_t pagesize = sysconf( _SC_PAGESIZE ); size_t pagesize = sysconf( _SC_PAGESIZE );
@ -3135,35 +3133,37 @@ static void SV_AllocStringPool( void )
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 ); ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
} }
} }
#else #else // !USE_MMAP
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 ); ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
#endif #endif // !USE_MMAP
str64.pstringarray = ptr; str64.pstringarray = ptr;
str64.pstringarraystatic = (byte*)ptr + str64.maxstringarray; str64.pstringarraystatic = (byte*)ptr + str64.maxstringarray;
str64.pstringbase = str64.poldstringbase = ptr; str64.pstringbase = str64.poldstringbase = ptr;
str64.plast = (byte*)ptr + 1; str64.plast = (byte*)ptr + 1;
svgame.globals->pStringBase = ptr; svgame.globals->pStringBase = ptr;
#else #else // !XASH_64BIT
svgame.stringspool = Mem_AllocPool( "Server Strings" ); svgame.stringspool = Mem_AllocPool( "Server Strings" );
svgame.globals->pStringBase = ""; svgame.globals->pStringBase = "";
#endif #endif // !XASH_64BIT
} }
static void SV_FreeStringPool( void ) static void SV_FreeStringPool( void )
{ {
#ifdef XASH_64BIT #if XASH_64BIT
Con_Reportf( "%s()\n", __func__ ); Con_Reportf( "%s()\n", __func__ );
#ifdef USE_MMAP #if USE_MMAP
if( str64.pstringarray != str64.staticstringarray ) if( str64.pstringarray != str64.staticstringarray )
munmap( str64.pstringarray, (str64.maxstringarray * 2) & ~(sysconf( _SC_PAGESIZE ) - 1) ); munmap( str64.pstringarray, (str64.maxstringarray * 2) & ~(sysconf( _SC_PAGESIZE ) - 1) );
else else
#endif #endif // USE_MMAP
{
Mem_Free( str64.staticstringarray ); Mem_Free( str64.staticstringarray );
#else }
#else // !XASH_64BIT
Mem_FreePool( &svgame.stringspool ); Mem_FreePool( &svgame.stringspool );
#endif #endif // !XASH_64BIT
} }
/* /*
@ -3234,9 +3234,7 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
{ {
char *newString = NULL; char *newString = NULL;
uint len; uint len;
#ifdef XASH_64BIT
int cmp; int cmp;
#endif
if( svgame.physFuncs.pfnAllocString != NULL ) if( svgame.physFuncs.pfnAllocString != NULL )
{ {
@ -3252,7 +3250,7 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
return i; return i;
} }
#ifdef XASH_64BIT #if XASH_64BIT
cmp = 1; cmp = 1;
if( !str64.allowdup ) if( !str64.allowdup )
@ -3290,18 +3288,18 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
str64.maxalloc = newString - str64.pstringarray; str64.maxalloc = newString - str64.pstringarray;
return newString - svgame.globals->pStringBase; return newString - svgame.globals->pStringBase;
#else #else // !XASH_64BIT
len = SV_ProcessString( NULL, szValue ); len = SV_ProcessString( NULL, szValue );
newString = Mem_Malloc( svgame.stringspool, len ); newString = Mem_Malloc( svgame.stringspool, len );
SV_ProcessString( newString, szValue ); SV_ProcessString( newString, szValue );
return newString - svgame.globals->pStringBase; return newString - svgame.globals->pStringBase;
#endif #endif // !XASH_64BIT
} }
void SV_PrintStr64Stats_f( void ) void SV_PrintStr64Stats_f( void )
{ {
#ifdef XASH_64BIT #if XASH_64BIT
Con_Printf( "====================\n" ); Con_Printf( "====================\n" );
Con_Printf( "64 bit string pool statistics\n" ); Con_Printf( "64 bit string pool statistics\n" );
Con_Printf( "====================\n" ); Con_Printf( "====================\n" );
@ -3310,9 +3308,9 @@ void SV_PrintStr64Stats_f( void )
Con_Printf( "maximum array usage: %lu\n", str64.maxalloc ); Con_Printf( "maximum array usage: %lu\n", str64.maxalloc );
Con_Printf( "overflow counter: %lu\n", str64.numoverflows ); Con_Printf( "overflow counter: %lu\n", str64.numoverflows );
Con_Printf( "dup string counter: %lu\n", str64.numdups ); Con_Printf( "dup string counter: %lu\n", str64.numdups );
#else #else // !XASH_64BIT
Con_Printf( "Not implemented\n" ); Con_Printf( "Not implemented\n" );
#endif #endif // !XASH_64BIT
} }
/* /*
@ -3326,7 +3324,7 @@ string_t SV_MakeString( const char *szValue )
{ {
if( svgame.physFuncs.pfnMakeString != NULL ) if( svgame.physFuncs.pfnMakeString != NULL )
return svgame.physFuncs.pfnMakeString( szValue ); return svgame.physFuncs.pfnMakeString( szValue );
#ifdef XASH_64BIT #if XASH_64BIT
{ {
long long ptrdiff = szValue - svgame.globals->pStringBase; long long ptrdiff = szValue - svgame.globals->pStringBase;
if( ptrdiff > INT_MAX || ptrdiff < INT_MIN ) if( ptrdiff > INT_MAX || ptrdiff < INT_MIN )
@ -3334,9 +3332,9 @@ string_t SV_MakeString( const char *szValue )
else else
return (int)ptrdiff; return (int)ptrdiff;
} }
#else #else // !XASH_64BIT
return szValue - svgame.globals->pStringBase; return szValue - svgame.globals->pStringBase;
#endif #endif // !XASH_64BIT
} }
/* /*

View File

@ -128,7 +128,6 @@ def configure(conf):
conf.define_cond('XASH_ENABLE_MAIN', conf.env.DISABLE_LAUNCHER) conf.define_cond('XASH_ENABLE_MAIN', conf.env.DISABLE_LAUNCHER)
conf.define_cond('XASH_NO_ASYNC_NS_RESOLVE', conf.options.NO_ASYNC_RESOLVE) conf.define_cond('XASH_NO_ASYNC_NS_RESOLVE', conf.options.NO_ASYNC_RESOLVE)
conf.define_cond('SUPPORT_BSP2_FORMAT', conf.options.SUPPORT_BSP2_FORMAT) conf.define_cond('SUPPORT_BSP2_FORMAT', conf.options.SUPPORT_BSP2_FORMAT)
conf.define_cond('XASH_64BIT', conf.env.DEST_SIZEOF_VOID_P != 4)
conf.define_cond('DBGHELP', conf.env.DEST_OS == 'win32') conf.define_cond('DBGHELP', conf.env.DEST_OS == 'win32')
conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1 conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1

View File

@ -247,6 +247,10 @@ Then you can use another oneliner to query all variables:
#error "Place your architecture name here! If this is a mistake, try to fix conditions above and report a bug" #error "Place your architecture name here! If this is a mistake, try to fix conditions above and report a bug"
#endif #endif
#if !XASH_64BIT && ( defined( __LP64__ ) || defined( _LP64 ))
#define XASH_64BIT 1
#endif
#if XASH_ARM == 8 #if XASH_ARM == 8
#define XASH_ARMv8 1 #define XASH_ARMv8 1
#elif XASH_ARM == 7 #elif XASH_ARM == 7