2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 01:45:19 +01:00

Revert "Revert ABI2, it wasn't meant to end up in master branch."

This reverts commit 950d210ec5.
This commit is contained in:
Alibek Omarov 2024-09-05 04:33:03 +03:00
parent 950d210ec5
commit b2273b1bce
5 changed files with 29 additions and 212 deletions

View File

@ -14,6 +14,9 @@
****/ ****/
#ifndef CONST_H #ifndef CONST_H
#define CONST_H #define CONST_H
#include <stddef.h> // ptrdiff_t
// //
// Constants shared by the engine and dlls // Constants shared by the engine and dlls
// This header file included by engine files and DLL files. // This header file included by engine files and DLL files.
@ -721,7 +724,7 @@ enum
}; };
typedef int func_t; typedef int func_t;
typedef int string_t; typedef ptrdiff_t string_t;
typedef unsigned short word; typedef unsigned short word;

View File

@ -126,14 +126,20 @@ dll_user_t *FS_FindLibrary( const char *dllname, qboolean directpath )
============================================================================= =============================================================================
*/ */
static void COM_GenerateCommonLibraryName( const char *name, const char *ext, char *out, size_t size ) static void COM_GenerateCommonLibraryName( const char *name, const char *ext, const char *suffix, char *out, size_t size )
{ {
#if ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) && XASH_X86 #if ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) && XASH_X86
Q_snprintf( out, size, "%s.%s", name, ext ); if( suffix )
Q_snprintf( out, size, "%s_%s.%s", name, suffix, ext );
else Q_snprintf( out, size, "%s.%s", name, ext );
#elif ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) #elif ( XASH_WIN32 || XASH_LINUX || XASH_APPLE )
Q_snprintf( out, size, "%s_%s.%s", name, Q_buildarch(), ext ); if( suffix )
Q_snprintf( out, size, "%s_%s_%s.%s", name, Q_buildarch(), suffix, ext );
else Q_snprintf( out, size, "%s_%s.%s", name, Q_buildarch(), ext );
#else #else
Q_snprintf( out, size, "%s_%s_%s.%s", name, Q_buildos(), Q_buildarch(), ext ); if( suffix )
Q_snprintf( out, size, "%s_%s_%s_%s.%s", name, Q_buildos(), Q_buildarch(), suffix, ext );
else Q_snprintf( out, size, "%s_%s_%s.%s", name, Q_buildos(), Q_buildarch(), ext );
#endif #endif
} }
@ -154,7 +160,7 @@ static void COM_GenerateClientLibraryPath( const char *name, char *out, size_t s
// we don't have any library prefixes, so we can safely append dll_path here // we don't have any library prefixes, so we can safely append dll_path here
Q_snprintf( dllpath, sizeof( dllpath ), "%s/%s", GI->dll_path, name ); Q_snprintf( dllpath, sizeof( dllpath ), "%s/%s", GI->dll_path, name );
COM_GenerateCommonLibraryName( dllpath, OS_LIB_EXT, out, size ); COM_GenerateCommonLibraryName( dllpath, OS_LIB_EXT, NULL, out, size );
#endif #endif
} }
@ -211,7 +217,13 @@ static void COM_GenerateServerLibraryPath( char *out, size_t size )
COM_StripExtension( dllpath ); COM_StripExtension( dllpath );
COM_StripIntelSuffix( dllpath ); COM_StripIntelSuffix( dllpath );
COM_GenerateCommonLibraryName( dllpath, ext, out, size ); #if XASH_ARCH_USES_ONLY_ABI2
COM_GenerateCommonLibraryName( dllpath, ext, NULL, out, size );
#elif XASH_64BIT
COM_GenerateCommonLibraryName( dllpath, ext, "st64", out, size );
#else
COM_GenerateCommonLibraryName( dllpath, ext, NULL, out, size );
#endif
#endif #endif
} }

View File

@ -125,7 +125,7 @@ typedef struct enginefuncs_s
void (*pfnAngleVectors)( const float *rgflVector, float *forward, float *right, float *up ); void (*pfnAngleVectors)( const float *rgflVector, float *forward, float *right, float *up );
edict_t* (*pfnCreateEntity)( void ); edict_t* (*pfnCreateEntity)( void );
void (*pfnRemoveEntity)( edict_t* e ); void (*pfnRemoveEntity)( edict_t* e );
edict_t* (*pfnCreateNamedEntity)( int className ); edict_t* (*pfnCreateNamedEntity)( string_t className );
void (*pfnMakeStatic)( edict_t *ent ); void (*pfnMakeStatic)( edict_t *ent );
int (*pfnEntIsOnFloor)( edict_t *e ); int (*pfnEntIsOnFloor)( edict_t *e );
int (*pfnDropToFloor)( edict_t* e ); int (*pfnDropToFloor)( edict_t* e );
@ -168,8 +168,8 @@ typedef struct enginefuncs_s
void* (*pfnPvAllocEntPrivateData)( edict_t *pEdict, long cb ); void* (*pfnPvAllocEntPrivateData)( edict_t *pEdict, long cb );
void* (*pfnPvEntPrivateData)( edict_t *pEdict ); void* (*pfnPvEntPrivateData)( edict_t *pEdict );
void (*pfnFreeEntPrivateData)( edict_t *pEdict ); void (*pfnFreeEntPrivateData)( edict_t *pEdict );
const char *(*pfnSzFromIndex)( int iString ); const char *(*pfnSzFromIndex)( string_t iString );
int (*pfnAllocString)( const char *szValue ); string_t (*pfnAllocString)( const char *szValue );
struct entvars_s *(*pfnGetVarsOfEnt)( edict_t *pEdict ); struct entvars_s *(*pfnGetVarsOfEnt)( edict_t *pEdict );
edict_t* (*pfnPEntityOfEntOffset)( int iEntOffset ); edict_t* (*pfnPEntityOfEntOffset)( int iEntOffset );
int (*pfnEntOffsetOfPEntity)( const edict_t *pEdict ); int (*pfnEntOffsetOfPEntity)( const edict_t *pEdict );

View File

@ -85,8 +85,8 @@ typedef struct entvars_s
int modelindex; int modelindex;
string_t model; string_t model;
int viewmodel; // player's viewmodel string_t viewmodel; // player's viewmodel
int weaponmodel; // what other players see string_t weaponmodel; // what other players see
vec3_t absmin; // BB max translated to world coord vec3_t absmin; // BB max translated to world coord
vec3_t absmax; // BB max translated to world coord vec3_t absmax; // BB max translated to world coord
@ -144,7 +144,7 @@ typedef struct entvars_s
int flags; int flags;
int colormap; // lowbyte topcolor, highbyte bottomcolor int colormap; // lowbyte topcolor, highbyte bottomcolor
int team; string_t team;
float max_health; float max_health;
float teleport_time; float teleport_time;

View File

@ -3000,25 +3000,6 @@ static void *GAME_EXPORT pfnPvEntPrivateData( edict_t *pEdict )
} }
#ifdef XASH_64BIT
static struct str64_s
{
size_t maxstringarray;
qboolean allowdup;
char *staticstringarray;
char *pstringarray;
char *pstringarraystatic;
char *pstringbase;
char *poldstringbase;
char *plast;
qboolean dynamic;
size_t maxalloc;
size_t numdups;
size_t numoverflows;
size_t totalalloc;
} str64;
#endif
/* /*
================== ==================
SV_EmptyStringPool SV_EmptyStringPool
@ -3028,17 +3009,7 @@ Free strings on server stop. Reset string pointer on 64 bits
*/ */
void SV_EmptyStringPool( void ) void SV_EmptyStringPool( void )
{ {
#ifdef XASH_64BIT
if( str64.dynamic ) // switch only after array fill (more space for multiplayer games)
str64.pstringbase = str64.pstringarray;
else
{
str64.pstringbase = str64.poldstringbase = str64.pstringarraystatic;
str64.plast = str64.pstringbase + 1;
}
#else
Mem_EmptyPool( svgame.stringspool ); Mem_EmptyPool( svgame.stringspool );
#endif
} }
/* /*
@ -3052,23 +3023,8 @@ 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
Con_Reportf( "%s(%d) %d\n", __func__, dynamic, str64.dynamic );
if( dynamic == str64.dynamic )
return;
str64.dynamic = dynamic;
SV_EmptyStringPool();
#endif
} }
#if XASH_AMD64 && XASH_LINUX && !XASH_ANDROID
#define USE_MMAP
#include <sys/mman.h>
#endif
/* /*
================== ==================
SV_AllocStringPool SV_AllocStringPool
@ -3081,104 +3037,13 @@ 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
void *ptr = NULL;
string lenstr;
Con_Reportf( "%s()\n", __func__ );
if( Sys_GetParmFromCmdLine( "-str64alloc", lenstr ) )
{
str64.maxstringarray = Q_atoi( lenstr );
if( str64.maxstringarray < 1024 || str64.maxstringarray >= INT_MAX )
str64.maxstringarray = 65536;
}
else str64.maxstringarray = 65536;
if( Sys_CheckParm( "-str64dup" ) )
str64.allowdup = true;
#ifdef USE_MMAP
{
uint flags;
size_t pagesize = sysconf( _SC_PAGESIZE );
int arrlen = (str64.maxstringarray * 2) & ~(pagesize - 1);
void *base = svgame.dllFuncs.pfnGameInit;
void *start = svgame.hInstance - arrlen;
#if defined(MAP_ANON)
flags = MAP_ANON | MAP_PRIVATE;
#elif defined(MAP_ANONYMOUS)
flags = MAP_ANONYMOUS | MAP_PRIVATE;
#endif
while( start - base > INT_MIN )
{
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, flags, 0, 0 );
if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX )
{
ptr = mapptr;
break;
}
if( mapptr ) munmap( mapptr, arrlen );
start -= arrlen;
}
if( !ptr )
{
start = base;
while( start - base < INT_MAX )
{
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, flags, 0, 0 );
if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX )
{
ptr = mapptr;
break;
}
if( mapptr ) munmap( mapptr, arrlen );
start += arrlen;
}
}
if( ptr )
{
Con_Reportf( "%s: Allocated string array near the server library: %p %p\n", __func__, base, ptr );
}
else
{
Con_Reportf( "%s: Failed to allocate string array near the server library!\n", __func__ );
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
}
}
#else
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
#endif
str64.pstringarray = ptr;
str64.pstringarraystatic = (byte*)ptr + str64.maxstringarray;
str64.pstringbase = str64.poldstringbase = ptr;
str64.plast = (byte*)ptr + 1;
svgame.globals->pStringBase = ptr;
#else
svgame.stringspool = Mem_AllocPool( "Server Strings" ); svgame.stringspool = Mem_AllocPool( "Server Strings" );
svgame.globals->pStringBase = ""; svgame.globals->pStringBase = "";
#endif
} }
static void SV_FreeStringPool( void ) static void SV_FreeStringPool( void )
{ {
#ifdef XASH_64BIT
Con_Reportf( "%s()\n", __func__ );
#ifdef USE_MMAP
if( str64.pstringarray != str64.staticstringarray )
munmap( str64.pstringarray, (str64.maxstringarray * 2) & ~(sysconf( _SC_PAGESIZE ) - 1) );
else
#endif
Mem_Free( str64.staticstringarray );
#else
Mem_FreePool( &svgame.stringspool ); Mem_FreePool( &svgame.stringspool );
#endif
} }
/* /*
@ -3249,9 +3114,6 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
{ {
char *newString = NULL; char *newString = NULL;
uint len; uint len;
#ifdef XASH_64BIT
int cmp;
#endif
if( svgame.physFuncs.pfnAllocString != NULL ) if( svgame.physFuncs.pfnAllocString != NULL )
{ {
@ -3267,67 +3129,16 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
return i; return i;
} }
#ifdef XASH_64BIT
cmp = 1;
if( !str64.allowdup )
{
for( newString = str64.poldstringbase + 1;
newString < str64.plast && ( cmp = Q_strcmp( newString, szValue ) );
newString += Q_strlen( newString ) + 1 );
}
if( cmp )
{
uint len = SV_ProcessString( NULL, szValue );
if( str64.plast - str64.poldstringbase + len + 1 > str64.maxstringarray )
{
str64.plast = str64.pstringbase + 1;
str64.poldstringbase = str64.pstringbase;
str64.numoverflows++;
}
//MsgDev( D_NOTE, "SV_AllocString: %ld %s\n", str64.plast - svgame.globals->pStringBase, szValue );
SV_ProcessString( str64.plast, szValue );
str64.totalalloc += len;
newString = str64.plast;
str64.plast += len;
}
else
{
str64.numdups++;
//MsgDev( D_NOTE, "SV_AllocString: dup %ld %s\n", newString - svgame.globals->pStringBase, szValue );
}
if( newString - str64.pstringarray > str64.maxalloc )
str64.maxalloc = newString - str64.pstringarray;
return newString - svgame.globals->pStringBase;
#else
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
} }
void SV_PrintStr64Stats_f( void ) void SV_PrintStr64Stats_f( void )
{ {
#ifdef XASH_64BIT
Con_Printf( "====================\n" );
Con_Printf( "64 bit string pool statistics\n" );
Con_Printf( "====================\n" );
Con_Printf( "string array size: %lu\n", str64.maxstringarray );
Con_Printf( "total alloc %lu\n", str64.totalalloc );
Con_Printf( "maximum array usage: %lu\n", str64.maxalloc );
Con_Printf( "overflow counter: %lu\n", str64.numoverflows );
Con_Printf( "dup string counter: %lu\n", str64.numdups );
#else
Con_Printf( "Not implemented\n" ); Con_Printf( "Not implemented\n" );
#endif
} }
/* /*
@ -3341,17 +3152,8 @@ 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
{
long long ptrdiff = szValue - svgame.globals->pStringBase;
if( ptrdiff > INT_MAX || ptrdiff < INT_MIN )
return SV_AllocString(szValue);
else
return (int)ptrdiff;
}
#else
return szValue - svgame.globals->pStringBase; return szValue - svgame.globals->pStringBase;
#endif
} }
/* /*