From f9205825b63e8b5fcf71606e218bc81af491d364 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:55:29 +0400 Subject: [PATCH 001/121] engine: platform: sdl: fixed psvita & nswitch platform initializing --- engine/platform/sdl/sys_sdl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/platform/sdl/sys_sdl.c b/engine/platform/sdl/sys_sdl.c index 75a8b613b..80d93f92e 100644 --- a/engine/platform/sdl/sys_sdl.c +++ b/engine/platform/sdl/sys_sdl.c @@ -63,15 +63,16 @@ void Platform_Init( void ) SDL_StopTextInput(); #endif // XASH_SDL == 2 -#if XASH_NSWITCH - NSwitch_Init(); -#elif XASH_WIN32 +#if XASH_WIN32 Wcon_CreateConsole(); // system console used by dedicated server or show fatal errors #elif XASH_POSIX Posix_Daemonize(); -#elif XASH_PSVITA +#if XASH_PSVITA PSVita_Init(); +#elif XASH_NSWITCH + NSwitch_Init(); #endif +#endif // XASH_POSIX SDLash_InitCursors(); } From 5c1e06ae749dbf5443180a0cc9b4748700424b40 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 02:37:19 +0300 Subject: [PATCH 002/121] public: crclib: optimize COM_HashKey, implement typical djb hashing as this function is used for hashtables with string lookup --- public/crclib.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/crclib.c b/public/crclib.c index 95013b583..0312f8205 100644 --- a/public/crclib.c +++ b/public/crclib.c @@ -457,10 +457,11 @@ returns hash key for string */ uint COM_HashKey( const char *string, uint hashSize ) { - uint i, hashKey = 0; + int hashKey = 5381; + unsigned char i; - for( i = 0; string[i]; i++ ) - hashKey = (hashKey + i) * 37 + Q_tolower( string[i] ); + while(( i = *string++ )) + hashKey = ( hashKey << 5 ) + hashKey + ( i & 0xDF ); - return (hashKey % hashSize); + return hashKey & ( hashSize - 1 ); } From 115ed82c19cec4b45faaf35777948ac71709cc08 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 02:39:02 +0300 Subject: [PATCH 003/121] engine: common: base_cmd: static-ize internal fuctions --- engine/common/base_cmd.c | 23 ++++++++++++++++------- engine/common/base_cmd.h | 11 ----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/engine/common/base_cmd.c b/engine/common/base_cmd.c index efdf718ed..1bb60c3ca 100644 --- a/engine/common/base_cmd.c +++ b/engine/common/base_cmd.c @@ -17,10 +17,20 @@ GNU General Public License for more details. #include "base_cmd.h" #include "cdll_int.h" -// TODO: use another hash function, as COM_HashKey depends on string length #define HASH_SIZE 128 // 128 * 4 * 4 == 2048 bytes + +typedef struct base_command_hashmap_s +{ + base_command_t *basecmd; // base command: cvar, alias or command + const char *name; // key for searching + base_command_type_e type; // type for faster searching + struct base_command_hashmap_s *next; +} base_command_hashmap_t; + static base_command_hashmap_t *hashed_cmds[HASH_SIZE]; +#define BaseCmd_HashKey( x ) COM_HashKey( name, HASH_SIZE ) + /* ============ BaseCmd_FindInBucket @@ -28,7 +38,7 @@ BaseCmd_FindInBucket Find base command in bucket ============ */ -base_command_hashmap_t *BaseCmd_FindInBucket( base_command_hashmap_t *bucket, base_command_type_e type, const char *name ) +static base_command_hashmap_t *BaseCmd_FindInBucket( base_command_hashmap_t *bucket, base_command_type_e type, const char *name ) { base_command_hashmap_t *i = bucket; for( ; i && ( i->type != type || Q_stricmp( name, i->name ) ); // filter out @@ -44,9 +54,9 @@ BaseCmd_GetBucket Get bucket which contain basecmd by given name ============ */ -base_command_hashmap_t *BaseCmd_GetBucket( const char *name ) +static base_command_hashmap_t *BaseCmd_GetBucket( const char *name ) { - return hashed_cmds[ COM_HashKey( name, HASH_SIZE ) ]; + return hashed_cmds[ BaseCmd_HashKey( name ) ]; } /* @@ -73,7 +83,7 @@ BaseCmd_Find Find every type of base command and write into arguments ============ */ -void BaseCmd_FindAll(const char *name, base_command_t **cmd, base_command_t **alias, base_command_t **cvar) +void BaseCmd_FindAll( const char *name, base_command_t **cmd, base_command_t **alias, base_command_t **cvar ) { base_command_hashmap_t *base = BaseCmd_GetBucket( name ); base_command_hashmap_t *i = base; @@ -101,7 +111,6 @@ void BaseCmd_FindAll(const char *name, base_command_t **cmd, base_command_t **al } } } - } /* @@ -159,7 +168,7 @@ Remove base command from hashmap */ void BaseCmd_Remove( base_command_type_e type, const char *name ) { - uint hash = COM_HashKey( name, HASH_SIZE ); + uint hash = BaseCmd_HashKey( name ); base_command_hashmap_t *i, *prev; for( prev = NULL, i = hashed_cmds[hash]; i && diff --git a/engine/common/base_cmd.h b/engine/common/base_cmd.h index f507c9e1e..c99a55d2c 100644 --- a/engine/common/base_cmd.h +++ b/engine/common/base_cmd.h @@ -17,8 +17,6 @@ GNU General Public License for more details. #ifndef BASE_CMD_H #define BASE_CMD_H -// TODO: Find cases when command hashmap works incorrect -// and maybe disable it #define XASH_HASHED_VARS #ifdef XASH_HASHED_VARS @@ -33,18 +31,9 @@ typedef enum base_command_type typedef void base_command_t; -typedef struct base_command_hashmap_s -{ - base_command_t *basecmd; // base command: cvar, alias or command - const char *name; // key for searching - base_command_type_e type; // type for faster searching - struct base_command_hashmap_s *next; -} base_command_hashmap_t; void BaseCmd_Init( void ); -base_command_hashmap_t *BaseCmd_GetBucket( const char *name ); -base_command_hashmap_t *BaseCmd_FindInBucket( base_command_hashmap_t *bucket, base_command_type_e type, const char *name ); base_command_t *BaseCmd_Find( base_command_type_e type, const char *name ); void BaseCmd_FindAll( const char *name, base_command_t **cmd, base_command_t **alias, base_command_t **cvar ); From 8e45a43ad2e638add15a5028a8b17b60dcdb0c77 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 02:39:54 +0300 Subject: [PATCH 004/121] engine: common: base_cmd: alphabetically order inserts for faster lookups --- engine/common/base_cmd.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/engine/common/base_cmd.c b/engine/common/base_cmd.c index 1bb60c3ca..e47a470e3 100644 --- a/engine/common/base_cmd.c +++ b/engine/common/base_cmd.c @@ -122,15 +122,23 @@ Add new typed base command to hashmap */ void BaseCmd_Insert( base_command_type_e type, base_command_t *basecmd, const char *name ) { - uint hash = COM_HashKey( name, HASH_SIZE ); - base_command_hashmap_t *elem; + base_command_hashmap_t *elem, *cur, *find; + uint hash = BaseCmd_HashKey( name ); elem = Z_Malloc( sizeof( base_command_hashmap_t ) ); elem->basecmd = basecmd; elem->type = type; elem->name = name; - elem->next = hashed_cmds[hash]; - hashed_cmds[hash] = elem; + + // link the variable in alphanumerical order + for( cur = NULL, find = hashed_cmds[hash]; + find && Q_strcmp( find->name, elem->name ) < 0; + cur = find, find = find->next ); + + if( cur ) cur->next = elem; + else hashed_cmds[hash] = elem; + + elem->next = find; } /* From bcbd1a59c622e8311ccf9bd59e80b695668878b8 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 02:40:48 +0300 Subject: [PATCH 005/121] engine: common: base_cmd: add a simple benchmark within basecmd_test command --- engine/common/base_cmd.c | 77 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/engine/common/base_cmd.c b/engine/common/base_cmd.c index e47a470e3..732a5b1e1 100644 --- a/engine/common/base_cmd.c +++ b/engine/common/base_cmd.c @@ -238,23 +238,27 @@ void BaseCmd_Stats_f( void ) if( len > maxsize ) maxsize = len; + } - Con_Printf( "Base command stats:\n"); - Con_Printf( "Bucket minimal length: %d\n", minsize ); - Con_Printf( "Bucket maximum length: %d\n", maxsize ); - Con_Printf( "Empty buckets: %d\n", empty ); + Con_Printf( "min length: %d, max length: %d, empty: %d\n", minsize, maxsize, empty ); } +typedef struct +{ + qboolean valid; + int lookups; +} basecmd_test_stats_t; + static void BaseCmd_CheckCvars( const char *key, const char *value, const void *unused, void *ptr ) { - base_command_t *v = BaseCmd_Find( HM_CVAR, key ); - qboolean *invalid = ptr; + basecmd_test_stats_t *stats = ptr; - if( !v ) + stats->lookups++; + if( !BaseCmd_Find( HM_CVAR, key )) { Con_Printf( "Cvar %s is missing in basecmd\n", key ); - *invalid = true; + stats->valid = false; } } @@ -267,38 +271,51 @@ testing order matches cbuf execute */ void BaseCmd_Test_f( void ) { - void *cmd; - cmdalias_t *a; - qboolean invalid = false; + basecmd_test_stats_t stats; + double start, end, dt; + int i; + + stats.valid = true; + stats.lookups = 0; + + start = Sys_DoubleTime() * 1000; - // Cmd_LookupCmds don't allows to check alias, so just iterate - for( a = Cmd_AliasGetList(); a; a = a->next ) + for( i = 0; i < 1000; i++ ) { - base_command_t *v = BaseCmd_Find( HM_CMDALIAS, a->name ); + cmdalias_t *a; + void *cmd; - if( !v ) + // Cmd_LookupCmds don't allows to check alias, so just iterate + for( a = Cmd_AliasGetList(); a; a = a->next, stats.lookups++ ) { - Con_Printf( "Alias %s is missing in basecmd\n", a->name ); - invalid = true; + if( !BaseCmd_Find( HM_CMDALIAS, a->name )) + { + Con_Printf( "Alias %s is missing in basecmd\n", a->name ); + stats.valid = false; + } } - } - - for( cmd = Cmd_GetFirstFunctionHandle(); cmd; - cmd = Cmd_GetNextFunctionHandle( cmd ) ) - { - base_command_t *v = BaseCmd_Find( HM_CMD, Cmd_GetName( cmd ) ); - if( !v ) + for( cmd = Cmd_GetFirstFunctionHandle(); cmd; + cmd = Cmd_GetNextFunctionHandle( cmd ), stats.lookups++ ) { - Con_Printf( "Command %s is missing in basecmd\n", Cmd_GetName( cmd ) ); - invalid = true; + if( !BaseCmd_Find( HM_CMD, Cmd_GetName( cmd ))) + { + Con_Printf( "Command %s is missing in basecmd\n", Cmd_GetName( cmd )); + stats.valid = false; + } } + + Cvar_LookupVars( 0, NULL, &stats.valid, (setpair_t)BaseCmd_CheckCvars ); } - Cvar_LookupVars( 0, NULL, &invalid, (setpair_t)BaseCmd_CheckCvars ); + end = Sys_DoubleTime() * 1000; - if( !invalid ) - { + dt = end - start; + + if( !stats.valid ) Con_Printf( "BaseCmd is valid\n" ); - } + + Con_Printf( "Test took %.3f ms, %d lookups, %.3f us/lookup\n", dt, stats.lookups, dt / stats.lookups * 1000 ); + + BaseCmd_Stats_f(); } From fb6e310eab093919a9d97d83416a83dc00661771 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 02:44:59 +0300 Subject: [PATCH 006/121] public: move va() function back to engine, it's not recommended to use in shared modules --- engine/common/common.c | 24 ++++++++++++++++++++++++ engine/common/common.h | 1 + public/crtlib.c | 24 ------------------------ public/crtlib.h | 1 - 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/engine/common/common.c b/engine/common/common.c index 684718ddd..45756357c 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -151,6 +151,30 @@ int GAME_EXPORT COM_RandomLong( int lLow, int lHigh ) return lLow + (n % x); } +/* +============ +va + +does a varargs printf into a temp buffer, +so I don't need to have varargs versions +of all text functions. +============ +*/ +char *va( const char *format, ... ) +{ + va_list argptr; + static char string[16][MAX_VA_STRING], *s; + static int stringindex = 0; + + s = string[stringindex]; + stringindex = (stringindex + 1) & 15; + va_start( argptr, format ); + Q_vsnprintf( s, sizeof( string[0] ), format, argptr ); + va_end( argptr ); + + return s; +} + /* =============================================================================== diff --git a/engine/common/common.h b/engine/common/common.h index 2ff096855..e80d8eea1 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -844,6 +844,7 @@ void COM_NormalizeAngles( vec3_t angles ); int COM_FileSize( const char *filename ); void COM_FreeFile( void *buffer ); int COM_CompareFileTime( const char *filename1, const char *filename2, int *iCompare ); +char *va( const char *format, ... ) _format( 1 ); // soundlib shared exports qboolean S_Init( void ); diff --git a/public/crtlib.c b/public/crtlib.c index 2a67f476d..4ca8484a8 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -619,30 +619,6 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) return out; } -/* -============ -va - -does a varargs printf into a temp buffer, -so I don't need to have varargs versions -of all text functions. -============ -*/ -char *va( const char *format, ... ) -{ - va_list argptr; - static char string[16][MAX_VA_STRING], *s; - static int stringindex = 0; - - s = string[stringindex]; - stringindex = (stringindex + 1) & 15; - va_start( argptr, format ); - Q_vsnprintf( s, sizeof( string[0] ), format, argptr ); - va_end( argptr ); - - return s; -} - /* ============ COM_FileBase diff --git a/public/crtlib.h b/public/crtlib.h index 4f1595847..5c4187a51 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -90,7 +90,6 @@ int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 ); void COM_StripColors( const char *in, char *out ); #define Q_memprint( val ) Q_pretifymem( val, 2 ) char *Q_pretifymem( float value, int digitsafterdecimal ); -char *va( const char *format, ... ) _format( 1 ); void COM_FileBase( const char *in, char *out ); const char *COM_FileExtension( const char *in ); void COM_DefaultExtension( char *path, const char *extension ); From fb2ba6a6e2c61e661c03ab69741f77e0c51493a1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:12:46 +0300 Subject: [PATCH 007/121] engine: common: net_buffer: add MSG_WriteStringf wrapper --- engine/common/net_buffer.c | 12 ++++++++++++ engine/common/net_buffer.h | 1 + 2 files changed, 13 insertions(+) diff --git a/engine/common/net_buffer.c b/engine/common/net_buffer.c index 567047f20..2ec7b0084 100644 --- a/engine/common/net_buffer.c +++ b/engine/common/net_buffer.c @@ -452,6 +452,18 @@ qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr ) return !sb->bOverflow; } +qboolean MSG_WriteStringf( sizebuf_t *sb, const char *format, ... ) +{ + va_list va; + char buf[MAX_VA_STRING]; + + va_start( va, format ); + Q_vsnprintf( buf, sizeof( buf ), format, va ); + va_end( va ); + + return MSG_WriteString( sb, buf ); +} + int MSG_ReadOneBit( sizebuf_t *sb ) { if( !MSG_Overflow( sb, 1 )) diff --git a/engine/common/net_buffer.h b/engine/common/net_buffer.h index 62ded8dca..0be9e25b3 100644 --- a/engine/common/net_buffer.h +++ b/engine/common/net_buffer.h @@ -102,6 +102,7 @@ void MSG_WriteVec3Coord( sizebuf_t *sb, const float *fa ); void MSG_WriteVec3Angles( sizebuf_t *sb, const float *fa ); qboolean MSG_WriteBytes( sizebuf_t *sb, const void *pBuf, int nBytes ); // same as MSG_WriteData qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr ); // returns false if it overflows the buffer. +qboolean MSG_WriteStringf( sizebuf_t *sb, const char *format, ... ) _format( 2 ); // helper functions _inline int MSG_GetNumBytesWritten( sizebuf_t *sb ) { return BitByte( sb->iCurBit ); } From ba1cf25314077e2f9d4502749bd31e27123bffac Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:13:52 +0300 Subject: [PATCH 008/121] engine: convert MSG_WriteString with va to MSG_WriteStringf --- engine/client/cl_custom.c | 2 +- engine/client/cl_parse.c | 6 +++--- engine/server/sv_client.c | 14 +++++++------- engine/server/sv_custom.c | 2 +- engine/server/sv_game.c | 2 +- engine/server/sv_save.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/engine/client/cl_custom.c b/engine/client/cl_custom.c index b279b3610..b028066e5 100644 --- a/engine/client/cl_custom.c +++ b/engine/client/cl_custom.c @@ -78,7 +78,7 @@ qboolean CL_CheckFile( sizebuf_t *msg, resource_t *pResource ) } MSG_BeginClientCmd( msg, clc_stringcmd ); - MSG_WriteString( msg, va( "dlfile %s", filepath )); + MSG_WriteStringf( msg, "dlfile %s", filepath ); host.downloadcount++; return false; diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index ba69c4a09..81f3c46f8 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -499,7 +499,7 @@ void CL_BatchResourceRequest( qboolean initialize ) if( !FBitSet( p->ucFlags, RES_REQUESTED )) { MSG_BeginClientCmd( &msg, clc_stringcmd ); - MSG_WriteString( &msg, va( "dlfile !MD5%s", MD5_Print( p->rgucMD5_hash ) ) ); + MSG_WriteStringf( &msg, "dlfile !MD5%s", MD5_Print( p->rgucMD5_hash ));; SetBits( p->ucFlags, RES_REQUESTED ); } break; @@ -1607,7 +1607,7 @@ void CL_RegisterResources( sizebuf_t *msg ) // done with all resources, issue prespawn command. // Include server count in case server disconnects and changes level during d/l MSG_BeginClientCmd( msg, clc_stringcmd ); - MSG_WriteString( msg, va( "spawn %i", cl.servercount )); + MSG_WriteStringf( msg, "spawn %i", cl.servercount ); } } else @@ -3078,7 +3078,7 @@ void CL_LegacyPrecache_f( void ) // done with all resources, issue prespawn command. // Include server count in case server disconnects and changes level during d/l MSG_BeginClientCmd( &cls.netchan.message, clc_stringcmd ); - MSG_WriteString( &cls.netchan.message, va( "begin %i", spawncount )); + MSG_WriteStringf( &cls.netchan.message, "begin %i", spawncount ); cls.signon = SIGNONS; } diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index e0b96b656..8d1cfcf3c 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -1420,7 +1420,7 @@ void SV_PutClientInServer( sv_client_t *cl ) if( svgame.globals->cdAudioTrack ) { MSG_BeginServerCmd( &msg, svc_stufftext ); - MSG_WriteString( &msg, va( "cd loop %3d\n", svgame.globals->cdAudioTrack )); + MSG_WriteStringf( &msg, "cd loop %3d\n", svgame.globals->cdAudioTrack ); svgame.globals->cdAudioTrack = 0; } @@ -1660,7 +1660,7 @@ static qboolean SV_New_f( sv_client_t *cl ) // server info string MSG_BeginServerCmd( &msg, svc_stufftext ); - MSG_WriteString( &msg, va( "fullserverinfo \"%s\"\n", SV_Serverinfo( ))); + MSG_WriteStringf( &msg, "fullserverinfo \"%s\"\n", SV_Serverinfo( )); // collect the info about all the players and send to me for( i = 0, cur = svs.clients; i < svs.maxclients; i++, cur++ ) @@ -2740,15 +2740,15 @@ static void SV_EntSendVars( sv_client_t *cl, edict_t *ent ) return; MSG_WriteByte( &cl->netchan.message, svc_stufftext ); - MSG_WriteString( &cl->netchan.message, va( "set ent_last_name \"%s\"\n", STRING( ent->v.targetname ) )); + MSG_WriteStringf( &cl->netchan.message, "set ent_last_name \"%s\"\n", STRING( ent->v.targetname )); MSG_WriteByte( &cl->netchan.message, svc_stufftext ); - MSG_WriteString( &cl->netchan.message, va( "set ent_last_num %i\n", NUM_FOR_EDICT( ent ) )); + MSG_WriteStringf( &cl->netchan.message, "set ent_last_num %i\n", NUM_FOR_EDICT( ent )); MSG_WriteByte( &cl->netchan.message, svc_stufftext ); - MSG_WriteString( &cl->netchan.message, va( "set ent_last_inst !%i_%i\n", NUM_FOR_EDICT( ent ), ent->serialnumber )); + MSG_WriteStringf( &cl->netchan.message, "set ent_last_inst !%i_%i\n", NUM_FOR_EDICT( ent ), ent->serialnumber ); MSG_WriteByte( &cl->netchan.message, svc_stufftext ); - MSG_WriteString( &cl->netchan.message, va( "set ent_last_origin \"%f %f %f\"\n", ent->v.origin[0], ent->v.origin[1], ent->v.origin[2])); + MSG_WriteStringf( &cl->netchan.message, "set ent_last_origin \"%f %f %f\"\n", ent->v.origin[0], ent->v.origin[1], ent->v.origin[2] ); MSG_WriteByte( &cl->netchan.message, svc_stufftext ); - MSG_WriteString( &cl->netchan.message, va( "set ent_last_class \"%s\"\n", STRING( ent->v.classname ))); + MSG_WriteStringf( &cl->netchan.message, "set ent_last_class \"%s\"\n", STRING( ent->v.classname )); MSG_WriteByte( &cl->netchan.message, svc_stufftext ); MSG_WriteString( &cl->netchan.message, "ent_getvars_cb\n" ); // why do we need this? } diff --git a/engine/server/sv_custom.c b/engine/server/sv_custom.c index ed65820e6..cb034efbe 100644 --- a/engine/server/sv_custom.c +++ b/engine/server/sv_custom.c @@ -304,7 +304,7 @@ qboolean SV_CheckFile( sizebuf_t *msg, const char *filename ) return true; MSG_BeginServerCmd( msg, svc_stufftext ); - MSG_WriteString( msg, va( "upload \"!MD5%s\"\n", MD5_Print( p.rgucMD5_hash ))); + MSG_WriteStringf( msg, "upload \"!MD5%s\"\n", MD5_Print( p.rgucMD5_hash )); return false; } diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 0f3f85c77..9661a3d60 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -2208,7 +2208,7 @@ SV_StartMusic void SV_StartMusic( const char *curtrack, const char *looptrack, int position ) { MSG_BeginServerCmd( &sv.multicast, svc_stufftext ); - MSG_WriteString( &sv.multicast, va( "music \"%s\" \"%s\" %d\n", curtrack, looptrack, position )); + MSG_WriteStringf( &sv.multicast, "music \"%s\" \"%s\" %d\n", curtrack, looptrack, position ); SV_Multicast( MSG_ALL, NULL, NULL, false, false ); } diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index 2c9da0cf9..006e48756 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -1389,7 +1389,7 @@ static void LoadClientState( SAVERESTOREDATA *pSaveData, const char *level, qboo { // NOTE: music is automatically goes across transition, never restore it on changelevel MSG_BeginServerCmd( &sv.signon, svc_stufftext ); - MSG_WriteString( &sv.signon, va( "music \"%s\" \"%s\" %i\n", header.introTrack, header.mainTrack, header.trackPosition )); + MSG_WriteStringf( &sv.signon, "music \"%s\" \"%s\" %i\n", header.introTrack, header.mainTrack, header.trackPosition ); } // don't go camera across the levels From 6b62f9c1b9da3c8e3edaea8dc2df9fb48b36cdc1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:19:32 +0300 Subject: [PATCH 009/121] engine: convert Cvar_Get with va to Cvar_Getf --- engine/common/host.c | 8 ++++---- engine/common/net_chan.c | 2 +- engine/common/net_ws.c | 4 ++-- engine/server/sv_main.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/common/host.c b/engine/common/host.c index 54bee1c19..8e45bf828 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -1173,10 +1173,10 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa con_gamemaps = Cvar_Get( "con_mapfilter", "1", FCVAR_ARCHIVE, "when true show only maps in game folder" ); Cvar_RegisterVariable( &sys_timescale ); - build = Cvar_Get( "buildnum", va( "%i", Q_buildnum_compat()), FCVAR_READ_ONLY, "returns a current build number" ); - ver = Cvar_Get( "ver", va( "%i/%s (hw build %i)", PROTOCOL_VERSION, XASH_COMPAT_VERSION, Q_buildnum_compat()), FCVAR_READ_ONLY, "shows an engine version" ); - Cvar_Get( "host_ver", va( "%i " XASH_VERSION " %s %s %s", Q_buildnum(), Q_buildos(), Q_buildarch(), Q_buildcommit() ), FCVAR_READ_ONLY, "detailed info about this build" ); - Cvar_Get( "host_lowmemorymode", va( "%i", XASH_LOW_MEMORY ), FCVAR_READ_ONLY, "indicates if engine compiled for low RAM consumption (0 - normal, 1 - low engine limits, 2 - low protocol limits)" ); + build = Cvar_Getf( "buildnum", FCVAR_READ_ONLY, "returns a current build number", "%i", Q_buildnum_compat()); + ver = Cvar_Getf( "ver", FCVAR_READ_ONLY, "shows an engine version", "%i/%s (hw build %i)", PROTOCOL_VERSION, XASH_COMPAT_VERSION, Q_buildnum_compat()); + Cvar_Getf( "host_ver", FCVAR_READ_ONLY, "detailed info about this build", "%i " XASH_VERSION " %s %s %s", Q_buildnum(), Q_buildos(), Q_buildarch(), Q_buildcommit()); + Cvar_Getf( "host_lowmemorymode", FCVAR_READ_ONLY, "indicates if engine compiled for low RAM consumption (0 - normal, 1 - low engine limits, 2 - low protocol limits)", "%i", XASH_LOW_MEMORY ); Mod_Init(); NET_Init(); diff --git a/engine/common/net_chan.c b/engine/common/net_chan.c index 934cf007a..d75d226f7 100644 --- a/engine/common/net_chan.c +++ b/engine/common/net_chan.c @@ -251,7 +251,7 @@ void Netchan_Init( void ) net_showpackets = Cvar_Get ("net_showpackets", "0", 0, "show network packets" ); net_chokeloopback = Cvar_Get( "net_chokeloop", "0", 0, "apply bandwidth choke to loopback packets" ); net_showdrop = Cvar_Get( "net_showdrop", "0", 0, "show packets that are dropped" ); - net_qport = Cvar_Get( "net_qport", va( "%i", port ), FCVAR_READ_ONLY, "current quake netport" ); + net_qport = Cvar_Getf( "net_qport", FCVAR_READ_ONLY, "current quake netport", "%i", port ); net_mempool = Mem_AllocPool( "Network Pool" ); diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index cb1ed789f..5a93cd386 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -2166,9 +2166,9 @@ void NET_Init( void ) net_address = Cvar_Get( "net_address", "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "contain local address of current client" ); net_ipname = Cvar_Get( "ip", "localhost", FCVAR_PRIVILEGED, "network ip address" ); net_iphostport = Cvar_Get( "ip_hostport", "0", FCVAR_READ_ONLY, "network ip host port" ); - net_hostport = Cvar_Get( "hostport", va( "%i", PORT_SERVER ), FCVAR_READ_ONLY, "network default host port" ); + net_hostport = Cvar_Getf( "hostport", FCVAR_READ_ONLY, "network default host port", "%i", PORT_SERVER ); net_ipclientport = Cvar_Get( "ip_clientport", "0", FCVAR_READ_ONLY, "network ip client port" ); - net_clientport = Cvar_Get( "clientport", va( "%i", PORT_CLIENT ), FCVAR_READ_ONLY, "network default client port" ); + net_clientport = Cvar_Getf( "clientport", FCVAR_READ_ONLY, "network default client port", "%i", PORT_CLIENT ); net_fakelag = Cvar_Get( "fakelag", "0", FCVAR_PRIVILEGED, "lag all incoming network data (including loopback) by xxx ms." ); net_fakeloss = Cvar_Get( "fakeloss", "0", FCVAR_PRIVILEGED, "act like we dropped the packet this % of the time." ); diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 43167322b..b57a8993f 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -874,7 +874,7 @@ void SV_Init( void ) SV_InitHostCommands(); - Cvar_Get( "protocol", va( "%i", PROTOCOL_VERSION ), FCVAR_READ_ONLY, "displays server protocol version" ); + Cvar_Getf( "protocol", FCVAR_READ_ONLY, "displays server protocol version", "%i", PROTOCOL_VERSION ); Cvar_Get( "suitvolume", "0.25", FCVAR_ARCHIVE, "HEV suit volume" ); Cvar_Get( "sv_background", "0", FCVAR_READ_ONLY, "indicate what background map is running" ); Cvar_Get( "gamedir", GI->gamefolder, FCVAR_READ_ONLY, "game folder" ); From b12b2aaf79d100591d9e8e9412e6702254e049e0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:28:53 +0300 Subject: [PATCH 010/121] engine: common: cmd: add Cbuf_AddTextf wrapper --- engine/common/cmd.c | 12 ++++++++++++ engine/common/common.h | 1 + 2 files changed, 13 insertions(+) diff --git a/engine/common/cmd.c b/engine/common/cmd.c index f4d673c78..17ae6b033 100644 --- a/engine/common/cmd.c +++ b/engine/common/cmd.c @@ -120,6 +120,18 @@ void Cbuf_AddText( const char *text ) Cbuf_AddTextToBuffer( &cmd_text, text ); } +void Cbuf_AddTextf( const char *fmt, ... ) +{ + va_list va; + char buf[MAX_VA_STRING]; + + va_start( va, fmt ); + Q_vsnprintf( buf, sizeof( buf ), fmt, va ); + va_end( va ); + + Cbuf_AddText( buf ); +} + /* ============ Cbuf_AddFilteredText diff --git a/engine/common/common.h b/engine/common/common.h index e80d8eea1..08404a3ab 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -425,6 +425,7 @@ void FS_Shutdown( void ); void Cbuf_Init( void ); void Cbuf_Clear( void ); void Cbuf_AddText( const char *text ); +void Cbuf_AddTextf( const char *text, ... ) _format( 1 ); void Cbuf_AddFilteredText( const char *text ); void Cbuf_InsertText( const char *text ); void Cbuf_ExecStuffCmds( void ); From d667845777e15d3bdd8e28f1fa3dfd82b63e36fe Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:31:27 +0300 Subject: [PATCH 011/121] engine: convert Cbuf_AddText with va to Cbuf_AddTextf --- engine/client/cl_gameui.c | 2 +- engine/client/cl_main.c | 2 +- engine/client/cl_parse.c | 2 +- engine/client/in_touch.c | 4 ++-- engine/client/ref_common.c | 2 +- engine/common/host.c | 6 +++--- engine/server/sv_cmds.c | 2 +- engine/server/sv_filter.c | 2 +- engine/server/sv_init.c | 2 +- engine/server/sv_save.c | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index d19087c5a..c74932fb3 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -838,7 +838,7 @@ send client connect */ static void GAME_EXPORT pfnClientJoin( const netadr_t adr ) { - Cbuf_AddText( va( "connect %s\n", NET_AdrToString( adr ))); + Cbuf_AddTextf( "connect %s\n", NET_AdrToString( adr )); } /* diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 2aad47e19..07c0de43d 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2086,7 +2086,7 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg ) if( NET_CompareAdr( from, cls.legacyserver )) { - Cbuf_AddText( va( "connect %s legacy\n", NET_AdrToString( from ))); + Cbuf_AddTextf( "connect %s legacy\n", NET_AdrToString( from )); memset( &cls.legacyserver, 0, sizeof( cls.legacyserver )); } } diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 81f3c46f8..016e8cd61 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -2001,7 +2001,7 @@ void CL_ParseExec( sizebuf_t *msg ) COM_FileBase( clgame.mapname, mapname ); if ( COM_CheckString( mapname ) ) - Cbuf_AddText( va( "exec %s.cfg\n", mapname ) ); + Cbuf_AddTextf( "exec %s.cfg\n", mapname ); } } diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index 7131b6c8c..f4d38f15a 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -737,7 +737,7 @@ static void Touch_ReloadConfig_f( void ) touch.edit = touch.selection = NULL; touch.resize_finger = touch.move_finger = touch.look_finger = touch.wheel_finger = -1; - Cbuf_AddText( va("exec %s\n", touch_config_file->string ) ); + Cbuf_AddTextf( "exec %s\n", touch_config_file->string ); } static touch_button_t *Touch_AddButton( touchbuttonlist_t *list, @@ -1111,7 +1111,7 @@ static void Touch_InitConfig( void ) //pfnGetScreenInfo( NULL ); //HACK: update hud screen parameters like iHeight if( FS_FileExists( touch_config_file->string, true ) ) { - Cbuf_AddText( va( "exec \"%s\"\n", touch_config_file->string ) ); + Cbuf_AddTextf( "exec \"%s\"\n", touch_config_file->string ); Cbuf_Execute(); } else diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index a736f51f3..9d8ee9b2d 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -224,7 +224,7 @@ static qboolean R_DoResetGamma( void ) static qboolean R_Init_Video_( const int type ) { host.apply_opengl_config = true; - Cbuf_AddText( va( "exec %s.cfg", ref.dllFuncs.R_GetConfigName())); + Cbuf_AddTextf( "exec %s.cfg", ref.dllFuncs.R_GetConfigName()); Cbuf_Execute(); host.apply_opengl_config = false; diff --git a/engine/common/host.c b/engine/common/host.c index 8e45bf828..73b367df7 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -827,7 +827,7 @@ void Host_Userconfigd_f( void ) for( i = 0; i < t->numfilenames; i++ ) { - Cbuf_AddText( va("exec %s\n", t->filenames[i] ) ); + Cbuf_AddTextf( "exec %s\n", t->filenames[i] ); } Mem_Free( t ); @@ -1221,7 +1221,7 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa Wcon_ShowConsole( false ); // hide console #endif // execute startup config and cmdline - Cbuf_AddText( va( "exec %s.rc\n", SI.rcName )); + Cbuf_AddTextf( "exec %s.rc\n", SI.rcName ); Cbuf_Execute(); if( !host.config_executed ) { @@ -1255,7 +1255,7 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa // execute server.cfg after commandline // so we have a chance to set servercfgfile - Cbuf_AddText( va( "exec %s\n", Cvar_VariableString( "servercfgfile" ))); + Cbuf_AddTextf( "exec %s\n", Cvar_VariableString( "servercfgfile" )); Cbuf_Execute(); } diff --git a/engine/server/sv_cmds.c b/engine/server/sv_cmds.c index 8812811da..1eb81d229 100644 --- a/engine/server/sv_cmds.c +++ b/engine/server/sv_cmds.c @@ -394,7 +394,7 @@ void SV_HazardCourse_f( void ) // special case for Gunman Chronicles: playing avi-file if( FS_FileExists( va( "media/%s.avi", GI->trainmap ), false )) { - Cbuf_AddText( va( "wait; movie %s\n", GI->trainmap )); + Cbuf_AddTextf( "wait; movie %s\n", GI->trainmap ); Host_EndGame( true, DEFAULT_ENDGAME_MESSAGE ); } else COM_NewGame( GI->trainmap ); diff --git a/engine/server/sv_filter.c b/engine/server/sv_filter.c index f6eb8df25..ccffeee82 100644 --- a/engine/server/sv_filter.c +++ b/engine/server/sv_filter.c @@ -159,7 +159,7 @@ static void SV_BanID_f( void ) cidfilter = filter; if( cl && !Q_stricmp( Cmd_Argv( Cmd_Argc() - 1 ), "kick" )) - Cbuf_AddText( va( "kick #%d \"Kicked and banned\"\n", cl->userid )); + Cbuf_AddTextf( "kick #%d \"Kicked and banned\"\n", cl->userid ); } static void SV_ListID_f( void ) diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 699b47b9c..a21d7cdde 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -628,7 +628,7 @@ void SV_ActivateServer( int runPhysics ) const char *cycle = Cvar_VariableString( "mapchangecfgfile" ); if( COM_CheckString( cycle )) - Cbuf_AddText( va( "exec %s\n", cycle )); + Cbuf_AddTextf( "exec %s\n", cycle ); } } diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index 006e48756..2ea3d7af9 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -1739,7 +1739,7 @@ static qboolean SaveGameSlot( const char *pSaveName, const char *pSaveComment ) } // pending the preview image for savegame - Cbuf_AddText( va( "saveshot \"%s\"\n", pSaveName )); + Cbuf_AddTextf( "saveshot \"%s\"\n", pSaveName ); Con_Printf( "Saving game to %s...\n", name ); version = SAVEGAME_VERSION; From 5ef97ae99eb5255fbc706be87ede91f2f1bf1238 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:37:45 +0300 Subject: [PATCH 012/121] engine: convert Info_SetValueForKey with va to Info_SetValueForKeyf --- engine/client/cl_main.c | 6 +++--- engine/server/sv_client.c | 12 ++++++------ engine/server/sv_game.c | 2 +- engine/server/sv_main.c | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 07c0de43d..959bdb312 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -1029,9 +1029,9 @@ void CL_SendConnectPacket( void ) Cvar_SetCheatState(); Cvar_FullSet( "sv_cheats", "0", FCVAR_READ_ONLY | FCVAR_SERVER ); - Info_SetValueForKey( protinfo, "d", va( "%d", input_devices ), sizeof( protinfo ) ); + Info_SetValueForKeyf( protinfo, "d", sizeof( protinfo ), "%d", input_devices ); Info_SetValueForKey( protinfo, "v", XASH_VERSION, sizeof( protinfo ) ); - Info_SetValueForKey( protinfo, "b", va( "%d", Q_buildnum() ), sizeof( protinfo ) ); + Info_SetValueForKeyf( protinfo, "b", sizeof( protinfo ), "%d", Q_buildnum( )); Info_SetValueForKey( protinfo, "o", Q_buildos(), sizeof( protinfo ) ); Info_SetValueForKey( protinfo, "a", Q_buildarch(), sizeof( protinfo ) ); } @@ -1065,7 +1065,7 @@ void CL_SendConnectPacket( void ) Info_SetValueForKey( protinfo, "uuid", key, sizeof( protinfo )); Info_SetValueForKey( protinfo, "qport", qport, sizeof( protinfo )); - Info_SetValueForKey( protinfo, "ext", va("%d", extensions), sizeof( protinfo )); + Info_SetValueForKeyf( protinfo, "ext", sizeof( protinfo ), "%d", extensions); Netchan_OutOfBandPrint( NS_CLIENT, adr, "connect %i %i \"%s\" \"%s\"\n", PROTOCOL_VERSION, cls.challenge, protinfo, cls.userinfo ); Con_Printf( "Trying to connect by modern protocol\n" ); diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 8d1cfcf3c..e4c1e8e55 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -432,7 +432,7 @@ void SV_ConnectClient( netadr_t from ) // build protinfo answer protinfo[0] = '\0'; - Info_SetValueForKey( protinfo, "ext", va( "%d", newcl->extensions ), sizeof( protinfo ) ); + Info_SetValueForKeyf( protinfo, "ext", sizeof( protinfo ), "%d", newcl->extensions ); // send the connect packet to the client Netchan_OutOfBandPrint( NS_SERVER, from, "client_connect %s", protinfo ); @@ -875,13 +875,13 @@ void SV_Info( netadr_t from, int protocolVersion ) SV_GetPlayerCount( &count, &bots ); // a1ba: send protocol version to distinguish old engine and new - Info_SetValueForKey( s, "p", va( "%i", PROTOCOL_VERSION ), sizeof( s )); + Info_SetValueForKeyf( s, "p", sizeof( s ), "%i", PROTOCOL_VERSION ); Info_SetValueForKey( s, "map", sv.name, sizeof( s )); Info_SetValueForKey( s, "dm", svgame.globals->deathmatch ? "1" : "0", sizeof( s )); Info_SetValueForKey( s, "team", svgame.globals->teamplay ? "1" : "0", sizeof( s )); Info_SetValueForKey( s, "coop", svgame.globals->coop ? "1" : "0", sizeof( s )); - Info_SetValueForKey( s, "numcl", va( "%i", count ), sizeof( s )); - Info_SetValueForKey( s, "maxcl", va( "%i", svs.maxclients ), sizeof( s )); + Info_SetValueForKeyf( s, "numcl", sizeof( s ), "%i", count ); + Info_SetValueForKeyf( s, "maxcl", sizeof( s ), "%i", svs.maxclients ); Info_SetValueForKey( s, "gamedir", GI->gamefolder, sizeof( s )); Info_SetValueForKey( s, "password", have_password ? "1" : "0", sizeof( s )); @@ -980,8 +980,8 @@ void SV_BuildNetAnswer( netadr_t from ) string[0] = '\0'; Info_SetValueForKey( string, "hostname", hostname.string, MAX_INFO_STRING ); Info_SetValueForKey( string, "gamedir", GI->gamefolder, MAX_INFO_STRING ); - Info_SetValueForKey( string, "current", va( "%i", count ), MAX_INFO_STRING ); - Info_SetValueForKey( string, "max", va( "%i", svs.maxclients ), MAX_INFO_STRING ); + Info_SetValueForKeyf( string, "current", MAX_INFO_STRING, "%i", count ); + Info_SetValueForKeyf( string, "max", MAX_INFO_STRING, "%i", svs.maxclients ); Info_SetValueForKey( string, "map", sv.name, MAX_INFO_STRING ); // send serverinfo diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 9661a3d60..ea9edadc1 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -3765,7 +3765,7 @@ void GAME_EXPORT pfnSetClientMaxspeed( const edict_t *pEdict, float fNewMaxspeed return; fNewMaxspeed = bound( -svgame.movevars.maxspeed, fNewMaxspeed, svgame.movevars.maxspeed ); - Info_SetValueForKey( cl->physinfo, "maxspd", va( "%.f", fNewMaxspeed ), MAX_INFO_STRING ); + Info_SetValueForKeyf( cl->physinfo, "maxspd", MAX_INFO_STRING, "%.f", fNewMaxspeed ); cl->edict->v.maxspeed = fNewMaxspeed; } diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index b57a8993f..532460085 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -781,11 +781,11 @@ void SV_AddToMaster( netadr_t from, sizebuf_t *msg ) } SV_GetPlayerCount( &clients, &bots ); - Info_SetValueForKey( s, "protocol", va( "%d", PROTOCOL_VERSION ), len ); // protocol version - Info_SetValueForKey( s, "challenge", va( "%u", challenge ), len ); // challenge number - Info_SetValueForKey( s, "players", va( "%d", clients ), len ); // current player number, without bots - Info_SetValueForKey( s, "max", va( "%d", svs.maxclients ), len ); // max_players - Info_SetValueForKey( s, "bots", va( "%d", bots ), len ); // bot count + Info_SetValueForKeyf( s, "protocol", len, "%d", PROTOCOL_VERSION ); // protocol version + Info_SetValueForKeyf( s, "challenge", len, "%u", challenge ); // challenge number + Info_SetValueForKeyf( s, "players", len, "%d", clients ); // current player number, without bots + Info_SetValueForKeyf( s, "max", len, "%d", svs.maxclients ); // max_players + Info_SetValueForKeyf( s, "bots", len, "%d", bots ); // bot count Info_SetValueForKey( s, "gamedir", GI->gamefolder, len ); // gamedir Info_SetValueForKey( s, "map", sv.name, len ); // current map Info_SetValueForKey( s, "type", (Host_IsDedicated()) ? "d" : "l", len ); // dedicated or local From a81fa84321f3fccb33dd205aee61d9745f2a871d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:00:26 +0300 Subject: [PATCH 013/121] engine: server: replace some obvious va uses to temp buffer and Q_snprintf --- engine/server/sv_game.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index ea9edadc1..71dfd5cfc 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -4886,7 +4886,12 @@ qboolean SV_ParseEdict( char **pfile, edict_t *ent ) pkvd[i].szKeyName = copystring( "angles" ); if( flYawAngle >= 0.0f ) - pkvd[i].szValue = copystring( va( "%g %g %g", ent->v.angles[0], flYawAngle, ent->v.angles[2] )); + { + char temp[MAX_VA_STRING]; + + Q_snprintf( temp, sizeof( temp ), "%g %g %g", ent->v.angles[0], flYawAngle, ent->v.angles[2] ); + pkvd[i].szValue = copystring( temp ); + } else if( flYawAngle == -1.0f ) pkvd[i].szValue = copystring( "-90 0 0" ); else if( flYawAngle == -2.0f ) @@ -4897,11 +4902,14 @@ qboolean SV_ParseEdict( char **pfile, edict_t *ent ) #ifdef HACKS_RELATED_HLMODS if( adjust_origin && !Q_strcmp( pkvd[i].szKeyName, "origin" )) { + char temp[MAX_VA_STRING]; char *pstart = pkvd[i].szValue; COM_ParseVector( &pstart, origin, 3 ); Mem_Free( pkvd[i].szValue ); // release old value, so we don't need these - pkvd[i].szValue = copystring( va( "%g %g %g", origin[0], origin[1], origin[2] - 16.0f )); + + Q_snprintf( temp, sizeof( temp ), "%g %g %g", origin[0], origin[1], origin[2] - 16.0f ); + pkvd[i].szValue = copystring( temp ); } #endif if( !Q_strcmp( pkvd[i].szKeyName, "light" )) From 9690fe933420de50384288245b88b05a16405b67 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:03:44 +0300 Subject: [PATCH 014/121] engine: client: replace some obvious va uses by temp buffer and Q_snprintf --- engine/client/cl_game.c | 12 ++++++++++-- engine/client/cl_parse.c | 7 ++++++- engine/client/cl_tent.c | 4 +++- engine/client/s_main.c | 13 ++++++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index d95b672db..43accb9a6 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -590,7 +590,11 @@ static void CL_InitTitles( const char *filename ) // initialize text messages (game_text) for( i = 0; i < MAX_TEXTCHANNELS; i++ ) { - cl_textmessage[i].pName = _copystring( clgame.mempool, va( TEXT_MSGNAME, i ), __FILE__, __LINE__ ); + char name[MAX_VA_STRING]; + + Q_snprintf( name, sizeof( name ), TEXT_MSGNAME, i ); + + cl_textmessage[i].pName = _copystring( clgame.mempool, name, __FILE__, __LINE__ ); cl_textmessage[i].pMessage = cl_textbuffer[i]; } @@ -1852,7 +1856,11 @@ client_textmessage_t *CL_TextMessageGet( const char *pName ) // first check internal messages for( i = 0; i < MAX_TEXTCHANNELS; i++ ) { - if( !Q_strcmp( pName, va( TEXT_MSGNAME, i ))) + char name[MAX_VA_STRING]; + + Q_snprintf( name, sizeof( name ), TEXT_MSGNAME, i ); + + if( !Q_strcmp( pName, name )) return cl_textmessage + i; } diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 016e8cd61..4c236725f 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -2694,10 +2694,15 @@ void CL_LegacyParseResourceList( sizebuf_t *msg ) for( i = 0; i < reslist.rescount; i++ ) { + char soundpath[MAX_VA_STRING]; const char *path; if( reslist.restype[i] == t_sound ) - path = va( DEFAULT_SOUNDPATH "%s", reslist.resnames[i] ); + { + Q_snprintf( soundpath, sizeof( soundpath ), DEFAULT_SOUNDPATH "%s", reslist.resnames[i] ); + + path = soundpath; + } else path = reslist.resnames[i]; if( FS_FileExists( path, false )) diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index e0e10c4c0..74b6dbf06 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -2929,7 +2929,9 @@ void CL_PlayerDecal( int playernum, int customIndex, int entityIndex, float *pos if( !pCust->nUserData1 ) { int sprayTextureIndex; - const char *decalname = va( "player%dlogo%d", playernum, customIndex ); + char decalname[MAX_VA_STRING]; + + Q_snprintf( decalname, sizeof( decalname ), "player%dlogo%d", playernum, customIndex ); sprayTextureIndex = ref.dllFuncs.GL_FindTexture( decalname ); if( sprayTextureIndex != 0 ) { diff --git a/engine/client/s_main.c b/engine/client/s_main.c index 3ba4ea138..6002ac329 100644 --- a/engine/client/s_main.c +++ b/engine/client/s_main.c @@ -1842,8 +1842,12 @@ void S_Music_f( void ) for( i = 0; i < 2; i++ ) { - const char *intro_path = va( "media/%s.%s", intro, ext[i] ); - const char *main_path = va( "media/%s.%s", main, ext[i] ); + char intro_path[MAX_VA_STRING]; + char main_path[MAX_VA_STRING]; + char track_path[MAX_VA_STRING]; + + Q_snprintf( intro_path, sizeof( intro_path ), "media/%s.%s", intro, ext[i] ); + Q_snprintf( main_path, sizeof( main_path ), "media/%s.%s", main, ext[i] ); if( FS_FileExists( intro_path, false ) && FS_FileExists( main_path, false )) { @@ -1851,7 +1855,10 @@ void S_Music_f( void ) S_StartBackgroundTrack( intro, main, 0, false ); break; } - else if( FS_FileExists( va( "media/%s.%s", track, ext[i] ), false )) + + Q_snprintf( track_path, sizeof( track_path ), "media/%s.%s", track, ext[i] ); + + if( FS_FileExists( track_path, false )) { // single non-looped theme S_StartBackgroundTrack( track, NULL, 0, false ); From 116a605248a08e97e97213a97a6046364e5d0fe6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:08:36 +0300 Subject: [PATCH 015/121] engine: common: replace some obvious va uses by temp buffer and Q_snprintf or equivalent code --- engine/common/con_utils.c | 8 ++++++-- engine/common/cvar.c | 9 +++++---- engine/common/host.c | 10 ++++++---- engine/common/mod_bmodel.c | 6 +++++- engine/common/mod_sprite.c | 4 +++- engine/common/mod_studio.c | 5 ++++- engine/common/net_ws.c | 6 +++++- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 3aed173f1..9ebd9be33 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -1041,10 +1041,14 @@ compare first argument with string */ static qboolean Cmd_CheckName( const char *name ) { - if( !Q_stricmp( Cmd_Argv( 0 ), name )) + char *p = Cmd_Argv( 0 ); + + if( !Q_stricmp( p, name )) return true; - if( !Q_stricmp( Cmd_Argv( 0 ), va( "\\%s", name ))) + + if( p[0] == '\\' && !Q_stricmp( &p[1], name )) return true; + return false; } diff --git a/engine/common/cvar.c b/engine/common/cvar.c index a38cc2f43..316119e38 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -1080,7 +1080,7 @@ void Cvar_Toggle_f( void ) v = !Cvar_VariableInteger( Cmd_Argv( 1 )); - Cvar_Set( Cmd_Argv( 1 ), va( "%i", v )); + Cvar_Set( Cmd_Argv( 1 ), v ? "1" : "0" ); } /* @@ -1162,7 +1162,6 @@ void Cvar_List_f( void ) { convar_t *var; const char *match = NULL; - char *value; int count = 0; size_t matchlen = 0; @@ -1174,6 +1173,8 @@ void Cvar_List_f( void ) for( var = cvar_vars; var; var = var->next ) { + char value[MAX_VA_STRING]; + if( var->name[0] == '@' ) continue; // never shows system cvars @@ -1181,8 +1182,8 @@ void Cvar_List_f( void ) continue; if( Q_colorstr( var->string )) - value = va( "\"%s\"", var->string ); - else value = va( "\"^2%s^7\"", var->string ); + Q_snprintf( value, sizeof( value ), "\"%s\"", var->string ); + else Q_snprintf( value, sizeof( value ), "\"^2%s^7\"", var->string ); if( FBitSet( var->flags, FCVAR_EXTENDED|FCVAR_ALLOCATED )) Con_Printf( " %-*s %s ^3%s^7\n", 32, var->name, value, var->desc ); diff --git a/engine/common/host.c b/engine/common/host.c index 73b367df7..d472d9f53 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -346,10 +346,10 @@ void Host_ChangeGame_f( void ) } else { - const char *arg1 = va( "%s", Cmd_Argv( 1 )); - const char *arg2 = va( "change game to '%s'", FI->games[i]->title ); + char finalmsg[MAX_VA_STRING]; - Host_NewInstance( arg1, arg2 ); + Q_snprintf( finalmsg, sizeof( finalmsg ), "change game to '%s'", FI->games[i]->title ); + Host_NewInstance( Cmd_Argv( 1 ), finalmsg ); } } @@ -384,9 +384,11 @@ void Host_Exec_f( void ) "pyro.cfg", "spy.cfg", "engineer.cfg", "civilian.cfg" }; int i; + char temp[MAX_VA_STRING]; qboolean allow = false; - unprivilegedWhitelist[0] = va( "%s.cfg", clgame.mapname ); + Q_snprintf( temp, sizeof( temp ), "%s.cfg", clgame.mapname ); + unprivilegedWhitelist[0] = temp; for( i = 0; i < ARRAYSIZE( unprivilegedWhitelist ); i++ ) { diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 8d2c0be3f..fd3236b7d 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -3019,9 +3019,13 @@ Mod_LoadBrushModel */ void Mod_LoadBrushModel( model_t *mod, const void *buffer, qboolean *loaded ) { + char poolname[MAX_VA_STRING]; + + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); + if( loaded ) *loaded = false; - loadmodel->mempool = Mem_AllocPool( va( "^2%s^7", loadmodel->name )); + loadmodel->mempool = Mem_AllocPool( poolname ); loadmodel->type = mod_brush; // loading all the lumps into heap diff --git a/engine/common/mod_sprite.c b/engine/common/mod_sprite.c index 5cc318272..f76774ae1 100644 --- a/engine/common/mod_sprite.c +++ b/engine/common/mod_sprite.c @@ -35,6 +35,7 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui dsprite_hl_t *pinhl; dsprite_t *pin; msprite_t *psprite; + char poolname[MAX_VA_STRING]; int i, size; if( loaded ) *loaded = false; @@ -54,7 +55,8 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui return; } - mod->mempool = Mem_AllocPool( va( "^2%s^7", mod->name )); + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name ); + mod->mempool = Mem_AllocPool( poolname ); if( i == SPRITE_VERSION_Q1 || i == SPRITE_VERSION_32 ) { diff --git a/engine/common/mod_studio.c b/engine/common/mod_studio.c index 504ff415c..77a0832c2 100644 --- a/engine/common/mod_studio.c +++ b/engine/common/mod_studio.c @@ -848,10 +848,13 @@ Mod_LoadStudioModel */ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ) { + char poolname[MAX_VA_STRING]; studiohdr_t *phdr; + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); + if( loaded ) *loaded = false; - loadmodel->mempool = Mem_AllocPool( va( "^2%s^7", loadmodel->name )); + loadmodel->mempool = Mem_AllocPool( poolname ); loadmodel->type = mod_studio; phdr = R_StudioLoadHeader( mod, buffer ); diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index 5a93cd386..b2ea7d386 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -2639,10 +2639,14 @@ void HTTP_Run( void ) if( curfile->state < HTTP_NS_RESOLVED ) { + char hostport[MAX_VA_STRING]; + if( fResolving ) continue; - res = NET_StringToSockaddr( va( "%s:%d", curfile->server->host, curfile->server->port ), &addr, true, AF_INET ); + Q_snprintf( hostport, sizeof( hostport ), "%s:%d", curfile->server->host, curfile->server->port ); + + res = NET_StringToSockaddr( hostport, &addr, true, AF_INET ); if( res == 2 ) { From 5ea5e1167bc8c459cea9981696014bc5e045bcd0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:15:42 +0300 Subject: [PATCH 016/121] engine: client: font: add CL_DrawStringf wrapper --- engine/client/cl_font.c | 12 ++++++++++++ engine/client/client.h | 1 + 2 files changed, 13 insertions(+) diff --git a/engine/client/cl_font.c b/engine/client/cl_font.c index b9fe68ebc..a5ac20769 100644 --- a/engine/client/cl_font.c +++ b/engine/client/cl_font.c @@ -260,6 +260,18 @@ int CL_DrawString( float x, float y, const char *s, rgba_t color, cl_font_t *fon return draw_len; } +int CL_DrawStringf( cl_font_t *font, float x, float y, rgba_t color, int flags, const char *fmt, ... ) +{ + va_list va; + char buf[MAX_VA_STRING]; + + va_start( va, fmt ); + Q_vsnprintf( buf, sizeof( buf ), fmt, va ); + va_end( va ); + + return CL_DrawString( x, y, buf, color, font, flags ); +} + void CL_DrawCharacterLen( cl_font_t *font, int number, int *width, int *height ) { if( !font || !font->valid ) return; diff --git a/engine/client/client.h b/engine/client/client.h index d4e40441c..0275fc5e7 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -817,6 +817,7 @@ int CL_DrawCharacter( float x, float y, int number, rgba_t color, cl_font_t *fon int CL_DrawString( float x, float y, const char *s, rgba_t color, cl_font_t *font, int flags ); void CL_DrawCharacterLen( cl_font_t *font, int number, int *width, int *height ); void CL_DrawStringLen( cl_font_t *font, const char *s, int *width, int *height, int flags ); +int CL_DrawStringf( cl_font_t *font, float x, float y, rgba_t color, int flags, const char *fmt, ... ) _format( 6 ); // From 2ef3d78d9fcb4037e22ff06db1ce7ebdd8be03fb Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:16:17 +0300 Subject: [PATCH 017/121] engine: client: netgraph: replace CL_DrawString with va calls by CL_DrawStringf --- engine/client/cl_netgraph.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/engine/client/cl_netgraph.c b/engine/client/cl_netgraph.c index 484adc1b4..ab693fd8c 100644 --- a/engine/client/cl_netgraph.c +++ b/engine/client/cl_netgraph.c @@ -393,10 +393,10 @@ static void NetGraph_DrawTextFields( int x, int y, int w, wrect_t rect, int coun { y -= net_graphheight->value; - CL_DrawString( x, y, va( "%.1f fps" , 1.0f / framerate ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, x, y, colors, FONT_DRAW_NORENDERMODE, "%.1f fps" , 1.0f / framerate); if( avg > 1.0f ) - CL_DrawString( x + 75, y, va( "%i ms" , (int)avg ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, x + 75, y, colors, FONT_DRAW_NORENDERMODE, "%i ms" , (int)avg ); y += 15; @@ -404,10 +404,12 @@ static void NetGraph_DrawTextFields( int x, int y, int w, wrect_t rect, int coun if( !out ) out = lastout; else lastout = out; - CL_DrawString( x, y, va( "in : %i %.2f kb/s", netstat_graph[j].msgbytes, cls.netchan.flow[FLOW_INCOMING].avgkbytespersec ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, x, y, colors, FONT_DRAW_NORENDERMODE, + "in : %i %.2f kb/s", netstat_graph[j].msgbytes, cls.netchan.flow[FLOW_INCOMING].avgkbytespersec ); y += 15; - CL_DrawString( x, y, va( "out: %i %.2f kb/s", out, cls.netchan.flow[FLOW_OUTGOING].avgkbytespersec ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, x, y, colors, FONT_DRAW_NORENDERMODE, + "out: %i %.2f kb/s", out, cls.netchan.flow[FLOW_OUTGOING].avgkbytespersec ); y += 15; if( graphtype > 2 ) @@ -415,14 +417,14 @@ static void NetGraph_DrawTextFields( int x, int y, int w, wrect_t rect, int coun int loss = (int)(( packet_loss + PACKETLOSS_AVG_FRAC ) - 0.01f ); int choke = (int)(( packet_choke + PACKETCHOKE_AVG_FRAC ) - 0.01f ); - CL_DrawString( x, y, va( "loss: %i choke: %i", loss, choke ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, x, y, colors, FONT_DRAW_NORENDERMODE, "loss: %i choke: %i", loss, choke ); } } if( graphtype < 3 ) - CL_DrawString( ptx, pty, va( "%i/s", (int)cl_cmdrate->value ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, ptx, pty, colors, FONT_DRAW_NORENDERMODE, "%i/s", (int)cl_cmdrate->value ); - CL_DrawString( ptx, last_y, va( "%i/s" , (int)cl_updaterate->value ), colors, font, FONT_DRAW_NORENDERMODE ); + CL_DrawStringf( font, ptx, last_y, colors, FONT_DRAW_NORENDERMODE, "%i/s" , (int)cl_updaterate->value ); } /* From d177b6f528720a2022853fe748dd27b437b92fde Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:22:30 +0300 Subject: [PATCH 018/121] engine: cvar: consolidate auto description for GLCONFIG cvars Fix bug when GLCONFIG cvars didn't had it's respective CLIENTDLL or GAMEUIDLL flags --- engine/common/common.c | 8 ++------ engine/common/cvar.c | 10 ++++++++-- engine/common/cvar.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/engine/common/common.c b/engine/common/common.c index 45756357c..c7c295c92 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -900,9 +900,7 @@ cvar_t *pfnCvar_RegisterClientVariable( const char *szName, const char *szValue, if( !Q_stricmp( szName, "motdfile" )) flags |= FCVAR_PRIVILEGED; - if( FBitSet( flags, FCVAR_GLCONFIG )) - return (cvar_t *)Cvar_Get( szName, szValue, flags, va( CVAR_GLCONFIG_DESCRIPTION, szName )); - return (cvar_t *)Cvar_Get( szName, szValue, flags|FCVAR_CLIENTDLL, Cvar_BuildAutoDescription( flags|FCVAR_CLIENTDLL )); + return (cvar_t *)Cvar_Get( szName, szValue, flags|FCVAR_CLIENTDLL, Cvar_BuildAutoDescription( szName, flags|FCVAR_CLIENTDLL )); } /* @@ -913,9 +911,7 @@ pfnCvar_RegisterVariable */ cvar_t *pfnCvar_RegisterGameUIVariable( const char *szName, const char *szValue, int flags ) { - if( FBitSet( flags, FCVAR_GLCONFIG )) - return (cvar_t *)Cvar_Get( szName, szValue, flags, va( CVAR_GLCONFIG_DESCRIPTION, szName )); - return (cvar_t *)Cvar_Get( szName, szValue, flags|FCVAR_GAMEUIDLL, Cvar_BuildAutoDescription( flags|FCVAR_GAMEUIDLL )); + return (cvar_t *)Cvar_Get( szName, szValue, flags|FCVAR_GAMEUIDLL, Cvar_BuildAutoDescription( szName, flags|FCVAR_GAMEUIDLL )); } /* diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 316119e38..6379f3613 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -95,10 +95,16 @@ Cvar_BuildAutoDescription build cvar auto description that based on the setup flags ============ */ -const char *Cvar_BuildAutoDescription( int flags ) +const char *Cvar_BuildAutoDescription( const char *szName, int flags ) { static char desc[256]; + if( FBitSet( flags, FCVAR_GLCONFIG )) + { + Q_snprintf( desc, sizeof( desc ), CVAR_GLCONFIG_DESCRIPTION, szName ); + return desc; + } + desc[0] = '\0'; if( FBitSet( flags, FCVAR_EXTDLL )) @@ -1187,7 +1193,7 @@ void Cvar_List_f( void ) if( FBitSet( var->flags, FCVAR_EXTENDED|FCVAR_ALLOCATED )) Con_Printf( " %-*s %s ^3%s^7\n", 32, var->name, value, var->desc ); - else Con_Printf( " %-*s %s ^3%s^7\n", 32, var->name, value, Cvar_BuildAutoDescription( var->flags )); + else Con_Printf( " %-*s %s ^3%s^7\n", 32, var->name, value, Cvar_BuildAutoDescription( var->name, var->flags )); count++; } diff --git a/engine/common/cvar.h b/engine/common/cvar.h index 3d167f4fd..aea979d3d 100644 --- a/engine/common/cvar.h +++ b/engine/common/cvar.h @@ -69,7 +69,7 @@ void Cvar_FullSet( const char *var_name, const char *value, int flags ); void Cvar_DirectSet( convar_t *var, const char *value ); void Cvar_Set( const char *var_name, const char *value ); void Cvar_SetValue( const char *var_name, float value ); -const char *Cvar_BuildAutoDescription( int flags ); +const char *Cvar_BuildAutoDescription( const char *szName, int flags ); float Cvar_VariableValue( const char *var_name ); int Cvar_VariableInteger( const char *var_name ); const char *Cvar_VariableString( const char *var_name ); From e664e80b27b26ca5050fe5431facee2d0b7168c7 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 06:25:57 +0300 Subject: [PATCH 019/121] engine: common: mod_bmodel: replace few more obvious va calls by temp buffer and Q_snprintf --- engine/common/mod_bmodel.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index fd3236b7d..8f1ebbfb6 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1517,7 +1517,10 @@ static void Mod_SetupSubmodels( dbspmodel_t *bmod ) if( i != 0 ) { - Mod_FindModelOrigin( ents, va( "*%i", i ), bm->origin ); + char temp[MAX_VA_STRING]; + + Q_snprintf( temp, sizeof( temp ), "*%i", i ); + Mod_FindModelOrigin( ents, temp, bm->origin ); // mark models that have origin brushes if( !VectorIsNull( bm->origin )) @@ -2022,7 +2025,9 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) // check wads in reverse order for( j = bmod->wadlist.count - 1; j >= 0; j-- ) { - char *texpath = va( "%s.wad/%s", bmod->wadlist.wadnames[j], texname ); + char texpath[MAX_VA_STRING]; + + Q_snprintf( texpath, sizeof( texpath ), "%s.wad/%s", bmod->wadlist.wadnames[j], texname ); if( FS_FileExists( texpath, false )) { @@ -2078,7 +2083,9 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) // check wads in reverse order for( j = bmod->wadlist.count - 1; j >= 0; j-- ) { - char *texpath = va( "%s.wad/%s.mip", bmod->wadlist.wadnames[j], tx->name ); + char texpath[MAX_VA_STRING]; + + Q_snprintf( texpath, sizeof( texpath ), "%s.wad/%s.mip", bmod->wadlist.wadnames[j], tx->name ); if( FS_FileExists( texpath, false )) { From da5ec565679b5d63bbbe943fd43149655fb72740 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 14 Mar 2023 00:35:07 +0300 Subject: [PATCH 020/121] engine: common: con_utils: fix const qualifier discard in Con_CheckName --- engine/common/con_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 9ebd9be33..a54def570 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -1041,7 +1041,7 @@ compare first argument with string */ static qboolean Cmd_CheckName( const char *name ) { - char *p = Cmd_Argv( 0 ); + const char *p = Cmd_Argv( 0 ); if( !Q_stricmp( p, name )) return true; From 412c635499e4dd308b5c61635a478ed370cb0d7b Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 03:46:20 +0300 Subject: [PATCH 021/121] public: add float_bits_t union to access float as 32-bit signed or unsigned integer --- public/xash3d_mathlib.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index 55fe77edb..85cbdb372 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -22,6 +22,8 @@ GNU General Public License for more details. #endif #include "build.h" +#include "xash3d_types.h" +#include "const.h" #include "com_model.h" #include "studio.h" @@ -135,6 +137,42 @@ GNU General Public License for more details. #define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist) #define bound( min, num, max ) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) +// horrible cast but helps not breaking strict aliasing in mathlib +// as union type punning should be fine in C but not in C++ +// so don't carry over this to C++ code +typedef union +{ + float fl; + uint32_t u; + int32_t i; +} float_bits_t; + +static inline uint32_t FloatAsUint( float v ) +{ + float_bits_t bits = { v }; + return bits.u; +} + +static inline int32_t FloatAsInt( float v ) +{ + float_bits_t bits = { v }; + return bits.i; +} + +static inline float IntAsFloat( int32_t i ) +{ + float_bits_t bits; + bits.i = i; + return bits.fl; +} + +static inline float UintAsFloat( uint32_t u ) +{ + float_bits_t bits; + bits.u = u; + return bits.fl; +} + float rsqrt( float number ); float anglemod( float a ); word FloatToHalf( float v ); From b96bfcfe7a5cda3c98f11e1f5cc2048cdb756cd5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 03:47:22 +0300 Subject: [PATCH 022/121] public: mathlib: convert FloatToHalf and HalfToFloat to use float_bits_t union --- public/xash3d_mathlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index 39dc30895..79a58c410 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -73,7 +73,7 @@ float SimpleSpline( float value ) word FloatToHalf( float v ) { - unsigned int i = *((unsigned int *)&v); + unsigned int i = FloatAsUint( v ); unsigned int e = (i >> 23) & 0x00ff; unsigned int m = i & 0x007fffff; unsigned short h; @@ -115,7 +115,7 @@ float HalfToFloat( word h ) } } - return *((float *)&f); + return UintAsFloat( f ); } /* From 19a785a98ae38485cab9cf46bcc4653396a39d6e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 03:48:44 +0300 Subject: [PATCH 023/121] public: mathlib: convert rsqrt to use float_bits_t union --- public/xash3d_mathlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index 79a58c410..f0e6d52a4 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -296,9 +296,9 @@ float rsqrt( float number ) return 0.0f; x = number * 0.5f; - i = *(int *)&number; // evil floating point bit level hacking + i = FloatAsInt( number ); // evil floating point bit level hacking i = 0x5f3759df - (i >> 1); // what the fuck? - y = *(float *)&i; + y = IntAsFloat( i ); y = y * (1.5f - (x * y * y)); // first iteration return y; From ef0b227967d5af588c6f27cdf1e5a88c583655c8 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 03:58:53 +0300 Subject: [PATCH 024/121] ref: gl: alias: fix strict aliasing by converting it to use float_bits_t union --- ref/gl/gl_alias.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ref/gl/gl_alias.c b/ref/gl/gl_alias.c index 71069a509..c96aa14af 100644 --- a/ref/gl/gl_alias.c +++ b/ref/gl/gl_alias.c @@ -292,8 +292,8 @@ void BuildTris( void ) t = (t + 0.5f) / m_pAliasHeader->skinheight; // Carmack use floats and Valve use shorts here... - *(float *)&g_commands[g_numcommands++] = s; - *(float *)&g_commands[g_numcommands++] = t; + g_commands[g_numcommands++] = FloatAsInt( s ); + g_commands[g_numcommands++] = FloatAsInt( t ); } } From 885cda971d37cedf5666742a8360eac8dfed8f56 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 03:59:14 +0300 Subject: [PATCH 025/121] engine: common: net_buffer: fix strict aliasing by converting it to use float_bits_t union --- engine/common/net_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/common/net_buffer.c b/engine/common/net_buffer.c index 2ec7b0084..5de653916 100644 --- a/engine/common/net_buffer.c +++ b/engine/common/net_buffer.c @@ -366,7 +366,7 @@ void MSG_WriteBitFloat( sizebuf_t *sb, float val ) Assert( sizeof( int ) == sizeof( float )); Assert( sizeof( float ) == 4 ); - intVal = *((int *)&val ); + intVal = FloatAsInt( val ); MSG_WriteUBitLong( sb, intVal, 32 ); } @@ -546,7 +546,7 @@ float MSG_ReadBitFloat( sizebuf_t *sb ) val |= ((int)sb->pData[byte + 4]) << ( 32 - bit ); sb->iCurBit += 32; - return *((float *)&val); + return IntAsFloat( val ); } qboolean MSG_ReadBits( sizebuf_t *sb, void *pOutData, int nBits ) From d4610e30fdc597bbb300bcf2f2e833f516a8ff7b Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 03:59:24 +0300 Subject: [PATCH 026/121] engine: common: net_encode: fix strict aliasing by converting it to use float_bits_t union --- engine/common/net_encode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/common/net_encode.c b/engine/common/net_encode.c index dc1c0f6c2..b8589e947 100644 --- a/engine/common/net_encode.c +++ b/engine/common/net_encode.c @@ -1009,8 +1009,8 @@ qboolean Delta_CompareField( delta_t *pField, void *from, void *to, double timeb val_b = Q_rint((*(float *)((byte *)to + pField->offset )) * 100.0 ); val_a -= Q_rint(timebase * 100.0); val_b -= Q_rint(timebase * 100.0); - fromF = *((int *)&val_a); - toF = *((int *)&val_b); + fromF = FloatAsInt( val_a ); + toF = FloatAsInt( val_b ); } else if( pField->flags & DT_TIMEWINDOW_BIG ) { @@ -1030,8 +1030,8 @@ qboolean Delta_CompareField( delta_t *pField, void *from, void *to, double timeb val_b = timebase - val_b; } - fromF = *((int *)&val_a); - toF = *((int *)&val_b); + fromF = FloatAsInt( val_a ); + toF = FloatAsInt( val_b ); } else if( pField->flags & DT_STRING ) { From fec3d33dcfe34eb446389bfbc933bf45670419c4 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 04:03:26 +0300 Subject: [PATCH 027/121] engine: client: cl_securedstub: fix strict aliasing in secured module initializing --- engine/client/cl_securedstub.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/client/cl_securedstub.c b/engine/client/cl_securedstub.c index fd7746b11..f45ba0245 100644 --- a/engine/client/cl_securedstub.c +++ b/engine/client/cl_securedstub.c @@ -405,12 +405,15 @@ static cldll_func_dst_t cldllFuncDst = void CL_GetSecuredClientAPI( CL_EXPORT_FUNCS F ) { - cldll_func_src_t cldllFuncSrc = { 0 }; modfuncs_t modFuncs = { 0 }; // secured client dlls need these - *(cldll_func_dst_t **)&cldllFuncSrc.pfnVidInit = &cldllFuncDst; - *(modfuncs_t **)&cldllFuncSrc.pfnInitialize = &modFuncs; + cldll_func_src_t cldllFuncSrc = + { + (void *)&modFuncs, + NULL, + (void *)&cldllFuncDst + }; // trying to fill interface now F( &cldllFuncSrc ); From 774ced312f82024347fe0063a2fc61b80c1ce952 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 04:12:09 +0300 Subject: [PATCH 028/121] wscript: enforce -Werror=strict-aliasing --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 7b9f45dc0..ecc73e51b 100644 --- a/wscript +++ b/wscript @@ -237,7 +237,7 @@ def configure(conf): '-Werror=sequence-point', # '-Werror=format=2', # '-Wdouble-promotion', # disable warning flood - '-Wstrict-aliasing', + '-Werror=strict-aliasing', '-Wmisleading-indentation', ] From 3a956a1ad31368cecff44feac8939779799357c2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 15 Mar 2023 04:58:00 +0300 Subject: [PATCH 029/121] engine: client: initialize variables in SPR_Width/Height/Frames functions, in case R_GetSpriteParms fails --- engine/client/cl_game.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 43accb9a6..907daf813 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1372,7 +1372,7 @@ pfnSPR_Frames */ int EXPORT pfnSPR_Frames( HSPRITE hPic ) { - int numFrames; + int numFrames = 0; ref.dllFuncs.R_GetSpriteParms( NULL, NULL, &numFrames, 0, CL_GetSpritePointer( hPic )); @@ -1387,7 +1387,7 @@ pfnSPR_Height */ static int GAME_EXPORT pfnSPR_Height( HSPRITE hPic, int frame ) { - int sprHeight; + int sprHeight = 0; ref.dllFuncs.R_GetSpriteParms( NULL, &sprHeight, NULL, frame, CL_GetSpritePointer( hPic )); @@ -1402,7 +1402,7 @@ pfnSPR_Width */ static int GAME_EXPORT pfnSPR_Width( HSPRITE hPic, int frame ) { - int sprWidth; + int sprWidth = 0; ref.dllFuncs.R_GetSpriteParms( &sprWidth, NULL, NULL, frame, CL_GetSpritePointer( hPic )); From 1630d87c0d3b1a7c4dcec3c62979164bfe751699 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 15 Mar 2023 04:58:33 +0300 Subject: [PATCH 030/121] engine: client: do not alter the state if invalid HANDLE was passed to pfnSPR_Set. Fixes Half-Life: MMod --- engine/client/cl_game.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 907daf813..fe3a71adf 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1417,7 +1417,13 @@ pfnSPR_Set */ static void GAME_EXPORT pfnSPR_Set( HSPRITE hPic, int r, int g, int b ) { - clgame.ds.pSprite = CL_GetSpritePointer( hPic ); + const model_t *sprite = CL_GetSpritePointer( hPic ); + + // a1ba: do not alter the state if invalid HSPRITE was passed + if( !sprite ) + return; + + clgame.ds.pSprite = sprite; clgame.ds.spriteColor[0] = bound( 0, r, 255 ); clgame.ds.spriteColor[1] = bound( 0, g, 255 ); clgame.ds.spriteColor[2] = bound( 0, b, 255 ); From 4ada40e8a8aaebeb7d06dc55956a161e1673a1b9 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 15 Mar 2023 06:28:20 +0300 Subject: [PATCH 031/121] engine: client: check if we should discard local player entity before HUD_AddEntity call, allowing CL_IsThirdPerson hack used in MMod --- engine/client/cl_frame.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index 81976384d..6aad74248 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -973,15 +973,6 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) if( !ent || !ent->model ) return false; - // check for adding this entity - if( !clgame.dllFuncs.pfnAddEntity( entityType, ent, ent->model->name )) - { - // local player was reject by game code, so ignore any effects - if( RP_LOCALCLIENT( ent )) - cl.local.apply_effects = false; - return false; - } - // don't add the player in firstperson mode if( RP_LOCALCLIENT( ent )) { @@ -991,6 +982,15 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) return false; } + // check for adding this entity + if( !clgame.dllFuncs.pfnAddEntity( entityType, ent, ent->model->name )) + { + // local player was reject by game code, so ignore any effects + if( RP_LOCALCLIENT( ent )) + cl.local.apply_effects = false; + return false; + } + if( entityType == ET_BEAM ) { ref.dllFuncs.CL_AddCustomBeam( ent ); From d085c5a84332b262cb2c51e0c30f9879fff641c5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 15 Mar 2023 06:29:17 +0300 Subject: [PATCH 032/121] ref: gl: gl_cull: remove thirdperson check, as it handled in client instead --- ref/gl/gl_cull.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ref/gl/gl_cull.c b/ref/gl/gl_cull.c index 3cd3af1dc..cd31c9cc3 100644 --- a/ref/gl/gl_cull.c +++ b/ref/gl/gl_cull.c @@ -65,10 +65,6 @@ int R_CullModel( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax ) return 1; } - // local client can't view himself if camera or thirdperson is not active - if( RP_LOCALCLIENT( e ) && !ENGINE_GET_PARM( PARM_THIRDPERSON ) && CL_IsViewEntityLocalPlayer()) - return 1; - if( R_CullBox( absmin, absmax )) return 1; From 33c0764e65b09b3284afb09f7fe3fc1a6f31b639 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 17 Mar 2023 17:29:40 +0300 Subject: [PATCH 033/121] engine: common: system: fix inverted COM_CheckStringEmpty in Sys_GetCurrentUser for Vita Thanks @fgsfdsfgs for pointing out --- engine/common/system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/common/system.c b/engine/common/system.c index 2c7178400..08ed09fe9 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -136,7 +136,7 @@ const char *Sys_GetCurrentUser( void ) #elif XASH_PSVITA static string username; sceAppUtilSystemParamGetString( SCE_SYSTEM_PARAM_ID_USERNAME, username, sizeof( username ) - 1 ); - if( !COM_CheckStringEmpty( username ) ) + if( COM_CheckStringEmpty( username )) return username; #elif XASH_POSIX && !XASH_ANDROID && !XASH_NSWITCH uid_t uid = geteuid(); From 8c80d3b85de6f7bd13990b1b0f08d3c989251cb0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 18 Mar 2023 20:34:08 +0300 Subject: [PATCH 034/121] engine: common: cvar: add exception for cl_dodmusic cvar to fix Day of Defeat Beta 1.3 music issue --- engine/common/cvar.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 6379f3613..1026016c3 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -39,6 +39,10 @@ static cvar_filter_quirks_t cvar_filter_quirks[] = "ricochet", "r_drawviewmodel", }, + { + "dod", + "cl_dodmusic" // Day of Defeat Beta 1.3 cvar + }, }; static cvar_filter_quirks_t *cvar_active_filter_quirks = NULL; From ea2a8b6785247ef6eb39a6e2241568038514292a Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 20 Mar 2023 16:03:09 +0300 Subject: [PATCH 035/121] 3rdparty: update submodules (extras, mainui, opus) --- 3rdparty/extras/xash-extras | 2 +- 3rdparty/mainui | 2 +- 3rdparty/opus/opus | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/3rdparty/extras/xash-extras b/3rdparty/extras/xash-extras index 9aba45274..853f633be 160000 --- a/3rdparty/extras/xash-extras +++ b/3rdparty/extras/xash-extras @@ -1 +1 @@ -Subproject commit 9aba4527435b1beda97ca8d8a5f1937cd0088c57 +Subproject commit 853f633be18892499a86e7f57fecf34640bd64f2 diff --git a/3rdparty/mainui b/3rdparty/mainui index 3cd540736..950376cc2 160000 --- a/3rdparty/mainui +++ b/3rdparty/mainui @@ -1 +1 @@ -Subproject commit 3cd540736b9806bccf170b73c66d533014b1a9ac +Subproject commit 950376cc28f0a52403ce68c569b749c4206cf230 diff --git a/3rdparty/opus/opus b/3rdparty/opus/opus index 997fdf54e..8cf872a18 160000 --- a/3rdparty/opus/opus +++ b/3rdparty/opus/opus @@ -1 +1 @@ -Subproject commit 997fdf54e781ae1c04dee42018f35388a04fe483 +Subproject commit 8cf872a186b96085b1bb3a547afd598354ebeb87 From 68be8157eacaa1041cb92ed423f6b63c905578db Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sat, 18 Mar 2023 23:31:58 +0400 Subject: [PATCH 036/121] engine: common: soundlib: added Sound_SupportedFileFormat function --- engine/common/common.h | 1 + engine/common/soundlib/snd_utils.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/engine/common/common.h b/engine/common/common.h index 08404a3ab..7835891db 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -566,6 +566,7 @@ int FS_GetStreamPos( stream_t *stream ); void FS_FreeStream( stream_t *stream ); qboolean Sound_Process( wavdata_t **wav, int rate, int width, uint flags ); uint Sound_GetApproxWavePlayLen( const char *filepath ); +qboolean Sound_SupportedFileFormat( const char *fileext ); // // host.c diff --git a/engine/common/soundlib/snd_utils.c b/engine/common/soundlib/snd_utils.c index 98626066f..0319bdaf8 100644 --- a/engine/common/soundlib/snd_utils.c +++ b/engine/common/soundlib/snd_utils.c @@ -290,3 +290,17 @@ qboolean Sound_Process( wavdata_t **wav, int rate, int width, uint flags ) return false; } + +qboolean Sound_SupportedFileFormat( const char *fileext ) +{ + const loadwavfmt_t *format; + if( COM_CheckStringEmpty( fileext )) + { + for( format = sound.loadformats; format && format->formatstring; format++ ) + { + if( !Q_stricmp( format->ext, fileext )) + return true; + } + } + return false; +} From 714b4f45e4b569f98f1e7b6ba84b87dd1d2d2cc4 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sat, 18 Mar 2023 23:47:44 +0400 Subject: [PATCH 037/121] engine: common: added COM_GetResourceTypeName function --- engine/common/common.c | 15 +++++++++++++++ engine/common/common.h | 1 + 2 files changed, 16 insertions(+) diff --git a/engine/common/common.c b/engine/common/common.c index c7c295c92..3e1fcaaea 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -1053,6 +1053,21 @@ qboolean COM_IsSafeFileToDownload( const char *filename ) return true; } +const char *COM_GetResourceTypeName( resourcetype_t restype ) +{ + switch( restype ) + { + case t_decal: return "decal"; + case t_eventscript: return "eventscript"; + case t_generic: return "generic"; + case t_model: return "model"; + case t_skin: return "skin"; + case t_sound: return "sound"; + case t_world: return "world"; + default: return "unknown"; + } +} + char *_copystring( poolhandle_t mempool, const char *s, const char *filename, int fileline ) { char *b; diff --git a/engine/common/common.h b/engine/common/common.h index 7835891db..10e1b06c1 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -638,6 +638,7 @@ void COM_HexConvert( const char *pszInput, int nInputLength, byte *pOutput ); int COM_SaveFile( const char *filename, const void *data, int len ); byte* COM_LoadFileForMe( const char *filename, int *pLength ); qboolean COM_IsSafeFileToDownload( const char *filename ); +const char *COM_GetResourceTypeName( resourcetype_t restype ); cvar_t *pfnCVarGetPointer( const char *szVarName ); int pfnDrawConsoleString( int x, int y, char *string ); void pfnDrawSetTextColor( float r, float g, float b ); From a03019f5e465f170fb5bd4373f2c45d6ceaa5911 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sat, 18 Mar 2023 23:55:40 +0400 Subject: [PATCH 038/121] engine: server: sv_init: enabled handling sound resources specifically This is for timely precaching on client side. Otherwise, files are being downloaded to client, but not precached immediatly after it, and therefore causing a late precaching of sound (obvious, this is bad) --- engine/server/sv_init.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index a21d7cdde..771b5c931 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -276,9 +276,17 @@ model_t *SV_ModelHandle( int modelindex ) return sv.models[modelindex]; } +static resourcetype_t SV_DetermineResourceType( const char *filename ) +{ + if( !Q_strncmp( filename, "sound/", 6 ) && Sound_SupportedFileFormat( COM_FileExtension( filename ))) + return t_sound; + else + return t_generic; +} + void SV_ReadResourceList( const char *filename ) { - string token; + string token; byte *afile; char *pfile; @@ -295,8 +303,23 @@ void SV_ReadResourceList( const char *filename ) if( !COM_IsSafeFileToDownload( token )) continue; - Con_DPrintf( " %s\n", token ); - SV_GenericIndex( token ); + COM_FixSlashes( token ); + resourcetype_t restype = SV_DetermineResourceType( token ); + Con_DPrintf( " %s (%s)\n", token, COM_GetResourceTypeName( restype )); + switch( restype ) + { + // TODO do we need to handle other resource types specifically too? + case t_sound: + { + const char *filepath = token; + filepath += 6; // skip "sound/" part + SV_SoundIndex( filepath ); + break; + } + default: + SV_GenericIndex( token ); + break; + } } Con_DPrintf( "----------------------------------\n" ); From eac8c116a87ac823669f3a8b4f2699e01dc6335e Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sun, 19 Mar 2023 00:05:52 +0400 Subject: [PATCH 039/121] engine: server: sv_init: compiling error fix & minor cleanup --- engine/server/sv_init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 771b5c931..9f9efdcae 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -278,7 +278,7 @@ model_t *SV_ModelHandle( int modelindex ) static resourcetype_t SV_DetermineResourceType( const char *filename ) { - if( !Q_strncmp( filename, "sound/", 6 ) && Sound_SupportedFileFormat( COM_FileExtension( filename ))) + if( !Q_strncmp( filename, DEFAULT_SOUNDPATH, sizeof( DEFAULT_SOUNDPATH ) - 1 ) && Sound_SupportedFileFormat( COM_FileExtension( filename ))) return t_sound; else return t_generic; @@ -289,6 +289,7 @@ void SV_ReadResourceList( const char *filename ) string token; byte *afile; char *pfile; + resourcetype_t restype; afile = FS_LoadFile( filename, NULL, false ); if( !afile ) return; @@ -304,7 +305,7 @@ void SV_ReadResourceList( const char *filename ) continue; COM_FixSlashes( token ); - resourcetype_t restype = SV_DetermineResourceType( token ); + restype = SV_DetermineResourceType( token ); Con_DPrintf( " %s (%s)\n", token, COM_GetResourceTypeName( restype )); switch( restype ) { @@ -312,7 +313,7 @@ void SV_ReadResourceList( const char *filename ) case t_sound: { const char *filepath = token; - filepath += 6; // skip "sound/" part + filepath += sizeof( DEFAULT_SOUNDPATH ) - 1; // skip "sound/" part SV_SoundIndex( filepath ); break; } From 1df1fc32dfcb7cbe790e5238987ceab1f9a97464 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 20 Mar 2023 16:51:13 +0300 Subject: [PATCH 040/121] scripts: gha: psvita: lock vitaGL revision, use --depth=1 in git clone --- scripts/gha/deps_psvita.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/gha/deps_psvita.sh b/scripts/gha/deps_psvita.sh index 8f98b27f9..69737a3d9 100644 --- a/scripts/gha/deps_psvita.sh +++ b/scripts/gha/deps_psvita.sh @@ -6,12 +6,14 @@ echo "Downloading vitasdk..." export VITASDK=/usr/local/vitasdk +VITAGL_SRCREV="c52391378c2bf1a00a0194c4fd88c35492d104b8" # lock vitaGL version to avoid compilation errors + install_package() { ./vdpm $1 || exit 1 } -git clone https://github.com/vitasdk/vdpm.git || exit 1 +git clone https://github.com/vitasdk/vdpm.git --depth=1 || exit 1 pushd vdpm ./bootstrap-vitasdk.sh || exit 1 install_package taihen @@ -24,18 +26,17 @@ popd echo "Downloading vitaGL..." -git clone https://github.com/Rinnegatamante/vitaGL.git || exit 1 +git clone https://github.com/Rinnegatamante/vitaGL.git -b "$VITAGL_SRCREV" --depth=1 || exit 1 echo "Downloading vitaGL fork of SDL2..." -git clone https://github.com/Northfear/SDL.git || exit 1 +git clone https://github.com/Northfear/SDL.git --depth=1 || exit 1 echo "Downloading vita-rtld..." -git clone https://github.com/fgsfdsfgs/vita-rtld.git || exit 1 +git clone https://github.com/fgsfdsfgs/vita-rtld.git --depth=1 || exit 1 echo "Downloading HLSDK..." rm -rf hlsdk-xash3d hlsdk-portable -# TODO: change to FWGS/hlsdk-portable.git when changes are merged in -git clone --recursive https://github.com/fgsfdsfgs/hlsdk-xash3d || exit 1 +git clone --recursive https://github.com/FWGS/hlsdk-portable || exit 1 From 2c8488f07abe5a18cf8e7df2153169c78fdb9dc0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 20 Mar 2023 18:04:29 +0300 Subject: [PATCH 041/121] scripts: gha: psvita: disable SINGLE_THREADED_GC for vitaGL as it was fixed in upstream (thanks, @fgsfds) --- scripts/gha/build_psvita.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gha/build_psvita.sh b/scripts/gha/build_psvita.sh index 19a9cda77..0a67f55b3 100644 --- a/scripts/gha/build_psvita.sh +++ b/scripts/gha/build_psvita.sh @@ -23,7 +23,7 @@ mkdir -p artifacts/ || die echo "Building vitaGL..." -make -C vitaGL NO_TEX_COMBINER=1 HAVE_UNFLIPPED_FBOS=1 HAVE_PTHREAD=1 SINGLE_THREADED_GC=1 MATH_SPEEDHACK=1 DRAW_SPEEDHACK=1 HAVE_CUSTOM_HEAP=1 -j2 install || die +make -C vitaGL NO_TEX_COMBINER=1 HAVE_UNFLIPPED_FBOS=1 HAVE_PTHREAD=1 MATH_SPEEDHACK=1 DRAW_SPEEDHACK=1 HAVE_CUSTOM_HEAP=1 -j2 install || die echo "Building vrtld..." From 3949422430b357875600c18d2b2a0656e916c069 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 20 Mar 2023 18:14:51 +0300 Subject: [PATCH 042/121] scripts: gha: psvita: fix HLSDK branches names, as all needed PSVita changes have been merged to hlsdk-portable --- scripts/gha/build_psvita.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/gha/build_psvita.sh b/scripts/gha/build_psvita.sh index 0a67f55b3..8ab28da31 100644 --- a/scripts/gha/build_psvita.sh +++ b/scripts/gha/build_psvita.sh @@ -49,11 +49,10 @@ cp build/engine/xash.vpk pkgtemp/ echo "Building HLSDK..." -# TODO: replace with hlsdk-portable and the correct branch names when PRs are merged pushd hlsdk-xash3d -build_hlsdk vita-mobile_hacks valve -build_hlsdk vita-opfor gearbox -build_hlsdk vita-bshift bshift +build_hlsdk mobile_hacks valve +build_hlsdk opfor gearbox +build_hlsdk bshift bshift popd echo "Generating default config files..." From dca637d4bb0a1beaa2034bd2207e5332c5e5a329 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 21 Mar 2023 04:25:32 +0300 Subject: [PATCH 043/121] engine: client: eliminate pfnServerCmd limit and, like GoldSrc, send our server command immediately to netchan --- engine/client/cl_game.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index fe3a71adf..358c27384 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1727,14 +1727,12 @@ pfnServerCmd */ static int GAME_EXPORT pfnServerCmd( const char *szCmdString ) { - string buf; - if( !COM_CheckString( szCmdString )) return 0; // just like the client typed "cmd xxxxx" at the console - Q_snprintf( buf, sizeof( buf ) - 1, "cmd %s\n", szCmdString ); - Cbuf_AddText( buf ); + MSG_BeginClientCmd( &cls.netchan.message, clc_stringcmd ); + MSG_WriteString( &cls.netchan.message, szCmdString ); return 1; } From cc6838ec9730532b07fe0b40dd45963bf1e83a92 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 21 Mar 2023 04:32:37 +0300 Subject: [PATCH 044/121] scripts: gha: psvita: try to fix vitaGL dependency fetching --- scripts/gha/deps_psvita.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/gha/deps_psvita.sh b/scripts/gha/deps_psvita.sh index 69737a3d9..35795a36a 100644 --- a/scripts/gha/deps_psvita.sh +++ b/scripts/gha/deps_psvita.sh @@ -26,7 +26,10 @@ popd echo "Downloading vitaGL..." -git clone https://github.com/Rinnegatamante/vitaGL.git -b "$VITAGL_SRCREV" --depth=1 || exit 1 +git clone https://github.com/Rinnegatamante/vitaGL.git || exit 1 +pushd vitaGL +git checkout $VITAGL_SRCREV || exit 1 +popd echo "Downloading vitaGL fork of SDL2..." From f8cf2c89538dd7cdb24520a4ec9b007d016ff922 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 21 Mar 2023 05:00:46 +0300 Subject: [PATCH 045/121] scripts: continious_upload: retry if upload failed --- scripts/continious_upload.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/continious_upload.sh b/scripts/continious_upload.sh index fb91611b9..bc4656b29 100755 --- a/scripts/continious_upload.sh +++ b/scripts/continious_upload.sh @@ -263,12 +263,21 @@ urlencode() { for FILE in "$@" ; do FULLNAME="${FILE}" BASENAME="$(basename "${FILE}")" - curl -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.manifold-preview" \ - -H "Content-Type: application/octet-stream" \ - --data-binary "@$FULLNAME" \ - "$upload_url?name=$(urlencode "$BASENAME")" - echo "" + + for retries in {1..10}; do + echo "Upload attempt $retries" + + if curl -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.manifold-preview" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@$FULLNAME" \ + "$upload_url?name=$(urlencode "$BASENAME")"; then + break + fi + + sleep 1m # try to avoid ratelimits??? + echo "" + done done $shatool "$@" From 098c4c009bddd27dac9635cc838796db09a40f80 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 21 Mar 2023 05:16:07 +0300 Subject: [PATCH 046/121] engine: platform: sdl: fix incorrect HICON cast in SetClassLongPtr call --- engine/platform/sdl/vid_sdl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index a1df9f85c..e23b7358b 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -619,7 +619,7 @@ static void WIN_SetWindowIcon( HICON ico ) if( SDL_GetWindowWMInfo( host.hWnd, &wminfo ) ) { - SetClassLongPtr( wminfo.info.win.window, GCLP_HICON, (LONG)ico ); + SetClassLongPtr( wminfo.info.win.window, GCLP_HICON, (LONG_PTR)ico ); } } #endif From 762e4da7a08dd874329ae9eb6d6aea38e6aa2a49 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Mar 2023 01:47:34 +0300 Subject: [PATCH 047/121] wscript: generic refactoring * Add RefDll class to aid in enabling renderers, creating help options, etc * Fix optimization flags and werrors are being added twice * Rewrite if not win32: if elif elif into a set of elifs * Remove mandatory=True in checks, as it's a default option --- wscript | 240 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 133 insertions(+), 107 deletions(-) diff --git a/wscript b/wscript index ecc73e51b..fc54f568c 100644 --- a/wscript +++ b/wscript @@ -29,6 +29,35 @@ class Subproject: return True +class RefDll: + def __init__(self, name, default, key = None): + self.name = name + self.default = default + self.dest = key if key else name.upper() + + def register_option(self, opt): + kw = dict() + if self.default: + act = 'disable' + kw['action'] = 'store_false' + else: + act = 'enable' + kw['action'] = 'store_true' + + key = '--%s-%s' % (act, self.name) + + kw['dest'] = self.dest + kw['default'] = self.default + kw['help'] = '%s %s renderer [default: %%default]' % (act, self.name) + + opt.add_option(key, **kw) + + def register_env(self, env, opts, force): + env[self.dest] = force or opts.__dict__[self.dest] + + def register_define(self, conf): + conf.define_cond('XASH_REF_%s_ENABLED' % self.dest, conf.env[self.dest]) + SUBDIRS = [ # always configured and built Subproject('public'), @@ -60,6 +89,14 @@ SUBDIRS = [ Subproject('ref/gl/vgl_shim', lambda x: x.env.DEST_OS == 'psvita'), ] +REFDLLS = [ + RefDll('soft', True), + RefDll('gl', True), + RefDll('gles1', False, 'NANOGL'), + RefDll('gles2', False, 'GLWES'), + RefDll('gl4es', False), +] + def options(opt): grp = opt.add_option_group('Common options') @@ -95,20 +132,8 @@ def options(opt): grp.add_option('--enable-all-renderers', action='store_true', dest='ALL_RENDERERS', default=False, help = 'enable all renderers supported by Xash3D FWGS [default: %default]') - grp.add_option('--enable-gles1', action='store_true', dest='NANOGL', default=False, - help = 'enable gles1 renderer [default: %default]') - - grp.add_option('--enable-gles2', action='store_true', dest='GLWES', default=False, - help = 'enable gles2 renderer [default: %default]') - - grp.add_option('--enable-gl4es', action='store_true', dest='GL4ES', default=False, - help = 'enable gles2 renderer [default: %default]') - - grp.add_option('--disable-gl', action='store_false', dest='GL', default=True, - help = 'disable opengl renderer [default: %default]') - - grp.add_option('--disable-soft', action='store_false', dest='SOFT', default=True, - help = 'disable soft renderer [default: %default]') + for dll in REFDLLS: + dll.register_option(grp) grp = opt.add_option_group('Utilities options') @@ -210,105 +235,105 @@ def configure(conf): conf.load('force_32bit') - compiler_optional_flags = [ -# '-Wall', '-Wextra', '-Wpedantic', - '-fdiagnostics-color=always', - '-Werror=return-type', - '-Werror=parentheses', - '-Werror=vla', - '-Werror=tautological-compare', - '-Werror=duplicated-cond', - '-Werror=bool-compare', - '-Werror=bool-operation', - '-Werror=cast-align=strict', # =strict is for GCC >=8 - '-Werror=packed', - '-Werror=packed-not-aligned', - '-Wuninitialized', # older GCC versions have -Wmaybe-uninitialized enabled by this switch, which is not accurate - # so just warn, not error - '-Winit-self', - '-Werror=implicit-fallthrough=2', # clang incompatible without "=2" - '-Werror=logical-op', - '-Werror=write-strings', - '-Werror=sizeof-pointer-memaccess', - '-Werror=sizeof-array-div', - '-Werror=sizeof-pointer-div', - '-Werror=string-compare', - '-Werror=use-after-free=3', - '-Werror=sequence-point', -# '-Werror=format=2', -# '-Wdouble-promotion', # disable warning flood - '-Werror=strict-aliasing', - '-Wmisleading-indentation', - ] - - c_compiler_optional_flags = [ - '-Werror=incompatible-pointer-types', - '-Werror=implicit-function-declaration', - '-Werror=int-conversion', - '-Werror=implicit-int', - '-Werror=strict-prototypes', - '-Werror=old-style-declaration', - '-Werror=old-style-definition', - '-Werror=declaration-after-statement', - '-Werror=enum-conversion', - '-Werror=jump-misses-init', - '-Werror=strict-prototypes', -# '-Werror=nested-externs', - '-fnonconst-initializers' # owcc - ] - cflags, linkflags = conf.get_optimization_flags() + cxxflags = list(cflags) # optimization flags are common between C and C++ but we need a copy # on the Switch, allow undefined symbols by default, which is needed for libsolder to work # we'll specifically disallow them for the engine executable # additionally, shared libs are linked without standard libs, we'll add those back in the engine wscript if conf.env.DEST_OS == 'nswitch': linkflags.remove('-Wl,--no-undefined') - conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles']) - conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-nostartfiles']) + linkflags.extend(['-nostdlib', '-nostartfiles']) # same on the vita if conf.env.DEST_OS == 'psvita': - conf.env.append_unique('CFLAGS_cshlib', ['-fPIC']) - conf.env.append_unique('CXXFLAGS_cxxshlib', ['-fPIC', '-fno-use-cxa-atexit']) - conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all']) - conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all']) - - # And here C++ flags starts to be treated separately - cxxflags = list(cflags) - if conf.env.COMPILER_CC != 'msvc' and not conf.options.DISABLE_WERROR: - conf.check_cc(cflags=cflags, linkflags=linkflags, msg='Checking for required C flags') - conf.check_cxx(cxxflags=cflags, linkflags=linkflags, msg='Checking for required C++ flags') - - conf.env.append_unique('CFLAGS', cflags) - conf.env.append_unique('CXXFLAGS', cxxflags) - conf.env.append_unique('LINKFLAGS', linkflags) + cflags.append('-fPIC') + cxxflags.extend(['-fPIC', '-fno-use-cxa-atexit']) + linkflags.extend(['-nostdlib', '-Wl,--unresolved-symbols=ignore-all']) - cxxflags += conf.filter_cxxflags(compiler_optional_flags, cflags) - cflags += conf.filter_cflags(compiler_optional_flags + c_compiler_optional_flags, cflags) + # check if we need to use irix linkflags + if conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc': + linkflags.remove('-Wl,--no-undefined') + linkflags.append('-Wl,--unresolved-symbols=ignore-all') + # check if we're in a sgug environment + if 'sgug' in os.environ['LD_LIBRARYN32_PATH']: + linkflags.append('-lc') - # check if we need to use irix linkflags - if conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc': - linkflags.remove('-Wl,--no-undefined') - linkflags.append('-Wl,--unresolved-symbols=ignore-all') - # check if we're in a sgug environment - if 'sgug' in os.environ['LD_LIBRARYN32_PATH']: - linkflags.append('-lc') + conf.check_cc(cflags=cflags, linkflags=linkflags, msg='Checking for required C flags') + conf.check_cxx(cxxflags=cxxflags, linkflags=linkflags, msg='Checking for required C++ flags') conf.env.append_unique('CFLAGS', cflags) conf.env.append_unique('CXXFLAGS', cxxflags) conf.env.append_unique('LINKFLAGS', linkflags) + if conf.env.COMPILER_CC != 'msvc' and not conf.options.DISABLE_WERROR: + opt_flags = [ + # '-Wall', '-Wextra', '-Wpedantic', + '-fdiagnostics-color=always', + + # stable diagnostics, forced to error, sorted + '-Werror=bool-compare', + '-Werror=bool-operation', + '-Werror=cast-align=strict', + '-Werror=duplicated-cond', + # '-Werror=format=2', + '-Werror=implicit-fallthrough=2', + '-Werror=logical-op', + '-Werror=packed', + '-Werror=packed-not-aligned', + '-Werror=parentheses', + '-Werror=return-type', + '-Werror=sequence-point', + '-Werror=sizeof-pointer-memaccess', + '-Werror=sizeof-array-div', + '-Werror=sizeof-pointer-div', + '-Werror=strict-aliasing', + '-Werror=string-compare', + '-Werror=tautological-compare', + '-Werror=use-after-free=3', + '-Werror=vla', + '-Werror=write-strings', + + # unstable diagnostics, may cause false positives + '-Winit-self', + '-Wmisleading-indentation', + '-Wunintialized', + + # disabled, flood + # '-Wdouble-promotion', + ] + + opt_cflags = [ + '-Werror=declaration-after-statement', + '-Werror=enum-conversion', + '-Werror=implicit-int', + '-Werror=implicit-function-declaration', + '-Werror=incompatible-pointer-types', + '-Werror=int-conversion', + '-Werror=jump-misses-init', + '-Werror=old-style-declaration', + '-Werror=old-style-definition', + '-Werror=strict-prototypes', + '-fnonconst-initializers' # owcc + ] + + opt_cxxflags = [] # TODO: + + cflags = conf.filter_cflags(opt_flags + opt_cflags, cflags) + cxxflags = conf.filter_cxxflags(opt_flags + opt_cxxflags, cxxflags) + + conf.env.append_unique('CFLAGS', cflags) + conf.env.append_unique('CXXFLAGS', cxxflags) + conf.env.ENABLE_UTILS = conf.options.ENABLE_UTILS conf.env.ENABLE_FUZZER = conf.options.ENABLE_FUZZER conf.env.DEDICATED = conf.options.DEDICATED conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY or conf.env.DEDICATED - conf.env.NANOGL = conf.options.NANOGL or conf.options.ALL_RENDERERS - conf.env.GLWES = conf.options.GLWES or conf.options.ALL_RENDERERS - conf.env.GL4ES = conf.options.GL4ES or conf.options.ALL_RENDERERS - conf.env.GL = conf.options.GL or conf.options.ALL_RENDERERS - conf.env.SOFT = conf.options.SOFT or conf.options.ALL_RENDERERS + setattr(conf, 'refdlls', REFDLLS) + + for refdll in REFDLLS: + refdll.register_env(conf.env, conf.options, conf.options.ALL_RENDERERS) conf.env.GAMEDIR = conf.options.GAMEDIR conf.define('XASH_GAMEDIR', conf.options.GAMEDIR) @@ -322,22 +347,19 @@ def configure(conf): elif conf.check_cc(header_name='malloc.h', mandatory=False): conf.define('ALLOCA_H', 'malloc.h') - if conf.env.DEST_OS != 'win32': - if conf.env.DEST_OS == 'nswitch': - conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER', mandatory=True) - if conf.env.HAVE_SOLDER and conf.env.LIB_SOLDER and conf.options.BUILD_TYPE == 'debug': - conf.env.LIB_SOLDER[0] += 'd' # load libsolderd in debug mode - elif conf.env.DEST_OS == 'psvita': - conf.check_cc(lib='vrtld', mandatory=True) - else: - conf.check_cc(lib='dl', mandatory=False) - - if not conf.env.LIB_M: # HACK: already added in xcompile! - conf.check_cc(lib='m') - - if conf.env.DEST_OS == 'android': - conf.check_cc(lib='log') - else: + if conf.env.DEST_OS == 'nswitch': + conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER') + if conf.env.HAVE_SOLDER and conf.env.LIB_SOLDER and conf.options.BUILD_TYPE == 'debug': + conf.env.LIB_SOLDER[0] += 'd' # load libsolderd in debug mode + conf.check_cc(lib='m') + elif conf.env.DEST_OS == 'psvita': + conf.check_cc(lib='vrtld') + conf.check_cc(lib='m') + elif conf.env.DEST_OS == 'android': + conf.check_cc(lib='dl') + conf.check_cc(lib='log') + # LIB_M added in xcompile! + elif conf.env.DEST_OS == 'win32': # Common Win32 libraries # Don't check them more than once, to save time # Usually, they are always available @@ -351,6 +373,10 @@ def configure(conf): else: for i in a: conf.check_cc(lib = i) + else: + conf.check_cc(lib='dl') + conf.check_cc(lib='m') + # check if we can use C99 tgmath if conf.check_cc(header_name='tgmath.h', mandatory=False): From 182d8edb42b4a84d62b3548b6c86d19990052286 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Mar 2023 01:50:53 +0300 Subject: [PATCH 048/121] engine: wscript: define enabled renderers as macros --- engine/wscript | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/wscript b/engine/wscript index e574ad17a..911cde934 100644 --- a/engine/wscript +++ b/engine/wscript @@ -126,6 +126,9 @@ def configure(conf): conf.define_cond('DBGHELP', conf.env.DEST_OS == 'win32') conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1 + for refdll in conf.refdlls: + refdll.register_define(conf) + def build(bld): # public includes for renderers and utils use bld(name = 'engine_includes', export_includes = '. common common/imagelib', use = 'filesystem_includes') From ec355a83d19999b834b999c25250de019f5a191e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Mar 2023 01:52:14 +0300 Subject: [PATCH 049/121] engine: client: ref_common: eliminate COM_FreeLibrary in renderer names query, hardcoding them instead --- engine/client/ref_common.c | 112 +++++++++++++++++------------------- engine/client/ref_common.h | 5 +- engine/common/com_strings.h | 4 -- 3 files changed, 56 insertions(+), 65 deletions(-) diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 9d8ee9b2d..255f127c1 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -565,66 +565,62 @@ static void SetWidthAndHeightFromCommandLine( void ) static void SetFullscreenModeFromCommandLine( void ) { #if !XASH_MOBILE_PLATFORM - if ( Sys_CheckParm("-fullscreen") ) + if( Sys_CheckParm( "-fullscreen" )) { Cvar_Set( "fullscreen", "1" ); } - else if ( Sys_CheckParm( "-windowed" ) ) + else if( Sys_CheckParm( "-windowed" )) { Cvar_Set( "fullscreen", "0" ); } #endif } -void R_CollectRendererNames( void ) +static void R_CollectRendererNames( void ) { - const char *renderers[] = DEFAULT_RENDERERS; - int i, cur; - - cur = 0; - for( i = 0; i < DEFAULT_RENDERERS_LEN; i++ ) + // ordering is important! + static const char *shortNames[] = { - string temp; - void *dll, *pfn; - - R_GetRendererName( temp, sizeof( temp ), renderers[i] ); - - dll = COM_LoadLibrary( temp, false, true ); - if( !dll ) - { - Con_Reportf( "R_CollectRendererNames: can't load library %s: %s\n", temp, COM_GetLibraryError() ); - continue; - } - - pfn = COM_GetProcAddress( dll, GET_REF_API ); - if( !pfn ) - { - Con_Reportf( "R_CollectRendererNames: can't find API entry point in %s\n", temp ); - COM_FreeLibrary( dll ); - continue; - } - - Q_strncpy( ref.shortNames[cur], renderers[i], sizeof( ref.shortNames[cur] )); - - pfn = COM_GetProcAddress( dll, GET_REF_HUMANREADABLE_NAME ); - if( !pfn ) // just in case - { - Con_Reportf( "R_CollectRendererNames: can't find GetHumanReadableName export in %s\n", temp ); - Q_strncpy( ref.readableNames[cur], renderers[i], sizeof( ref.readableNames[cur] )); - } - else - { - REF_HUMANREADABLE_NAME GetHumanReadableName = (REF_HUMANREADABLE_NAME)pfn; - - GetHumanReadableName( ref.readableNames[cur], sizeof( ref.readableNames[cur] )); - } +#if XASH_REF_GL_ENABLED + "gl", +#endif +#if XASH_REF_NANOGL_ENABLED + "gles1", +#endif +#if XASH_REF_GLWES_ENABLED + "gles2", +#endif +#if XASH_REF_GL4ES_ENABLED + "gl4es", +#endif +#if XASH_REF_SOFT_ENABLED + "soft", +#endif + }; - Con_Printf( "Found renderer %s: %s\n", ref.shortNames[cur], ref.readableNames[cur] ); + // ordering is important here too! + static const char *readableNames[ARRAYSIZE( shortNames )] = + { +#if XASH_REF_GL_ENABLED + "OpenGL", +#endif +#if XASH_REF_NANOGL_ENABLED + "GLES1 (NanoGL)", +#endif +#if XASH_REF_GLWES_ENABLED + "GLES2 (gl-wes-v2)", +#endif +#if XASH_REF_GL4ES_ENABLED + "GL4ES", +#endif +#if XASH_REF_SOFT_ENABLED + "Software", +#endif + }; - cur++; - COM_FreeLibrary( dll ); - } - ref.numRenderers = cur; + ref.numRenderers = ARRAYSIZE( shortNames ); + ref.shortNames = shortNames; + ref.readableNames = readableNames; } qboolean R_Init( void ) @@ -678,30 +674,28 @@ qboolean R_Init( void ) // 1. Command line `-ref` argument. // 2. `ref_dll` cvar. // 3. Detected renderers in `DEFAULT_RENDERERS` order. - requested[0] = '\0'; - if( !Sys_GetParmFromCmdLine( "-ref", requested ) && COM_CheckString( r_refdll->string ) ) - // r_refdll is set to empty by default, so we can change hardcoded defaults just in case - Q_strncpy( requested, r_refdll->string, sizeof( requested ) ); + requested[0] = 0; + + if( !success && Sys_GetParmFromCmdLine( "-ref", requested )) + success = R_LoadRenderer( requested ); - if ( requested[0] ) + if( !success && COM_CheckString( r_refdll->string )) + { + Q_strncpy( requested, r_refdll->string, sizeof( requested )); success = R_LoadRenderer( requested ); + } if( !success ) { int i; - // cycle through renderers that we collected in CollectRendererNames - for( i = 0; i < ref.numRenderers; i++ ) + for( i = 0; i < ref.numRenderers && !success; i++ ) { // skip renderer that was requested but failed to load - if( !Q_strcmp( requested, ref.shortNames[i] ) ) + if( !Q_strcmp( requested, ref.shortNames[i] )) continue; success = R_LoadRenderer( ref.shortNames[i] ); - - // yay, found working one - if( success ) - break; } } diff --git a/engine/client/ref_common.h b/engine/client/ref_common.h index a8ee14050..3904d58b7 100644 --- a/engine/client/ref_common.h +++ b/engine/client/ref_common.h @@ -27,9 +27,10 @@ struct ref_state_s HINSTANCE hInstance; ref_interface_t dllFuncs; + // depends on build configuration int numRenderers; - string shortNames[DEFAULT_RENDERERS_LEN]; - string readableNames[DEFAULT_RENDERERS_LEN]; + const char **shortNames; + const char **readableNames; }; extern struct ref_state_s ref; diff --git a/engine/common/com_strings.h b/engine/common/com_strings.h index 50bde3737..d3dc7dca4 100644 --- a/engine/common/com_strings.h +++ b/engine/common/com_strings.h @@ -68,8 +68,4 @@ GNU General Public License for more details. #define XASH_VERSION "0.20" // engine current version #define XASH_COMPAT_VERSION "0.99" // version we are based on -// renderers order is important, software is always a last chance fallback -#define DEFAULT_RENDERERS { "gl", "gles1", "gles2", "gl4es", "soft" } -#define DEFAULT_RENDERERS_LEN 5 - #endif//COM_STRINGS_H From 35ff06240778435a861cec7c34d31ddc82ac32ba Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Mar 2023 02:09:23 +0300 Subject: [PATCH 050/121] wscript: restore NSwitch and PSVita specific link and compiler flags --- wscript | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wscript b/wscript index fc54f568c..7eaecbcbc 100644 --- a/wscript +++ b/wscript @@ -243,16 +243,16 @@ def configure(conf): # additionally, shared libs are linked without standard libs, we'll add those back in the engine wscript if conf.env.DEST_OS == 'nswitch': linkflags.remove('-Wl,--no-undefined') - linkflags.extend(['-nostdlib', '-nostartfiles']) - + conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles']) + conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-nostartfiles']) # same on the vita - if conf.env.DEST_OS == 'psvita': - cflags.append('-fPIC') - cxxflags.extend(['-fPIC', '-fno-use-cxa-atexit']) - linkflags.extend(['-nostdlib', '-Wl,--unresolved-symbols=ignore-all']) - + elif conf.env.DEST_OS == 'psvita': + conf.env.append_unique('CFLAGS_cshlib', ['-fPIC']) + conf.env.append_unique('CXXFLAGS_cxxshlib', ['-fPIC', '-fno-use-cxa-atexit']) + conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all']) + conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all']) # check if we need to use irix linkflags - if conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc': + elif conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc': linkflags.remove('-Wl,--no-undefined') linkflags.append('-Wl,--unresolved-symbols=ignore-all') # check if we're in a sgug environment From 8bb5ec5e26bac440beebc5f2c3860d320f3e9aae Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Mar 2023 02:54:14 +0300 Subject: [PATCH 051/121] ref: remove renderer description export, it's unused now --- engine/ref_api.h | 3 --- ref/gl/gl_context.c | 13 ------------- ref/soft/r_context.c | 5 ----- 3 files changed, 21 deletions(-) diff --git a/engine/ref_api.h b/engine/ref_api.h index 1ac5adcb1..dbcef6d04 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -621,9 +621,6 @@ typedef struct ref_interface_s typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals ); #define GET_REF_API "GetRefAPI" -typedef void (*REF_HUMANREADABLE_NAME)( char *out, size_t len ); -#define GET_REF_HUMANREADABLE_NAME "GetRefHumanReadableName" - #ifdef REF_DLL #define DEFINE_ENGINE_SHARED_CVAR( x, y ) cvar_t *x = NULL; #define DECLARE_ENGINE_SHARED_CVAR( x, y ) extern cvar_t *x; diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index c95c01550..2673c93e2 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -512,16 +512,3 @@ int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, return REF_API_VERSION; } - -void EXPORT GetRefHumanReadableName( char *out, size_t size ) -{ -#if defined XASH_NANOGL - Q_strncpy( out, "GLES1(NanoGL)", size ); -#elif defined XASH_WES - Q_strncpy( out, "GLES2(gl-wes-v2)", size ); -#elif defined XASH_GL4ES - Q_strncpy( out, "GLES2(gl4es)", size ); -#else - Q_strncpy( out, "OpenGL", size ); -#endif -} diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index d02ff9e86..3004cb8e6 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -582,8 +582,3 @@ int EXPORT GAME_EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t return REF_API_VERSION; } - -void EXPORT GetRefHumanReadableName( char *out, size_t size ) -{ - Q_strncpy( out, "Software", size ); -} From 3ccbc7a28cdfcd08981ac583eb1895886e18e647 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Mar 2023 18:03:06 +0300 Subject: [PATCH 052/121] engine: client: ref_common: r_refdll is not a VIDRESTART cvar --- engine/client/ref_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 255f127c1..732f2a3a2 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -635,7 +635,7 @@ qboolean R_Init( void ) gl_msaa_samples = Cvar_Get( "gl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" ); gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" ); r_showtree = Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" ); - r_refdll = Cvar_Get( "r_refdll", "", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "choose renderer implementation, if supported" ); + r_refdll = Cvar_Get( "r_refdll", "", FCVAR_RENDERINFO, "choose renderer implementation, if supported" ); // cvars that are expected to exist Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" ); From e673fe9a02c2a909efb498860c58027cf2fb0e0c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 25 Mar 2023 03:27:32 +0300 Subject: [PATCH 053/121] filesystem: only create readwrite directories if they look like a gamedirectory in rodir --- filesystem/filesystem.c | 70 ++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index e09c3f1a5..7de8c0691 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -907,31 +907,55 @@ static qboolean FS_ReadGameInfo( const char *filepath, const char *gamedir, game /* ================ -FS_CheckForGameDir +FS_CheckForQuakeGameDir + +Checks if game directory resembles Quake Engine game directory +(some of checks may as well work with Xash gamedirs, it's not a bug) ================ */ -static qboolean FS_CheckForGameDir( const char *gamedir ) +static qboolean FS_CheckForQuakeGameDir( const char *gamedir, qboolean direct ) { - char buf[MAX_VA_STRING]; + // if directory contain config.cfg or progs.dat it's 100% gamedir + // quake mods probably always archived but can missed config.cfg before first running + const char *files[] = { "config.cfg", "progs.dat", "pak0.pak" }; + int i; - // if directory contain config.cfg it's 100% gamedir - Q_snprintf( buf, sizeof( buf ), "%s/config.cfg", gamedir ); - if( FS_FileExists( buf, false )) - return true; + for( i = 0; i < sizeof( files ) / sizeof( files[0] ); i++ ) + { + char buf[MAX_VA_STRING]; - // if directory contain progs.dat it's 100% gamedir - Q_snprintf( buf, sizeof( buf ), "%s/progs.dat", gamedir ); - if( FS_FileExists( buf, false )) - return true; + Q_snprintf( buf, sizeof( buf ), "%s/%s", gamedir, files[i] ); + if( direct ? FS_SysFileExists( buf ) : FS_FileExists( buf, false )) + return true; + } - // quake mods probably always archived but can missed config.cfg before first running - Q_snprintf( buf, sizeof( buf ), "%s/pak0.pak", gamedir ); - if( FS_FileExists( buf, false )) - return true; + return false; +} + +/* +=============== +FS_CheckForXashGameDir + +Checks if game directory resembles Xash3D game directory +=============== +*/ +static qboolean FS_CheckForXashGameDir( const char *gamedir, qboolean direct ) +{ + // if directory contain gameinfo.txt or liblist.gam it's 100% gamedir + const char *files[] = { "gameinfo.txt", "liblist.gam" }; + int i; + + for( i = 0; i < sizeof( files ) / sizeof( files[0] ); i++ ) + { + char buf[MAX_SYSPATH]; - // NOTE; adds here some additional checks if you wished + Q_snprintf( buf, sizeof( buf ), "%s/%s", gamedir, files[i] ); + if( direct ? FS_SysFileExists( buf ) : FS_FileExists( buf, false )) + return true; + } return false; + } /* @@ -990,7 +1014,7 @@ static qboolean FS_ParseGameInfo( const char *gamedir, gameinfo_t *GameInfo ) FS_ConvertGameInfo( gamedir, gameinfo_path, liblist_path ); // force to create gameinfo for specified game if missing - if(( FS_CheckForGameDir( gamedir ) || !Q_stricmp( fs_gamedir, gamedir )) && !FS_FileExists( gameinfo_path, false )) + if(( FS_CheckForQuakeGameDir( gamedir, false ) || !Q_stricmp( fs_gamedir, gamedir )) && !FS_FileExists( gameinfo_path, false )) { gameinfo_t tmpGameInfo; memset( &tmpGameInfo, 0, sizeof( tmpGameInfo )); @@ -1340,17 +1364,21 @@ qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char for( i = 0; i < dirs.numstrings; i++ ) { char roPath[MAX_SYSPATH]; - char rwPath[MAX_SYSPATH]; Q_snprintf( roPath, sizeof( roPath ), "%s/%s/", fs_rodir, dirs.strings[i] ); - Q_snprintf( rwPath, sizeof( rwPath ), "%s/%s/", fs_rootdir, dirs.strings[i] ); // check if it's a directory if( !FS_SysFolderExists( roPath )) continue; - // no need to check folders here, FS_CreatePath will not fail - FS_CreatePath( rwPath ); + // check if it's gamedir + if( FS_CheckForXashGameDir( roPath, true ) || FS_CheckForQuakeGameDir( roPath, true )) + { + char rwPath[MAX_SYSPATH]; + + Q_snprintf( rwPath, sizeof( rwPath ), "%s/%s/", fs_rootdir, dirs.strings[i] ); + FS_CreatePath( rwPath ); + } } stringlistfreecontents( &dirs ); From 1caa2765312af1fe9cc93676bae3d48aa44f2f0c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 25 Mar 2023 06:58:03 +0300 Subject: [PATCH 054/121] engine: common: imagelib: fix loading cubemaps Loop break was a bug that was added after refactoring imagelib loader. In fact, it was mindlessly copypasted from old code, where same break was used to quickly exit from inner format bruteforcing loop, than outer cubemap loading loop. --- engine/common/imagelib/img_main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/engine/common/imagelib/img_main.c b/engine/common/imagelib/img_main.c index dbdfb7e4b..11d8d51d5 100644 --- a/engine/common/imagelib/img_main.c +++ b/engine/common/imagelib/img_main.c @@ -321,10 +321,9 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) { for( i = 0; i < 6; i++ ) { - if( Image_ProbeLoad( extfmt, loadname, cmap->type[i].suf, cmap->type[i].hint ) && - FS_AddSideToPack( cmap->type[i].flags )) // process flags to flip some sides + if( Image_ProbeLoad( extfmt, loadname, cmap->type[i].suf, cmap->type[i].hint )) { - break; + FS_AddSideToPack( cmap->type[i].flags ); } if( image.num_sides != i + 1 ) // check side @@ -339,7 +338,7 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) } } - // make sure what all sides is loaded + // make sure that all sides is loaded if( image.num_sides != 6 ) { // unexpected errors ? From 2c77f4c566c952717bc76e64dd475ac921972a45 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 03:47:42 +0300 Subject: [PATCH 055/121] engine: client: notify client.dll about local player in firstplayer mode for use in custom renderers --- engine/client/cl_frame.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index 6aad74248..e4c2141c7 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -970,6 +970,8 @@ all the visible entities should pass this filter */ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) { + qboolean draw_player = true; + if( !ent || !ent->model ) return false; @@ -979,7 +981,12 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) cl.local.apply_effects = true; if( !CL_IsThirdPerson( ) && ( ent->index == cl.viewentity )) - return false; + { + // we don't draw player in default renderer in firstperson mode + // but let the client.dll know about player entity anyway + // for use in custom renderers + draw_player = false; + } } // check for adding this entity @@ -991,6 +998,9 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) return false; } + if( !draw_player ) + return false; + if( entityType == ET_BEAM ) { ref.dllFuncs.CL_AddCustomBeam( ent ); From fcda7517fe91ef55164b6fce55e67b02a09ce052 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 19 Feb 2023 12:28:46 +0300 Subject: [PATCH 056/121] engine: common: soundlib: add support for MP3 looping through custom ID3v2.4.0 tagging --- Documentation/extensions/mp3-loops.md | 22 +++ engine/common/soundlib/snd_main.c | 1 - engine/common/soundlib/snd_mp3.c | 184 ++++++++++++++++++++++++++ utils/run-fuzzer/wscript | 1 + 4 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 Documentation/extensions/mp3-loops.md diff --git a/Documentation/extensions/mp3-loops.md b/Documentation/extensions/mp3-loops.md new file mode 100644 index 000000000..59fd6efd1 --- /dev/null +++ b/Documentation/extensions/mp3-loops.md @@ -0,0 +1,22 @@ +## Looping MP3 extension + +It is now possible to loop MP3 file in Xash3D FWGS by adding a custom text tag with `LOOP_START` or `LOOPSTART` in description and time point (in raw samples) in value. + +### Example with foobar2000 +1. Open Foobar2000 +2. Add your .mp3 file to playlist +3. Right click to newly added file and select Properties +4. In Metadata tab, at the bottom of the table, select "+add new" +5. In newly added line replace `«input field name»` with `LOOP_START` (without any symbols). +6. Press Tab and enter loop time point in raw samples. For example, `0` will replay sound file from beginning to end indefinitely. + +### Possible alternatives +1. Classic WAV files looping. HQ WAV files can take too much disk space, and recommended software supporting cue points is paid, outdated and can't run on modern systems. (Although there is alternative that's proven to work with idTech-based engines called LoopAuditioneer.) +2. Vorbis looping through comment. Engine doesn't support Vorbis but this extension was highly inspired by this hack. + +### Known bugs and limitations +1. At this time using MP3 as SFX requires complete decoding. This can cause noticeable stutters, so keep MP3 file length in mind. +2. We deliberately only support modern ID3v2.3 and ID3v2.4 tags. Using ID3v1 is not possible. + + + diff --git a/engine/common/soundlib/snd_main.c b/engine/common/soundlib/snd_main.c index bd32b8d49..564f10ada 100644 --- a/engine/common/soundlib/snd_main.c +++ b/engine/common/soundlib/snd_main.c @@ -280,7 +280,6 @@ void FS_FreeStream( stream_t *stream ) } #if XASH_ENGINE_TESTS - #define IMPLEMENT_SOUNDLIB_FUZZ_TARGET( export, target ) \ int EXPORT export( const uint8_t *Data, size_t Size ) \ { \ diff --git a/engine/common/soundlib/snd_mp3.c b/engine/common/soundlib/snd_mp3.c index 16e142f6b..15adce8b9 100644 --- a/engine/common/soundlib/snd_mp3.c +++ b/engine/common/soundlib/snd_mp3.c @@ -16,6 +16,184 @@ GNU General Public License for more details. #include "soundlib.h" #include "libmpg/libmpg.h" +#pragma pack( push, 1 ) +typedef struct did3v2_header_s +{ + char ident[3]; // must be "ID3" + uint8_t major_ver; // must be 4 + uint8_t minor_ver; // must be 0 + uint8_t flags; + uint32_t length; // size of extended header, padding and frames +} did3v2_header_t; +STATIC_ASSERT( sizeof( did3v2_header_t ) == 10, + "invalid did3v2_header_t size" ); + +typedef struct did3v2_extended_header_s +{ + uint32_t length; + uint8_t flags_length; + uint8_t flags[1]; +} did3v2_extended_header_t; +STATIC_ASSERT( sizeof( did3v2_extended_header_t ) == 6, + "invalid did3v2_extended_header_t size" ); + +typedef struct did3v2_frame_s +{ + char frame_id[4]; + uint32_t length; + uint8_t flags[2]; +} did3v2_frame_t; +STATIC_ASSERT( sizeof( did3v2_frame_t ) == 10, + "invalid did3v2_frame_t size" ); +#pragma pack( pop ) + +typedef enum did3v2_header_flags_e +{ + ID3V2_HEADER_UNSYHCHRONIZATION = BIT( 7U ), + ID3V2_HEADER_EXTENDED_HEADER = BIT( 6U ), + ID3V2_HEADER_EXPERIMENTAL = BIT( 5U ), + ID3V2_HEADER_FOOTER_PRESENT = BIT( 4U ), +} did3v2_header_flags_t; + +#define CHECK_IDENT( ident, b0, b1, b2 ) ((( ident )[0]) == ( b0 ) && (( ident )[1]) == ( b1 ) && (( ident )[2]) == ( b2 )) +#define CHECK_FRAME_ID( ident, b0, b1, b2, b3 ) ( CHECK_IDENT( ident, b0, b1, b2 ) && (( ident )[3]) == ( b3 )) + +static uint32_t Sound_ParseSynchInteger( uint32_t v ) +{ + uint32_t res = 0; + + // read as big endian + res |= (( v >> 24 ) & 0x7f ) << 0; + res |= (( v >> 16 ) & 0x7f ) << 7; + res |= (( v >> 8 ) & 0x7f ) << 14; + res |= (( v >> 0 ) & 0x7f ) << 21; + + return res; +} + +static void Sound_HandleCustomID3Comment( const char *key, const char *value ) +{ + if( !Q_strcmp( key, "LOOP_START" ) || !Q_strcmp( key, "LOOPSTART" )) + sound.loopstart = Q_atoi( value ); + // unknown comment is not an error +} + +static qboolean Sound_ParseID3Frame( const did3v2_frame_t *frame, const byte *buffer, size_t frame_length ) +{ + if( CHECK_FRAME_ID( frame->frame_id, 'T', 'X', 'X', 'X' )) + { + string key, value; + int32_t key_len, value_len; + + if( buffer[0] == 0x00 || buffer[1] == 0x03 ) + { + key_len = Q_strncpy( key, &buffer[1], sizeof( key )); + value_len = frame_length - (1 + key_len + 1); + if( value_len <= 0 || value_len >= sizeof( value )) + { + Con_Printf( S_ERROR "Sound_ParseID3Frame: invalid TXXX description, possibly broken file.\n" ); + return false; + } + + memcpy( value, &buffer[1 + key_len + 1], value_len ); + value[value_len + 1] = 0; + + Sound_HandleCustomID3Comment( key, value ); + } + else + { + if( buffer[0] == 0x01 || buffer[0] == 0x02 ) // UTF-16 with BOM + Con_Printf( S_ERROR "Sound_ParseID3Frame: UTF-16 encoding is unsupported. Use UTF-8 or ISO-8859!\n" ); + else + Con_Printf( S_ERROR "Sound_ParseID3Frame: unknown TXXX tag encoding %d, possibly broken file.\n", buffer[0] ); + return false; + } + } + + return true; +} + +static qboolean Sound_ParseID3Tag( const byte *buffer, fs_offset_t filesize ) +{ + const did3v2_header_t *header = (const did3v2_header_t *)buffer; + const byte *buffer_begin = buffer; + uint32_t tag_length; + + if( filesize < sizeof( *header )) + return false; + + buffer += sizeof( *header ); + + // support only id3v2 + if( !CHECK_IDENT( header->ident, 'I', 'D', '3' )) + { + // old id3v1 header found + if( CHECK_IDENT( header->ident, 'T', 'A', 'G' )) + Con_Printf( S_ERROR "Sound_ParseID3Tag: ID3v1 is not supported! Convert to ID3v2.4!\n", header->major_ver ); + + return true; // missing tag header is not an error + } + + // support only latest id3 v2.4 + if( header->major_ver != 4 || header->minor_ver == 0xff ) + { + Con_Printf( S_ERROR "Sound_ParseID3Tag: invalid ID3v2 tag version 2.%d.%d. Convert to ID3v2.4!\n", header->major_ver, header->minor_ver ); + return false; + } + + tag_length = Sound_ParseSynchInteger( header->length ); + if( tag_length > filesize - sizeof( *header )) + { + Con_Printf( S_ERROR "Sound_ParseID3Tag: invalid tag length %u, possibly broken file.\n", tag_length ); + return false; + } + + // just skip extended header + if( FBitSet( header->flags, ID3V2_HEADER_EXTENDED_HEADER )) + { + const did3v2_extended_header_t *ext_header = (const did3v2_extended_header_t *)buffer; + uint32_t ext_length = Sound_ParseSynchInteger( ext_header->length ); + + if( ext_length > tag_length ) + { + Con_Printf( S_ERROR "Sound_ParseID3Tag: invalid extended header length %u, possibly broken file.\n", ext_length ); + return false; + } + + buffer += ext_length; + } + + while( buffer - buffer_begin < tag_length ) + { + const did3v2_frame_t *frame = (const did3v2_frame_t *)buffer; + uint32_t frame_length = Sound_ParseSynchInteger( frame->length ); + + if( frame_length > tag_length ) + { + Con_Printf( S_ERROR "Sound_ParseID3Tag: invalid frame length %u, possibly broken file.\n", frame_length ); + return false; + } + + buffer += sizeof( *frame ); + + // parse can fail, but it's ok to continue + Sound_ParseID3Frame( frame, buffer, frame_length ); + + buffer += frame_length; + } + + return true; +} + +#if XASH_ENGINE_TESTS +int EXPORT Fuzz_Sound_ParseID3Tag( const uint8_t *Data, size_t Size ) +{ + memset( &sound, 0, sizeof( sound )); + Sound_ParseID3Tag( Data, Size ); + return 0; +} +#endif + /* ================================================================= @@ -59,6 +237,12 @@ qboolean Sound_LoadMPG( const char *name, const byte *buffer, fs_offset_t filesi padsize = sound.size % FRAME_SIZE; pos += FRAME_SIZE; // evaluate pos + if( !Sound_ParseID3Tag( buffer, filesize )) + { + Con_DPrintf( S_WARN "Sound_LoadMPG: (%s) failed to extract LOOP_START tag\n", name ); + sound.loopstart = -1; + } + if( !sound.size ) { // bad mpeg file ? diff --git a/utils/run-fuzzer/wscript b/utils/run-fuzzer/wscript index 11174c8a9..ba471aabc 100644 --- a/utils/run-fuzzer/wscript +++ b/utils/run-fuzzer/wscript @@ -33,6 +33,7 @@ def add_runner_target(bld, lib, func): def build(bld): add_runner_target(bld, 'libxash.so', 'Sound_LoadMPG') + add_runner_target(bld, 'libxash.so', 'Sound_ParseID3Tag') add_runner_target(bld, 'libxash.so', 'Sound_LoadWAV') add_runner_target(bld, 'libxash.so', 'Image_LoadBMP') add_runner_target(bld, 'libxash.so', 'Image_LoadPNG') From 0746cb5365cb76b3c1159fe55da3ae06bb1387bf Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Thu, 23 Mar 2023 19:46:10 +0400 Subject: [PATCH 057/121] engine: platform: psvita: disabled back touch sensor --- engine/platform/psvita/sys_psvita.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engine/platform/psvita/sys_psvita.c b/engine/platform/psvita/sys_psvita.c index 079166711..996a36863 100644 --- a/engine/platform/psvita/sys_psvita.c +++ b/engine/platform/psvita/sys_psvita.c @@ -90,8 +90,7 @@ void PSVita_Init( void ) chdir( xashdir ); } - sceCtrlSetSamplingModeExt( SCE_CTRL_MODE_ANALOG_WIDE ); - sceTouchSetSamplingState( SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START ); + sceTouchSetSamplingState( SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_STOP ); scePowerSetArmClockFrequency( 444 ); scePowerSetBusClockFrequency( 222 ); scePowerSetGpuClockFrequency( 222 ); From e3103249f48a0b0dd2b2b0d686b5956b287321dd Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Thu, 23 Mar 2023 20:06:53 +0400 Subject: [PATCH 058/121] engine: platform: psvita: added developer mode button to launcher --- engine/common/launcher.c | 6 +- engine/platform/platform.h | 1 + .../sce_sys/livearea/contents/template.xml | 9 +++ engine/platform/psvita/sys_psvita.c | 61 ++++++++++++++++++- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/engine/common/launcher.c b/engine/common/launcher.c index 598c1c17a..4c2f9d661 100644 --- a/engine/common/launcher.c +++ b/engine/common/launcher.c @@ -91,9 +91,13 @@ _inline int Sys_Start( void ) #if !XASH_WIN32 int main( int argc, char **argv ) { +#if XASH_PSVITA + // inject -dev -console into args if required + szArgc = PSVita_GetArgv( argc, argv, &szArgv ); +#else szArgc = argc; szArgv = argv; - +#endif // XASH_PSVITA return Sys_Start(); } #else diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 76805fa4f..90a705b92 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -60,6 +60,7 @@ void NSwitch_Shutdown( void ); void PSVita_Init( void ); void PSVita_Shutdown( void ); qboolean PSVita_GetBasePath( char *buf, const size_t buflen ); +int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv ); void PSVita_InputUpdate( void ); #endif diff --git a/engine/platform/psvita/sce_sys/livearea/contents/template.xml b/engine/platform/psvita/sce_sys/livearea/contents/template.xml index 1bfb84603..16ef0ae9e 100644 --- a/engine/platform/psvita/sce_sys/livearea/contents/template.xml +++ b/engine/platform/psvita/sce_sys/livearea/contents/template.xml @@ -8,4 +8,13 @@ startup.png + + + + psla:dev + + Developer mode + + + diff --git a/engine/platform/psvita/sys_psvita.c b/engine/platform/psvita/sys_psvita.c index 996a36863..0ed9343bd 100644 --- a/engine/platform/psvita/sys_psvita.c +++ b/engine/platform/psvita/sys_psvita.c @@ -24,6 +24,7 @@ GNU General Public License for more details. #include #define DATA_PATH "data/xash3d" +#define MAX_ARGV 5 // "" -log -dev X NULL // 200MB libc heap, 512K main thread stack, 40MB for loading game DLLs // the rest goes to vitaGL @@ -75,17 +76,73 @@ const size_t __vrtld_num_exports = sizeof( aux_exports ) / sizeof( *aux_exports /* end of export crap */ +static const char *PSVita_GetLaunchParameter( char *outbuf ) +{ + SceAppUtilAppEventParam param; + memset( ¶m, 0, sizeof( param ) ); + sceAppUtilReceiveAppEvent( ¶m ); + if( param.type == 0x05 ) + { + sceAppUtilAppEventParseLiveArea( ¶m, outbuf ); + return outbuf; + } + return NULL; +} + void Platform_ShellExecute( const char *path, const char *parms ) { Con_Reportf( S_WARN "Tried to shell execute ;%s; -- not supported\n", path ); } +/* +=========== +PSVita_GetArgv + +On the PS Vita under normal circumstances argv is empty, so we'll construct our own +based on which button the user pressed in the LiveArea launcher. +=========== +*/ +int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv ) +{ + static const char *fake_argv[MAX_ARGV] = { "app0:/eboot.bin", NULL }; + int fake_argc = 1; + char tmp[2048] = { 0 }; + SceAppUtilInitParam initParam = { 0 }; + SceAppUtilBootParam bootParam = { 0 }; + + // on the Vita under normal circumstances argv is empty, unless we're launching from Change Game + sceAppUtilInit( &initParam, &bootParam ); + + if( in_argc > 1 ) + { + // probably coming from Change Game, in which case we just need to keep the old args + *out_argv = in_argv; + return in_argc; + } + + // got empty args, which means that we're probably coming from LiveArea + // construct argv based on which button the user pressed in the LiveArea launcher + if( PSVita_GetLaunchParameter( tmp )) + { + if( !Q_strcmp( tmp, "dev" )) + { + // user hit the "Developer Mode" button, inject "-log" and "-dev" arguments + fake_argv[fake_argc++] = "-log"; + fake_argv[fake_argc++] = "-dev"; + fake_argv[fake_argc++] = "2"; + } + } + + *out_argv = (char **)fake_argv; + return fake_argc; +} + void PSVita_Init( void ) { char xashdir[1024] = { 0 }; // cd to the base dir immediately for library loading to work - if ( PSVita_GetBasePath( xashdir, sizeof( xashdir ) ) ) + if( PSVita_GetBasePath( xashdir, sizeof( xashdir ))) { chdir( xashdir ); } @@ -97,7 +154,7 @@ void PSVita_Init( void ) scePowerSetGpuXbarClockFrequency( 166 ); sceSysmoduleLoadModule( SCE_SYSMODULE_NET ); - if ( vrtld_init( 0 ) < 0 ) + if( vrtld_init( 0 ) < 0 ) { Sys_Error( "Could not init vrtld: %s\n", vrtld_dlerror( ) ); } From e024a67436cb2107c97174dc9eb8ee2cc958c064 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Thu, 23 Mar 2023 20:08:59 +0400 Subject: [PATCH 059/121] engine: platform: psvita: fixed vrtld error reporting --- engine/platform/psvita/sys_psvita.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/platform/psvita/sys_psvita.c b/engine/platform/psvita/sys_psvita.c index 0ed9343bd..a57ca3557 100644 --- a/engine/platform/psvita/sys_psvita.c +++ b/engine/platform/psvita/sys_psvita.c @@ -156,7 +156,7 @@ void PSVita_Init( void ) if( vrtld_init( 0 ) < 0 ) { - Sys_Error( "Could not init vrtld: %s\n", vrtld_dlerror( ) ); + Sys_Error( "Could not init vrtld:\n%s\n", vrtld_dlerror() ); } // init vitaGL, leaving some memory for DLL mapping From 575179dbf5ef1311622fabf965b83e8d2a7f3193 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Thu, 23 Mar 2023 20:13:17 +0400 Subject: [PATCH 060/121] engine: client: added default dead zone values for psvita platform --- common/defaults.h | 4 ++++ engine/client/in_joy.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/defaults.h b/common/defaults.h index bd76b244c..2c7537f40 100644 --- a/common/defaults.h +++ b/common/defaults.h @@ -191,6 +191,10 @@ Default build-depended cvar and constant values #define DEFAULT_M_IGNORE "0" #endif // DEFAULT_M_IGNORE +#ifndef DEFAULT_JOY_DEADZONE + #define DEFAULT_JOY_DEADZONE "4096" +#endif // DEFAULT_JOY_DEADZONE + #ifndef DEFAULT_DEV #define DEFAULT_DEV 0 #endif // DEFAULT_DEV diff --git a/engine/client/in_joy.c b/engine/client/in_joy.c index 8c407fd7a..1a3db0994 100644 --- a/engine/client/in_joy.c +++ b/engine/client/in_joy.c @@ -393,10 +393,10 @@ void Joy_Init( void ) joy_forward_key_threshold = Cvar_Get( "joy_forward_key_threshold", "24576", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "forward axis key event emit threshold. Value from 0 to 32767"); // by default, we rely on deadzone detection come from system, but some glitchy devices report false deadzones - joy_side_deadzone = Cvar_Get( "joy_side_deadzone", "0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "side axis deadzone. Value from 0 to 32767" ); - joy_forward_deadzone = Cvar_Get( "joy_forward_deadzone", "0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "forward axis deadzone. Value from 0 to 32767"); - joy_pitch_deadzone = Cvar_Get( "joy_pitch_deadzone", "0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "pitch axis deadzone. Value from 0 to 32767"); - joy_yaw_deadzone = Cvar_Get( "joy_yaw_deadzone", "0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "yaw axis deadzone. Value from 0 to 32767" ); + joy_side_deadzone = Cvar_Get( "joy_side_deadzone", DEFAULT_JOY_DEADZONE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "side axis deadzone. Value from 0 to 32767" ); + joy_forward_deadzone = Cvar_Get( "joy_forward_deadzone", DEFAULT_JOY_DEADZONE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "forward axis deadzone. Value from 0 to 32767"); + joy_pitch_deadzone = Cvar_Get( "joy_pitch_deadzone", DEFAULT_JOY_DEADZONE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "pitch axis deadzone. Value from 0 to 32767"); + joy_yaw_deadzone = Cvar_Get( "joy_yaw_deadzone", DEFAULT_JOY_DEADZONE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "yaw axis deadzone. Value from 0 to 32767" ); joy_axis_binding = Cvar_Get( "joy_axis_binding", "sfpyrl", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "axis hardware id to engine inner axis binding, " "s - side, f - forward, y - yaw, p - pitch, r - left trigger, l - right trigger" ); From 48e199bfa16e014c31c7882464d683f053f89afd Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Fri, 24 Mar 2023 03:25:11 +0400 Subject: [PATCH 061/121] engine: common: enabled printing logs to stderr for psvita platform only in developer mode --- engine/common/sys_con.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/common/sys_con.c b/engine/common/sys_con.c index daecebb96..8b4a3670e 100644 --- a/engine/common/sys_con.c +++ b/engine/common/sys_con.c @@ -265,11 +265,19 @@ static void Sys_PrintStdout( const char *logtime, const char *msg ) IOS_Log( buf ); #endif // TARGET_OS_IOS -#if (XASH_NSWITCH && NSWITCH_DEBUG) || XASH_PSVITA // REMOVEME +#if XASH_NSWITCH && NSWITCH_DEBUG // just spew it to stderr normally in debug mode fprintf( stderr, "%s %s", logtime, buf ); #endif // XASH_NSWITCH && NSWITCH_DEBUG +#if XASH_PSVITA + // spew to stderr only in developer mode + if( host_developer.value ) + { + fprintf( stderr, "%s %s", logtime, buf ); + } +#endif + #elif !XASH_WIN32 // Wcon does the job Sys_PrintLogfile( STDOUT_FILENO, logtime, msg, XASH_COLORIZE_CONSOLE ); Sys_FlushStdout(); From 3361e74f54ae55104be23a5083cce8121aef26de Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sun, 26 Mar 2023 18:37:34 +0400 Subject: [PATCH 062/121] engine: client: console: fixed console scrolling on psvita platform --- engine/client/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/client/console.c b/engine/client/console.c index 07894d17b..b59b418d1 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -1596,13 +1596,13 @@ void Key_Console( int key ) } // console scrolling - if( key == K_PGUP ) + if( key == K_PGUP || key == K_DPAD_UP ) { Con_PageUp( 1 ); return; } - if( key == K_PGDN ) + if( key == K_PGDN || key == K_DPAD_DOWN ) { Con_PageDown( 1 ); return; From 127bd89b4481f58a0df5701775f0d25f64dbbd4c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 03:56:36 +0300 Subject: [PATCH 063/121] filesystem: remove unused watch.c file, added by mistake from inotify branch --- filesystem/watch.c | 117 --------------------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 filesystem/watch.c diff --git a/filesystem/watch.c b/filesystem/watch.c deleted file mode 100644 index 1d4cf7eac..000000000 --- a/filesystem/watch.c +++ /dev/null @@ -1,117 +0,0 @@ -#if 0 -#include "build.h" -#if XASH_LINUX -#include -#include -#include -#endif -#include "filesystem_internal.h" -#include "common/com_strings.h" - -#define MAX_FS_WATCHES 256 - -struct -{ -#if XASH_LINUX - int fd; - int count; - struct - { - fs_event_callback_t callback; - int fd; - } watch[MAX_FS_WATCHES]; -#endif // XASH_LINUX -} fsnotify; - -#if XASH_LINUX -static qboolean FS_InotifyInit( void ) -{ - int fd; - - if(( fd = inotify_init1( IN_NONBLOCK )) < 0 ) - { - Con_Printf( S_ERROR "inotify_init1 failed: %s", strerror( errno )); - return false; - } - - fsnotify.fd = fd; - return true; -} - -static qboolean FS_InotifyWasInit( void ) -{ - return fsnotify.fd >= 0; -} -#endif - -/* -=============== -FS_AddWatch - -Adds on-disk path to filesystem watcher list -Every file modification will call back -=============== -*/ -int FS_AddWatch( const char *path, fs_event_callback_t callback ) -{ -#if XASH_LINUX - int fd; - const uint mask = IN_CREATE | IN_DELETE | IN_MODIFY; - - if( !FS_InotifyWasInit() && !FS_InotifyInit()) - return false; - - if(( fd = inotify_add_watch( fsnotify.fd, path, mask )) < 0 ) - { - Con_Printf( S_ERROR "inotify_add_watch failed: %s", strerror( errno )); - return false; - } - - fsnotify.watch[fsnotify.count].fd = fd; - fsnotify.watch[fsnotify.count].callback = callback; - - return true; -#else - return false; -#endif -} - -/* -=============== -FS_WatchFrame - -Polls any changes and runs call backs -=============== -*/ -void FS_WatchFrame( void ) -{ -#if XASH_LINUX - int i; - - for( i = 0; i < fsnotify.count; i++ ) - { - struct inotify_event events; - } - -#endif -} - -/* -=============== -FS_WatchInitialize - -initializes filesystem watcher subsystem -=============== -*/ -qboolean FS_WatchInitialize( void ) -{ -#if XASH_LINUX - fsnotify.fd = -1; // only call inotify init when requested - fsnotify.count = 0; - - return true; -#else - return false; -#endif -} -#endif // 0 From 3e67445ef3c664058e7f15cb45c455b8e0b6118d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 04:27:55 +0300 Subject: [PATCH 064/121] scripts: gha: psvita: fix building HLSDK, exit if we can't move to a directory --- scripts/gha/build_psvita.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/gha/build_psvita.sh b/scripts/gha/build_psvita.sh index 8ab28da31..c9731a7e1 100644 --- a/scripts/gha/build_psvita.sh +++ b/scripts/gha/build_psvita.sh @@ -27,7 +27,7 @@ make -C vitaGL NO_TEX_COMBINER=1 HAVE_UNFLIPPED_FBOS=1 HAVE_PTHREAD=1 MATH_SPEED echo "Building vrtld..." -pushd vita-rtld +pushd vita-rtld || die cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release || die_configure cmake --build build -- -j2 || die cmake --install build || die @@ -35,7 +35,7 @@ popd echo "Building SDL..." -pushd SDL +pushd SDL || die cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DVIDEO_VITA_VGL=ON || die_configure cmake --build build -- -j2 || die cmake --install build || die @@ -49,7 +49,7 @@ cp build/engine/xash.vpk pkgtemp/ echo "Building HLSDK..." -pushd hlsdk-xash3d +pushd hlsdk-portable || die build_hlsdk mobile_hacks valve build_hlsdk opfor gearbox build_hlsdk bshift bshift @@ -92,6 +92,6 @@ popd echo "Packaging artifacts..." -pushd pkgtemp +pushd pkgtemp || die 7z a -t7z ../artifacts/xash3d-fwgs-psvita.7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -r xash.vpk data/ popd From b3c1c173a979033e0e5ff94fadf842873050a1c1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 04:30:21 +0300 Subject: [PATCH 065/121] scripts: gha: exit if we can't move to a specified directory --- scripts/gha/build_motomagx.sh | 4 ++-- scripts/gha/build_nswitch.sh | 2 +- scripts/gha/build_nswitch_docker.sh | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/gha/build_motomagx.sh b/scripts/gha/build_motomagx.sh index fda2c356a..e38aadbeb 100755 --- a/scripts/gha/build_motomagx.sh +++ b/scripts/gha/build_motomagx.sh @@ -3,12 +3,12 @@ . scripts/lib.sh . /opt/toolchains/motomagx/setenv-z6.sh -cd $GITHUB_WORKSPACE +cd $GITHUB_WORKSPACE || die mkdir -p Xash/valve/cl_dlls mkdir -p Xash/valve/dlls -pushd hlsdk +pushd hlsdk || die ./waf configure -T fast --enable-magx --enable-simple-mod-hacks build install --destdir=../Xash || die popd diff --git a/scripts/gha/build_nswitch.sh b/scripts/gha/build_nswitch.sh index 03f0353d9..1f841354c 100644 --- a/scripts/gha/build_nswitch.sh +++ b/scripts/gha/build_nswitch.sh @@ -15,6 +15,6 @@ docker run --name xash-build --rm -v `pwd`:`pwd` -w `pwd` devkitpro/devkita64:la echo "Packaging artifacts..." -pushd pkgtemp +pushd pkgtemp || die 7z a -t7z ../artifacts/xash3d-fwgs-nswitch.7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -r xash3d/ popd diff --git a/scripts/gha/build_nswitch_docker.sh b/scripts/gha/build_nswitch_docker.sh index 18aa6dec7..4421a5be0 100644 --- a/scripts/gha/build_nswitch_docker.sh +++ b/scripts/gha/build_nswitch_docker.sh @@ -44,8 +44,7 @@ echo "Building engine..." echo "Building HLSDK..." -# TODO: replace with hlsdk-portable when PRs are merged -pushd hlsdk-portable +pushd hlsdk-portable || die build_hlsdk mobile_hacks valve build_hlsdk opfor gearbox build_hlsdk bshift bshift From dca4226e4bf6748ce8f7ba9b8864f6efea77400d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 04:50:16 +0300 Subject: [PATCH 066/121] github: re-use PrimeXT's actions to upload artifacts to GitHub Releases --- .github/workflows/c-cpp.yml | 47 ++++-- scripts/continious_upload.sh | 292 ----------------------------------- 2 files changed, 38 insertions(+), 301 deletions(-) delete mode 100755 scripts/continious_upload.sh diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 8acc1eb40..bec7513fe 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -49,9 +49,7 @@ jobs: env: SDL_VERSION: 2.26.2 GH_CPU_ARCH: ${{ matrix.targetarch }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ANDROID_SDK_TOOLS_VER: 4333796 - UPLOADTOOL_ISPRERELEASE: true steps: - name: Checkout uses: actions/checkout@v3 @@ -61,8 +59,6 @@ jobs: run: bash scripts/gha/deps_${{ matrix.targetos }}.sh - name: Build engine run: bash scripts/gha/build_${{ matrix.targetos }}.sh - - name: Upload engine (prereleases) - run: bash scripts/continious_upload.sh artifacts/* - name: Upload engine (artifacts) uses: actions/upload-artifact@v3 with: @@ -78,9 +74,6 @@ jobs: container: image: bilelmoussaoui/flatpak-github-actions:freedesktop-22.08 options: --privileged - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - UPLOADTOOL_ISPRERELEASE: true steps: - name: Checkout uses: actions/checkout@v3 @@ -91,5 +84,41 @@ jobs: with: bundle: ${{ matrix.app }}.flatpak manifest-path: scripts/flatpak/${{ matrix.app }}.yml - - name: Upload engine (prereleases) - run: bash scripts/continious_upload.sh ${{ matrix.app }}.flatpak + - name: Upload engine (artifacts) + uses: actions/upload-artifact@v3 + with: + name: artifact-${{ matrix.targetos }}-${{ matrix.targetarch }} + path: artifacts/* + release: + name: "Upload releases" + runs-on: ubuntu-latest + needs: [build, flatpak] + if: ${{ github.event_name == 'push' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Fetch artifacts + uses: actions/download-artifact@v3.0.1 + with: + path: artifacts/ + - name: Repackage binaries + working-directory: artifacts/ + run: | + for i in artifact-* su.xash.Engine.*; do + mv "$i"/* . + rm -rf "$i" + done + - name: Remove old release + uses: FWGS/delete-tag-and-release@v0.2.1 + with: + delete_release: true + tag_name: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} + - name: Upload new release + uses: FWGS/upload-release-action@2.3.0 + with: + release_name: Xash3D FWGS Continuous ${{ github.ref_name }} Build + tag: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} + prerelease: true + repo_token: ${{ secrets.GITHUB_TOKEN }} + file_glob: true + file: artifacts/* diff --git a/scripts/continious_upload.sh b/scripts/continious_upload.sh deleted file mode 100755 index bc4656b29..000000000 --- a/scripts/continious_upload.sh +++ /dev/null @@ -1,292 +0,0 @@ -#!/bin/bash - -# MIT License -# -# Copyright (c) 2016 Simon Peter -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -set +x # Do not leak information - -# Exit immediately if one of the files given as arguments is not there -# because we don't want to delete the existing release if we don't have -# the new files that should be uploaded -for file in "$@" -do - if [ ! -e "$file" ] - then echo "$file is missing, giving up." >&2; exit 1 - fi -done - -if [ $# -eq 0 ]; then - echo "No artifacts to use for release, giving up." - exit 0 -fi - -if command -v sha256sum >/dev/null 2>&1 ; then - shatool="sha256sum" -elif command -v shasum >/dev/null 2>&1 ; then - shatool="shasum -a 256" # macOS fallback -else - echo "Neither sha256sum nor shasum is available, cannot check hashes" -fi - -RELEASE_BODY="" -GIT_REPO_SLUG="$REPO_SLUG" - -if [ ! -z "$GITHUB_ACTIONS" ] ; then - GIT_COMMIT="$GITHUB_SHA" - GIT_REPO_SLUG="$GITHUB_REPOSITORY" - if [[ "$GITHUB_REF" == "refs/tags/"* ]] ; then - GIT_TAG="${GITHUB_REF#refs/tags/}" - fi - RELEASE_BODY="GitHub Actions build log: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" -fi - -if [ ! -z "$UPLOADTOOL_BODY" ] ; then - RELEASE_BODY="$UPLOADTOOL_BODY" -fi - -# The calling script (usually .travis.yml) can set a suffix to be used for -# the tag and release name. This way it is possible to have a release for -# the output of the CI/CD pipeline (marked as 'continuous') and also test -# builds for other branches. -# If this build was triggered by a tag, call the result a Release -if [ ! -z "$UPLOADTOOL_SUFFIX" ] ; then - if [ "$UPLOADTOOL_SUFFIX" = "$GIT_TAG" ] ; then - RELEASE_NAME="$GIT_TAG" - RELEASE_TITLE="Release build ($GIT_TAG)" - is_prerelease="false" - else - RELEASE_NAME="continuous-$UPLOADTOOL_SUFFIX" - RELEASE_TITLE="Continuous build ($UPLOADTOOL_SUFFIX)" - if [ -z "$UPLOADTOOL_ISPRERELEASE" ] ; then - is_prerelease="false" - else - is_prerelease="true" - fi - - fi -else - if [ "$GITHUB_ACTIONS" = "true" ]; then - if [ "$GITHUB_REF_TYPE" == "branch" ]; then - if [ "$GITHUB_REF_NAME" == "master" ]; then - RELEASE_NAME="continuous" - RELEASE_TITLE="Continuous build" - else - RELEASE_NAME="continuous-$GITHUB_REF_NAME" - RELEASE_TITLE="Continuous build ($GITHUB_REF_NAME)" - fi - if [ -z "$UPLOADTOOL_ISPRERELEASE" ]; then - is_prerelease="false" - else - is_prerelease="true" - fi - elif [ "$GITHUB_REF_TYPE" == "tag" ]; then - case $(tr '[:upper:]' '[:lower:]' <<< "$GITHUB_REF_NAME") in - *-alpha*|*-beta*|*-rc*) - RELEASE_NAME="$GITHUB_REF_NAME" - RELEASE_TITLE="Pre-release build ($GITHUB_REF_NAME)" - is_prerelease="true" - ;; - *) - RELEASE_NAME="$GITHUB_REF_NAME" - RELEASE_TITLE="Release build ($GITHUB_REF_NAME)" - is_prerelease="false" - ;; - esac - fi - else - # ,, is a bash-ism to convert variable to lower case - case $(tr '[:upper:]' '[:lower:]' <<< "$GIT_TAG") in - "") - # Do not use "latest" as it is reserved by GitHub - RELEASE_NAME="continuous" - RELEASE_TITLE="Continuous build" - if [ -z "$UPLOADTOOL_ISPRERELEASE" ] ; then - is_prerelease="false" - else - is_prerelease="true" - fi - ;; - *-alpha*|*-beta*|*-rc*) - RELEASE_NAME="$GIT_TAG" - RELEASE_TITLE="Pre-release build ($GIT_TAG)" - is_prerelease="true" - ;; - *) - RELEASE_NAME="$GIT_TAG" - RELEASE_TITLE="Release build ($GIT_TAG)" - is_prerelease="false" - ;; - esac - fi -fi - -# Do not upload non-master branch builds -if [ "$GITHUB_EVENT_NAME" == "pull_request" ] ; then - echo "Release uploading disabled for pull requests, uploading to transfer.sh instead" - rm -f ./uploaded-to - for FILE in "$@" ; do - BASENAME="$(basename "${FILE}")" - curl --upload-file $FILE "https://transfer.sh/$BASENAME" > ./one-upload - echo "$(cat ./one-upload)" # this way we get a newline - echo -n "$(cat ./one-upload)\\n" >> ./uploaded-to # this way we get a \n but no newline - done - $shatool "$@" - exit 0 -fi - -if [ ! -z "$GITHUB_ACTIONS" ] ; then - echo "Running on GitHub Actions" - if [ -z "$GITHUB_TOKEN" ] ; then - echo "\$GITHUB_TOKEN missing, please add the following to your run action:" - echo "env:" - echo " GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}" - exit 1 - fi -else - echo "Not running on known CI" - if [ -z "$GIT_REPO_SLUG" ] ; then - read -r -p "Repo Slug (GitHub username/reponame): " GIT_REPO_SLUG - fi - if [ -z "$GITHUB_TOKEN" ] ; then - read -r -s -p "Token (https://github.com/settings/tokens): " GITHUB_TOKEN - fi -fi - -tag_url="https://api.github.com/repos/$GIT_REPO_SLUG/git/refs/tags/$RELEASE_NAME" -tag_infos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${tag_url}") -echo "tag_infos: $tag_infos" -tag_sha=$(echo "$tag_infos" | grep '"sha":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1) -echo "tag_sha: $tag_sha" - -release_url="https://api.github.com/repos/$GIT_REPO_SLUG/releases/tags/$RELEASE_NAME" -echo "Getting the release ID..." -echo "release_url: $release_url" -release_infos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${release_url}") -echo "release_infos: $release_infos" -release_id=$(echo "$release_infos" | grep "\"id\":" | head -n 1 | tr -s " " | cut -f 3 -d" " | cut -f 1 -d ",") -echo "release ID: $release_id" -upload_url=$(echo "$release_infos" | grep '"upload_url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1) -echo "upload_url: $upload_url" -release_url=$(echo "$release_infos" | grep '"url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1) -echo "release_url: $release_url" -target_commit_sha=$(echo "$release_infos" | grep '"target_commitish":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1) -echo "target_commit_sha: $target_commit_sha" - -if [ "$GIT_COMMIT" != "$target_commit_sha" ] ; then - - echo "GIT_COMMIT != target_commit_sha, hence deleting $RELEASE_NAME..." - - if [ ! -z "$release_id" ]; then - delete_url="https://api.github.com/repos/$GIT_REPO_SLUG/releases/$release_id" - echo "Delete the release..." - echo "delete_url: $delete_url" - curl -XDELETE \ - --header "Authorization: token ${GITHUB_TOKEN}" \ - "${delete_url}" - fi - - # echo "Checking if release with the same name is still there..." - # echo "release_url: $release_url" - # curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" \ - # "$release_url" - - if [ "$RELEASE_NAME" == "continuous" ] ; then - # if this is a continuous build tag, then delete the old tag - # in preparation for the new release - echo "Delete the tag..." - delete_url="https://api.github.com/repos/$GIT_REPO_SLUG/git/refs/tags/$RELEASE_NAME" - echo "delete_url: $delete_url" - curl -XDELETE \ - --header "Authorization: token ${GITHUB_TOKEN}" \ - "${delete_url}" - fi - - echo "Create release..." - - release_infos=$(curl -H "Authorization: token ${GITHUB_TOKEN}" \ - --data '{"tag_name": "'"$RELEASE_NAME"'","target_commitish": "'"$GIT_COMMIT"'","name": "'"$RELEASE_TITLE"'","body": "'"$RELEASE_BODY"'","draft": false,"prerelease": '$is_prerelease'}' "https://api.github.com/repos/$GIT_REPO_SLUG/releases") - - echo "$release_infos" - - unset upload_url - upload_url=$(echo "$release_infos" | grep '"upload_url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1) - echo "upload_url: $upload_url" - - unset release_url - release_url=$(echo "$release_infos" | grep '"url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1) - echo "release_url: $release_url" - -fi # if [ "$GIT_COMMIT" != "$tag_sha" ] - -if [ -z "$release_url" ] ; then - echo "Cannot figure out the release URL for $RELEASE_NAME" - exit 1 -fi - -echo "Upload binaries to the release..." - -# Need to URL encode the basename, so we have this function to do so -urlencode() { - # urlencode - old_lc_collate=$LC_COLLATE - LC_COLLATE=C - local length="${#1}" - for (( i = 0; i < length; i++ )); do - local c="${1:$i:1}" - case $c in - [a-zA-Z0-9.~_-]) printf '%s' "$c" ;; - *) printf '%%%02X' "'$c" ;; - esac - done - LC_COLLATE=$old_lc_collate -} - -for FILE in "$@" ; do - FULLNAME="${FILE}" - BASENAME="$(basename "${FILE}")" - - for retries in {1..10}; do - echo "Upload attempt $retries" - - if curl -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.manifold-preview" \ - -H "Content-Type: application/octet-stream" \ - --data-binary "@$FULLNAME" \ - "$upload_url?name=$(urlencode "$BASENAME")"; then - break - fi - - sleep 1m # try to avoid ratelimits??? - echo "" - done -done - -$shatool "$@" - -if [ "$GIT_COMMIT" != "$tag_sha" ] ; then - echo "Publish the release..." - - release_infos=$(curl -H "Authorization: token ${GITHUB_TOKEN}" \ - --data '{"draft": false}' "$release_url") - - echo "$release_infos" -fi # if [ "$GIT_COMMIT" != "$tag_sha" ] From 9a42f4149ff67f54258e778482f77b77083556cd Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 17:18:09 +0300 Subject: [PATCH 067/121] engine: client: disable enabling mouse cursor in key_message (typing in chat) --- engine/client/input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/client/input.c b/engine/client/input.c index 24e713493..256a234fb 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -176,7 +176,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) // since SetCursorType controls cursor visibility // execute it first, and then check mouse grab state - if( newstate == key_menu || newstate == key_console || newstate == key_message ) + if( newstate == key_menu || newstate == key_console ) { Platform_SetCursorType( dc_arrow ); From 96c30371b74177e94e29f67225729dde6524ec78 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 17:19:29 +0300 Subject: [PATCH 068/121] engine: client: better specify rawinput enabling condition on Win32 --- engine/client/input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/client/input.c b/engine/client/input.c index 256a234fb..7989385ba 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -214,7 +214,7 @@ void IN_CheckMouseState( qboolean active ) static qboolean s_bRawInput, s_bMouseGrab; #if XASH_WIN32 - qboolean useRawInput = CVAR_TO_BOOL( m_rawinput ) && clgame.client_dll_uses_sdl || clgame.dllFuncs.pfnLookEvent; + qboolean useRawInput = ( CVAR_TO_BOOL( m_rawinput ) && clgame.client_dll_uses_sdl ) || clgame.dllFuncs.pfnLookEvent != NULL; #else qboolean useRawInput = true; // always use SDL code #endif From 6e27926a103d178d0c1de1f2d43077b4769323a9 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 Mar 2023 17:28:19 +0300 Subject: [PATCH 069/121] engine: simplify XASH_USE_EVDEV macro usage by giving it's defined positive value --- common/defaults.h | 4 ++-- engine/client/input.c | 12 ++++++------ engine/platform/linux/in_evdev.c | 2 +- engine/platform/platform.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/defaults.h b/common/defaults.h index 2c7537f40..e8fbaec6d 100644 --- a/common/defaults.h +++ b/common/defaults.h @@ -70,7 +70,7 @@ SETUP BACKENDS DEFINITIONS #define XASH_MESSAGEBOX MSGBOX_ANDROID #endif // XASH_MESSAGEBOX - #define XASH_USE_EVDEV + #define XASH_USE_EVDEV 1 #define XASH_DYNAMIC_DLADDR #elif XASH_LINUX // we are building for Linux without SDL2, can draw only to framebuffer yet @@ -86,7 +86,7 @@ SETUP BACKENDS DEFINITIONS #define XASH_SOUND SOUND_ALSA #endif // XASH_SOUND - #define XASH_USE_EVDEV + #define XASH_USE_EVDEV 1 #elif XASH_DOS4GW #ifndef XASH_VIDEO #define XASH_VIDEO VIDEO_DOS diff --git a/engine/client/input.c b/engine/client/input.c index 7989385ba..6452dfd2c 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -183,7 +183,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) #if XASH_ANDROID Android_ShowMouse( true ); #endif -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV Evdev_SetGrab( false ); #endif } @@ -194,7 +194,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) #if XASH_ANDROID Android_ShowMouse( false ); #endif -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV Evdev_SetGrab( true ); #endif } @@ -399,7 +399,7 @@ void IN_Shutdown( void ) { IN_DeactivateMouse( ); -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV Evdev_Shutdown(); #endif @@ -426,7 +426,7 @@ void IN_Init( void ) Touch_Init(); -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV Evdev_Init(); #endif } @@ -532,7 +532,7 @@ static void IN_CollectInput( float *forward, float *side, float *pitch, float *y *pitch += y * m_pitch->value; *yaw -= x * m_yaw->value; -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV IN_EvdevMove( yaw, pitch ); #endif } @@ -590,7 +590,7 @@ void IN_EngineAppendMove( float frametime, void *cmd1, qboolean active ) void IN_Commands( void ) { -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV IN_EvdevFrame(); #endif diff --git a/engine/platform/linux/in_evdev.c b/engine/platform/linux/in_evdev.c index 46075f382..bb8c7a134 100644 --- a/engine/platform/linux/in_evdev.c +++ b/engine/platform/linux/in_evdev.c @@ -13,7 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #include "platform/platform.h" -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV #include "common.h" diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 90a705b92..d65cb2087 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -149,7 +149,7 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * // // in_evdev.c // -#ifdef XASH_USE_EVDEV +#if XASH_USE_EVDEV void Evdev_SetGrab( qboolean grab ); void Evdev_Shutdown( void ); void Evdev_Init( void ); From b2ea8c9d18620ed26dce6e02d02fb6ad45b6a09b Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Mon, 27 Mar 2023 20:29:09 +0400 Subject: [PATCH 070/121] engine: platform: win32: enabled attaching to existing console instead of creating new --- engine/platform/win32/con_win.c | 78 ++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/engine/platform/win32/con_win.c b/engine/platform/win32/con_win.c index 63a4102bd..dfea3f27a 100644 --- a/engine/platform/win32/con_win.c +++ b/engine/platform/win32/con_win.c @@ -29,7 +29,10 @@ WIN32 CONSOLE typedef struct { - char title[64]; + string title; + string previousTitle; + UINT previousCodePage; + UINT previousOutputCodePage; HWND hWnd; HANDLE hInput; HANDLE hOutput; @@ -45,6 +48,7 @@ typedef struct string lineBuffer[COMMAND_HISTORY]; qboolean inputEnabled; qboolean consoleVisible; + qboolean attached; // log stuff qboolean log_active; @@ -129,7 +133,7 @@ static void Wcon_PrintInternal( const char *msg, int length ) void Wcon_ShowConsole( qboolean show ) { - if( !s_wcd.hWnd || show == s_wcd.consoleVisible ) + if( !s_wcd.hWnd || show == s_wcd.consoleVisible || s_wcd.attached ) return; s_wcd.consoleVisible = show; @@ -482,7 +486,8 @@ void Wcon_WinPrint( const char *pMsg ) Wcon_PrintInternal( s_wcd.consoleText, s_wcd.consoleTextLen ); } - Wcon_UpdateStatusLine(); + if( !s_wcd.attached ) + Wcon_UpdateStatusLine(); } /* @@ -509,7 +514,16 @@ void Wcon_CreateConsole( void ) s_wcd.log_active = true; // always make log } - AllocConsole(); + s_wcd.attached = ( AttachConsole( ATTACH_PARENT_PROCESS ) != 0 ); + if( s_wcd.attached ) { + GetConsoleTitle( &s_wcd.previousTitle, sizeof( s_wcd.previousTitle )); + s_wcd.previousCodePage = GetConsoleCP(); + s_wcd.previousOutputCodePage = GetConsoleOutputCP(); + } + else { + AllocConsole(); + } + SetConsoleTitle( s_wcd.title ); SetConsoleCP( CP_UTF8 ); SetConsoleOutputCP( CP_UTF8 ); @@ -525,22 +539,25 @@ void Wcon_CreateConsole( void ) return; } - SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW ); + if( !s_wcd.attached ) + { + SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW ); - // show console if needed - if( host.con_showalways ) - { - // make console visible - ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT ); - UpdateWindow( s_wcd.hWnd ); - SetForegroundWindow( s_wcd.hWnd ); - SetFocus( s_wcd.hWnd ); - s_wcd.consoleVisible = true; - } - else - { - s_wcd.consoleVisible = false; - ShowWindow( s_wcd.hWnd, SW_HIDE ); + // show console if needed + if( host.con_showalways ) + { + // make console visible + ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT ); + UpdateWindow( s_wcd.hWnd ); + SetForegroundWindow( s_wcd.hWnd ); + SetFocus( s_wcd.hWnd ); + s_wcd.consoleVisible = true; + } + else + { + s_wcd.consoleVisible = false; + ShowWindow( s_wcd.hWnd, SW_HIDE ); + } } } @@ -573,10 +590,21 @@ void Wcon_DestroyConsole( void ) Sys_CloseLog(); - if( s_wcd.hWnd ) + if( !s_wcd.attached ) + { + if( s_wcd.hWnd ) + { + ShowWindow( s_wcd.hWnd, SW_HIDE ); + s_wcd.hWnd = 0; + } + } + else { - ShowWindow( s_wcd.hWnd, SW_HIDE ); - s_wcd.hWnd = 0; + // reverts title & code page for console window that was before starting Xash3D + SetConsoleCP( s_wcd.previousCodePage ); + SetConsoleOutputCP( s_wcd.previousOutputCodePage ); + SetConsoleTitle( &s_wcd.previousTitle ); + Con_Printf( "Press Enter to continue...\n" ); } FreeConsole(); @@ -595,8 +623,8 @@ returned input text */ char *Wcon_Input( void ) { - int i; - int eventsCount; + DWORD i; + DWORD eventsCount; static INPUT_RECORD events[1024]; if( !s_wcd.inputEnabled ) @@ -642,7 +670,7 @@ set server status string in console */ void Wcon_SetStatus( const char *pStatus ) { - if( host.type != HOST_DEDICATED ) + if( host.type != HOST_DEDICATED || s_wcd.attached ) return; Q_strncpy( s_wcd.statusLine, pStatus, sizeof( s_wcd.statusLine ) - 1 ); From 2ea549f250a5d84421a93b45fd21512e0dfd09d9 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 19:49:35 +0300 Subject: [PATCH 071/121] github: update upload-release-action to 2.5.0, print outputs in repackage binaries step --- .github/workflows/c-cpp.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index bec7513fe..33e40cc10 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -108,13 +108,14 @@ jobs: mv "$i"/* . rm -rf "$i" done + ls -R . - name: Remove old release uses: FWGS/delete-tag-and-release@v0.2.1 with: delete_release: true tag_name: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} - name: Upload new release - uses: FWGS/upload-release-action@2.3.0 + uses: FWGS/upload-release-action@2.5.0 with: release_name: Xash3D FWGS Continuous ${{ github.ref_name }} Build tag: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} From 29e32310cfe1777aec0662cfaebd6edc04403d47 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 20:08:42 +0300 Subject: [PATCH 072/121] github: update linux builds to ubuntu-20.04 --- .github/workflows/c-cpp.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 33e40cc10..66b8475b0 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -13,24 +13,24 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-18.04 + - os: ubuntu-20.04 targetos: linux targetarch: amd64 - - os: ubuntu-18.04 + - os: ubuntu-20.04 targetos: linux targetarch: i386 # - os: ubuntu-aarch64-20.04 # targetos: linux # targetarch: aarch64 -# - os: ubuntu-18.04 +# - os: ubuntu-20.04 # targetos: android # targetarch: 32 -# - os: ubuntu-18.04 +# - os: ubuntu-20.04 # targetos: android # targetarch: 64 -# - os: ubuntu-18.04 +# - os: ubuntu-20.04 # targetos: motomagx # targetarch: armv6 From f1487cf576ca08ddcc981cbf8ae62134d974d281 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 20:42:14 +0300 Subject: [PATCH 073/121] engine: ref_api: bump RefAPI version to 4, R_StudioEstimateFrame now has time argument --- engine/ref_api.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine/ref_api.h b/engine/ref_api.h index dbcef6d04..944afbd7e 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -33,7 +33,8 @@ GNU General Public License for more details. // 1. Initial release // 2. FS functions are removed, instead we have full fs_api_t // 3. SlerpBones, CalcBonePosition/Quaternion calls were moved to libpublic/mathlib -#define REF_API_VERSION 3 +// 4. R_StudioEstimateFrame now has time argument +#define REF_API_VERSION 4 #define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP) @@ -499,7 +500,7 @@ typedef struct ref_interface_s void (*R_ClearAllDecals)( void ); // studio interface - float (*R_StudioEstimateFrame)( cl_entity_t *e, mstudioseqdesc_t *pseqdesc ); + float (*R_StudioEstimateFrame)( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time ); void (*R_StudioLerpMovement)( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); void (*CL_InitStudioAPI)( void ); From 55bf0e8a53ead52adb6b2ceec2b023a5e81ae268 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 20:42:44 +0300 Subject: [PATCH 074/121] ref: gl: adapt to RefAPI 4 changes --- ref/gl/gl_local.h | 3 +-- ref/gl/gl_studio.c | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index 91d9f9c91..bd807d491 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -471,12 +471,11 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ); void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); float CL_GetSequenceDuration( cl_entity_t *ent, int sequence ); struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e ); -float CL_GetStudioEstimatedFrame( cl_entity_t *ent ); int R_GetEntityRenderMode( cl_entity_t *ent ); void R_DrawStudioModel( cl_entity_t *e ); player_info_t *pfnPlayerInfo( int index ); void R_GatherPlayerLight( void ); -float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc ); +float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time ); void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); void R_StudioResetPlayerModels( void ); void CL_InitStudioAPI( void ); diff --git a/ref/gl/gl_studio.c b/ref/gl/gl_studio.c index e55936d11..7e330a2f7 100644 --- a/ref/gl/gl_studio.c +++ b/ref/gl/gl_studio.c @@ -178,7 +178,7 @@ static void R_StudioSetupTimings( void ) { // synchronize with server time g_studio.time = gpGlobals->time; - g_studio.frametime = gpGlobals->time - gpGlobals->oldtime; + g_studio.frametime = gpGlobals->time - gpGlobals->oldtime; } else { @@ -626,14 +626,14 @@ StudioEstimateFrame ==================== */ -float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc ) +float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time ) { double dfdt, f; if( g_studio.interpolate ) { - if( g_studio.time < e->curstate.animtime ) dfdt = 0.0; - else dfdt = (g_studio.time - e->curstate.animtime) * e->curstate.framerate * pseqdesc->fps; + if( time < e->curstate.animtime ) dfdt = 0.0; + else dfdt = (time - e->curstate.animtime) * e->curstate.framerate * pseqdesc->fps; } else dfdt = 0; @@ -883,7 +883,7 @@ void R_StudioMergeBones( cl_entity_t *e, model_t *m_pSubModel ) pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; - f = R_StudioEstimateFrame( e, pseqdesc ); + f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, m_pSubModel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); @@ -949,7 +949,7 @@ void R_StudioSetupBones( cl_entity_t *e ) pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; - f = R_StudioEstimateFrame( e, pseqdesc ); + f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); @@ -2789,7 +2789,7 @@ static void R_StudioClientEvents( void ) if( pseqdesc->numevents == 0 ) return; - end = R_StudioEstimateFrame( e, pseqdesc ); + end = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); start = end - e->curstate.framerate * gpGlobals->frametime * pseqdesc->fps; pevent = (mstudioevent_t *)((byte *)m_pStudioHeader + pseqdesc->eventindex); From 67903b55ccbddda611459ebbfb8a2c6738687647 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 20:42:57 +0300 Subject: [PATCH 075/121] ref: soft: adapt to RefAPI 4 changes --- ref/soft/r_local.h | 3 +-- ref/soft/r_studio.c | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 3ee559cc1..277abaae8 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -553,12 +553,11 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ); void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); float CL_GetSequenceDuration( cl_entity_t *ent, int sequence ); struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e ); -float CL_GetStudioEstimatedFrame( cl_entity_t *ent ); int R_GetEntityRenderMode( cl_entity_t *ent ); void R_DrawStudioModel( cl_entity_t *e ); player_info_t *pfnPlayerInfo( int index ); void R_GatherPlayerLight( void ); -float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc ); +float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time ); void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); void R_StudioResetPlayerModels( void ); void CL_InitStudioAPI( void ); diff --git a/ref/soft/r_studio.c b/ref/soft/r_studio.c index e3df3fa3a..3d32a17b6 100644 --- a/ref/soft/r_studio.c +++ b/ref/soft/r_studio.c @@ -617,14 +617,14 @@ StudioEstimateFrame ==================== */ -float GAME_EXPORT R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc ) +float GAME_EXPORT R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time ) { double dfdt, f; if( g_studio.interpolate ) { - if( g_studio.time < e->curstate.animtime ) dfdt = 0.0; - else dfdt = (g_studio.time - e->curstate.animtime) * e->curstate.framerate * pseqdesc->fps; + if( time < e->curstate.animtime ) dfdt = 0.0; + else dfdt = (time - e->curstate.animtime) * e->curstate.framerate * pseqdesc->fps; } else dfdt = 0; @@ -874,7 +874,7 @@ void R_StudioMergeBones( cl_entity_t *e, model_t *m_pSubModel ) pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; - f = R_StudioEstimateFrame( e, pseqdesc ); + f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, m_pSubModel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); @@ -940,7 +940,7 @@ void R_StudioSetupBones( cl_entity_t *e ) pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; - f = R_StudioEstimateFrame( e, pseqdesc ); + f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); @@ -2561,7 +2561,7 @@ static void R_StudioClientEvents( void ) if( pseqdesc->numevents == 0 ) return; - end = R_StudioEstimateFrame( e, pseqdesc ); + end = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); start = end - e->curstate.framerate * gpGlobals->frametime * pseqdesc->fps; pevent = (mstudioevent_t *)((byte *)m_pStudioHeader + pseqdesc->eventindex); From 4b5ee87de1a57b2986f9eddcfb6529c337d988ab Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 20:43:30 +0300 Subject: [PATCH 076/121] engine: client: adapt to RefAPI 4 changes. Fix interpolation issue after reloading a save --- engine/client/cl_frame.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index e4c2141c7..32ed990e0 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -241,7 +241,7 @@ CL_GetStudioEstimatedFrame ==================== */ -float CL_GetStudioEstimatedFrame( cl_entity_t *ent ) +static float CL_GetStudioEstimatedFrame( cl_entity_t *ent ) { studiohdr_t *pstudiohdr; mstudioseqdesc_t *pseqdesc; @@ -255,7 +255,7 @@ float CL_GetStudioEstimatedFrame( cl_entity_t *ent ) { sequence = bound( 0, ent->curstate.sequence, pstudiohdr->numseq - 1 ); pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + sequence; - return ref.dllFuncs.R_StudioEstimateFrame( ent, pseqdesc ); + return ref.dllFuncs.R_StudioEstimateFrame( ent, pseqdesc, cl.time ); } } From f34b35be5a3b9188d9eca9e18f070a597d7cb524 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 21:12:17 +0300 Subject: [PATCH 077/121] engine: client: avi: re-attribute AVI support code by restoring original author copyright --- engine/client/avi/avi_win.c | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/client/avi/avi_win.c b/engine/client/avi/avi_win.c index 534b31ceb..eec1dfa45 100644 --- a/engine/client/avi/avi_win.c +++ b/engine/client/avi/avi_win.c @@ -1,5 +1,6 @@ /* avi_win.c - playing AVI files (based on original AVIKit code, Win32 version) +Copyright (c) 2003-2004, Ruari O'Sullivan Copyright (C) 2010 Uncle Mike This program is free software: you can redistribute it and/or modify From 6c62136f115128ba5f53b1c325f459139505fe94 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 21:08:22 +0300 Subject: [PATCH 078/121] engine: client: avi: convert filename to wide characters before passing it into VFW API --- engine/client/avi/avi_win.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/engine/client/avi/avi_win.c b/engine/client/avi/avi_win.c index eec1dfa45..c6d020e9b 100644 --- a/engine/client/avi/avi_win.c +++ b/engine/client/avi/avi_win.c @@ -64,7 +64,7 @@ static int (_stdcall *pAVIStreamTimeToSample)( PAVISTREAM pavi, LONG lTime ); static void* (_stdcall *pAVIStreamGetFrame)( PGETFRAME pg, LONG lPos ); static int (_stdcall *pAVIStreamGetFrameClose)( PGETFRAME pg ); static dword (_stdcall *pAVIStreamRelease)( PAVISTREAM pavi ); -static int (_stdcall *pAVIFileOpen)( PAVIFILE *ppfile, LPCSTR szFile, UINT uMode, LPCLSID lpHandler ); +static int (_stdcall *pAVIFileOpenW)( PAVIFILE *ppfile, LPCWSTR szFile, UINT uMode, LPCLSID lpHandler ); static int (_stdcall *pAVIFileGetStream)( PAVIFILE pfile, PAVISTREAM *ppavi, DWORD fccType, LONG lParam ); static int (_stdcall *pAVIStreamReadFormat)( PAVISTREAM pavi, LONG lPos,LPVOID lpFormat, LONG *lpcbFormat ); static int (_stdcall *pAVIStreamStart)( PAVISTREAM pavi ); @@ -77,7 +77,7 @@ static dllfunc_t avifile_funcs[] = { "AVIFileExit", (void **) &pAVIFileExit }, { "AVIFileGetStream", (void **) &pAVIFileGetStream }, { "AVIFileInit", (void **) &pAVIFileInit }, -{ "AVIFileOpenA", (void **) &pAVIFileOpen }, +{ "AVIFileOpenW", (void **) &pAVIFileOpenW }, { "AVIFileRelease", (void **) &pAVIFileRelease }, { "AVIStreamGetFrame", (void **) &pAVIStreamGetFrame }, { "AVIStreamGetFrameClose", (void **) &pAVIStreamGetFrameClose }, @@ -494,6 +494,7 @@ void AVI_OpenVideo( movie_state_t *Avi, const char *filename, qboolean load_audi AVISTREAMINFO stream_info; int opened_streams = 0; LONG hr; + wchar_t pathBuffer[MAX_PATH]; // default state: non-working. Avi->active = false; @@ -502,8 +503,15 @@ void AVI_OpenVideo( movie_state_t *Avi, const char *filename, qboolean load_audi // can't load Video For Windows :-( if( !avi_initialized ) return; + // convert to wide char + if( MultiByteToWideChar( CP_UTF8, 0, filename, -1, pathBuffer, ARRAYSIZE( pathBuffer )) <= 0 ) + { + Con_DPrintf( S_ERROR "filename buffer limit exceeded\n" ); + return; + } + // load the AVI - hr = pAVIFileOpen( &Avi->pfile, filename, OF_SHARE_DENY_WRITE, 0L ); + hr = pAVIFileOpenW( &Avi->pfile, pathBuffer, OF_SHARE_DENY_WRITE, 0L ); if( hr != 0 ) // error opening AVI: { From 881a7edb9f7fa0a9a40890beb8e1f180c0feaba2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 28 Mar 2023 23:32:43 +0300 Subject: [PATCH 079/121] github: try to fix uploading release again --- .github/workflows/c-cpp.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 66b8475b0..a82e9c838 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -34,12 +34,12 @@ jobs: # targetos: motomagx # targetarch: armv6 - - os: ubuntu-20.04 - targetos: nswitch - targetarch: arm64 - - os: ubuntu-20.04 - targetos: psvita - targetarch: armv7hf +# - os: ubuntu-20.04 +# targetos: nswitch +# targetarch: arm64 +# - os: ubuntu-20.04 +# targetos: psvita +# targetarch: armv7hf - os: windows-latest targetos: win32 targetarch: amd64 @@ -94,28 +94,28 @@ jobs: runs-on: ubuntu-latest needs: [build, flatpak] if: ${{ github.event_name == 'push' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - name: Fetch artifacts uses: actions/download-artifact@v3.0.1 with: path: artifacts/ - name: Repackage binaries - working-directory: artifacts/ run: | + cd artifacts/ for i in artifact-* su.xash.Engine.*; do mv "$i"/* . rm -rf "$i" done ls -R . + cd ../ - name: Remove old release - uses: FWGS/delete-tag-and-release@v0.2.1 + uses: FWGS/delete-tag-and-release@v0.2.1-dev with: - delete_release: true tag_name: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} + delete_release: true + github_token: ${{ secrets.GITHUB_TOKEN }} - name: Upload new release - uses: FWGS/upload-release-action@2.5.0 + uses: FWGS/upload-release-action@2.5.1 with: release_name: Xash3D FWGS Continuous ${{ github.ref_name }} Build tag: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} From 55b048aab93f7fd27e1baedb07b1c56d330ae822 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 29 Mar 2023 00:05:40 +0300 Subject: [PATCH 080/121] github: enable nswitch and psvita CI builds back, test if continuous tag gets correctly deleted --- .github/workflows/c-cpp.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index a82e9c838..1669895cf 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -34,12 +34,12 @@ jobs: # targetos: motomagx # targetarch: armv6 -# - os: ubuntu-20.04 -# targetos: nswitch -# targetarch: arm64 -# - os: ubuntu-20.04 -# targetos: psvita -# targetarch: armv7hf + - os: ubuntu-20.04 + targetos: nswitch + targetarch: arm64 + - os: ubuntu-20.04 + targetos: psvita + targetarch: armv7hf - os: windows-latest targetos: win32 targetarch: amd64 From 7cac1d290d7bf014a68d9c91f698251dd822ba15 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 29 Mar 2023 00:22:47 +0300 Subject: [PATCH 081/121] scripts: gha: it's pretty safe to not do clean on Waf, since it's much better at tracking modified files --- scripts/gha/build_nswitch_docker.sh | 1 - scripts/gha/build_psvita.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/scripts/gha/build_nswitch_docker.sh b/scripts/gha/build_nswitch_docker.sh index 4421a5be0..a4901351c 100644 --- a/scripts/gha/build_nswitch_docker.sh +++ b/scripts/gha/build_nswitch_docker.sh @@ -8,7 +8,6 @@ build_hlsdk() git checkout $1 ./waf configure -T release --nswitch || die_configure ./waf build install --destdir=../pkgtemp/xash3d || die - ./waf clean } echo "Setting up environment..." diff --git a/scripts/gha/build_psvita.sh b/scripts/gha/build_psvita.sh index c9731a7e1..c9b2036b1 100644 --- a/scripts/gha/build_psvita.sh +++ b/scripts/gha/build_psvita.sh @@ -8,7 +8,6 @@ build_hlsdk() git checkout $1 ./waf configure -T release --psvita || die_configure ./waf build install --destdir=../pkgtemp/data/xash3d || die - ./waf clean } export VITASDK=/usr/local/vitasdk From 53987f47e29c796d2c9e02889ef03682d66457bd Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 30 Mar 2023 04:40:48 +0300 Subject: [PATCH 082/121] engine: client: use alternative ease-in ease-out function in sound fade --- engine/client/s_main.c | 2 +- public/xash3d_mathlib.c | 18 ------------------ public/xash3d_mathlib.h | 1 - 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/engine/client/s_main.c b/engine/client/s_main.c index 6002ac329..176af52b8 100644 --- a/engine/client/s_main.c +++ b/engine/client/s_main.c @@ -159,7 +159,7 @@ void S_UpdateSoundFade( void ) } // spline it. - f = SimpleSpline( f ); + f = -( cos( M_PI * f ) - 1 ) / 2; f = bound( 0.0f, f, 1.0f ); soundfade.percent = soundfade.initial_percent * f; diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index f0e6d52a4..c4872e283 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -53,24 +53,6 @@ float anglemod( float a ) return a; } -/* -================= -SimpleSpline - -NOTE: ripped from hl2 source -hermite basis function for smooth interpolation -Similar to Gain() above, but very cheap to call -value should be between 0 & 1 inclusive -================= -*/ -float SimpleSpline( float value ) -{ - float valueSquared = value * value; - - // nice little ease-in, ease-out spline-like curve - return (3.0f * valueSquared - 2.0f * valueSquared * value); -} - word FloatToHalf( float v ) { unsigned int i = FloatAsUint( v ); diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index 85cbdb372..1d2e8368c 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -177,7 +177,6 @@ float rsqrt( float number ); float anglemod( float a ); word FloatToHalf( float v ); float HalfToFloat( word h ); -float SimpleSpline( float value ); void RoundUpHullSize( vec3_t size ); int SignbitsForPlane( const vec3_t normal ); int PlaneTypeForNormal( const vec3_t normal ); From 8888b456df00c155f3713ea1b35742f6bdbc0aef Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 30 Mar 2023 04:42:48 +0300 Subject: [PATCH 083/121] engine: client: cl_tent: rewrite R_Sprite_Explode to be closer to original function but support Xash extensions --- engine/client/cl_tent.c | 45 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 74b6dbf06..110318ff9 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -1245,37 +1245,28 @@ apply params for exploding sprite */ void GAME_EXPORT R_Sprite_Explode( TEMPENTITY *pTemp, float scale, int flags ) { - if( !pTemp ) return; + qboolean noadditive, drawalpha, rotate; - if( FBitSet( flags, TE_EXPLFLAG_NOADDITIVE )) - { - // solid sprite - pTemp->entity.curstate.rendermode = kRenderNormal; - pTemp->entity.curstate.renderamt = 255; - } - else if( FBitSet( flags, TE_EXPLFLAG_DRAWALPHA )) - { - // alpha sprite (came from hl2) - pTemp->entity.curstate.rendermode = kRenderTransAlpha; - pTemp->entity.curstate.renderamt = 180; - } - else - { - // additive sprite - pTemp->entity.curstate.rendermode = kRenderTransAdd; - pTemp->entity.curstate.renderamt = 180; - } + if( !pTemp ) + return; - if( FBitSet( flags, TE_EXPLFLAG_ROTATE )) - { - // came from hl2 - pTemp->entity.angles[2] = COM_RandomLong( 0, 360 ); - } + noadditive = FBitSet( flags, TE_EXPLFLAG_NOADDITIVE ); + drawalpha = FBitSet( flags, TE_EXPLFLAG_DRAWALPHA ); + rotate = FBitSet( flags, TE_EXPLFLAG_ROTATE ); - pTemp->entity.curstate.renderfx = kRenderFxNone; - pTemp->entity.baseline.origin[2] = 8; - pTemp->entity.origin[2] += 10; pTemp->entity.curstate.scale = scale; + pTemp->entity.baseline.origin[2] = 8.0f; + pTemp->entity.origin[2] = pTemp->entity.origin[2] + 10.0f; + if( rotate ) + pTemp->entity.angles[2] = COM_RandomFloat( 0.0, 360.0f ); + + pTemp->entity.curstate.rendermode = noadditive ? kRenderNormal : + drawalpha ? kRenderTransAlpha : kRenderTransAdd; + pTemp->entity.curstate.renderamt = noadditive ? 0xff : 0xb4; + pTemp->entity.curstate.renderfx = 0; + pTemp->entity.curstate.rendercolor.r = 0; + pTemp->entity.curstate.rendercolor.g = 0; + pTemp->entity.curstate.rendercolor.b = 0; } /* From b99e7a630430f09b12187868fb89df60e01551fa Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 31 Mar 2023 01:16:17 +0300 Subject: [PATCH 084/121] engine: network: include build info to default HTTP useragent --- engine/common/net_ws.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index b2ea7d386..bd665d463 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -2684,11 +2684,23 @@ void HTTP_Run( void ) if( curfile->state < HTTP_REQUEST ) // Request not formatted { + string useragent; + + if( !COM_CheckStringEmpty( http_useragent->string ) || !Q_strcmp( http_useragent->string, "xash3d" )) + { + Q_snprintf( useragent, sizeof( useragent ), "%s/%s (%s-%s; build %d; %s)", + XASH_ENGINE_NAME, XASH_VERSION, Q_buildos( ), Q_buildarch( ), Q_buildnum( ), Q_buildcommit( )); + } + else + { + Q_strncpy( useragent, http_useragent->string, sizeof( useragent )); + } + curfile->query_length = Q_snprintf( curfile->buf, sizeof( curfile->buf ), "GET %s%s HTTP/1.0\r\n" "Host: %s\r\n" "User-Agent: %s\r\n\r\n", curfile->server->path, - curfile->path, curfile->server->host, http_useragent->string ); + curfile->path, curfile->server->host, useragent ); curfile->header_size = 0; curfile->bytes_sent = 0; curfile->state = HTTP_REQUEST; From c2992afb4a9f7cbc98fffec4548c30990095d386 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 31 Mar 2023 01:22:41 +0300 Subject: [PATCH 085/121] engine: network: make all HTTP commands and cvars restricted, except http_addcustomserver. Also zero http_useragent by default (it's autogenerated now) --- engine/common/net_ws.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index bd665d463..ae5625c5f 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -3043,16 +3043,16 @@ void HTTP_Init( void ) http.first_file = http.last_file = NULL; - Cmd_AddRestrictedCommand("http_download", &HTTP_Download_f, "add file to download queue"); - Cmd_AddRestrictedCommand("http_skip", &HTTP_Skip_f, "skip current download server"); - Cmd_AddRestrictedCommand("http_cancel", &HTTP_Cancel_f, "cancel current download"); - Cmd_AddRestrictedCommand("http_clear", &HTTP_Clear_f, "cancel all downloads"); - Cmd_AddCommand("http_list", &HTTP_List_f, "list all queued downloads"); - Cmd_AddCommand("http_addcustomserver", &HTTP_AddCustomServer_f, "add custom fastdl server"); - http_useragent = Cvar_Get( "http_useragent", "xash3d", FCVAR_ARCHIVE, "User-Agent string" ); - http_autoremove = Cvar_Get( "http_autoremove", "1", FCVAR_ARCHIVE, "remove broken files" ); - http_timeout = Cvar_Get( "http_timeout", "45", FCVAR_ARCHIVE, "timeout for http downloader" ); - http_maxconnections = Cvar_Get( "http_maxconnections", "4", FCVAR_ARCHIVE, "maximum http connection number" ); + Cmd_AddRestrictedCommand( "http_download", HTTP_Download_f, "add file to download queue" ); + Cmd_AddRestrictedCommand( "http_skip", HTTP_Skip_f, "skip current download server" ); + Cmd_AddRestrictedCommand( "http_cancel", HTTP_Cancel_f, "cancel current download" ); + Cmd_AddRestrictedCommand( "http_clear", HTTP_Clear_f, "cancel all downloads" ); + Cmd_AddRestrictedCommand( "http_list", HTTP_List_f, "list all queued downloads" ); + Cmd_AddCommand( "http_addcustomserver", HTTP_AddCustomServer_f, "add custom fastdl server"); + http_useragent = Cvar_Get( "http_useragent", "", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "User-Agent string" ); + http_autoremove = Cvar_Get( "http_autoremove", "1", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "remove broken files" ); + http_timeout = Cvar_Get( "http_timeout", "45", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "timeout for http downloader" ); + http_maxconnections = Cvar_Get( "http_maxconnections", "4", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "maximum http connection number" ); // Read servers from fastdl.txt line = serverfile = (char *)FS_LoadFile( "fastdl.txt", 0, false ); From 892e5c59eba3ba1c7baefef31847f206364f3ab3 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 2 Apr 2023 22:48:47 +0300 Subject: [PATCH 086/121] engine: server: convert public_server cvar to static allocation --- engine/server/server.h | 2 +- engine/server/sv_main.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/engine/server/server.h b/engine/server/server.h index 6d488aea4..a62f9e4c8 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -443,6 +443,7 @@ extern convar_t hostname; extern convar_t skill; extern convar_t coop; extern convar_t sv_cheats; +extern convar_t public_server; extern convar_t *sv_pausable; // allows pause in multiplayer extern convar_t *sv_check_errors; @@ -451,7 +452,6 @@ extern convar_t *sv_lighting_modulate; extern convar_t *sv_novis; extern convar_t *sv_hostmap; extern convar_t *sv_validate_changelevel; -extern convar_t *public_server; //=========================================================== // diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 532460085..50e8ee364 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -123,13 +123,14 @@ CVAR_DEFINE_AUTO( sv_voicequality, "3", FCVAR_ARCHIVE|FCVAR_SERVER, "voice chat CVAR_DEFINE_AUTO( sv_enttools_enable, "0", FCVAR_ARCHIVE|FCVAR_PROTECTED, "enable powerful and dangerous entity tools" ); CVAR_DEFINE_AUTO( sv_enttools_maxfire, "5", FCVAR_ARCHIVE|FCVAR_PROTECTED, "limit ent_fire actions count to prevent flooding" ); +CVAR_DEFINE( public_server, "public", "0", 0, "change server type from private to public" ); + convar_t *sv_novis; // disable server culling entities by vis convar_t *sv_pausable; convar_t *timeout; // seconds without any message convar_t *sv_lighting_modulate; convar_t *sv_maxclients; convar_t *sv_check_errors; -convar_t *public_server; // should heartbeats be sent convar_t *sv_reconnect_limit; // minimum seconds between connect messages convar_t *sv_validate_changelevel; convar_t *sv_sendvelocity; @@ -716,7 +717,7 @@ let it know we are alive, and log information */ static void Master_Heartbeat( void ) { - if(( !public_server->value && !sv_nat.value ) || svs.maxclients == 1 ) + if(( !public_server.value && !sv_nat.value ) || svs.maxclients == 1 ) return; // only public servers send heartbeats // check for time wraparound @@ -935,7 +936,7 @@ void SV_Init( void ) Cvar_RegisterVariable( &sv_stopspeed ); sv_maxclients = Cvar_Get( "maxplayers", "1", FCVAR_LATCH, "server max capacity" ); sv_check_errors = Cvar_Get( "sv_check_errors", "0", FCVAR_ARCHIVE, "check edicts for errors" ); - public_server = Cvar_Get ("public", "0", 0, "change server type from private to public" ); + Cvar_RegisterVariable( &public_server ); sv_lighting_modulate = Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" ); sv_reconnect_limit = Cvar_Get ("sv_reconnect_limit", "3", FCVAR_ARCHIVE, "max reconnect attempts" ); Cvar_RegisterVariable( &sv_failuretime ); @@ -1112,7 +1113,7 @@ void SV_Shutdown( const char *finalmsg ) if( svs.clients ) SV_FinalMessage( finalmsg, false ); - if( public_server->value && svs.maxclients != 1 ) + if( public_server.value && svs.maxclients != 1 ) Master_Shutdown(); NET_Config( false, false ); From 93a7ccd14ffedd22235199920ab45dadd29c7186 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 00:14:38 +0300 Subject: [PATCH 087/121] engine: network: add net_gai_state_t enum for NET_StringToAdrNB result value --- engine/client/cl_main.c | 6 ++--- engine/common/net_ws.c | 49 +++++++++++++++++++---------------------- engine/common/net_ws.h | 9 +++++++- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 959bdb312..662cc9356 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -1084,7 +1084,7 @@ Resend a connect message if the last one has timed out void CL_CheckForResend( void ) { netadr_t adr; - int res; + net_gai_state_t res; qboolean bandwidthTest; if( cls.internetservers_wait ) @@ -1117,13 +1117,13 @@ void CL_CheckForResend( void ) res = NET_StringToAdrNB( cls.servername, &adr ); - if( !res ) + if( res == NET_EAI_NONAME ) { CL_Disconnect(); return; } - if( res == 2 ) + if( res == NET_EAI_AGAIN ) { cls.connect_time = MAX_HEARTBEAT; return; diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index ae5625c5f..e6ff71344 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -398,7 +398,7 @@ void *NET_ThreadStart( void *unused ) #define mutex_lock EnterCriticalSection #define mutex_unlock LeaveCriticalSection #define detach_thread( x ) CloseHandle(x) -#define create_thread( pfn ) nsthread.thread = CreateThread( NULL, 0, pfn, NULL, 0, NULL ) +#define create_thread( pfn ) ( nsthread.thread = CreateThread( NULL, 0, pfn, NULL, 0, NULL )) #define mutex_t CRITICAL_SECTION #define thread_t HANDLE DWORD WINAPI NET_ThreadStart( LPVOID unused ) @@ -477,7 +477,7 @@ idnewt:28000 192.246.40.70:28000 ============= */ -static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, qboolean nonblocking, int family ) +static net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, qboolean nonblocking, int family ) { int ret = 0, port; char *colon; @@ -486,7 +486,7 @@ static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, q struct sockaddr_storage temp; if( !net.initialized ) - return false; + return NET_EAI_NONAME; memset( sadr, 0, sizeof( *sadr )); @@ -497,7 +497,7 @@ static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, q ((struct sockaddr_in6 *)sadr)->sin6_port = htons((short)port); memcpy(((struct sockaddr_in6 *)sadr)->sin6_addr.s6_addr, ip6, sizeof( struct in6_addr )); - return true; + return NET_EAI_OK; } Q_strncpy( copy, s, sizeof( copy )); @@ -530,14 +530,14 @@ static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, q if( nsthread.busy ) { mutex_unlock( &nsthread.mutexres ); - return 2; + return NET_EAI_AGAIN; } if( !Q_strcmp( copy, nsthread.hostname )) { ret = nsthread.result; - nsthread.hostname[0] = 0; + nsthread.hostname[0] = '\0'; nsthread.family = AF_UNSPEC; temp = nsthread.addr; memset( &nsthread.addr, 0, sizeof( nsthread.addr )); @@ -554,11 +554,11 @@ static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, q if( create_thread( NET_ThreadStart )) { asyncfailed = false; - return 2; + return NET_EAI_AGAIN; } else // failed to create thread { - Con_Reportf( S_ERROR "NET_StringToSockaddr: failed to create thread!\n"); + Con_Reportf( S_ERROR "NET_StringToSockaddr: failed to create thread!\n"); nsthread.busy = false; } } @@ -577,7 +577,8 @@ static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, q if( family == AF_INET6 ) sadr->ss_family = AF_INET6; else sadr->ss_family = AF_INET; - return 0; + + return NET_EAI_NONAME; } sadr->ss_family = temp.ss_family; @@ -595,7 +596,7 @@ static int NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, q } } - return 1; + return NET_EAI_OK; } /* @@ -1041,10 +1042,9 @@ qboolean NET_StringToAdrEx( const char *string, netadr_t *adr, int family ) return true; } - if( !NET_StringToSockaddr( string, &s, false, family )) + if( NET_StringToSockaddr( string, &s, false, family ) != NET_EAI_OK ) return false; NET_SockadrToNetadr( &s, adr ); - return true; } @@ -1054,13 +1054,13 @@ qboolean NET_StringToAdr( const char *string, netadr_t *adr ) return NET_StringToAdrEx( string, adr, AF_UNSPEC ); } -int NET_StringToAdrNB( const char *string, netadr_t *adr ) +net_gai_state_t NET_StringToAdrNB( const char *string, netadr_t *adr ) { struct sockaddr_storage s; - int res; + net_gai_state_t res; memset( adr, 0, sizeof( netadr_t )); - if( !Q_stricmp( string, "localhost" ) || !Q_stricmp( string, "loopback" )) + if( !Q_stricmp( string, "localhost" ) || !Q_stricmp( string, "loopback" )) { adr->type = NA_LOOPBACK; return true; @@ -1068,12 +1068,10 @@ int NET_StringToAdrNB( const char *string, netadr_t *adr ) res = NET_StringToSockaddr( string, &s, true, AF_UNSPEC ); - if( res == 0 || res == 2 ) - return res; - - NET_SockadrToNetadr( &s, adr ); + if( res == NET_EAI_OK ) + NET_SockadrToNetadr( &s, adr ); - return true; + return res; } /* @@ -2578,7 +2576,6 @@ void HTTP_Run( void ) for( curfile = http.first_file; curfile; curfile = curfile->next ) { - int res; struct sockaddr_storage addr; if( curfile->state == HTTP_FREE ) @@ -2639,6 +2636,7 @@ void HTTP_Run( void ) if( curfile->state < HTTP_NS_RESOLVED ) { + net_gai_state_t res; char hostport[MAX_VA_STRING]; if( fResolving ) @@ -2648,13 +2646,13 @@ void HTTP_Run( void ) res = NET_StringToSockaddr( hostport, &addr, true, AF_INET ); - if( res == 2 ) + if( res == NET_EAI_AGAIN ) { fResolving = true; continue; } - if( !res ) + if( res == NET_EAI_NONAME ) { Con_Printf( S_ERROR "failed to resolve server address for %s!\n", curfile->server->host ); HTTP_FreeFile( curfile, true ); // Cannot connect @@ -2665,7 +2663,7 @@ void HTTP_Run( void ) if( curfile->state < HTTP_CONNECTED ) // Connection not enstabilished { - res = connect( curfile->socket, (struct sockaddr*)&addr, NET_SockAddrLen( &addr ) ); + int res = connect( curfile->socket, (struct sockaddr*)&addr, NET_SockAddrLen( &addr ) ); if( res ) { @@ -2712,8 +2710,7 @@ void HTTP_Run( void ) while( curfile->bytes_sent < curfile->query_length ) { - res = send( curfile->socket, curfile->buf + curfile->bytes_sent, curfile->query_length - curfile->bytes_sent, 0 ); - + int res = send( curfile->socket, curfile->buf + curfile->bytes_sent, curfile->query_length - curfile->bytes_sent, 0 ); if( res < 0 ) { diff --git a/engine/common/net_ws.h b/engine/common/net_ws.h index 727809021..f45851e5b 100644 --- a/engine/common/net_ws.h +++ b/engine/common/net_ws.h @@ -23,6 +23,13 @@ typedef enum NS_COUNT } netsrc_t; +typedef enum +{ + NET_EAI_NONAME = 0, + NET_EAI_OK = 1, + NET_EAI_AGAIN = 2 +} net_gai_state_t; + // Max length of unreliable message #define MAX_DATAGRAM 16384 @@ -59,7 +66,7 @@ qboolean NET_IsReservedAdr( netadr_t a ); qboolean NET_CompareClassBAdr( const netadr_t a, const netadr_t b ); qboolean NET_StringToAdr( const char *string, netadr_t *adr ); qboolean NET_StringToFilterAdr( const char *s, netadr_t *adr, uint *prefixlen ); -int NET_StringToAdrNB( const char *string, netadr_t *adr ); +net_gai_state_t NET_StringToAdrNB( const char *string, netadr_t *adr ); int NET_CompareAdrSort( const void *_a, const void *_b ); qboolean NET_CompareAdr( const netadr_t a, const netadr_t b ); qboolean NET_CompareBaseAdr( const netadr_t a, const netadr_t b ); From 01e05422230eef0d3e94ee74299bc69980680cdc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 00:57:47 +0300 Subject: [PATCH 088/121] engine: server: move master announce logic to masterlist, keep unique heartbeat challenge and heartbeat timer for each master --- engine/common/common.h | 4 + engine/common/masterlist.c | 196 +++++++++++++++++++++++++++++++------ engine/server/server.h | 3 +- engine/server/sv_client.c | 8 +- engine/server/sv_cmds.c | 4 +- engine/server/sv_init.c | 2 +- engine/server/sv_main.c | 79 ++------------- 7 files changed, 187 insertions(+), 109 deletions(-) diff --git a/engine/common/common.h b/engine/common/common.h index 10e1b06c1..0aa2ebbc6 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -876,6 +876,10 @@ void NET_InitMasters( void ); void NET_SaveMasters( void ); qboolean NET_SendToMasters( netsrc_t sock, size_t len, const void *data ); qboolean NET_IsMasterAdr( netadr_t adr ); +void NET_MasterHeartbeat( void ); +void NET_MasterClear( void ); +void NET_MasterShutdown( void ); +qboolean NET_GetMaster( netadr_t from, uint *challenge, double *last_heartbeat ); #ifdef REF_DLL #error "common.h in ref_dll" diff --git a/engine/common/masterlist.c b/engine/common/masterlist.c index bb2edcc84..0900918bd 100644 --- a/engine/common/masterlist.c +++ b/engine/common/masterlist.c @@ -14,22 +14,49 @@ GNU General Public License for more details. */ #include "common.h" #include "netchan.h" +#include "server.h" typedef struct master_s { struct master_s *next; - qboolean sent; + qboolean sent; // TODO: get rid of this internal state qboolean save; string address; netadr_t adr; // temporary, rewritten after each send + + uint heartbeat_challenge; + double last_heartbeat; } master_t; -struct masterlist_s +static struct masterlist_s { master_t *list; qboolean modified; } ml; +static CVAR_DEFINE_AUTO( sv_verbose_heartbeats, "0", 0, "print every heartbeat to console" ); + +#define HEARTBEAT_SECONDS ((sv_nat.value > 0.0f) ? 60.0f : 300.0f) // 1 or 5 minutes + +/* +======================== +NET_GetMasterHostByName +======================== +*/ +static net_gai_state_t NET_GetMasterHostByName( master_t *m ) +{ + net_gai_state_t res = NET_StringToAdrNB( m->address, &m->adr ); + + if( res == NET_EAI_OK ) + return res; + + m->adr.type = NA_UNUSED; + if( res == NET_EAI_NONAME ) + Con_Reportf( "Can't resolve adr: %s\n", m->address ); + + return res; +} + /* ======================== NET_SendToMasters @@ -45,65 +72,176 @@ qboolean NET_SendToMasters( netsrc_t sock, size_t len, const void *data ) for( list = ml.list; list; list = list->next ) { - int res; - if( list->sent ) continue; - res = NET_StringToAdrNB( list->address, &list->adr ); - - if( !res ) + switch( NET_GetMasterHostByName( list )) { - Con_Reportf( "Can't resolve adr: %s\n", list->address ); + case NET_EAI_AGAIN: + list->sent = false; + wait = true; + break; + case NET_EAI_NONAME: list->sent = true; - list->adr.type = NA_UNUSED; - continue; + break; + case NET_EAI_OK: + list->sent = true; + NET_SendPacket( sock, len, data, list->adr ); + break; } + } - if( res == 2 ) - { + if( !wait ) + { + // reset sent state + for( list = ml.list; list; list = list->next ) list->sent = false; - list->adr.type = NA_UNUSED; - wait = true; - continue; - } + } + + return wait; +} + +/* +======================== +NET_AnnounceToMaster + +======================== +*/ +static void NET_AnnounceToMaster( master_t *m ) +{ + sizebuf_t msg; + char buf[16]; + + m->heartbeat_challenge = COM_RandomLong( 0, INT_MAX ); - list->sent = true; + MSG_Init( &msg, "Master Join", buf, sizeof( buf )); + MSG_WriteBytes( &msg, "q\xFF", 2 ); + MSG_WriteDword( &msg, m->heartbeat_challenge ); - NET_SendPacket( sock, len, data, list->adr ); + NET_SendPacket( NS_SERVER, MSG_GetNumBytesWritten( &msg ), MSG_GetBuf( &msg ), m->adr ); + + if( sv_verbose_heartbeats.value ) + { + Con_Printf( S_NOTE "sent heartbeat to %s (%s, 0x%x)\n", + m->address, NET_AdrToString( m->adr ), m->heartbeat_challenge ); } +} - if( !wait ) +/* +======================== +NET_AnnounceToMaster + +======================== +*/ +void NET_MasterClear( void ) +{ + master_t *m; + + for( m = ml.list; m; m = m->next ) + m->last_heartbeat = MAX_HEARTBEAT; +} + +/* +======================== +NET_MasterHeartbeat + +======================== +*/ +void NET_MasterHeartbeat( void ) +{ + master_t *m; + + if(( !public_server.value && !sv_nat.value ) || svs.maxclients == 1 ) + return; // only public servers send heartbeats + + for( m = ml.list; m; m = m->next ) { - list = ml.list; + if( host.realtime - m->last_heartbeat < HEARTBEAT_SECONDS ) + continue; - while( list ) + switch( NET_GetMasterHostByName( m )) { - list->sent = false; - list = list->next; + case NET_EAI_AGAIN: + m->last_heartbeat = MAX_HEARTBEAT; // retry on next frame + if( sv_verbose_heartbeats.value ) + Con_Printf( S_NOTE "delay heartbeat to next frame until %s resolves\n", m->address ); + + break; + case NET_EAI_NONAME: + m->last_heartbeat = host.realtime; // try to resolve again on next heartbeat + break; + case NET_EAI_OK: + m->last_heartbeat = host.realtime; + NET_AnnounceToMaster( m ); + break; } } +} - return wait; +/* +================= +NET_MasterShutdown + +Informs all masters that this server is going down +(ignored by master servers in current implementation) +================= +*/ +void NET_MasterShutdown( void ) +{ + NET_Config( true, false ); // allow remote + while( NET_SendToMasters( NS_SERVER, 2, "\x62\x0A" )); } + /* ======================== -NET_IsMasterAdr +NET_GetMasterFromAdr ======================== */ -qboolean NET_IsMasterAdr( netadr_t adr ) +static master_t *NET_GetMasterFromAdr( netadr_t adr ) { master_t *master; for( master = ml.list; master; master = master->next ) { if( NET_CompareAdr( adr, master->adr )) - return true; + return master; } - return false; + return NULL; +} + + +/* +======================== +NET_GetMaster +======================== +*/ +qboolean NET_GetMaster( netadr_t from, uint *challenge, double *last_heartbeat ) +{ + master_t *m; + + m = NET_GetMasterFromAdr( from ); + + if( m ) + { + *challenge = m->heartbeat_challenge; + *last_heartbeat = m->last_heartbeat; + } + + return m != NULL; +} + +/* +======================== +NET_IsMasterAdr + +======================== +*/ +qboolean NET_IsMasterAdr( netadr_t adr ) +{ + return NET_GetMasterFromAdr( adr ) != NULL; } /* @@ -277,6 +415,8 @@ void NET_InitMasters( void ) Cmd_AddRestrictedCommand( "clearmasters", NET_ClearMasters_f, "clear masterserver list" ); Cmd_AddCommand( "listmasters", NET_ListMasters_f, "list masterservers" ); + Cvar_RegisterVariable( &sv_verbose_heartbeats ); + // keep main master always there NET_AddMaster( MASTERSERVER_ADR, false ); NET_LoadMasters( ); diff --git a/engine/server/server.h b/engine/server/server.h index a62f9e4c8..6c59ba627 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -374,9 +374,7 @@ typedef struct entity_state_t *baselines; // [GI->max_edicts] entity_state_t *static_entities; // [MAX_STATIC_ENTITIES]; - double last_heartbeat; challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting - uint heartbeat_challenge; } server_static_t; //============================================================================= @@ -444,6 +442,7 @@ extern convar_t skill; extern convar_t coop; extern convar_t sv_cheats; extern convar_t public_server; +extern convar_t sv_nat; extern convar_t *sv_pausable; // allows pause in multiplayer extern convar_t *sv_check_errors; diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index e4c1e8e55..9a4e0171c 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -475,7 +475,7 @@ void SV_ConnectClient( netadr_t from ) Log_Printf( "\"%s<%i><%i><>\" connected, address \"%s\"\n", newcl->name, newcl->userid, i, NET_AdrToString( newcl->netchan.remote_address )); if( count == 1 || count == svs.maxclients ) - svs.last_heartbeat = MAX_HEARTBEAT; + NET_MasterClear(); } /* @@ -542,7 +542,7 @@ edict_t *SV_FakeConnect( const char *netname ) cl->state = cs_spawned; if( count == 1 || count == svs.maxclients ) - svs.last_heartbeat = MAX_HEARTBEAT; + NET_MasterClear(); return cl->edict; } @@ -619,7 +619,7 @@ void SV_DropClient( sv_client_t *cl, qboolean crash ) } if( i == svs.maxclients ) - svs.last_heartbeat = MAX_HEARTBEAT; + NET_MasterClear(); } /* @@ -3116,7 +3116,7 @@ void SV_ConnectionlessPacket( netadr_t from, sizebuf_t *msg ) else if( !Q_strcmp( pcmd, "s" )) SV_AddToMaster( from, msg ); else if( !Q_strcmp( pcmd, "T" "Source" )) SV_TSourceEngineQuery( from ); else if( !Q_strcmp( pcmd, "i" )) NET_SendPacket( NS_SERVER, 5, "\xFF\xFF\xFF\xFFj", from ); // A2A_PING - else if( !Q_strcmp( pcmd, "c" ) && Cvar_VariableInteger( "sv_nat" ) && NET_IsMasterAdr( from )) + else if( !Q_strcmp( pcmd, "c" ) && sv_nat.value && NET_IsMasterAdr( from )) { netadr_t to; if( NET_StringToAdr( Cmd_Argv( 1 ), &to ) && !NET_IsReservedAdr( to )) diff --git a/engine/server/sv_cmds.c b/engine/server/sv_cmds.c index 1eb81d229..b2bcf4695 100644 --- a/engine/server/sv_cmds.c +++ b/engine/server/sv_cmds.c @@ -749,9 +749,9 @@ void SV_ConSay_f( void ) SV_Heartbeat_f ================== */ -void SV_Heartbeat_f( void ) +static void SV_Heartbeat_f( void ) { - svs.last_heartbeat = MAX_HEARTBEAT; + NET_MasterClear(); } /* diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 9f9efdcae..3ac2043d5 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -1012,7 +1012,7 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba } // heartbeats will always be sent to the id master - svs.last_heartbeat = MAX_HEARTBEAT; // send immediately + NET_MasterClear(); // get actual movevars SV_UpdateMovevars( true ); diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 50e8ee364..59923634a 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -18,8 +18,6 @@ GNU General Public License for more details. #include "net_encode.h" #include "platform/platform.h" -#define HEARTBEAT_SECONDS ((sv_nat.value > 0.0f) ? 60.0f : 300.0f) // 1 or 5 minutes - // server cvars CVAR_DEFINE_AUTO( sv_lan, "0", 0, "server is a lan server ( no heartbeat, no authentication, no non-class C addresses, 9999.0 rate, etc." ); CVAR_DEFINE_AUTO( sv_lan_rate, "20000.0", 0, "rate for lan server" ); @@ -142,8 +140,6 @@ convar_t *sv_allow_mouse; convar_t *sv_allow_joystick; convar_t *sv_allow_vr; -static void Master_Heartbeat( void ); - //============================================================================ /* ================ @@ -668,7 +664,7 @@ void Host_ServerFrame( void ) Platform_UpdateStatusLine (); // send a heartbeat to the master if needed - Master_Heartbeat (); + NET_MasterHeartbeat (); } /* @@ -683,68 +679,6 @@ void Host_SetServerState( int state ) } //============================================================================ - -/* -================= -Master_Add -================= -*/ -static void Master_Add( void ) -{ - sizebuf_t msg; - char buf[16]; - uint challenge; - - NET_Config( true, false ); // allow remote - - svs.heartbeat_challenge = challenge = COM_RandomLong( 0, INT_MAX ); - - MSG_Init( &msg, "Master Join", buf, sizeof( buf )); - MSG_WriteBytes( &msg, "q\xFF", 2 ); - MSG_WriteDword( &msg, challenge ); - - if( NET_SendToMasters( NS_SERVER, MSG_GetNumBytesWritten( &msg ), MSG_GetBuf( &msg ))) - svs.last_heartbeat = MAX_HEARTBEAT; -} - -/* -================ -Master_Heartbeat - -Send a message to the master every few minutes to -let it know we are alive, and log information -================ -*/ -static void Master_Heartbeat( void ) -{ - if(( !public_server.value && !sv_nat.value ) || svs.maxclients == 1 ) - return; // only public servers send heartbeats - - // check for time wraparound - if( svs.last_heartbeat > host.realtime ) - svs.last_heartbeat = host.realtime; - - if(( host.realtime - svs.last_heartbeat ) < HEARTBEAT_SECONDS ) - return; // not time to send yet - - svs.last_heartbeat = host.realtime; - - Master_Add(); -} - -/* -================= -Master_Shutdown - -Informs all masters that this server is going down -================= -*/ -static void Master_Shutdown( void ) -{ - NET_Config( true, false ); // allow remote - while( NET_SendToMasters( NS_SERVER, 2, "\x62\x0A" )); -} - /* ================= SV_AddToMaster @@ -755,18 +689,19 @@ Master will validate challenge and this server to public list */ void SV_AddToMaster( netadr_t from, sizebuf_t *msg ) { - uint challenge, challenge2; + uint challenge, challenge2, heartbeat_challenge; char s[MAX_INFO_STRING] = "0\n"; // skip 2 bytes of header int clients, bots; + double last_heartbeat; const int len = sizeof( s ); - if( !NET_IsMasterAdr( from )) + if( !NET_GetMaster( from, &heartbeat_challenge, &last_heartbeat )) { Con_Printf( S_WARN "unexpected master server info query packet from %s\n", NET_AdrToString( from )); return; } - if( svs.last_heartbeat + sv_master_response_timeout.value < host.realtime ) + if( last_heartbeat + sv_master_response_timeout.value < host.realtime ) { Con_Printf( S_WARN "unexpected master server info query packet (too late? try increasing sv_master_response_timeout value)\n"); return; @@ -775,7 +710,7 @@ void SV_AddToMaster( netadr_t from, sizebuf_t *msg ) challenge = MSG_ReadDword( msg ); challenge2 = MSG_ReadDword( msg ); - if( challenge2 != svs.heartbeat_challenge ) + if( challenge2 != heartbeat_challenge ) { Con_Printf( S_WARN "unexpected master server info query packet (wrong challenge!)\n" ); return; @@ -1114,7 +1049,7 @@ void SV_Shutdown( const char *finalmsg ) SV_FinalMessage( finalmsg, false ); if( public_server.value && svs.maxclients != 1 ) - Master_Shutdown(); + NET_MasterShutdown(); NET_Config( false, false ); SV_UnloadProgs (); From 37e3cf7e8650cd930602b8790a7f404a4d485195 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 02:46:23 +0300 Subject: [PATCH 089/121] public: crtlib: remove unused functions --- public/crtlib.c | 34 ---------------------------------- public/crtlib.h | 3 --- 2 files changed, 37 deletions(-) diff --git a/public/crtlib.c b/public/crtlib.c index 4ca8484a8..1c0b3e8e8 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -23,20 +23,6 @@ GNU General Public License for more details. #include "crtlib.h" #include "xash3d_mathlib.h" -void Q_strnupr( const char *in, char *out, size_t size_out ) -{ - if( size_out == 0 ) return; - - while( *in && size_out > 1 ) - { - if( *in >= 'a' && *in <= 'z' ) - *out++ = *in++ + 'A' - 'a'; - else *out++ = *in++; - size_out--; - } - *out = '\0'; -} - void Q_strnlwr( const char *in, char *out, size_t size_out ) { if( size_out == 0 ) return; @@ -527,26 +513,6 @@ void COM_StripColors( const char *in, char *out ) *out = '\0'; } -uint Q_hashkey( const char *string, uint hashSize, qboolean caseinsensitive ) -{ - uint i, hashKey = 0; - - if( caseinsensitive ) - { - for( i = 0; string[i]; i++) - hashKey += (i * 119) * Q_tolower( string[i] ); - } - else - { - for( i = 0; string[i]; i++ ) - hashKey += (i + 119) * (int)string[i]; - } - - hashKey = ((hashKey ^ (hashKey >> 10)) ^ (hashKey >> 20)) & (hashSize - 1); - - return hashKey; -} - char *Q_pretifymem( float value, int digitsafterdecimal ) { static char output[8][32]; diff --git a/public/crtlib.h b/public/crtlib.h index 5c4187a51..97441d28e 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -58,8 +58,6 @@ const char *Q_buildcommit( void ); // // crtlib.c // -#define Q_strupr( in, out ) Q_strnupr( in, out, 99999 ) -void Q_strnupr( const char *in, char *out, size_t size_out ); #define Q_strlwr( in, out ) Q_strnlwr( in, out, 99999 ) void Q_strnlwr( const char *in, char *out, size_t size_out ); #define Q_strlen( str ) (( str ) ? strlen(( str )) : 0 ) @@ -70,7 +68,6 @@ char Q_tolower( const char in ); size_t Q_strncat( char *dst, const char *src, size_t siz ); #define Q_strcpy( dst, src ) Q_strncpy( dst, src, 99999 ) size_t Q_strncpy( char *dst, const char *src, size_t siz ); -uint Q_hashkey( const char *string, uint hashSize, qboolean caseinsensitive ); qboolean Q_isdigit( const char *str ); qboolean Q_isspace( const char *str ); int Q_atoi( const char *str ); From 48988e66bd7cd59c867377f426c63ea1ff462db9 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:11:39 +0300 Subject: [PATCH 090/121] engine: client: fix missing HTTP_ResetProcessState call --- engine/client/cl_parse.c | 9 ++++++--- engine/client/client.h | 1 - engine/common/net_ws.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 4c236725f..ebacd0158 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -587,7 +587,7 @@ int CL_EstimateNeededResources( void ) return nTotalSize; } -void CL_StartResourceDownloading( const char *pszMessage, qboolean bCustom ) +static void CL_StartResourceDownloading( const char *pszMessage, qboolean bCustom ) { resourceinfo_t ri; @@ -603,6 +603,8 @@ void CL_StartResourceDownloading( const char *pszMessage, qboolean bCustom ) } else { + HTTP_ResetProcessState(); + cls.state = ca_validate; cls.dl.custom = false; } @@ -2665,15 +2667,14 @@ CL_ParseResourceList void CL_LegacyParseResourceList( sizebuf_t *msg ) { int i = 0; - static struct { int rescount; int restype[MAX_LEGACY_RESOURCES]; char resnames[MAX_LEGACY_RESOURCES][MAX_QPATH]; } reslist; - memset( &reslist, 0, sizeof( reslist )); + memset( &reslist, 0, sizeof( reslist )); reslist.rescount = MSG_ReadWord( msg ) - 1; if( reslist.rescount > MAX_LEGACY_RESOURCES ) @@ -2690,6 +2691,8 @@ void CL_LegacyParseResourceList( sizebuf_t *msg ) return; } + HTTP_ResetProcessState(); + host.downloadcount = 0; for( i = 0; i < reslist.rescount; i++ ) diff --git a/engine/client/client.h b/engine/client/client.h index 0275fc5e7..32bb57d4f 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -892,7 +892,6 @@ void CL_ParseLegacyServerMessage( sizebuf_t *msg, qboolean normal_message ); void CL_LegacyPrecache_f( void ); void CL_ParseTempEntity( sizebuf_t *msg ); -void CL_StartResourceDownloading( const char *pszMessage, qboolean bCustom ); qboolean CL_DispatchUserMessage( const char *pszName, int iSize, void *pbuf ); qboolean CL_RequestMissingResources( void ); void CL_RegisterResources ( sizebuf_t *msg ); diff --git a/engine/common/net_ws.h b/engine/common/net_ws.h index f45851e5b..d45db4fb2 100644 --- a/engine/common/net_ws.h +++ b/engine/common/net_ws.h @@ -89,6 +89,7 @@ void HTTP_AddCustomServer( const char *url ); void HTTP_AddDownload( const char *path, int size, qboolean process ); void HTTP_ClearCustomServers( void ); void HTTP_Shutdown( void ); +void HTTP_ResetProcessState( void ); void HTTP_Init( void ); void HTTP_Run( void ); From 597027277cb139be9ea77a7e4add0b6c09a1a2c1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:12:03 +0300 Subject: [PATCH 091/121] engine: server: remove some totally unused functions --- engine/server/server.h | 1 - engine/server/sv_filter.c | 4 ++-- engine/server/sv_frame.c | 24 ----------------------- engine/server/sv_phys.c | 23 ---------------------- engine/server/sv_pmove.c | 5 ----- engine/server/sv_world.c | 40 --------------------------------------- 6 files changed, 2 insertions(+), 95 deletions(-) diff --git a/engine/server/server.h b/engine/server/server.h index 6c59ba627..4515d8e6b 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -587,7 +587,6 @@ void SV_InactivateClients( void ); int SV_FindBestBaselineForStatic( int index, entity_state_t **baseline, entity_state_t *to ); void SV_WriteFrameToClient( sv_client_t *client, sizebuf_t *msg ); void SV_BuildClientFrame( sv_client_t *client ); -void SV_SendMessagesToAll( void ); void SV_SkipUpdates( void ); // diff --git a/engine/server/sv_filter.c b/engine/server/sv_filter.c index ccffeee82..cc4031e38 100644 --- a/engine/server/sv_filter.c +++ b/engine/server/sv_filter.c @@ -383,7 +383,7 @@ qboolean SV_CheckIP( netadr_t *adr ) static void SV_AddIP_PrintUsage( void ) { Con_Printf(S_USAGE "addip \n" - S_USAGE_INDENT "addip \n" + S_USAGE_INDENT "addip \n" "Use 0 minutes for permanent\n" "ipaddress A.B.C.D/24 is equivalent to A.B.C.0 and A.B.C\n" "NOTE: IPv6 addresses only support prefix format!\n"); @@ -392,7 +392,7 @@ static void SV_AddIP_PrintUsage( void ) static void SV_RemoveIP_PrintUsage( void ) { Con_Printf(S_USAGE "removeip [removeAll]\n" - S_USAGE_INDENT "removeip [removeAll]\n" + S_USAGE_INDENT "removeip [removeAll]\n" "Use removeAll to delete all ip filters which ipaddress or ipaddress/CIDR includes\n"); } diff --git a/engine/server/sv_frame.c b/engine/server/sv_frame.c index c1452a244..669319fc9 100644 --- a/engine/server/sv_frame.c +++ b/engine/server/sv_frame.c @@ -927,30 +927,6 @@ void SV_SendClientMessages( void ) sv.current_client = NULL; } -/* -======================= -SV_SendMessagesToAll - -e.g. before changing level -======================= -*/ -void SV_SendMessagesToAll( void ) -{ - sv_client_t *cl; - int i; - - if( sv.state == ss_dead ) - return; - - for( i = 0, cl = svs.clients; i < svs.maxclients; i++, cl++ ) - { - if( cl->state >= cs_connected ) - SetBits( cl->flags, FCL_SEND_NET_MESSAGE ); - } - - SV_SendClientMessages(); -} - /* ======================= SV_SkipUpdates diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index 069ad1c1c..2b5faceb3 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -718,29 +718,6 @@ void SV_AddGravity( edict_t *ent ) SV_CheckVelocity( ent ); } -/* -============ -SV_AddHalfGravity - -============ -*/ -void SV_AddHalfGravity( edict_t *ent, float timestep ) -{ - float ent_gravity; - - if( ent->v.gravity ) - ent_gravity = ent->v.gravity; - else ent_gravity = 1.0f; - - // Add 1/2 of the total gravitational effects over this timestep - ent->v.velocity[2] -= ( 0.5f * ent_gravity * sv_gravity.value * timestep ); - ent->v.velocity[2] += ( ent->v.basevelocity[2] * sv.frametime ); - ent->v.basevelocity[2] = 0.0f; - - // bound velocity - SV_CheckVelocity( ent ); -} - /* =============================================================================== diff --git a/engine/server/sv_pmove.c b/engine/server/sv_pmove.c index fed1cd8eb..6770b5c41 100644 --- a/engine/server/sv_pmove.c +++ b/engine/server/sv_pmove.c @@ -354,11 +354,6 @@ static void GAME_EXPORT pfnParticle( const float *origin, int color, float life, MSG_WriteByte( &sv.reliable_datagram, bound( 0, life * 8, 255 )); } -int SV_TestLine( const vec3_t start, const vec3_t end, int flags ) -{ - return PM_TestLineExt( svgame.pmove, svgame.pmove->physents, svgame.pmove->numphysent, start, end, flags ); -} - static int GAME_EXPORT pfnTestPlayerPosition( float *pos, pmtrace_t *ptrace ) { return PM_TestPlayerPosition( svgame.pmove, pos, ptrace, NULL ); diff --git a/engine/server/sv_world.c b/engine/server/sv_world.c index 71079e65e..77a4aa551 100644 --- a/engine/server/sv_world.c +++ b/engine/server/sv_world.c @@ -170,46 +170,6 @@ hull_t *SV_HullForBox( const vec3_t mins, const vec3_t maxs ) return &box_hull; } -/* -================== -SV_HullAutoSelect - -select the apropriate hull automatically -================== -*/ -hull_t *SV_HullAutoSelect( model_t *model, const vec3_t mins, const vec3_t maxs, const vec3_t size, vec3_t offset ) -{ - float curdiff; - float lastdiff = 999; - int i, hullNumber = 0; // assume we fail - vec3_t clip_size; - hull_t *hull; - - // NOTE: this is not matched with hardcoded values in some cases... - for( i = 0; i < MAX_MAP_HULLS; i++ ) - { - VectorSubtract( model->hulls[i].clip_maxs, model->hulls[i].clip_mins, clip_size ); - curdiff = floor( VectorAvg( size )) - floor( VectorAvg( clip_size )); - curdiff = fabs( curdiff ); - - if( curdiff < lastdiff ) - { - hullNumber = i; - lastdiff = curdiff; - } - } - - // TraceHull stuff - hull = &model->hulls[hullNumber]; - - // calculate an offset value to center the origin - // NOTE: never get offset of drawing hull - if( !hullNumber ) VectorCopy( hull->clip_mins, offset ); - else VectorSubtract( hull->clip_mins, mins, offset ); - - return hull; -} - /* ================== SV_HullForBsp From a8de11643c4a148100416a5e3ed220543c99ca11 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:13:19 +0300 Subject: [PATCH 092/121] engine: platform: sdl: make GL_CreateContext and GL_DeleteContext functions static --- engine/platform/sdl/events.h | 2 -- engine/platform/sdl/vid_sdl.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/engine/platform/sdl/events.h b/engine/platform/sdl/events.h index e42df28e6..a47c40a06 100644 --- a/engine/platform/sdl/events.h +++ b/engine/platform/sdl/events.h @@ -25,8 +25,6 @@ void VID_RestoreScreenResolution( void ); qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ); void VID_DestroyWindow( void ); void GL_InitExtensions( void ); -qboolean GL_CreateContext( void ); -qboolean GL_UpdateContext( void ); qboolean GL_DeleteContext( void ); void VID_SaveWindowSize( int width, int height ); diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index e23b7358b..cf0d697f6 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -491,7 +491,7 @@ qboolean GL_DeleteContext( void ) GL_CreateContext ================= */ -qboolean GL_CreateContext( void ) +static qboolean GL_CreateContext( void ) { #if SDL_VERSION_ATLEAST(2, 0, 0) if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL) @@ -508,7 +508,7 @@ qboolean GL_CreateContext( void ) GL_UpdateContext ================= */ -qboolean GL_UpdateContext( void ) +static qboolean GL_UpdateContext( void ) { #if SDL_VERSION_ATLEAST( 2, 0, 0 ) if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context )) From 12efcf1c443c3af4e29ec8a610feb87edc7116ac Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:13:50 +0300 Subject: [PATCH 093/121] engine: network: remove some totally ununsed functions --- engine/common/net_chan.c | 15 ---------- engine/common/net_ws.c | 62 ---------------------------------------- engine/common/net_ws.h | 2 -- engine/common/netchan.h | 1 - 4 files changed, 80 deletions(-) diff --git a/engine/common/net_chan.c b/engine/common/net_chan.c index d75d226f7..2f093f3d4 100644 --- a/engine/common/net_chan.c +++ b/engine/common/net_chan.c @@ -1711,21 +1711,6 @@ void Netchan_TransmitBits( netchan_t *chan, int length, byte *data ) } } -/* -=============== -Netchan_Transmit - -tries to send an unreliable message to a connection, and handles the -transmition / retransmition of the reliable messages. - -A 0 length will still generate a packet and deal with the reliable messages. -================ -*/ -void Netchan_Transmit( netchan_t *chan, int lengthInBytes, byte *data ) -{ - Netchan_TransmitBits( chan, lengthInBytes << 3, data ); -} - /* ================= Netchan_Process diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index e6ff71344..a9929516b 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -1681,68 +1681,6 @@ void NET_SendPacket( netsrc_t sock, size_t length, const void *data, netadr_t to NET_SendPacketEx( sock, length, data, to, 0 ); } -/* -==================== -NET_BufferToBufferCompress - -generic fast compression -==================== -*/ -qboolean NET_BufferToBufferCompress( byte *dest, uint *destLen, byte *source, uint sourceLen ) -{ - uint uCompressedLen = 0; - byte *pbOut = NULL; - - memcpy( dest, source, sourceLen ); - pbOut = LZSS_Compress( source, sourceLen, &uCompressedLen ); - - if( pbOut && uCompressedLen > 0 && uCompressedLen <= *destLen ) - { - memcpy( dest, pbOut, uCompressedLen ); - *destLen = uCompressedLen; - free( pbOut ); - return true; - } - else - { - if( pbOut ) free( pbOut ); - memcpy( dest, source, sourceLen ); - *destLen = sourceLen; - return false; - } -} - -/* -==================== -NET_BufferToBufferDecompress - -generic fast decompression -==================== -*/ -qboolean NET_BufferToBufferDecompress( byte *dest, uint *destLen, byte *source, uint sourceLen ) -{ - if( LZSS_IsCompressed( source )) - { - uint uDecompressedLen = LZSS_GetActualSize( source ); - - if( uDecompressedLen <= *destLen ) - { - *destLen = LZSS_Decompress( source, dest ); - } - else - { - return false; - } - } - else - { - memcpy( dest, source, sourceLen ); - *destLen = sourceLen; - } - - return true; -} - /* ==================== NET_IPSocket diff --git a/engine/common/net_ws.h b/engine/common/net_ws.h index d45db4fb2..effd597a8 100644 --- a/engine/common/net_ws.h +++ b/engine/common/net_ws.h @@ -72,8 +72,6 @@ qboolean NET_CompareAdr( const netadr_t a, const netadr_t b ); qboolean NET_CompareBaseAdr( const netadr_t a, const netadr_t b ); qboolean NET_CompareAdrByMask( const netadr_t a, const netadr_t b, uint prefixlen ); qboolean NET_GetPacket( netsrc_t sock, netadr_t *from, byte *data, size_t *length ); -qboolean NET_BufferToBufferCompress( byte *dest, uint *destLen, byte *source, uint sourceLen ); -qboolean NET_BufferToBufferDecompress( byte *dest, uint *destLen, byte *source, uint sourceLen ); void NET_SendPacket( netsrc_t sock, size_t length, const void *data, netadr_t to ); void NET_SendPacketEx( netsrc_t sock, size_t length, const void *data, netadr_t to, size_t splitsize ); void NET_ClearLagData( qboolean bClient, qboolean bServer ); diff --git a/engine/common/netchan.h b/engine/common/netchan.h index 3acc28bbc..6a283803c 100644 --- a/engine/common/netchan.h +++ b/engine/common/netchan.h @@ -294,7 +294,6 @@ qboolean Netchan_CopyNormalFragments( netchan_t *chan, sizebuf_t *msg, size_t *l qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg ); void Netchan_CreateFragments( netchan_t *chan, sizebuf_t *msg ); int Netchan_CreateFileFragments( netchan_t *chan, const char *filename ); -void Netchan_Transmit( netchan_t *chan, int lengthInBytes, byte *data ); void Netchan_TransmitBits( netchan_t *chan, int lengthInBits, byte *data ); void Netchan_OutOfBand( int net_socket, netadr_t adr, int length, byte *data ); void Netchan_OutOfBandPrint( int net_socket, netadr_t adr, const char *format, ... ) _format( 3 ); From 3614cfa878c1b34e6767d1dfa7264633b6c4b4fe Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:49:59 +0300 Subject: [PATCH 094/121] engine: client: avi: remove unused function --- engine/client/avi/avi.h | 1 - engine/client/avi/avi_stub.c | 5 ----- engine/client/avi/avi_win.c | 8 -------- 3 files changed, 14 deletions(-) diff --git a/engine/client/avi/avi.h b/engine/client/avi/avi.h index 6435a1615..20fb04507 100644 --- a/engine/client/avi/avi.h +++ b/engine/client/avi/avi.h @@ -27,7 +27,6 @@ int AVI_GetAudioChunk( movie_state_t *Avi, char *audiodata, int offset, int leng void AVI_OpenVideo( movie_state_t *Avi, const char *filename, qboolean load_audio, int quiet ); movie_state_t *AVI_LoadVideo( const char *filename, qboolean load_audio ); int AVI_TimeToSoundPosition( movie_state_t *Avi, int time ); -int AVI_GetVideoFrameCount( movie_state_t *Avi ); void AVI_CloseVideo( movie_state_t *Avi ); qboolean AVI_IsActive( movie_state_t *Avi ); void AVI_FreeVideo( movie_state_t *Avi ); diff --git a/engine/client/avi/avi_stub.c b/engine/client/avi/avi_stub.c index bb64b13fd..0c6504d2e 100644 --- a/engine/client/avi/avi_stub.c +++ b/engine/client/avi/avi_stub.c @@ -57,11 +57,6 @@ int AVI_TimeToSoundPosition( movie_state_t *Avi, int time ) return 0; } -int AVI_GetVideoFrameCount( movie_state_t *Avi ) -{ - return 0; -} - void AVI_CloseVideo( movie_state_t *Avi ) { ; diff --git a/engine/client/avi/avi_win.c b/engine/client/avi/avi_win.c index c6d020e9b..ed1e5ba20 100644 --- a/engine/client/avi/avi_win.c +++ b/engine/client/avi/avi_win.c @@ -279,14 +279,6 @@ int AVI_GetVideoFrameNumber( movie_state_t *Avi, float time ) return (time * Avi->video_fps); } -int AVI_GetVideoFrameCount( movie_state_t *Avi ) -{ - if( !Avi->active ) - return 0; - - return Avi->video_frames; -} - int AVI_TimeToSoundPosition( movie_state_t *Avi, int time ) { if( !Avi->active || !Avi->audio_stream ) From 192d510924609945e97d680f7e3a3ada9b8e079c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:51:12 +0300 Subject: [PATCH 095/121] engine: client: remove unused function CL_FreeEntity and everything that used it --- engine/client/cl_efrag.c | 40 -------------------------------------- engine/client/cl_game.c | 7 ------- engine/client/client.h | 2 -- engine/client/ref_common.c | 10 ---------- 4 files changed, 59 deletions(-) diff --git a/engine/client/cl_efrag.c b/engine/client/cl_efrag.c index 366134a2b..668c12da1 100644 --- a/engine/client/cl_efrag.c +++ b/engine/client/cl_efrag.c @@ -33,46 +33,6 @@ static mnode_t *r_pefragtopnode; static vec3_t r_emins, r_emaxs; static cl_entity_t *r_addent; -/* -================ -R_RemoveEfrags - -Call when removing an object from the world or moving it to another position -================ -*/ -void R_RemoveEfrags( cl_entity_t *ent ) -{ - efrag_t *ef, *old, *walk, **prev; - - ef = ent->efrag; - - while( ef ) - { - prev = &ef->leaf->efrags; - while( 1 ) - { - walk = *prev; - if( !walk ) break; - - if( walk == ef ) - { - // remove this fragment - *prev = ef->leafnext; - break; - } - else prev = &walk->leafnext; - } - - old = ef; - ef = ef->entnext; - - // put it on the free list - old->entnext = clgame.free_efrags; - clgame.free_efrags = old; - } - ent->efrag = NULL; -} - /* =================== R_SplitEntityOnNode diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 358c27384..2471efc4c 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1064,13 +1064,6 @@ void CL_LinkUserMessage( char *pszName, const int svc_num, int iSize ) CL_ClearUserMessage( pszName, svc_num ); } -void CL_FreeEntity( cl_entity_t *pEdict ) -{ - Assert( pEdict != NULL ); - R_RemoveEfrags( pEdict ); - CL_KillDeadBeams( pEdict ); -} - void CL_ClearWorld( void ) { cl_entity_t *worldmodel; diff --git a/engine/client/client.h b/engine/client/client.h index 32bb57d4f..f07a78db7 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -835,7 +835,6 @@ void CL_FreeEdicts( void ); void CL_ClearWorld( void ); void CL_DrawCenterPrint( void ); void CL_ClearSpriteTextures( void ); -void CL_FreeEntity( cl_entity_t *pEdict ); void CL_CenterPrint( const char *text, float y ); void CL_TextMessageParse( byte *pMemFile, int fileSize ); client_textmessage_t *CL_TextMessageGet( const char *pName ); @@ -1002,7 +1001,6 @@ const ref_overview_t *GL_GetOverviewParms( void ); // void R_StoreEfrags( efrag_t **ppefrag, int framecount ); void R_AddEfrags( cl_entity_t *ent ); -void R_RemoveEfrags( cl_entity_t *ent ); // // cl_tent.c // diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 732f2a3a2..81e6dd1dd 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -74,16 +74,6 @@ static void pfnStudioEvent( const mstudioevent_t *event, const cl_entity_t *e ) clgame.dllFuncs.pfnStudioEvent( event, e ); } -static efrag_t* pfnGetEfragsFreeList( void ) -{ - return clgame.free_efrags; -} - -static void pfnSetEfragsFreeList( efrag_t *list ) -{ - clgame.free_efrags = list; -} - static model_t *pfnGetDefaultSprite( enum ref_defaultsprite_e spr ) { switch( spr ) From 27d9fc0afe25935bc7fd6c03418eb7e4642a8736 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:51:48 +0300 Subject: [PATCH 096/121] engine: client: sound: remove unused functions --- engine/client/s_main.c | 30 ------------------------------ engine/client/s_mix.c | 13 ------------- engine/client/sound.h | 2 -- 3 files changed, 45 deletions(-) diff --git a/engine/client/s_main.c b/engine/client/s_main.c index 176af52b8..718014b8c 100644 --- a/engine/client/s_main.c +++ b/engine/client/s_main.c @@ -1292,36 +1292,6 @@ void S_StreamAviSamples( void *Avi, int entnum, float fvol, float attn, float sy } } -/* -=================== -S_GetRawSamplesLength -=================== -*/ -uint S_GetRawSamplesLength( int entnum ) -{ - rawchan_t *ch; - - if( !( ch = S_FindRawChannel( entnum, false ))) - return 0; - - return ch->s_rawend <= paintedtime ? 0 : (float)(ch->s_rawend - paintedtime) * DMA_MSEC_PER_SAMPLE; -} - -/* -=================== -S_ClearRawChannel -=================== -*/ -void S_ClearRawChannel( int entnum ) -{ - rawchan_t *ch; - - if( !( ch = S_FindRawChannel( entnum, false ))) - return; - - ch->s_rawend = 0; -} - /* =================== S_FreeIdleRawChannels diff --git a/engine/client/s_mix.c b/engine/client/s_mix.c index f58b5063a..11a5232bb 100644 --- a/engine/client/s_mix.c +++ b/engine/client/s_mix.c @@ -117,13 +117,6 @@ _inline void MIX_ActivatePaintbuffer( int ipaintbuffer ) paintbuffers[ipaintbuffer].factive = true; } -// don't mix into this paintbuffer -_inline void MIX_DeactivatePaintbuffer( int ipaintbuffer ) -{ - Assert( ipaintbuffer < CPAINTBUFFERS ); - paintbuffers[ipaintbuffer].factive = false; -} - _inline void MIX_SetCurrentPaintbuffer( int ipaintbuffer ) { Assert( ipaintbuffer < CPAINTBUFFERS ); @@ -169,12 +162,6 @@ _inline void MIX_ResetPaintbufferFilterCounters( void ) paintbuffers[i].ifilter = FILTERTYPE_NONE; } -_inline void MIX_ResetPaintbufferFilterCounter( int ipaintbuffer ) -{ - Assert( ipaintbuffer < CPAINTBUFFERS ); - paintbuffers[ipaintbuffer].ifilter = 0; -} - // return pointer to front paintbuffer pbuf, given index _inline portable_samplepair_t *MIX_GetPFrontFromIPaint( int ipaintbuffer ) { diff --git a/engine/client/sound.h b/engine/client/sound.h index d55ee5337..48c7d5ade 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -276,8 +276,6 @@ void S_RawEntSamples( int entnum, uint samples, uint rate, word width, word chan void S_RawSamples( uint samples, uint rate, word width, word channels, const byte *data, int entnum ); void S_StopSound( int entnum, int channel, const char *soundname ); void S_UpdateFrame( struct ref_viewpass_s *rvp ); -uint S_GetRawSamplesLength( int entnum ); -void S_ClearRawChannel( int entnum ); void S_StopAllSounds( qboolean ambient ); void S_FreeSounds( void ); From 2e8ab13242b36d7e87a2903d54d691aa564de8ba Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 03:26:19 +0300 Subject: [PATCH 097/121] engine: client: fix parsing svc_spawnentity on old protocol --- engine/client/cl_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index ebacd0158..627950221 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -2889,7 +2889,7 @@ void CL_ParseLegacyServerMessage( sizebuf_t *msg, qboolean normal_message ) cl.frames[cl.parsecountmod].graphdata.sound += MSG_GetNumBytesRead( msg ) - bufStart; break; case svc_spawnstatic: - CL_ParseStaticEntity( msg ); + CL_LegacyParseStaticEntity( msg ); break; case svc_event_reliable: CL_ParseReliableEvent( msg ); From 004ac8105ecd4882d05ad54b01f6ddde0b46b169 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:04:25 +0300 Subject: [PATCH 098/121] engine: common: identification: static-ize all functions --- engine/common/identification.c | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/engine/common/identification.c b/engine/common/identification.c index cc5e50ba5..f51fcc198 100644 --- a/engine/common/identification.c +++ b/engine/common/identification.c @@ -35,7 +35,7 @@ static bloomfilter_t id; #define bf64_mask ((1U<<6)-1) -bloomfilter_t BloomFilter_Process( const char *buffer, int size ) +static bloomfilter_t BloomFilter_Process( const char *buffer, int size ) { dword crc32; bloomfilter_t value = 0; @@ -55,12 +55,12 @@ bloomfilter_t BloomFilter_Process( const char *buffer, int size ) return value; } -bloomfilter_t BloomFilter_ProcessStr( const char *buffer ) +static bloomfilter_t BloomFilter_ProcessStr( const char *buffer ) { return BloomFilter_Process( buffer, Q_strlen( buffer ) ); } -uint BloomFilter_Weight( bloomfilter_t value ) +static uint BloomFilter_Weight( bloomfilter_t value ) { int weight = 0; @@ -77,7 +77,7 @@ uint BloomFilter_Weight( bloomfilter_t value ) return weight; } -qboolean BloomFilter_ContainsString( bloomfilter_t filter, const char *str ) +static qboolean BloomFilter_ContainsString( bloomfilter_t filter, const char *str ) { bloomfilter_t value = BloomFilter_ProcessStr( str ); @@ -94,9 +94,9 @@ IDENTIFICATION #define MAXBITS_GEN 30 #define MAXBITS_CHECK MAXBITS_GEN + 6 -qboolean ID_ProcessFile( bloomfilter_t *value, const char *path ); +static qboolean ID_ProcessFile( bloomfilter_t *value, const char *path ); -void ID_BloomFilter_f( void ) +static void ID_BloomFilter_f( void ) { bloomfilter_t value = 0; int i; @@ -111,7 +111,7 @@ void ID_BloomFilter_f( void ) // Msg( "%s: %d\n", Cmd_Argv( i ), BloomFilter_ContainsString( value, Cmd_Argv( i ) ) ); } -qboolean ID_VerifyHEX( const char *hex ) +static qboolean ID_VerifyHEX( const char *hex ) { uint chars = 0; char prev = 0; @@ -153,7 +153,7 @@ qboolean ID_VerifyHEX( const char *hex ) return false; } -void ID_VerifyHEX_f( void ) +static void ID_VerifyHEX_f( void ) { if( ID_VerifyHEX( Cmd_Argv( 1 ) ) ) Msg( "Good\n" ); @@ -162,7 +162,7 @@ void ID_VerifyHEX_f( void ) } #if XASH_LINUX -qboolean ID_ProcessCPUInfo( bloomfilter_t *value ) +static qboolean ID_ProcessCPUInfo( bloomfilter_t *value ) { int cpuinfofd = open( "/proc/cpuinfo", O_RDONLY ); char buffer[1024], *pbuf, *pbuf2; @@ -198,7 +198,7 @@ qboolean ID_ProcessCPUInfo( bloomfilter_t *value ) return true; } -qboolean ID_ValidateNetDevice( const char *dev ) +static qboolean ID_ValidateNetDevice( const char *dev ) { const char *prefix = "/sys/class/net"; byte *pfile; @@ -226,7 +226,7 @@ qboolean ID_ValidateNetDevice( const char *dev ) return true; } -int ID_ProcessNetDevices( bloomfilter_t *value ) +static int ID_ProcessNetDevices( bloomfilter_t *value ) { const char *prefix = "/sys/class/net"; DIR *dir; @@ -250,7 +250,7 @@ int ID_ProcessNetDevices( bloomfilter_t *value ) return count; } -int ID_CheckNetDevices( bloomfilter_t value ) +static int ID_CheckNetDevices( bloomfilter_t value ) { const char *prefix = "/sys/class/net"; @@ -278,7 +278,7 @@ int ID_CheckNetDevices( bloomfilter_t value ) return count; } -void ID_TestCPUInfo_f( void ) +static void ID_TestCPUInfo_f( void ) { bloomfilter_t value = 0; @@ -290,7 +290,7 @@ void ID_TestCPUInfo_f( void ) #endif -qboolean ID_ProcessFile( bloomfilter_t *value, const char *path ) +static qboolean ID_ProcessFile( bloomfilter_t *value, const char *path ) { int fd = open( path, O_RDONLY ); char buffer[256]; @@ -317,7 +317,7 @@ qboolean ID_ProcessFile( bloomfilter_t *value, const char *path ) } #if !XASH_WIN32 -int ID_ProcessFiles( bloomfilter_t *value, const char *prefix, const char *postfix ) +static int ID_ProcessFiles( bloomfilter_t *value, const char *prefix, const char *postfix ) { DIR *dir; struct dirent *entry; @@ -337,7 +337,7 @@ int ID_ProcessFiles( bloomfilter_t *value, const char *prefix, const char *postf return count; } -int ID_CheckFiles( bloomfilter_t value, const char *prefix, const char *postfix ) +static int ID_CheckFiles( bloomfilter_t value, const char *prefix, const char *postfix ) { DIR *dir; struct dirent *entry; @@ -360,7 +360,7 @@ int ID_CheckFiles( bloomfilter_t value, const char *prefix, const char *postfix return count; } #else -int ID_GetKeyData( HKEY hRootKey, char *subKey, char *value, LPBYTE data, DWORD cbData ) +static int ID_GetKeyData( HKEY hRootKey, char *subKey, char *value, LPBYTE data, DWORD cbData ) { HKEY hKey; @@ -376,7 +376,7 @@ int ID_GetKeyData( HKEY hRootKey, char *subKey, char *value, LPBYTE data, DWORD RegCloseKey( hKey ); return 1; } -int ID_SetKeyData( HKEY hRootKey, char *subKey, DWORD dwType, char *value, LPBYTE data, DWORD cbData) +static int ID_SetKeyData( HKEY hRootKey, char *subKey, DWORD dwType, char *value, LPBYTE data, DWORD cbData) { HKEY hKey; if( RegCreateKey( hRootKey, subKey, &hKey ) != ERROR_SUCCESS ) @@ -394,7 +394,7 @@ int ID_SetKeyData( HKEY hRootKey, char *subKey, DWORD dwType, char *value, LPBYT #define BUFSIZE 4096 -int ID_RunWMIC(char *buffer, const char *cmdline) +static int ID_RunWMIC(char *buffer, const char *cmdline) { HANDLE g_IN_Rd = NULL; HANDLE g_IN_Wr = NULL; @@ -438,7 +438,7 @@ int ID_RunWMIC(char *buffer, const char *cmdline) return bSuccess; } -int ID_ProcessWMIC( bloomfilter_t *value, const char *cmdline ) +static int ID_ProcessWMIC( bloomfilter_t *value, const char *cmdline ) { char buffer[BUFSIZE], token[BUFSIZE], *pbuf; int count = 0; @@ -458,7 +458,7 @@ int ID_ProcessWMIC( bloomfilter_t *value, const char *cmdline ) return count; } -int ID_CheckWMIC( bloomfilter_t value, const char *cmdline ) +static int ID_CheckWMIC( bloomfilter_t value, const char *cmdline ) { char buffer[BUFSIZE], token[BUFSIZE], *pbuf; int count = 0; @@ -486,7 +486,7 @@ int ID_CheckWMIC( bloomfilter_t value, const char *cmdline ) char *IOS_GetUDID( void ); #endif -bloomfilter_t ID_GenerateRawId( void ) +static bloomfilter_t ID_GenerateRawId( void ) { bloomfilter_t value = 0; int count = 0; @@ -519,7 +519,7 @@ bloomfilter_t ID_GenerateRawId( void ) return value; } -uint ID_CheckRawId( bloomfilter_t filter ) +static uint ID_CheckRawId( bloomfilter_t filter ) { bloomfilter_t value = 0; int count = 0; @@ -563,7 +563,7 @@ uint ID_CheckRawId( bloomfilter_t filter ) #define SYSTEM_XOR_MASK 0x10331c2dce4c91db #define GAME_XOR_MASK 0x7ffc48fbac1711f1 -void ID_Check( void ) +static void ID_Check( void ) { uint weight = BloomFilter_Weight( id ); uint mincount = weight >> 2; From d8355a651fbac3ee4b00a87879a0d0599995ebb8 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:12:47 +0300 Subject: [PATCH 099/121] engine: add missing Sequence_Init and Sequence_OnLevelLoad calls --- engine/client/cl_main.c | 5 +++++ engine/server/sv_init.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 662cc9356..78aefe9f0 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -23,6 +23,7 @@ GNU General Public License for more details. #include "library.h" #include "vid_common.h" #include "pm_local.h" +#include "sequence.h" #define MAX_TOTAL_CMDS 32 #define MAX_CMD_BUFFER 8000 @@ -239,6 +240,9 @@ void CL_SignonReply( void ) if( cl.proxy_redirect && !cls.spectator ) CL_Disconnect(); cl.proxy_redirect = false; + + if( cls.demoplayback ) + Sequence_OnLevelLoad( clgame.mapname ); break; } } @@ -3123,6 +3127,7 @@ void CL_Init( void ) VID_Init(); // init video S_Init(); // init sound Voice_Init( VOICE_DEFAULT_CODEC, 3 ); // init voice + Sequence_Init(); // unreliable buffer. unsed for unreliable commands and voice stream MSG_Init( &cls.datagram, "cls.datagram", cls.datagram_buf, sizeof( cls.datagram_buf )); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 3ac2043d5..a6e3baf92 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -19,6 +19,7 @@ GNU General Public License for more details. #include "library.h" #include "voice.h" #include "pm_local.h" +#include "sequence.h" #if XASH_LOW_MEMORY != 2 int SV_UPDATE_BACKUP = SINGLEPLAYER_BACKUP; @@ -1011,6 +1012,8 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba SV_InitEdict( ent ); } + Sequence_OnLevelLoad( sv.name ); + // heartbeats will always be sent to the id master NET_MasterClear(); From 84edd9d0c4d2fb28d469bb367de262f310b9792d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:17:02 +0300 Subject: [PATCH 100/121] engine: client: use ReadVec3Angles in svc_setangle, as server uses WriteVec3Angles --- engine/client/cl_parse.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 627950221..ec7f5a556 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -1238,11 +1238,9 @@ CL_ParseSetAngle set the view angle to this absolute value ================ */ -void CL_ParseSetAngle( sizebuf_t *msg ) +static void CL_ParseSetAngle( sizebuf_t *msg ) { - cl.viewangles[0] = MSG_ReadBitAngle( msg, 16 ); - cl.viewangles[1] = MSG_ReadBitAngle( msg, 16 ); - cl.viewangles[2] = MSG_ReadBitAngle( msg, 16 ); + MSG_ReadVec3Angles( msg, cl.viewangles ); } /* From 9cdce1ce69630aaed2ffb69ba50afb855c060486 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:17:54 +0300 Subject: [PATCH 101/121] engine: network: remove unused MSG_Read/WriteBitFloat --- engine/common/net_buffer.c | 37 ------------------------------------- engine/common/net_buffer.h | 2 -- 2 files changed, 39 deletions(-) diff --git a/engine/common/net_buffer.c b/engine/common/net_buffer.c index 5de653916..1b4cc5f0d 100644 --- a/engine/common/net_buffer.c +++ b/engine/common/net_buffer.c @@ -359,17 +359,6 @@ void MSG_WriteVec3Angles( sizebuf_t *sb, const float *fa ) MSG_WriteBitAngle( sb, fa[2], 16 ); } -void MSG_WriteBitFloat( sizebuf_t *sb, float val ) -{ - int intVal; - - Assert( sizeof( int ) == sizeof( float )); - Assert( sizeof( float ) == 4 ); - - intVal = FloatAsInt( val ); - MSG_WriteUBitLong( sb, intVal, 32 ); -} - void MSG_WriteCmdExt( sizebuf_t *sb, int cmd, netsrc_t type, const char *name ) { #ifdef DEBUG_NET_MESSAGES_SEND @@ -523,32 +512,6 @@ uint MSG_ReadUBitLong( sizebuf_t *sb, int numbits ) return ret; } -float MSG_ReadBitFloat( sizebuf_t *sb ) -{ - int val; - int bit, byte; - - Assert( sizeof( float ) == sizeof( int )); - Assert( sizeof( float ) == 4 ); - - if( MSG_Overflow( sb, 32 )) - return 0.0f; - - bit = sb->iCurBit & 0x7; - byte = sb->iCurBit >> 3; - - val = sb->pData[byte] >> bit; - val |= ((int)sb->pData[byte + 1]) << ( 8 - bit ); - val |= ((int)sb->pData[byte + 2]) << ( 16 - bit ); - val |= ((int)sb->pData[byte + 3]) << ( 24 - bit ); - - if( bit != 0 ) - val |= ((int)sb->pData[byte + 4]) << ( 32 - bit ); - sb->iCurBit += 32; - - return IntAsFloat( val ); -} - qboolean MSG_ReadBits( sizebuf_t *sb, void *pOutData, int nBits ) { byte *pOut = (byte *)pOutData; diff --git a/engine/common/net_buffer.h b/engine/common/net_buffer.h index 0be9e25b3..b532daed4 100644 --- a/engine/common/net_buffer.h +++ b/engine/common/net_buffer.h @@ -84,7 +84,6 @@ void MSG_WriteSBitLong( sizebuf_t *sb, int data, int numbits ); void MSG_WriteBitLong( sizebuf_t *sb, uint data, int numbits, qboolean bSigned ); qboolean MSG_WriteBits( sizebuf_t *sb, const void *pData, int nBits ); void MSG_WriteBitAngle( sizebuf_t *sb, float fAngle, int numbits ); -void MSG_WriteBitFloat( sizebuf_t *sb, float val ); // Byte-write functions #define MSG_BeginServerCmd( sb, cmd ) MSG_WriteCmdExt( sb, cmd, NS_SERVER, NULL ) @@ -117,7 +116,6 @@ _inline byte *MSG_GetBuf( sizebuf_t *sb ) { return sb->pData; } // just an alias // Bit-read functions int MSG_ReadOneBit( sizebuf_t *sb ); -float MSG_ReadBitFloat( sizebuf_t *sb ); qboolean MSG_ReadBits( sizebuf_t *sb, void *pOutData, int nBits ); float MSG_ReadBitAngle( sizebuf_t *sb, int numbits ); int MSG_ReadSBitLong( sizebuf_t *sb, int numbits ); From d7848b7b8d90a246120a566af0f31ccad873cd18 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:30:08 +0300 Subject: [PATCH 102/121] engine: client: efx: remove unused CL_FreeParticle --- engine/client/cl_efx.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/engine/client/cl_efx.c b/engine/client/cl_efx.c index 6a07dd494..c9dae2181 100644 --- a/engine/client/cl_efx.c +++ b/engine/client/cl_efx.c @@ -140,26 +140,6 @@ void CL_FreeParticles( void ) cl_particles = NULL; } -/* -================ -CL_FreeParticle - -move particle to freelist -================ -*/ -void CL_FreeParticle( particle_t *p ) -{ - if( p->deathfunc ) - { - // call right the deathfunc before die - p->deathfunc( p ); - p->deathfunc = NULL; - } - - p->next = cl_free_particles; - cl_free_particles = p; -} - /* ================ CL_AllocParticleFast From b0c71c598f4eacd849285ba720dcc6c1086940fe Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:30:27 +0300 Subject: [PATCH 103/121] engine: common: remove unused Mod_AmbientLevels --- engine/common/mod_bmodel.c | 18 ------------------ engine/common/mod_local.h | 1 - 2 files changed, 19 deletions(-) diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 8f1ebbfb6..e1a9577b7 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -745,24 +745,6 @@ qboolean Mod_HeadnodeVisible( mnode_t *node, const byte *visbits, int *lastleaf return false; } -/* -================== -Mod_AmbientLevels - -grab the ambient sound levels for current point -================== -*/ -void Mod_AmbientLevels( const vec3_t p, byte *pvolumes ) -{ - mleaf_t *leaf; - - if( !worldmodel || !p || !pvolumes ) - return; - - leaf = Mod_PointInLeaf( p, worldmodel->nodes ); - *(int *)pvolumes = *(int *)leaf->ambient_sound_level; -} - /* ================= Mod_FindModelOrigin diff --git a/engine/common/mod_local.h b/engine/common/mod_local.h index 3dcf50dc2..f02d5a0d4 100644 --- a/engine/common/mod_local.h +++ b/engine/common/mod_local.h @@ -156,7 +156,6 @@ int Mod_CheckLump( const char *filename, const int lump, int *lumpsize ); int Mod_ReadLump( const char *filename, const int lump, void **lumpdata, int *lumpsize ); int Mod_SaveLump( const char *filename, const int lump, void *lumpdata, int lumpsize ); mleaf_t *Mod_PointInLeaf( const vec3_t p, mnode_t *node ); -void Mod_AmbientLevels( const vec3_t p, byte *pvolumes ); int Mod_SampleSizeForFace( msurface_t *surf ); byte *Mod_GetPVSForPoint( const vec3_t p ); void Mod_UnloadBrushModel( model_t *mod ); From 4005ef831a69b907e022a301a3448f97e1f12061 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:31:12 +0300 Subject: [PATCH 104/121] engine: common: remove unused IsBackgroundMap/Demo calls, remove unused gamma function --- engine/client/cl_main.c | 10 ---------- engine/common/common.h | 3 --- engine/common/dedicated.c | 10 ---------- engine/common/gamma.c | 16 ---------------- 4 files changed, 39 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 78aefe9f0..a162b8849 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -150,16 +150,6 @@ qboolean CL_DisableVisibility( void ) return cls.envshot_disable_vis; } -qboolean CL_IsBackgroundDemo( void ) -{ - return ( cls.demoplayback && cls.demonum != -1 ); -} - -qboolean CL_IsBackgroundMap( void ) -{ - return ( cl.background && !cls.demoplayback ); -} - char *CL_Userinfo( void ) { return cls.userinfo; diff --git a/engine/common/common.h b/engine/common/common.h index 0aa2ebbc6..0d6f7e943 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -780,8 +780,6 @@ int SV_GetMaxClients( void ); qboolean CL_IsRecordDemo( void ); qboolean CL_IsTimeDemo( void ); qboolean CL_IsPlaybackDemo( void ); -qboolean CL_IsBackgroundDemo( void ); -qboolean CL_IsBackgroundMap( void ); qboolean SV_Initialized( void ); qboolean CL_LoadProgs( const char *name ); void CL_ProcessFile( qboolean successfully_received, const char *filename ); @@ -860,7 +858,6 @@ void S_StopAllSounds( qboolean ambient ); // gamma routines void BuildGammaTable( float gamma, float brightness ); byte LightToTexGamma( byte b ); -byte TextureToGamma( byte b ); // // identification.c diff --git a/engine/common/dedicated.c b/engine/common/dedicated.c index a7d4ba8b3..39ea7c4a5 100644 --- a/engine/common/dedicated.c +++ b/engine/common/dedicated.c @@ -70,16 +70,6 @@ qboolean CL_DisableVisibility( void ) return false; } -qboolean CL_IsBackgroundDemo( void ) -{ - return false; -} - -qboolean CL_IsBackgroundMap( void ) -{ - return false; -} - void CL_Init( void ) { diff --git a/engine/common/gamma.c b/engine/common/gamma.c index 87fd772c0..aac4a6c46 100644 --- a/engine/common/gamma.c +++ b/engine/common/gamma.c @@ -20,7 +20,6 @@ GNU General Public License for more details. //----------------------------------------------------------------------------- // Gamma conversion support //----------------------------------------------------------------------------- -static byte texgammatable[256]; // palette is sent through this to convert to screen gamma static byte lightgammatable[256]; static int lineargammatable[1024]; static int screengammatable[1024]; @@ -60,13 +59,6 @@ void BuildGammaTable( float lightgamma, float brightness ) lightgammatable[i] = bound( 0, inf, 255 ); } - for( i = 0; i < 256; i++ ) - { - f = 255.0f * pow(( float )i / 255.0f, TEXGAMMA ); - inf = (int)(f + 0.5f); - texgammatable[i] = bound( 0, inf, 255 ); - } - for( i = 0; i < 1024; i++ ) { // convert from screen gamma space to linear space @@ -84,11 +76,3 @@ byte LightToTexGamma( byte b ) else return lightgammatable[b]; } - -byte TextureToGamma( byte b ) -{ - if( FBitSet( host.features, ENGINE_LINEAR_GAMMA_SPACE )) - return b; - else - return texgammatable[b]; -} From eef1e1868a067a2125b048491236f84e8c3f867e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:31:58 +0300 Subject: [PATCH 105/121] engine: common: remove unused BaseCmd_Replace --- engine/common/base_cmd.c | 26 -------------------------- engine/common/base_cmd.h | 1 - 2 files changed, 27 deletions(-) diff --git a/engine/common/base_cmd.c b/engine/common/base_cmd.c index 732a5b1e1..78b5b33fe 100644 --- a/engine/common/base_cmd.c +++ b/engine/common/base_cmd.c @@ -141,32 +141,6 @@ void BaseCmd_Insert( base_command_type_e type, base_command_t *basecmd, const ch elem->next = find; } -/* -============ -BaseCmd_Replace - -Used in case, when basecmd has been registered, but gamedll wants to register it's own -============ -*/ -qboolean BaseCmd_Replace( base_command_type_e type, base_command_t *basecmd, const char *name ) -{ - base_command_hashmap_t *i = BaseCmd_GetBucket( name ); - - for( ; i && ( i->type != type || Q_stricmp( name, i->name ) ) ; // filter out - i = i->next ); - - if( !i ) - { - Con_Reportf( S_ERROR "BaseCmd_Replace: couldn't find %s\n", name); - return false; - } - - i->basecmd = basecmd; - i->name = name; // may be freed after - - return true; -} - /* ============ BaseCmd_Remove diff --git a/engine/common/base_cmd.h b/engine/common/base_cmd.h index c99a55d2c..671dee42b 100644 --- a/engine/common/base_cmd.h +++ b/engine/common/base_cmd.h @@ -38,7 +38,6 @@ base_command_t *BaseCmd_Find( base_command_type_e type, const char *name ); void BaseCmd_FindAll( const char *name, base_command_t **cmd, base_command_t **alias, base_command_t **cvar ); void BaseCmd_Insert ( base_command_type_e type, base_command_t *basecmd, const char *name ); -qboolean BaseCmd_Replace( base_command_type_e type, base_command_t *basecmd, const char *name ); // only if same name void BaseCmd_Remove ( base_command_type_e type, const char *name ); void BaseCmd_Stats_f( void ); // to be registered later void BaseCmd_Test_f( void ); // to be registered later From 5d387101b9a480cd0a2013ddc45479f2323d88f0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:32:17 +0300 Subject: [PATCH 106/121] engine: client: remove unused Key_IsBind --- engine/client/client.h | 1 - engine/client/keys.c | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/engine/client/client.h b/engine/client/client.h index f07a78db7..a354bfa4d 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -1155,7 +1155,6 @@ void CL_PlayVideo_f( void ); // keys.c // int Key_IsDown( int keynum ); -const char *Key_IsBind( int keynum ); void Key_Event( int key, int down ); void Key_Init( void ); void Key_WriteBindings( file_t *f ); diff --git a/engine/client/keys.c b/engine/client/keys.c index 2f53ac888..9c65d3d7d 100644 --- a/engine/client/keys.c +++ b/engine/client/keys.c @@ -159,18 +159,6 @@ int GAME_EXPORT Key_IsDown( int keynum ) return keys[keynum].down; } -/* -=================== -Key_GetBind -=================== -*/ -const char *Key_IsBind( int keynum ) -{ - if( keynum == -1 || !keys[keynum].binding ) - return NULL; - return keys[keynum].binding; -} - /* =================== Key_StringToKeynum From dc0982932b525758330d9ff593f048719aee21a4 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:24:47 +0300 Subject: [PATCH 107/121] engine: common: sequence: static-ize private functions --- engine/common/sequence.c | 104 +++++++++++++++++++-------------------- engine/sequence.h | 2 - 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/engine/common/sequence.c b/engine/common/sequence.c index ca9b72e13..fd78c2fc3 100644 --- a/engine/common/sequence.c +++ b/engine/common/sequence.c @@ -62,7 +62,7 @@ Sequence_GetCommandEnumForName ============= */ -sequenceCommandEnum_e Sequence_GetCommandEnumForName( const char *commandName, sequenceCommandType_e type ) +static sequenceCommandEnum_e Sequence_GetCommandEnumForName( const char *commandName, sequenceCommandType_e type ) { int i; @@ -82,7 +82,7 @@ Sequence_ResetDefaults ============= */ -void Sequence_ResetDefaults( sequenceCommandLine_s *destination, sequenceCommandLine_s *source ) +static void Sequence_ResetDefaults( sequenceCommandLine_s *destination, sequenceCommandLine_s *source ) { if( !source ) { @@ -131,7 +131,7 @@ Sequence_WriteDefaults ============= */ -void Sequence_WriteDefaults( sequenceCommandLine_s *source, sequenceCommandLine_s *destination ) +static void Sequence_WriteDefaults( sequenceCommandLine_s *source, sequenceCommandLine_s *destination ) { if( !destination ) Con_Reportf( S_ERROR "Attempt to bake defaults into a non-existant command." ); @@ -210,7 +210,7 @@ Sequence_BakeDefaults ============= */ -void Sequence_BakeDefaults( sequenceCommandLine_s *destination, sequenceCommandLine_s *source ) +static void Sequence_BakeDefaults( sequenceCommandLine_s *destination, sequenceCommandLine_s *source ) { char *saveName, *saveMessage; @@ -243,7 +243,7 @@ Sequence_SkipWhitespace ============= */ -qboolean Sequence_SkipWhitespace( void ) +static qboolean Sequence_SkipWhitespace( void ) { qboolean newLine = false; @@ -267,7 +267,7 @@ Sequence_IsNameValueChar ============= */ -qboolean Sequence_IsNameValueChar( char ch ) +static qboolean Sequence_IsNameValueChar( char ch ) { if( isalnum( ch ) ) return true; @@ -291,7 +291,7 @@ Sequence_IsSymbol ============= */ -qboolean Sequence_IsSymbol( char ch ) +static qboolean Sequence_IsSymbol( char ch ) { switch( ch ) { @@ -316,7 +316,7 @@ Sequence_GetNameValueString ============= */ -size_t Sequence_GetNameValueString( char *token, size_t len ) +static size_t Sequence_GetNameValueString( char *token, size_t len ) { char *p; @@ -346,7 +346,7 @@ Sequence_GetSymbol ============= */ -char Sequence_GetSymbol( void ) +static char Sequence_GetSymbol( void ) { char ch; @@ -366,7 +366,7 @@ Sequence_ValidateNameValueString ============= */ -void Sequence_ValidateNameValueString( char *token ) +static void Sequence_ValidateNameValueString( char *token ) { char *scan; @@ -383,7 +383,7 @@ Sequence_GetToken ============= */ -size_t Sequence_GetToken( char *token, size_t size ) +static size_t Sequence_GetToken( char *token, size_t size ) { Sequence_SkipWhitespace( ); @@ -408,7 +408,7 @@ Sequence_GetLine ============= */ -size_t Sequence_GetLine( char *line, int lineMaxLen ) +static size_t Sequence_GetLine( char *line, int lineMaxLen ) { int lineLen; char *read; @@ -439,7 +439,7 @@ Sequence_StripComments ============= */ -void Sequence_StripComments( char *buffer, int *pBufSize ) +static void Sequence_StripComments( char *buffer, int *pBufSize ) { char *eof = buffer + *pBufSize; char *read = buffer; @@ -506,7 +506,7 @@ Sequence_ReadInt ============= */ -int Sequence_ReadInt( void ) +static int Sequence_ReadInt( void ) { char str[MAX_STRING]; @@ -522,7 +522,7 @@ Sequence_ReadFloat ============= */ -float Sequence_ReadFloat( void ) +static float Sequence_ReadFloat( void ) { char str[MAX_STRING]; @@ -538,7 +538,7 @@ Sequence_ReadFloat ============= */ -void Sequence_ReadString( char **dest, char *string, size_t len ) +static void Sequence_ReadString( char **dest, char *string, size_t len ) { Sequence_SkipWhitespace( ); Sequence_GetNameValueString( string, len ); @@ -552,7 +552,7 @@ Sequence_ReadQuotedString ============= */ -void Sequence_ReadQuotedString( char **dest, char *str, size_t len ) +static void Sequence_ReadQuotedString( char **dest, char *str, size_t len ) { char *write, ch; @@ -585,7 +585,7 @@ Sequence_ConfirmCarriageReturnOrSymbol ============= */ -qboolean Sequence_ConfirmCarriageReturnOrSymbol( char symbol ) +static qboolean Sequence_ConfirmCarriageReturnOrSymbol( char symbol ) { if( Sequence_SkipWhitespace( ) ) return true; @@ -599,7 +599,7 @@ Sequence_IsCommandAModifier ============= */ -qboolean Sequence_IsCommandAModifier( sequenceCommandEnum_e commandEnum ) +static qboolean Sequence_IsCommandAModifier( sequenceCommandEnum_e commandEnum ) { int i; @@ -619,7 +619,7 @@ Sequence_ReadCommandData ============= */ -void Sequence_ReadCommandData( sequenceCommandEnum_e commandEnum, sequenceCommandLine_s *defaults ) +static void Sequence_ReadCommandData( sequenceCommandEnum_e commandEnum, sequenceCommandLine_s *defaults ) { char temp[1024]; @@ -722,7 +722,7 @@ Sequence_ParseModifier ============= */ -char Sequence_ParseModifier( sequenceCommandLine_s *defaults ) +static char Sequence_ParseModifier( sequenceCommandLine_s *defaults ) { char modifierName[MAX_STRING]; char delimiter; @@ -756,7 +756,7 @@ Sequence_AddCommandLineToEntry ============= */ -void Sequence_AddCommandLineToEntry( sequenceCommandLine_s *commandLine, sequenceEntry_s *entry ) +static void Sequence_AddCommandLineToEntry( sequenceCommandLine_s *commandLine, sequenceEntry_s *entry ) { sequenceCommandLine_s *scan; @@ -776,7 +776,7 @@ Sequence_ParseModifierLine ============= */ -char Sequence_ParseModifierLine( sequenceEntry_s *entry, sequenceCommandType_e modifierType ) +static char Sequence_ParseModifierLine( sequenceEntry_s *entry, sequenceCommandType_e modifierType ) { sequenceCommandLine_s *newCommandLine; char delimiter = ','; @@ -808,7 +808,7 @@ Sequence_ParseCommand ============= */ -char Sequence_ParseCommand( sequenceCommandLine_s *newCommandLine ) +static char Sequence_ParseCommand( sequenceCommandLine_s *newCommandLine ) { char commandName[MAX_STRING], ch; sequenceCommandEnum_e commandEnum; @@ -847,7 +847,7 @@ Sequence_ParseCommandLine ============= */ -char Sequence_ParseCommandLine( sequenceEntry_s *entry ) +static char Sequence_ParseCommandLine( sequenceEntry_s *entry ) { char symbol; sequenceCommandLine_s *newCommandLine; @@ -874,7 +874,7 @@ Sequence_ParseMacro ============= */ -char Sequence_ParseMacro( sequenceEntry_s *entry ) +static char Sequence_ParseMacro( sequenceEntry_s *entry ) { char symbol; sequenceCommandLine_s *newCommandLine; @@ -902,7 +902,7 @@ Sequence_ParseLine ============= */ -char Sequence_ParseLine( char start, sequenceEntry_s *entry ) +static char Sequence_ParseLine( char start, sequenceEntry_s *entry ) { char end = '\0'; @@ -933,7 +933,7 @@ Sequence_CalcEntryDuration ============= */ -float Sequence_CalcEntryDuration( sequenceEntry_s *entry ) +static float Sequence_CalcEntryDuration( sequenceEntry_s *entry ) { float duration; sequenceCommandLine_s *cmd; @@ -952,7 +952,7 @@ Sequence_DoesEntryContainInfiniteLoop ============= */ -qboolean Sequence_DoesEntryContainInfiniteLoop( sequenceEntry_s *entry ) +static qboolean Sequence_DoesEntryContainInfiniteLoop( sequenceEntry_s *entry ) { sequenceCommandLine_s *cmd; @@ -971,7 +971,7 @@ Sequence_IsEntrySafe ============= */ -qboolean Sequence_IsEntrySafe( sequenceEntry_s *entry ) +static qboolean Sequence_IsEntrySafe( sequenceEntry_s *entry ) { float duration; sequenceCommandLine_s *cmd; @@ -998,7 +998,7 @@ Sequence_CreateDefaultsCommand ============= */ -void Sequence_CreateDefaultsCommand( sequenceEntry_s *entry ) +static void Sequence_CreateDefaultsCommand( sequenceEntry_s *entry ) { sequenceCommandLine_s *cmd; @@ -1026,7 +1026,7 @@ Sequence_ParseEntry ============= */ -char Sequence_ParseEntry( void ) +static char Sequence_ParseEntry( void ) { char symbol; char token[MAX_STRING]; @@ -1068,7 +1068,7 @@ Sequence_FindSentenceGroup ============= */ -sentenceGroupEntry_s *Sequence_FindSentenceGroup( const char *groupName ) +static sentenceGroupEntry_s *Sequence_FindSentenceGroup( const char *groupName ) { sentenceGroupEntry_s *groupEntry; @@ -1152,7 +1152,7 @@ Sequence_AddSentenceGroup ============= */ -sentenceGroupEntry_s *Sequence_AddSentenceGroup( char *groupName ) +static sentenceGroupEntry_s *Sequence_AddSentenceGroup( char *groupName ) { sentenceGroupEntry_s *entry, *last; @@ -1181,7 +1181,7 @@ Sequence_AddSentenceToGroup ============= */ -void Sequence_AddSentenceToGroup( char *groupName, char *data ) +static void Sequence_AddSentenceToGroup( char *groupName, char *data ) { sentenceEntry_s *entry, *last; sentenceGroupEntry_s *group; @@ -1223,7 +1223,7 @@ Sequence_ParseSentenceLine ============= */ -qboolean Sequence_ParseSentenceLine( void ) +static qboolean Sequence_ParseSentenceLine( void ) { char data[1024]; char fullgroup[64]; @@ -1265,7 +1265,7 @@ Sequence_ParseSentenceBlock ============== */ -char Sequence_ParseSentenceBlock( void ) +static char Sequence_ParseSentenceBlock( void ) { qboolean end = false; char ch = Sequence_GetSymbol( ); @@ -1286,7 +1286,7 @@ Sequence_ParseGlobalDataBlock ============== */ -char Sequence_ParseGlobalDataBlock( void ) +static char Sequence_ParseGlobalDataBlock( void ) { char token[MAX_STRING]; @@ -1304,7 +1304,7 @@ Sequence_GetEntryForName ============== */ -sequenceEntry_s *Sequence_GetEntryForName( const char *entryName ) +static sequenceEntry_s *Sequence_GetEntryForName( const char *entryName ) { sequenceEntry_s *scan; @@ -1323,7 +1323,7 @@ Sequence_CopyCommand ============== */ -sequenceCommandLine_s *Sequence_CopyCommand( sequenceCommandLine_s *commandOrig ) +static sequenceCommandLine_s *Sequence_CopyCommand( sequenceCommandLine_s *commandOrig ) { sequenceCommandLine_s *commandCopy; @@ -1354,7 +1354,7 @@ Sequence_CopyCommandList ============== */ -sequenceCommandLine_s *Sequence_CopyCommandList( sequenceCommandLine_s *list ) +static sequenceCommandLine_s *Sequence_CopyCommandList( sequenceCommandLine_s *list ) { sequenceCommandLine_s *scan, *copy, *new, *prev; @@ -1389,7 +1389,7 @@ Sequence_ExpandGosubsForEntry ============== */ -qboolean Sequence_ExpandGosubsForEntry( sequenceEntry_s *entry ) +static qboolean Sequence_ExpandGosubsForEntry( sequenceEntry_s *entry ) { sequenceCommandLine_s *cmd, *copyList, *scan; sequenceEntry_s *gosubEntry; @@ -1437,7 +1437,7 @@ Sequence_ExpandAllGosubs ============== */ -void Sequence_ExpandAllGosubs( void ) +static void Sequence_ExpandAllGosubs( void ) { sequenceEntry_s *scan; qboolean isComplete = true; @@ -1457,7 +1457,7 @@ Sequence_FlattenEntry ============== */ -void Sequence_FlattenEntry( sequenceEntry_s *entry ) +static void Sequence_FlattenEntry( sequenceEntry_s *entry ) { sequenceCommandLine_s *cmd, *last = NULL; @@ -1491,7 +1491,7 @@ Sequence_FlattenAllEntries ============== */ -void Sequence_FlattenAllEntries( void ) +static void Sequence_FlattenAllEntries( void ) { sequenceEntry_s *entry; @@ -1551,7 +1551,7 @@ Sequence_ParseFile ============== */ -void Sequence_ParseFile( const char *fileName, qboolean isGlobal ) +static void Sequence_ParseFile( const char *fileName, qboolean isGlobal ) { byte *buffer; fs_offset_t bufSize = 0; @@ -1608,7 +1608,7 @@ Sequence_FreeCommand ============== */ -void Sequence_FreeCommand( sequenceCommandLine_s *kill ) +static void Sequence_FreeCommand( sequenceCommandLine_s *kill ) { Z_Free( kill->fireTargetNames ); Z_Free( kill->speakerName ); @@ -1625,7 +1625,7 @@ Sequence_FreeEntry ============== */ -void Sequence_FreeEntry( sequenceEntry_s *kill ) +static void Sequence_FreeEntry( sequenceEntry_s *kill ) { sequenceCommandLine_s *dead; @@ -1647,7 +1647,7 @@ Sequence_FreeSentence ============== */ -void Sequence_FreeSentence( sentenceEntry_s *sentenceEntry ) +static void Sequence_FreeSentence( sentenceEntry_s *sentenceEntry ) { Z_Free( sentenceEntry->data ); Z_Free( sentenceEntry ); @@ -1659,7 +1659,7 @@ Sequence_FreeSentenceGroup ============== */ -void Sequence_FreeSentenceGroup( sentenceGroupEntry_s *groupEntry ) +static void Sequence_FreeSentenceGroup( sentenceGroupEntry_s *groupEntry ) { Z_Free( groupEntry->groupName ); Z_Free( groupEntry ); @@ -1671,7 +1671,7 @@ Sequence_FreeSentenceGroupEntries ============== */ -void Sequence_FreeSentenceGroupEntries( sentenceGroupEntry_s *groupEntry, qboolean purgeGlobals ) +static void Sequence_FreeSentenceGroupEntries( sentenceGroupEntry_s *groupEntry, qboolean purgeGlobals ) { sentenceEntry_s *sentenceEntry; sentenceEntry_s *deadSentence; @@ -1711,7 +1711,7 @@ Sequence_PurgeEntries ============== */ -void Sequence_PurgeEntries( qboolean purgeGlobals ) +static void Sequence_PurgeEntries( qboolean purgeGlobals ) { sequenceEntry_s *scan; sequenceEntry_s *dead; diff --git a/engine/sequence.h b/engine/sequence.h index 84854fa07..e7d8aabc6 100644 --- a/engine/sequence.h +++ b/engine/sequence.h @@ -195,11 +195,9 @@ struct sentenceGroupEntry_ // Function declarations //--------------------------------------------------------------------------- sequenceEntry_s* Sequence_Get( const char* fileName, const char* entryName ); -void Sequence_ParseFile( const char* fileName, qboolean isGlobal ); void Sequence_OnLevelLoad( const char* mapName ); sentenceEntry_s* Sequence_PickSentence( const char *groupName, int pickMethod, int *picked ); void Sequence_Init( void ); -void Sequence_PurgeEntries( qboolean purgeGlobals ); sentenceEntry_s *Sequence_GetSentenceByIndex( unsigned int index ); #endif // _INCLUDE_SEQUENCE_H_ From fd795d5612284c66ca93c45bcc1f6f3a20e23bc6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 04:57:41 +0300 Subject: [PATCH 108/121] ref: soft: cleanup unused functions --- ref/soft/r_context.c | 17 ------------ ref/soft/r_edge.c | 38 -------------------------- ref/soft/r_light.c | 23 ---------------- ref/soft/r_local.h | 13 +-------- ref/soft/r_main.c | 3 ++- ref/soft/r_math.c | 58 --------------------------------------- ref/soft/r_misc.c | 16 ----------- ref/soft/r_polyse.c | 22 --------------- ref/soft/r_scan.c | 63 ------------------------------------------- ref/soft/r_studio.c | 29 -------------------- ref/soft/r_surf.c | 48 +-------------------------------- ref/soft/r_trialias.c | 21 --------------- 12 files changed, 4 insertions(+), 347 deletions(-) diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index 3004cb8e6..c455fbbb8 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -26,23 +26,6 @@ static void GAME_EXPORT R_ClearScreen( void ) } -static qboolean GAME_EXPORT IsNormalPass( void ) -{ - return RP_NORMALPASS(); -} - -static void GAME_EXPORT R_IncrementSpeedsCounter( int type ) -{ - switch( type ) - { - case RS_ACTIVE_TENTS: - r_stats.c_active_tents_count++; - break; - default: - gEngfuncs.Host_Error( "R_IncrementSpeedsCounter: unsupported type %d\n", type ); - } -} - static const byte * GAME_EXPORT R_GetTextureOriginalBuffer( unsigned int idx ) { image_t *glt = R_GetTexture( idx ); diff --git a/ref/soft/r_edge.c b/ref/soft/r_edge.c index e5b8e5715..36f69b5d8 100644 --- a/ref/soft/r_edge.c +++ b/ref/soft/r_edge.c @@ -25,14 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void R_SurfacePatch (void) { } - -void R_EdgeCodeStart (void) -{ -} - -void R_EdgeCodeEnd (void) -{ -} #endif @@ -973,36 +965,6 @@ void D_TurbulentSurf (surf_t *s) } } -/* -============== -D_SkySurf -============== -*/ -void D_SkySurf (surf_t *s) -{ - pface = s->msurf; - miplevel = 0; - if (!pface->texinfo->texture) - return; - cacheblock = R_GetTexture(pface->texinfo->texture->gl_texturenum)->pixels[0]; - cachewidth = 256; - - d_zistepu = s->d_zistepu; - d_zistepv = s->d_zistepv; - d_ziorigin = s->d_ziorigin; - - D_CalcGradients (pface); - - D_DrawSpans16 (s->spans); - -// set up a gradient for the background surface that places it -// effectively at infinity distance from the viewpoint - d_zistepu = 0; - d_zistepv = 0; - d_ziorigin = -0.9; - - D_DrawZSpans (s->spans); -} qboolean alphaspans; diff --git a/ref/soft/r_light.c b/ref/soft/r_light.c index 1e84d77dc..aa341aff5 100644 --- a/ref/soft/r_light.c +++ b/ref/soft/r_light.c @@ -174,29 +174,6 @@ void R_PushDlights( void ) } } -/* -============= -R_CountDlights -============= -*/ -int R_CountDlights( void ) -{ - dlight_t *l; - int i, numDlights = 0; - - for( i = 0; i < MAX_DLIGHTS; i++ ) - { - l = gEngfuncs.GetDynamicLight( i ); - - if( l->die < gpGlobals->time || !l->radius ) - continue; - - numDlights++; - } - - return numDlights; -} - /* ============= R_CountSurfaceDlights diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 277abaae8..2940d6fe1 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -374,7 +374,6 @@ void GL_BackendStartFrame( void ); void GL_BackendEndFrame( void ); void GL_CleanUpTextureUnits( int last ); void GL_Bind( int tmu, unsigned int texnum ); -void GL_LoadTexMatrix( const matrix4x4 m ); void GL_LoadTexMatrixExt( const float *glmatrix ); void GL_LoadMatrix( const matrix4x4 source ); void GL_TexGen( unsigned int coord, unsigned int mode ); @@ -465,7 +464,6 @@ void R_MarkLights( dlight_t *light, int bit, mnode_t *node ); colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lightspot, vec3_t lightvec ); int R_CountSurfaceDlights( msurface_t *surf ); colorVec R_LightPoint( const vec3_t p0 ); -int R_CountDlights( void ); #endif // // gl_rmain.c @@ -488,17 +486,11 @@ void R_DrawFog( void ); // // gl_rmath.c // -void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ); -void Matrix4x4_FromArrayFloatGL( matrix4x4 out, const float in[16] ); void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ); void Matrix4x4_ConcatTranslate( matrix4x4 out, float x, float y, float z ); void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float z ); -void Matrix4x4_ConcatScale( matrix4x4 out, float x ); -void Matrix4x4_ConcatScale3( matrix4x4 out, float x, float y, float z ); void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z ); void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float z ); -void Matrix4x4_CreateScale( matrix4x4 out, float x ); -void Matrix4x4_CreateScale3( matrix4x4 out, float x, float y, float z ); void Matrix4x4_CreateProjection(matrix4x4 out, float xMax, float xMin, float yMax, float yMin, float zNear, float zFar); void Matrix4x4_CreateOrtho(matrix4x4 m, float xLeft, float xRight, float yBottom, float yTop, float zNear, float zFar); void Matrix4x4_CreateModelview( matrix4x4 out ); @@ -522,7 +514,6 @@ texture_t *R_TextureAnimation( msurface_t *s ); void GL_SetupFogColorForSurfaces( void ); void R_DrawAlphaTextureChains( void ); void GL_RebuildLightmaps( void ); -void GL_InitRandomTable( void ); void GL_BuildLightmaps( void ); void GL_ResetFogColor( void ); void R_GenerateVBO(); @@ -551,7 +542,6 @@ void R_DrawSpriteModel( cl_entity_t *e ); void R_StudioInit( void ); void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ); void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); -float CL_GetSequenceDuration( cl_entity_t *ent, int sequence ); struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e ); int R_GetEntityRenderMode( cl_entity_t *ent ); void R_DrawStudioModel( cl_entity_t *e ); @@ -1009,8 +999,6 @@ extern affinetridesc_t r_affinetridesc; void D_DrawSurfaces (void); void R_DrawParticle( void ); void D_ViewChanged (void); -void D_WarpScreen (void); -void R_PolysetUpdateTables (void); //=======================================================================// @@ -1198,6 +1186,7 @@ void R_ScanEdges (void); // // r_surf.c // +void GL_InitRandomTable( void ); void D_FlushCaches( void ); // diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index 243429adb..379c0dccc 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -1311,7 +1311,7 @@ void R_DrawBrushModel(cl_entity_t *pent) if (!topnode) return; // no part in a visible leaf - alphaspans = true; + alphaspans = true; VectorCopy (RI.currententity->origin, r_entorigin); VectorSubtract (RI.vieworg, r_entorigin, tr.modelorg); //VectorSubtract (r_origin, RI.currententity->origin, modelorg); @@ -1971,6 +1971,7 @@ qboolean GAME_EXPORT R_Init( void ) R_StudioInit(); R_SpriteInit(); R_InitTurb(); + GL_InitRandomTable(); return true; } diff --git a/ref/soft/r_math.c b/ref/soft/r_math.c index 4c835623d..90600eadd 100644 --- a/ref/soft/r_math.c +++ b/ref/soft/r_math.c @@ -99,46 +99,6 @@ void Matrix4x4_CreateModelview( matrix4x4 out ) out[1][2] = 1.0f; } -void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ) -{ - out[ 0] = in[0][0]; - out[ 1] = in[1][0]; - out[ 2] = in[2][0]; - out[ 3] = in[3][0]; - out[ 4] = in[0][1]; - out[ 5] = in[1][1]; - out[ 6] = in[2][1]; - out[ 7] = in[3][1]; - out[ 8] = in[0][2]; - out[ 9] = in[1][2]; - out[10] = in[2][2]; - out[11] = in[3][2]; - out[12] = in[0][3]; - out[13] = in[1][3]; - out[14] = in[2][3]; - out[15] = in[3][3]; -} - -void Matrix4x4_FromArrayFloatGL( matrix4x4 out, const float in[16] ) -{ - out[0][0] = in[0]; - out[1][0] = in[1]; - out[2][0] = in[2]; - out[3][0] = in[3]; - out[0][1] = in[4]; - out[1][1] = in[5]; - out[2][1] = in[6]; - out[3][1] = in[7]; - out[0][2] = in[8]; - out[1][2] = in[9]; - out[2][2] = in[10]; - out[3][2] = in[11]; - out[0][3] = in[12]; - out[1][3] = in[13]; - out[2][3] = in[14]; - out[3][3] = in[15]; -} - void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z ) { out[0][0] = 1.0f; @@ -247,21 +207,3 @@ void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float Matrix4x4_CreateRotate( temp, angle, x, y, z ); Matrix4x4_Concat( out, base, temp ); } - -void Matrix4x4_ConcatScale( matrix4x4 out, float x ) -{ - matrix4x4 base, temp; - - Matrix4x4_Copy( base, out ); - Matrix4x4_CreateScale( temp, x ); - Matrix4x4_Concat( out, base, temp ); -} - -void Matrix4x4_ConcatScale3( matrix4x4 out, float x, float y, float z ) -{ - matrix4x4 base, temp; - - Matrix4x4_Copy( base, out ); - Matrix4x4_CreateScale3( temp, x, y, z ); - Matrix4x4_Concat( out, base, temp ); -} diff --git a/ref/soft/r_misc.c b/ref/soft/r_misc.c index e984a27e7..d385c167d 100644 --- a/ref/soft/r_misc.c +++ b/ref/soft/r_misc.c @@ -157,22 +157,6 @@ void TransformVector (vec3_t in, vec3_t out) out[2] = DotProduct(in,RI.vforward); } -/* -================ -R_TransformPlane -================ -*/ -void R_TransformPlane (mplane_t *p, float *normal, float *dist) -{ - float d; - - d = DotProduct (RI.vieworg, p->normal); - *dist = p->dist - d; -// TODO: when we have rotating entities, this will need to use the view matrix - TransformVector (p->normal, normal); -} - - /* =============== R_SetUpFrustumIndexes diff --git a/ref/soft/r_polyse.c b/ref/soft/r_polyse.c index 0d36d386c..93861f857 100644 --- a/ref/soft/r_polyse.c +++ b/ref/soft/r_polyse.c @@ -123,28 +123,6 @@ void R_RasterizeAliasPolySmooth (void); void R_PolysetScanLeftEdge(int height); qboolean R_PolysetScanLeftEdge_C(int height); -/* -================ -R_PolysetUpdateTables -================ -*/ -void R_PolysetUpdateTables (void) -{ - int i; - byte *s; - - if (r_affinetridesc.skinwidth != skinwidth || - r_affinetridesc.pskin != skinstart) - { - skinwidth = r_affinetridesc.skinwidth; - skinstart = r_affinetridesc.pskin; - s = skinstart; - for (i=0 ; imodel != NULL && ent->model->type == mod_studio ) - { - pstudiohdr = (studiohdr_t *)gEngfuncs.Mod_Extradata( mod_studio, ent->model ); - - if( pstudiohdr ) - { - sequence = bound( 0, sequence, pstudiohdr->numseq - 1 ); - pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + sequence; - - if( pseqdesc->numframes > 1 && pseqdesc->fps > 0 ) - return (float)pseqdesc->numframes / (float)pseqdesc->fps; - } - } - - return 0.1f; -} - - /* ==================== StudioFxTransform diff --git a/ref/soft/r_surf.c b/ref/soft/r_surf.c index e1d44681d..48b7fc31b 100644 --- a/ref/soft/r_surf.c +++ b/ref/soft/r_surf.c @@ -353,7 +353,7 @@ void R_BuildLightMap (void) #endif -void R_InitRandomTable( void ) +void GL_InitRandomTable( void ) { int tu, tv; @@ -1105,52 +1105,6 @@ surfcache_t *D_SCAlloc (int width, int size) return new; } - -/* -================= -D_SCDump -================= -*/ -void D_SCDump (void) -{ - surfcache_t *test; - - for (test = sc_base ; test ; test = test->next) - { - if (test == sc_rover) - gEngfuncs.Con_Printf ("ROVER:\n"); - gEngfuncs.Con_Printf ("%p : %i bytes %i width\n",test, test->size, test->width); - } -} - -//============================================================================= - -// if the num is not a power of 2, assume it will not repeat - -int MaskForNum (int num) -{ - if (num==128) - return 127; - if (num==64) - return 63; - if (num==32) - return 31; - if (num==16) - return 15; - return 255; -} - -int D_log2 (int num) -{ - int c; - - c = 0; - - while (num>>=1) - c++; - return c; -} - //============================================================================= void R_DecalComputeBasis( msurface_t *surf, int flags, vec3_t textureSpaceBasis[3] ); void R_DrawSurfaceDecals( void ) diff --git a/ref/soft/r_trialias.c b/ref/soft/r_trialias.c index 51e7bfdc0..9595a6c4b 100644 --- a/ref/soft/r_trialias.c +++ b/ref/soft/r_trialias.c @@ -25,7 +25,6 @@ float r_avertexnormals[NUMVERTEXNORMALS][3] = { void R_AliasSetUpTransform (void); -void R_AliasTransformVector (vec3_t in, vec3_t out, float m[3][4] ); void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv); void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv ); @@ -42,19 +41,6 @@ R_AliasCheckBBox #define BBOX_MUST_CLIP_Z 2 #define BBOX_TRIVIAL_REJECT 8 - -/* -================ -R_AliasTransformVector -================ -*/ -void R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4] ) -{ - out[0] = DotProduct(in, xf[0]) + xf[0][3]; - out[1] = DotProduct(in, xf[1]) + xf[1][3]; - out[2] = DotProduct(in, xf[2]) + xf[2][3]; -} - void VectorInverse (vec3_t v) { v[0] = -v[0]; @@ -238,13 +224,6 @@ void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ) fv->flags |= ALIAS_BOTTOM_CLIP; } -void R_AliasWorldToScreen( const float *v, float *out ) -{ - out[0] = DotProduct(v, aliastransform[0]) + aliastransform[0][3]; - out[1] = DotProduct(v, aliastransform[1]) + aliastransform[1][3]; - out[2] = DotProduct(v, aliastransform[2]) + aliastransform[2][3]; -} - void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, int s, int t ) { vec3_t v = {x, y, z}; From 550ced9c3654ccf13b2c45f17ad73b0bf6f13eb6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 05:05:18 +0300 Subject: [PATCH 109/121] ref: gl: cleanup unused functions in frustum --- public/xash3d_mathlib.c | 43 ---------- public/xash3d_mathlib.h | 1 - ref/gl/gl_cull.c | 12 --- ref/gl/gl_frustum.c | 169 ---------------------------------------- ref/gl/gl_frustum.h | 10 --- 5 files changed, 235 deletions(-) diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index c4872e283..a588ca08c 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -183,49 +183,6 @@ int PlaneTypeForNormal( const vec3_t normal ) return PLANE_NONAXIAL; } -/* -================= -PlanesGetIntersectionPoint - -================= -*/ -qboolean PlanesGetIntersectionPoint( const mplane_t *plane1, const mplane_t *plane2, const mplane_t *plane3, vec3_t out ) -{ - vec3_t n1, n2, n3; - vec3_t n1n2, n2n3, n3n1; - float denom; - - VectorNormalize2( plane1->normal, n1 ); - VectorNormalize2( plane2->normal, n2 ); - VectorNormalize2( plane3->normal, n3 ); - - CrossProduct( n1, n2, n1n2 ); - CrossProduct( n2, n3, n2n3 ); - CrossProduct( n3, n1, n3n1 ); - - denom = DotProduct( n1, n2n3 ); - VectorClear( out ); - - // check if the denominator is zero (which would mean that no intersection is to be found - if( denom == 0.0f ) - { - // no intersection could be found, return <0,0,0> - return false; - } - - // compute intersection point -#if 0 - VectorMAMAM( plane1->dist, n2n3, plane2->dist, n3n1, plane3->dist, n1n2, out ); -#else - VectorMA( out, plane1->dist, n2n3, out ); - VectorMA( out, plane2->dist, n3n1, out ); - VectorMA( out, plane3->dist, n1n2, out ); -#endif - VectorScale( out, ( 1.0f / denom ), out ); - - return true; -} - /* ================= NearestPOW diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index 1d2e8368c..82bedb0e5 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -188,7 +188,6 @@ void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up ); void VectorAngles( const float *forward, float *angles ); void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up ); void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles ); -qboolean PlanesGetIntersectionPoint( const struct mplane_s *plane1, const struct mplane_s *plane2, const struct mplane_s *plane3, vec3_t out ); void PlaneIntersect( const struct mplane_s *plane, const vec3_t p0, const vec3_t p1, vec3_t out ); void ClearBounds( vec3_t mins, vec3_t maxs ); diff --git a/ref/gl/gl_cull.c b/ref/gl/gl_cull.c index cd31c9cc3..b13b96386 100644 --- a/ref/gl/gl_cull.c +++ b/ref/gl/gl_cull.c @@ -35,18 +35,6 @@ qboolean R_CullBox( const vec3_t mins, const vec3_t maxs ) return GL_FrustumCullBox( &RI.frustum, mins, maxs, 0 ); } -/* -================= -R_CullSphere - -Returns true if the sphere is completely outside the frustum -================= -*/ -qboolean R_CullSphere( const vec3_t centre, const float radius ) -{ - return GL_FrustumCullSphere( &RI.frustum, centre, radius, 0 ); -} - /* ============= R_CullModel diff --git a/ref/gl/gl_frustum.c b/ref/gl/gl_frustum.c index 92e995f07..46dd2be93 100644 --- a/ref/gl/gl_frustum.c +++ b/ref/gl/gl_frustum.c @@ -16,21 +16,6 @@ GNU General Public License for more details. #include "gl_local.h" #include "xash3d_mathlib.h" -void GL_FrustumEnablePlane( gl_frustum_t *out, int side ) -{ - Assert( side >= 0 && side < FRUSTUM_PLANES ); - - // make sure what plane is ready - if( !VectorIsNull( out->planes[side].normal )) - SetBits( out->clipFlags, BIT( side )); -} - -void GL_FrustumDisablePlane( gl_frustum_t *out, int side ) -{ - Assert( side >= 0 && side < FRUSTUM_PLANES ); - ClearBits( out->clipFlags, BIT( side )); -} - void GL_FrustumSetPlane( gl_frustum_t *out, int side, const vec3_t vecNormal, float flDist ) { Assert( side >= 0 && side < FRUSTUM_PLANES ); @@ -43,30 +28,6 @@ void GL_FrustumSetPlane( gl_frustum_t *out, int side, const vec3_t vecNormal, fl SetBits( out->clipFlags, BIT( side )); } -void GL_FrustumNormalizePlane( gl_frustum_t *out, int side ) -{ - float length; - - Assert( side >= 0 && side < FRUSTUM_PLANES ); - - // normalize - length = VectorLength( out->planes[side].normal ); - - if( length ) - { - float ilength = (1.0f / length); - out->planes[side].normal[0] *= ilength; - out->planes[side].normal[1] *= ilength; - out->planes[side].normal[2] *= ilength; - out->planes[side].dist *= ilength; - } - - out->planes[side].type = PlaneTypeForNormal( out->planes[side].normal ); - out->planes[side].signbits = SignbitsForPlane( out->planes[side].normal ); - - SetBits( out->clipFlags, BIT( side )); -} - void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float flFovX, float flFovY ) { float xs, xc; @@ -135,136 +96,6 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT GL_FrustumSetPlane( out, FRUSTUM_BOTTOM, iup, -yBottom - orgOffset ); } -void GL_FrustumInitBox( gl_frustum_t *out, const vec3_t org, float radius ) -{ - vec3_t normal; - int i; - - for( i = 0; i < FRUSTUM_PLANES; i++ ) - { - // setup normal for each direction - VectorClear( normal ); - normal[((i >> 1) + 1) % 3] = (i & 1) ? 1.0f : -1.0f; - GL_FrustumSetPlane( out, i, normal, DotProduct( org, normal ) - radius ); - } -} - -void GL_FrustumInitProjFromMatrix( gl_frustum_t *out, const matrix4x4 projection ) -{ - int i; - - // left - out->planes[FRUSTUM_LEFT].normal[0] = projection[0][3] + projection[0][0]; - out->planes[FRUSTUM_LEFT].normal[1] = projection[1][3] + projection[1][0]; - out->planes[FRUSTUM_LEFT].normal[2] = projection[2][3] + projection[2][0]; - out->planes[FRUSTUM_LEFT].dist = -(projection[3][3] + projection[3][0]); - - // right - out->planes[FRUSTUM_RIGHT].normal[0] = projection[0][3] - projection[0][0]; - out->planes[FRUSTUM_RIGHT].normal[1] = projection[1][3] - projection[1][0]; - out->planes[FRUSTUM_RIGHT].normal[2] = projection[2][3] - projection[2][0]; - out->planes[FRUSTUM_RIGHT].dist = -(projection[3][3] - projection[3][0]); - - // bottom - out->planes[FRUSTUM_BOTTOM].normal[0] = projection[0][3] + projection[0][1]; - out->planes[FRUSTUM_BOTTOM].normal[1] = projection[1][3] + projection[1][1]; - out->planes[FRUSTUM_BOTTOM].normal[2] = projection[2][3] + projection[2][1]; - out->planes[FRUSTUM_BOTTOM].dist = -(projection[3][3] + projection[3][1]); - - // top - out->planes[FRUSTUM_TOP].normal[0] = projection[0][3] - projection[0][1]; - out->planes[FRUSTUM_TOP].normal[1] = projection[1][3] - projection[1][1]; - out->planes[FRUSTUM_TOP].normal[2] = projection[2][3] - projection[2][1]; - out->planes[FRUSTUM_TOP].dist = -(projection[3][3] - projection[3][1]); - - // near - out->planes[FRUSTUM_NEAR].normal[0] = projection[0][3] + projection[0][2]; - out->planes[FRUSTUM_NEAR].normal[1] = projection[1][3] + projection[1][2]; - out->planes[FRUSTUM_NEAR].normal[2] = projection[2][3] + projection[2][2]; - out->planes[FRUSTUM_NEAR].dist = -(projection[3][3] + projection[3][2]); - - // far - out->planes[FRUSTUM_FAR].normal[0] = projection[0][3] - projection[0][2]; - out->planes[FRUSTUM_FAR].normal[1] = projection[1][3] - projection[1][2]; - out->planes[FRUSTUM_FAR].normal[2] = projection[2][3] - projection[2][2]; - out->planes[FRUSTUM_FAR].dist = -(projection[3][3] - projection[3][2]); - - for( i = 0; i < FRUSTUM_PLANES; i++ ) - { - GL_FrustumNormalizePlane( out, i ); - } -} - -void GL_FrustumComputeCorners( gl_frustum_t *out, vec3_t corners[8] ) -{ - memset( corners, 0, sizeof( vec3_t ) * 8 ); - - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_LEFT], &out->planes[FRUSTUM_TOP], &out->planes[FRUSTUM_FAR], corners[0] ); - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_RIGHT], &out->planes[FRUSTUM_TOP], &out->planes[FRUSTUM_FAR], corners[1] ); - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_LEFT], &out->planes[FRUSTUM_BOTTOM], &out->planes[FRUSTUM_FAR], corners[2] ); - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_RIGHT], &out->planes[FRUSTUM_BOTTOM], &out->planes[FRUSTUM_FAR], corners[3] ); - - if( FBitSet( out->clipFlags, BIT( FRUSTUM_NEAR ))) - { - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_LEFT], &out->planes[FRUSTUM_TOP], &out->planes[FRUSTUM_NEAR], corners[4] ); - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_RIGHT], &out->planes[FRUSTUM_TOP], &out->planes[FRUSTUM_NEAR], corners[5] ); - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_LEFT], &out->planes[FRUSTUM_BOTTOM], &out->planes[FRUSTUM_NEAR], corners[6] ); - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_RIGHT], &out->planes[FRUSTUM_BOTTOM], &out->planes[FRUSTUM_NEAR], corners[7] ); - } - else - { - PlanesGetIntersectionPoint( &out->planes[FRUSTUM_LEFT], &out->planes[FRUSTUM_RIGHT], &out->planes[FRUSTUM_TOP], corners[4] ); - VectorCopy( corners[4], corners[5] ); - VectorCopy( corners[4], corners[6] ); - VectorCopy( corners[4], corners[7] ); - } -} - -void GL_FrustumComputeBounds( gl_frustum_t *out, vec3_t mins, vec3_t maxs ) -{ - vec3_t corners[8]; - int i; - - GL_FrustumComputeCorners( out, corners ); - - ClearBounds( mins, maxs ); - - for( i = 0; i < 8; i++ ) - AddPointToBounds( corners[i], mins, maxs ); -} - -void GL_FrustumDrawDebug( gl_frustum_t *out ) -{ - vec3_t bbox[8]; - int i; - - GL_FrustumComputeCorners( out, bbox ); - - // g-cont. frustum must be yellow :-) - pglColor4f( 1.0f, 1.0f, 0.0f, 1.0f ); - pglDisable( GL_TEXTURE_2D ); - pglBegin( GL_LINES ); - - for( i = 0; i < 2; i += 1 ) - { - pglVertex3fv( bbox[i+0] ); - pglVertex3fv( bbox[i+2] ); - pglVertex3fv( bbox[i+4] ); - pglVertex3fv( bbox[i+6] ); - pglVertex3fv( bbox[i+0] ); - pglVertex3fv( bbox[i+4] ); - pglVertex3fv( bbox[i+2] ); - pglVertex3fv( bbox[i+6] ); - pglVertex3fv( bbox[i*2+0] ); - pglVertex3fv( bbox[i*2+1] ); - pglVertex3fv( bbox[i*2+4] ); - pglVertex3fv( bbox[i*2+5] ); - } - - pglEnd(); - pglEnable( GL_TEXTURE_2D ); -} - // cull methods qboolean GL_FrustumCullBox( gl_frustum_t *out, const vec3_t mins, const vec3_t maxs, int userClipFlags ) { diff --git a/ref/gl/gl_frustum.h b/ref/gl/gl_frustum.h index 0b310a80f..520ebff82 100644 --- a/ref/gl/gl_frustum.h +++ b/ref/gl/gl_frustum.h @@ -33,20 +33,10 @@ typedef struct gl_frustum_s void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float flFovX, float flFovY ); void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yTop, float yBottom, float flZNear, float flZFar ); -void GL_FrustumInitBox( gl_frustum_t *out, const vec3_t org, float radius ); // used for pointlights -void GL_FrustumInitProjFromMatrix( gl_frustum_t *out, const matrix4x4 projection ); void GL_FrustumSetPlane( gl_frustum_t *out, int side, const vec3_t vecNormal, float flDist ); -void GL_FrustumNormalizePlane( gl_frustum_t *out, int side ); -void GL_FrustumComputeBounds( gl_frustum_t *out, vec3_t mins, vec3_t maxs ); -void GL_FrustumComputeCorners( gl_frustum_t *out, vec3_t bbox[8] ); -void GL_FrustumDrawDebug( gl_frustum_t *out ); // cull methods qboolean GL_FrustumCullBox( gl_frustum_t *out, const vec3_t mins, const vec3_t maxs, int userClipFlags ); qboolean GL_FrustumCullSphere( gl_frustum_t *out, const vec3_t centre, float radius, int userClipFlags ); -// plane manipulating -void GL_FrustumEnablePlane( gl_frustum_t *out, int side ); -void GL_FrustumDisablePlane( gl_frustum_t *out, int side ); - #endif//GL_FRUSTUM_H From 79624fa400ddf0382b03998f4d27bd071a368182 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 05:06:08 +0300 Subject: [PATCH 110/121] ref: gl: cleanup unused functions --- ref/gl/gl_backend.c | 12 ------- ref/gl/gl_image.c | 17 ---------- ref/gl/gl_local.h | 13 -------- ref/gl/gl_rlight.c | 23 ------------- ref/gl/gl_rmath.c | 78 --------------------------------------------- ref/gl/gl_studio.c | 29 ----------------- 6 files changed, 172 deletions(-) diff --git a/ref/gl/gl_backend.c b/ref/gl/gl_backend.c index f3f4e2a5e..a3276a9b0 100644 --- a/ref/gl/gl_backend.c +++ b/ref/gl/gl_backend.c @@ -116,18 +116,6 @@ void GL_BackendEndFrame( void ) memset( &r_stats, 0, sizeof( r_stats )); } -/* -================= -GL_LoadTexMatrix -================= -*/ -void GL_LoadTexMatrix( const matrix4x4 m ) -{ - pglMatrixMode( GL_TEXTURE ); - GL_LoadMatrix( m ); - glState.texIdentityMatrix[glState.activeTMU] = false; -} - /* ================= GL_LoadTexMatrixExt diff --git a/ref/gl/gl_image.c b/ref/gl/gl_image.c index 5c4aed516..b1060aa18 100644 --- a/ref/gl/gl_image.c +++ b/ref/gl/gl_image.c @@ -1931,23 +1931,6 @@ void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor ) gEngfuncs.FS_FreeImage( pic ); } -/* -================ -GL_TexMemory - -return size of all uploaded textures -================ -*/ -int GL_TexMemory( void ) -{ - int i, total = 0; - - for( i = 0; i < gl_numTextures; i++ ) - total += gl_textures[i].size; - - return total; -} - /* ============================================================================== diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index bd807d491..e50cf7f63 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -294,7 +294,6 @@ void GL_CleanUpTextureUnits( int last ); void GL_Bind( GLint tmu, GLenum texnum ); void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t ); void GL_SetTexCoordArrayMode( GLenum mode ); -void GL_LoadTexMatrix( const matrix4x4 m ); void GL_LoadTexMatrixExt( const float *glmatrix ); void GL_LoadMatrix( const matrix4x4 source ); void GL_TexGen( GLenum coord, GLenum mode ); @@ -319,7 +318,6 @@ qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ); // int R_CullModel( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax ); qboolean R_CullBox( const vec3_t mins, const vec3_t maxs ); -qboolean R_CullSphere( const vec3_t centre, const float radius ); int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags ); // @@ -368,7 +366,6 @@ void R_InitDlightTexture( void ); void R_TextureList_f( void ); void R_InitImages( void ); void R_ShutdownImages( void ); -int GL_TexMemory( void ); // // gl_rlight.c @@ -381,7 +378,6 @@ void R_MarkLights( dlight_t *light, int bit, mnode_t *node ); colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lightspot, vec3_t lightvec ); int R_CountSurfaceDlights( msurface_t *surf ); colorVec R_LightPoint( const vec3_t p0 ); -int R_CountDlights( void ); // // gl_rmain.c @@ -407,16 +403,9 @@ int CL_FxBlend( cl_entity_t *e ); // gl_rmath.c // void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ); -void Matrix4x4_FromArrayFloatGL( matrix4x4 out, const float in[16] ); void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ); void Matrix4x4_ConcatTranslate( matrix4x4 out, float x, float y, float z ); void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float z ); -void Matrix4x4_ConcatScale( matrix4x4 out, float x ); -void Matrix4x4_ConcatScale3( matrix4x4 out, float x, float y, float z ); -void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z ); -void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float z ); -void Matrix4x4_CreateScale( matrix4x4 out, float x ); -void Matrix4x4_CreateScale3( matrix4x4 out, float x, float y, float z ); void Matrix4x4_CreateProjection(matrix4x4 out, float xMax, float xMin, float yMax, float yMin, float zNear, float zFar); void Matrix4x4_CreateOrtho(matrix4x4 m, float xLeft, float xRight, float yBottom, float yTop, float zNear, float zFar); void Matrix4x4_CreateModelview( matrix4x4 out ); @@ -467,9 +456,7 @@ void R_DrawSpriteModel( cl_entity_t *e ); // gl_studio.c // void R_StudioInit( void ); -void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ); void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); -float CL_GetSequenceDuration( cl_entity_t *ent, int sequence ); struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e ); int R_GetEntityRenderMode( cl_entity_t *ent ); void R_DrawStudioModel( cl_entity_t *e ); diff --git a/ref/gl/gl_rlight.c b/ref/gl/gl_rlight.c index 896799894..514b58b43 100644 --- a/ref/gl/gl_rlight.c +++ b/ref/gl/gl_rlight.c @@ -171,29 +171,6 @@ void R_PushDlights( void ) } } -/* -============= -R_CountDlights -============= -*/ -int R_CountDlights( void ) -{ - dlight_t *l; - int i, numDlights = 0; - - for( i = 0; i < MAX_DLIGHTS; i++ ) - { - l = gEngfuncs.GetDynamicLight( i ); - - if( l->die < gpGlobals->time || !l->radius ) - continue; - - numDlights++; - } - - return numDlights; -} - /* ============= R_CountSurfaceDlights diff --git a/ref/gl/gl_rmath.c b/ref/gl/gl_rmath.c index 69fb4eb24..0406a0c3f 100644 --- a/ref/gl/gl_rmath.c +++ b/ref/gl/gl_rmath.c @@ -119,26 +119,6 @@ void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ) out[15] = in[3][3]; } -void Matrix4x4_FromArrayFloatGL( matrix4x4 out, const float in[16] ) -{ - out[0][0] = in[0]; - out[1][0] = in[1]; - out[2][0] = in[2]; - out[3][0] = in[3]; - out[0][1] = in[4]; - out[1][1] = in[5]; - out[2][1] = in[6]; - out[3][1] = in[7]; - out[0][2] = in[8]; - out[1][2] = in[9]; - out[2][2] = in[10]; - out[3][2] = in[11]; - out[0][3] = in[12]; - out[1][3] = in[13]; - out[2][3] = in[14]; - out[3][3] = in[15]; -} - void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z ) { out[0][0] = 1.0f; @@ -190,46 +170,6 @@ void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float out[3][3]=1.0f; } -void Matrix4x4_CreateScale( matrix4x4 out, float x ) -{ - out[0][0] = x; - out[0][1] = 0.0f; - out[0][2] = 0.0f; - out[0][3] = 0.0f; - out[1][0] = 0.0f; - out[1][1] = x; - out[1][2] = 0.0f; - out[1][3] = 0.0f; - out[2][0] = 0.0f; - out[2][1] = 0.0f; - out[2][2] = x; - out[2][3] = 0.0f; - out[3][0] = 0.0f; - out[3][1] = 0.0f; - out[3][2] = 0.0f; - out[3][3] = 1.0f; -} - -void Matrix4x4_CreateScale3( matrix4x4 out, float x, float y, float z ) -{ - out[0][0] = x; - out[0][1] = 0.0f; - out[0][2] = 0.0f; - out[0][3] = 0.0f; - out[1][0] = 0.0f; - out[1][1] = y; - out[1][2] = 0.0f; - out[1][3] = 0.0f; - out[2][0] = 0.0f; - out[2][1] = 0.0f; - out[2][2] = z; - out[2][3] = 0.0f; - out[3][0] = 0.0f; - out[3][1] = 0.0f; - out[3][2] = 0.0f; - out[3][3] = 1.0f; -} - void Matrix4x4_ConcatTranslate( matrix4x4 out, float x, float y, float z ) { matrix4x4 base, temp; @@ -247,21 +187,3 @@ void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float Matrix4x4_CreateRotate( temp, angle, x, y, z ); Matrix4x4_Concat( out, base, temp ); } - -void Matrix4x4_ConcatScale( matrix4x4 out, float x ) -{ - matrix4x4 base, temp; - - Matrix4x4_Copy( base, out ); - Matrix4x4_CreateScale( temp, x ); - Matrix4x4_Concat( out, base, temp ); -} - -void Matrix4x4_ConcatScale3( matrix4x4 out, float x, float y, float z ) -{ - matrix4x4 base, temp; - - Matrix4x4_Copy( base, out ); - Matrix4x4_CreateScale3( temp, x, y, z ); - Matrix4x4_Concat( out, base, temp ); -} diff --git a/ref/gl/gl_studio.c b/ref/gl/gl_studio.c index 7e330a2f7..30ea87dd2 100644 --- a/ref/gl/gl_studio.c +++ b/ref/gl/gl_studio.c @@ -676,35 +676,6 @@ float R_StudioEstimateInterpolant( cl_entity_t *e ) return dadt; } -/* -==================== -CL_GetSequenceDuration - -==================== -*/ -float CL_GetSequenceDuration( cl_entity_t *ent, int sequence ) -{ - studiohdr_t *pstudiohdr; - mstudioseqdesc_t *pseqdesc; - - if( ent->model != NULL && ent->model->type == mod_studio ) - { - pstudiohdr = (studiohdr_t *)gEngfuncs.Mod_Extradata( mod_studio, ent->model ); - - if( pstudiohdr ) - { - sequence = bound( 0, sequence, pstudiohdr->numseq - 1 ); - pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + sequence; - - if( pseqdesc->numframes > 1 && pseqdesc->fps > 0 ) - return (float)pseqdesc->numframes / (float)pseqdesc->fps; - } - } - - return 0.1f; -} - - /* ==================== StudioFxTransform From 2fb19a0cfdfd5de77a3a9fb73a0d16f5dce9b367 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 05:14:59 +0300 Subject: [PATCH 111/121] public: matrixlib: cleanup unused functions --- public/matrixlib.c | 121 ---------------------------------------- public/xash3d_mathlib.h | 8 --- 2 files changed, 129 deletions(-) diff --git a/public/matrixlib.c b/public/matrixlib.c index 522732ac6..a783c24b2 100644 --- a/public/matrixlib.c +++ b/public/matrixlib.c @@ -217,62 +217,6 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_ } } -void Matrix3x4_TransformPositivePlane( const matrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) -{ - float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] ); - float iscale = 1.0f / scale; - - out[0] = (normal[0] * in[0][0] + normal[1] * in[0][1] + normal[2] * in[0][2]) * iscale; - out[1] = (normal[0] * in[1][0] + normal[1] * in[1][1] + normal[2] * in[1][2]) * iscale; - out[2] = (normal[0] * in[2][0] + normal[1] * in[2][1] + normal[2] * in[2][2]) * iscale; - *dist = d * scale + ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] ); -} - -void Matrix3x4_Invert_Simple( matrix3x4 out, const matrix3x4 in1 ) -{ - // we only support uniform scaling, so assume the first row is enough - // (note the lack of sqrt here, because we're trying to undo the scaling, - // this means multiplying by the inverse scale twice - squaring it, which - // makes the sqrt a waste of time) - float scale = 1.0f / (in1[0][0] * in1[0][0] + in1[0][1] * in1[0][1] + in1[0][2] * in1[0][2]); - - // invert the rotation by transposing and multiplying by the squared - // recipricol of the input matrix scale as described above - out[0][0] = in1[0][0] * scale; - out[0][1] = in1[1][0] * scale; - out[0][2] = in1[2][0] * scale; - out[1][0] = in1[0][1] * scale; - out[1][1] = in1[1][1] * scale; - out[1][2] = in1[2][1] * scale; - out[2][0] = in1[0][2] * scale; - out[2][1] = in1[1][2] * scale; - out[2][2] = in1[2][2] * scale; - - // invert the translate - out[0][3] = -(in1[0][3] * out[0][0] + in1[1][3] * out[0][1] + in1[2][3] * out[0][2]); - out[1][3] = -(in1[0][3] * out[1][0] + in1[1][3] * out[1][1] + in1[2][3] * out[1][2]); - out[2][3] = -(in1[0][3] * out[2][0] + in1[1][3] * out[2][1] + in1[2][3] * out[2][2]); -} - -void Matrix3x4_Transpose( matrix3x4 out, const matrix3x4 in1 ) -{ - // transpose only rotational component - out[0][0] = in1[0][0]; - out[0][1] = in1[1][0]; - out[0][2] = in1[2][0]; - out[1][0] = in1[0][1]; - out[1][1] = in1[1][1]; - out[1][2] = in1[2][1]; - out[2][0] = in1[0][2]; - out[2][1] = in1[1][2]; - out[2][2] = in1[2][2]; - - // copy origin - out[0][3] = in1[0][3]; - out[1][3] = in1[1][3]; - out[2][3] = in1[2][3]; -} - /* ================== Matrix3x4_TransformAABB @@ -360,40 +304,6 @@ void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matri out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3]; } -void Matrix4x4_SetOrigin( matrix4x4 out, float x, float y, float z ) -{ - out[0][3] = x; - out[1][3] = y; - out[2][3] = z; -} - -void Matrix4x4_OriginFromMatrix( const matrix4x4 in, float *out ) -{ - out[0] = in[0][3]; - out[1] = in[1][3]; - out[2] = in[2][3]; -} - -void Matrix4x4_FromOriginQuat( matrix4x4 out, const vec4_t quaternion, const vec3_t origin ) -{ - out[0][0] = 1.0f - 2.0f * quaternion[1] * quaternion[1] - 2.0f * quaternion[2] * quaternion[2]; - out[1][0] = 2.0f * quaternion[0] * quaternion[1] + 2.0f * quaternion[3] * quaternion[2]; - out[2][0] = 2.0f * quaternion[0] * quaternion[2] - 2.0f * quaternion[3] * quaternion[1]; - out[0][3] = origin[0]; - out[0][1] = 2.0f * quaternion[0] * quaternion[1] - 2.0f * quaternion[3] * quaternion[2]; - out[1][1] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[2] * quaternion[2]; - out[2][1] = 2.0f * quaternion[1] * quaternion[2] + 2.0f * quaternion[3] * quaternion[0]; - out[1][3] = origin[1]; - out[0][2] = 2.0f * quaternion[0] * quaternion[2] + 2.0f * quaternion[3] * quaternion[1]; - out[1][2] = 2.0f * quaternion[1] * quaternion[2] - 2.0f * quaternion[3] * quaternion[0]; - out[2][2] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[1] * quaternion[1]; - out[2][3] = origin[2]; - out[3][0] = 0.0f; - out[3][1] = 0.0f; - out[3][2] = 0.0f; - out[3][3] = 1.0f; -} - void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale ) { float angle, sr, sp, sy, cr, cp, cy; @@ -525,17 +435,6 @@ void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, *dist = d * scale + ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] ); } -void Matrix4x4_TransformStandardPlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) -{ - float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] ); - float iscale = 1.0f / scale; - - out[0] = (normal[0] * in[0][0] + normal[1] * in[0][1] + normal[2] * in[0][2]) * iscale; - out[1] = (normal[0] * in[1][0] + normal[1] * in[1][1] + normal[2] * in[1][2]) * iscale; - out[2] = (normal[0] * in[2][0] + normal[1] * in[2][1] + normal[2] * in[2][2]) * iscale; - *dist = d * scale - ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] ); -} - void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 ) { // we only support uniform scaling, so assume the first row is enough @@ -568,26 +467,6 @@ void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 ) out[3][3] = 1.0f; } -void Matrix4x4_Transpose( matrix4x4 out, const matrix4x4 in1 ) -{ - out[0][0] = in1[0][0]; - out[0][1] = in1[1][0]; - out[0][2] = in1[2][0]; - out[0][3] = in1[3][0]; - out[1][0] = in1[0][1]; - out[1][1] = in1[1][1]; - out[1][2] = in1[2][1]; - out[1][3] = in1[3][1]; - out[2][0] = in1[0][2]; - out[2][1] = in1[1][2]; - out[2][2] = in1[2][2]; - out[2][3] = in1[3][2]; - out[3][0] = in1[0][3]; - out[3][1] = in1[1][3]; - out[3][2] = in1[2][3]; - out[3][3] = in1[3][3]; -} - qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 ) { float *temp; diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index 82bedb0e5..70fb01292 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -217,13 +217,10 @@ void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 ); void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec3_t origin ); void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale ); -void Matrix3x4_TransformPositivePlane( const matrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const vec3_t maxs, vec3_t absmin, vec3_t absmax ); void Matrix3x4_SetOrigin( matrix3x4 out, float x, float y, float z ); -void Matrix3x4_Invert_Simple( matrix3x4 out, const matrix3x4 in1 ); void Matrix3x4_OriginFromMatrix( const matrix3x4 in, float *out ); void Matrix3x4_AnglesFromMatrix( const matrix3x4 in, vec3_t out ); -void Matrix3x4_Transpose( matrix3x4 out, const matrix3x4 in1 ); #define Matrix4x4_LoadIdentity( mat ) Matrix4x4_Copy( mat, m_matrix4x4_identity ) #define Matrix4x4_Copy( out, in ) memcpy( out, in, sizeof( matrix4x4 )) @@ -233,15 +230,10 @@ void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] ); void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] ); void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ); -void Matrix4x4_FromOriginQuat( matrix4x4 out, const vec4_t quaternion, const vec3_t origin ); void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale ); void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); -void Matrix4x4_TransformStandardPlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin ); -void Matrix4x4_SetOrigin( matrix4x4 out, float x, float y, float z ); void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 ); -void Matrix4x4_OriginFromMatrix( const matrix4x4 in, float *out ); -void Matrix4x4_Transpose( matrix4x4 out, const matrix4x4 in1 ); qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 ); float V_CalcFov( float *fov_x, float width, float height ); From 12ed0924463c8cd6c405bde397e263c4534a3871 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 06:03:29 +0300 Subject: [PATCH 112/121] engine: client: register VGui surface cvars --- engine/client/cl_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index a162b8849..23b4c4595 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2856,6 +2856,7 @@ void CL_InitLocal( void ) Cvar_RegisterVariable( &cl_test_bandwidth ); Voice_RegisterCvars(); + VGui_RegisterCvars(); // register our variables cl_crosshair = Cvar_Get( "crosshair", "1", FCVAR_ARCHIVE, "show weapon chrosshair" ); From cee3757e6fa830d2109d5e2d1a6ecd228070c19d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 06:04:18 +0300 Subject: [PATCH 113/121] engine: common: hpak: add hpak deletion in validate function --- engine/common/hpak.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/engine/common/hpak.c b/engine/common/hpak.c index a949fe5b2..d247d21ef 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -101,7 +101,6 @@ void HPAK_CreatePak( const char *filename, resource_t *pResource, byte *pData, f byte md5[16]; file_t *fout; MD5Context_t ctx; - dresource_t dresource; if( !COM_CheckString( filename )) return; @@ -377,7 +376,7 @@ void HPAK_AddLump( qboolean bUseQueue, const char *name, resource_t *pResource, FS_Rename( dstname, srcname ); } -static qboolean HPAK_Validate( const char *filename, qboolean quiet ) +static qboolean HPAK_Validate( const char *filename, qboolean quiet, qboolean delete ) { file_t *f; hpak_lump_t *dataDir; @@ -412,6 +411,7 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet ) { Con_DPrintf( S_ERROR "HPAK_ValidatePak: %s does not have a valid HPAK header.\n", pakname ); FS_Close( f ); + if( delete ) FS_Delete( pakname ); return false; } @@ -422,6 +422,7 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet ) { Con_DPrintf( S_ERROR "HPAK_ValidatePak: %s has too many lumps %u.\n", pakname, num_lumps ); FS_Close( f ); + if( delete ) FS_Delete( pakname ); return false; } @@ -439,7 +440,8 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet ) // odd max size Con_DPrintf( S_ERROR "HPAK_ValidatePak: lump %i has invalid size %s\n", i, Q_pretifymem( dataDir[i].disksize, 2 )); Mem_Free( dataDir ); - FS_Close(f); + FS_Close( f ); + if( delete ) FS_Delete( pakname ); return false; } @@ -465,6 +467,7 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet ) Mem_Free( dataPak ); Mem_Free( dataDir ); FS_Close( f ); + if( delete ) FS_Delete( pakname ); return false; } else Con_DPrintf( S_ERROR "failed\n" ); @@ -483,11 +486,6 @@ static qboolean HPAK_Validate( const char *filename, qboolean quiet ) return true; } -void HPAK_ValidatePak( const char *filename ) -{ - HPAK_Validate( filename, true ); -} - void HPAK_CheckIntegrity( const char *filename ) { string pakname; @@ -498,7 +496,7 @@ void HPAK_CheckIntegrity( const char *filename ) Q_strncpy( pakname, filename, sizeof( pakname )); COM_ReplaceExtension( pakname, ".hpk" ); - HPAK_ValidatePak( pakname ); + HPAK_Validate( pakname, true, true ); } void HPAK_CheckSize( const char *filename ) @@ -1090,7 +1088,7 @@ void HPAK_Validate_f( void ) return; } - HPAK_Validate( Cmd_Argv( 1 ), false ); + HPAK_Validate( Cmd_Argv( 1 ), false, false ); } void HPAK_Init( void ) From c24a1fafc52c33411fb97e85e1f0d8b6fd086393 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 06:04:48 +0300 Subject: [PATCH 114/121] engine: add missing HPAK_CheckSize/Integrity calls --- engine/client/cl_parse.c | 2 ++ engine/common/host.c | 2 ++ engine/server/sv_init.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index ec7f5a556..c7d6eaf6e 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -851,6 +851,8 @@ void CL_ParseServerData( sizebuf_t *msg, qboolean legacy ) qboolean background; int i; + HPAK_CheckSize( CUSTOM_RES_PATH ); + Con_Reportf( "%s packet received.\n", legacy ? "Legacy serverdata" : "Serverdata" ); cls.timestart = Sys_DoubleTime(); diff --git a/engine/common/host.c b/engine/common/host.c index d472d9f53..459fa11e7 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -1213,6 +1213,8 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa } else Cmd_AddRestrictedCommand( "minimize", Host_Minimize_f, "minimize main window to tray" ); + HPAK_CheckIntegrity( CUSTOM_RES_PATH ); + host.errorframe = 0; // post initializations diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index a6e3baf92..06263c5ab 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -945,6 +945,9 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba current_skill = bound( 0, current_skill, 3 ); Cvar_SetValue( "skill", (float)current_skill ); + // enforce hpk_maxsize + HPAK_CheckSize( CUSTOM_RES_PATH ); + // force normal player collisions for single player if( svs.maxclients == 1 ) Cvar_SetValue( "sv_clienttrace", 1 ); From 129de871e34fb3635c16bab584e35c8b0ad0cbd2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 06:22:49 +0300 Subject: [PATCH 115/121] engine: common: hpak: use statically allocated hpk_maxsize cvar because gamedll can re-register it for some reason --- engine/common/hpak.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/common/hpak.c b/engine/common/hpak.c index d247d21ef..bd61774b8 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -29,10 +29,10 @@ typedef struct hash_pack_queue_s struct hash_pack_queue_s *next; } hash_pack_queue_t; -convar_t *hpk_maxsize; -hash_pack_queue_t *gp_hpak_queue = NULL; -hpak_header_t hash_pack_header; -hpak_info_t hash_pack_info; +static CVAR_DEFINE_AUTO( hpk_maxsize, "4", FCVAR_ARCHIVE, "set limit by size for all HPK-files ( 0 - unlimited )" ); +static hash_pack_queue_t *gp_hpak_queue = NULL; +static hpak_header_t hash_pack_header; +static hpak_info_t hash_pack_info; const char *HPAK_TypeFromIndex( int type ) { @@ -504,7 +504,7 @@ void HPAK_CheckSize( const char *filename ) string pakname; int maxsize; - maxsize = hpk_maxsize->value; + maxsize = hpk_maxsize.value; if( maxsize <= 0 ) return; if( !COM_CheckString( filename ) ) @@ -515,8 +515,8 @@ void HPAK_CheckSize( const char *filename ) if( FS_FileSize( pakname, false ) > ( maxsize * 1048576 )) { - Con_Printf( "Server: Size of %s > %f MB, deleting.\n", filename, hpk_maxsize->value ); - Log_Printf( "Server: Size of %s > %f MB, deleting.\n", filename, hpk_maxsize->value ); + Con_Printf( "Server: Size of %s > %f MB, deleting.\n", filename, hpk_maxsize.value ); + Log_Printf( "Server: Size of %s > %f MB, deleting.\n", filename, hpk_maxsize.value ); FS_Delete( filename ); } } @@ -1097,7 +1097,7 @@ void HPAK_Init( void ) Cmd_AddRestrictedCommand( "hpkremove", HPAK_Remove_f, "remove specified file from HPK-file" ); Cmd_AddRestrictedCommand( "hpkval", HPAK_Validate_f, "validate specified HPK-file" ); Cmd_AddRestrictedCommand( "hpkextract", HPAK_Extract_f, "extract all lumps from specified HPK-file" ); - hpk_maxsize = Cvar_Get( "hpk_maxsize", "0", FCVAR_ARCHIVE, "set limit by size for all HPK-files ( 0 - unlimited )" ); + Cvar_RegisterVariable( &hpk_maxsize ); gp_hpak_queue = NULL; } From 4bce1936458914c33ddaf6d23da6dfc10968fe12 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 3 Apr 2023 06:45:05 +0300 Subject: [PATCH 116/121] mainui: update --- 3rdparty/mainui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/mainui b/3rdparty/mainui index 950376cc2..78d2b3d0b 160000 --- a/3rdparty/mainui +++ b/3rdparty/mainui @@ -1 +1 @@ -Subproject commit 950376cc28f0a52403ce68c569b749c4206cf230 +Subproject commit 78d2b3d0b1fe2015b19a8d55ecf96a421f20c7a6 From 935134fc8e8258c28b2d0f52175e3b02cd82680a Mon Sep 17 00:00:00 2001 From: Jonathan Poncelet <3692034+noodlecollie@users.noreply.github.com> Date: Wed, 5 Apr 2023 18:26:02 +0100 Subject: [PATCH 117/121] Squashed commit of the following: commit f8295628c44b7379dd6e53b636c5b34adc3ed418 Merge: c382b6ad ec96e247 Author: Jonathan Poncelet <3692034+noodlecollie@users.noreply.github.com> Date: Wed Apr 5 17:39:05 2023 +0100 Merge pull request #2 from noodlecollie/update-readme Updated readme commit ec96e247e731c6c8fec34ae949e94f84cdc43893 Author: Jonathan Poncelet <3692034+noodlecollie@users.noreply.github.com> Date: Wed Apr 5 17:16:58 2023 +0100 Trying a better actions trigger filter commit 5187305c498224b2af5d86bc24a4d2e6e39cf9c4 Author: Jonathan Poncelet <3692034+noodlecollie@users.noreply.github.com> Date: Wed Apr 5 16:56:39 2023 +0100 Fixed a path I broke commit a2fc86fc040c00ee7ce4aafb66abb6500ab268e0 Author: Jonathan Poncelet <3692034+noodlecollie@users.noreply.github.com> Date: Wed Apr 5 16:51:59 2023 +0100 Some updates to CI commit 45a14a143cca9e71c0e3088ba361bfc544c7fde1 Author: Jonathan Poncelet <3692034+noodlecollie@users.noreply.github.com> Date: Wed Apr 5 11:20:20 2023 +0100 Updated readme --- .github/workflows/c-cpp.yml | 8 +++++++- README.md | 33 ++++++++------------------------- scripts/gha/build_linux.sh | 14 +++++++------- scripts/gha/build_win32.sh | 2 +- scripts/travis/build_linux.sh | 10 +++++----- 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index b340e3d6f..e8f68761e 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -1,5 +1,11 @@ name: Build & Deploy Engine -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: # cleanup: # runs-on: self-hosted diff --git a/README.md b/README.md index cdbee540d..02fedb90f 100644 --- a/README.md +++ b/README.md @@ -13,25 +13,21 @@ See [here](https://github.com/x6herbius/afterburner-game/releases). Please note, ## I want to compile the game from source, how do I do that? -### Prerequisites - -*64-bit builds of the game will be supported in future, but are not at the moment.* Until 64-bit support is properly implemented, 32-bit compilers and libraries are required. +### Game prerequisites -Ensure that you have Python 3 installed on your computer, as well as the appropriate C/C++ development tools for your platform (Windows and Linux are supported). You will also need to ensure that the **32-bit development** version of the [SDL2 library](https://www.libsdl.org/download-2.0.php) is installed. If this is not available for download for your platform, you should compile it from source. +Ensure that you have Python 3 installed on your computer, as well as the appropriate C/C++ development tools for your platform (Windows and Linux are supported). The required dependencies for the Xash3D engine are listed in the original Xash3D readme [later in this file](#prerequisites) - you should follow the appropriate steps for your platform to install them. Note that for Afterburner, **64-bit builds are now supported and recommended**, but if you want to compile in 32-bit, you will need the 32-bit versions of the dependencies. -For detailed information on the prerequisites for your platform, see the Xash3D FWGS readme [here](https://github.com/FWGS/xash3d-fwgs), or at the bottom of this file. Note that some of the 32-bit dependencies on Linux may also need to have their 64-bit counterparts installed in order for the configuration step to correctly detect them; for example, on Ubuntu the `libfreetype-dev` and `libfontconfig1-dev` dependencies need to be installed alongside their `libfreetype-dev:i386` and `libfontconfig1-dev:i386` counterparts. +Clone this repository using `git clone --recursive`. If you don't use the `--recursive` switch, the game **will not** compile without manually initialising the subrepositories. If you find yourself needing to do this, run `git submodule update --init --recursive` from within the root directory of the repository. -Finally, clone this repository using `git clone --recursive`. If you don't use the `--recursive` switch, the game **will not** compile without manually initialising the subrepositories. If you find yourself needing to do this, run `git submodule update --init --recursive` from within the root directory of the repository. - -### Building +### Building the game To build, open a terminal in the root of the repository and call: ``` -python3 ./waf configure --disable-vgui --win-style-install --build-type=debug --prefix=build/debug +python3 ./waf configure --64bits --build-type=debug --prefix=build/debug --enable-packaging ``` -This will set up the build for a debug version of the game. Note that if you downloaded SDL2 from the website and it is not available in the system path, you will need to pass the path to the directory you extracted it to via the `--sdl2` option, eg. `--sdl2=/path/to/SDL2`. +This will set up the build for a debug version of the game. Note that if you downloaded SDL2 from the SDL website (eg. for a Windows build) and it is not available in the system path, you will need to pass the path to the directory you extracted it to via the `--sdl2` option, eg. `--sdl2=/path/to/SDL2`. To build the game and copy all output to the `build/debug` folder in the root of the repo, call: @@ -41,16 +37,6 @@ python3 ./waf build install For more information, or a list of all available options, run `python3 ./waf --help`. Note that most of these will be for advanced users only. -## Why is Mac not supported any more? - -[Apple have deprecated OpenGL support on Mac](https://www.anandtech.com/show/12894/apple-deprecates-opengl-across-all-oses). I'm not gonna lie - this is incredibly irritating, because OpenGL was the easiest way to write graphics-based applications that worked across the three big operating systems. In response, the developers of the Xash3D engine used by Afterburner have decided [not to support the engine on Mac](https://github.com/FWGS/xash3d-fwgs/issues/61), because to do so would now require too much extra work and testing. - -If you wish to try compiling the game for Mac then feel free - in theory the engine should be compatible as long as you have a version of MacOS that supports OpenGL. However, I won't be able to help you out, so you'll be on your own. - -## I want to contribute! - -Since this project is currently only in active development by myself, I don't have any set roadmap or procedure for contributing. If you would like to get involved, please drop me a line (jonathan.poncelet@talk21.com, or [@x6herbius](https://twitter.com/x6herbius) on Twitter) and we can discuss! - ## Credits Many thanks to: @@ -68,17 +54,14 @@ For posterity, the Xash3D engine readme is below. ----- -## Xash3D FWGS Engine Readme -[![Build Status](https://api.travis-ci.org/FWGS/xash3d-fwgs.svg?branch=master)](https://travis-ci.org/FWGS/xash3d-fwgs) [![Discord Server](https://img.shields.io/discord/355697768582610945.svg)](https://discord.gg/TbnHcVb) -======= # Xash3D FWGS Engine [![GitHub Actions Status](https://github.com/FWGS/xash3d-fwgs/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/FWGS/xash3d-fwgs/actions/workflows/c-cpp.yml) [![FreeBSD Build Status](https://img.shields.io/cirrus/github/FWGS/xash3d-fwgs?label=freebsd%20build)](https://cirrus-ci.com/github/FWGS/xash3d-fwgs) [![Discord Server](https://img.shields.io/discord/355697768582610945.svg)](http://fwgsdiscord.mentality.rip/) \ -[![Download Stable](https://img.shields.io/badge/download-stable-yellow)](https://github.com/FWGS/xash3d-fwgs/releases/latest) [![Download Testing](https://img.shields.io/badge/downloads-testing-orange)](https://github.com/FWGS/xash3d-fwgs/releases/tag/continuous) +[![Download Stable](https://img.shields.io/badge/download-stable-yellow)](https://github.com/FWGS/xash3d-fwgs/releases/latest) [![Download Testing](https://img.shields.io/badge/downloads-testing-orange)](https://github.com/FWGS/xash3d-fwgs/releases/tag/continuous) Xash3D FWGS is a fork of Xash3D Engine by Unkle Mike with extended features and crossplatform. ``` -Xash3D is a game engine, aimed to provide compatibility with Half-Life Engine, +Xash3D is a game engine, aimed to provide compatibility with Half-Life Engine, as well as to give game developers well known workflow and extend it. Read more about Xash3D on ModDB: https://www.moddb.com/engines/xash3d-engine ``` diff --git a/scripts/gha/build_linux.sh b/scripts/gha/build_linux.sh index b2660b594..5c614b4ff 100755 --- a/scripts/gha/build_linux.sh +++ b/scripts/gha/build_linux.sh @@ -2,11 +2,11 @@ . scripts/lib.sh -APP=xash3d-fwgs +APP=afterburner APPDIR=$APP.AppDir APPIMAGE=$APP-$ARCH.AppImage -DS=xashds-linux +DS=afterburner-ds-linux DSDIR=$DS-$ARCH DSTARGZ=$DS-$ARCH.tar.gz @@ -77,15 +77,15 @@ build_appimage() if [ "$XASH3D_BASEDIR" = "" ]; then export XASH3D_BASEDIR=$PWD fi -echo "Xash3D FWGS installed as AppImage." +echo "Afterburner installed as AppImage." echo "Base directory is $XASH3D_BASEDIR. Set XASH3D_BASEDIR environment variable to override this" export XASH3D_EXTRAS_PAK1="${APPDIR}"/valve/extras.pk3 -${DEBUGGER} "${APPDIR}"/xash3d "$@" +${DEBUGGER} "${APPDIR}"/afterburner "$@" exit $? EOF - chmod +x "$APPDIR"/xash3d "$APPDIR"/AppRun # Engine launcher & engine launcher script + chmod +x "$APPDIR"/afterburner "$APPDIR"/AppRun # Engine launcher & engine launcher script echo "Contents of AppImage: " ls -R "$APPDIR" @@ -94,8 +94,8 @@ EOF cat > "$APPDIR/$APP.desktop" < Date: Fri, 7 Apr 2023 11:16:10 +0100 Subject: [PATCH 118/121] Fixed incorrect pointers --- engine/platform/win32/con_win.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/platform/win32/con_win.c b/engine/platform/win32/con_win.c index eccbc2b7a..5539545c3 100644 --- a/engine/platform/win32/con_win.c +++ b/engine/platform/win32/con_win.c @@ -486,7 +486,7 @@ void Wcon_WinPrint( const char *pMsg ) Wcon_PrintInternal( s_wcd.consoleText, s_wcd.consoleTextLen ); } - if( !s_wcd.attached ) + if( !s_wcd.attached ) Wcon_UpdateStatusLine(); } @@ -516,7 +516,7 @@ void Wcon_CreateConsole( void ) s_wcd.attached = ( AttachConsole( ATTACH_PARENT_PROCESS ) != 0 ); if( s_wcd.attached ) { - GetConsoleTitle( &s_wcd.previousTitle, sizeof( s_wcd.previousTitle )); + GetConsoleTitle( s_wcd.previousTitle, sizeof( s_wcd.previousTitle )); s_wcd.previousCodePage = GetConsoleCP(); s_wcd.previousOutputCodePage = GetConsoleOutputCP(); } @@ -532,7 +532,7 @@ void Wcon_CreateConsole( void ) s_wcd.hInput = GetStdHandle( STD_INPUT_HANDLE ); s_wcd.hOutput = GetStdHandle( STD_OUTPUT_HANDLE ); s_wcd.inputEnabled = true; - + if( !SetConsoleCtrlHandler( &Wcon_HandleConsole, TRUE )) { Con_Reportf( S_ERROR "Couldn't attach console handler function\n" ); @@ -540,7 +540,7 @@ void Wcon_CreateConsole( void ) } if( !s_wcd.attached ) - { + { SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW ); // show console if needed @@ -591,7 +591,7 @@ void Wcon_DestroyConsole( void ) Sys_CloseLog(); if( !s_wcd.attached ) - { + { if( s_wcd.hWnd ) { ShowWindow( s_wcd.hWnd, SW_HIDE ); @@ -603,7 +603,7 @@ void Wcon_DestroyConsole( void ) // reverts title & code page for console window that was before starting Xash3D SetConsoleCP( s_wcd.previousCodePage ); SetConsoleOutputCP( s_wcd.previousOutputCodePage ); - SetConsoleTitle( &s_wcd.previousTitle ); + SetConsoleTitle( s_wcd.previousTitle ); Con_Printf( "Press Enter to continue...\n" ); } @@ -626,7 +626,7 @@ char *Wcon_Input( void ) DWORD i; DWORD eventsCount; static INPUT_RECORD events[1024]; - + if( !s_wcd.inputEnabled ) return NULL; From a4c0311927d79164ab191db138fe3bb60915857b Mon Sep 17 00:00:00 2001 From: Jonathan Poncelet Date: Fri, 7 Apr 2023 11:40:07 +0100 Subject: [PATCH 119/121] Trying aliasing fix --- game_libs/dlls/utils/utils.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/game_libs/dlls/utils/utils.cpp b/game_libs/dlls/utils/utils.cpp index 2127b3d86..4cfcaf5e4 100644 --- a/game_libs/dlls/utils/utils.cpp +++ b/game_libs/dlls/utils/utils.cpp @@ -112,9 +112,20 @@ UTIL_SharedRandomFloat */ float UTIL_SharedRandomFloat( unsigned int seed, float low, float high ) { + union FloatInt + { + float f; + int i; + }; + unsigned int range; + FloatInt lowVal; + FloatInt highVal; + + lowVal.f = low; + highVal.f = high; - U_Srand( (int)seed + *(int *)&low + *(int *)&high ); + U_Srand( (int)seed + lowVal.i + highVal.i ); U_Random(); U_Random(); From 4e1765fdea99f41ad51011ee8786c47a8606f64a Mon Sep 17 00:00:00 2001 From: Jonathan Poncelet Date: Fri, 7 Apr 2023 11:51:19 +0100 Subject: [PATCH 120/121] Another tentative aliasing fix --- common/mathlib.h | 10 ++++++++-- game_libs/common/mathlib.h | 10 ++++++++-- game_libs/pm_shared/pm_math.c | 21 ++++++++++----------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/common/mathlib.h b/common/mathlib.h index fc3885997..4f67963eb 100644 --- a/common/mathlib.h +++ b/common/mathlib.h @@ -28,9 +28,15 @@ typedef vec_t vec4_t[4]; // x,y,z,w struct mplane_s; extern vec3_t vec3_origin; -extern int nanmask; -#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) +#ifdef XASH_IRIX +#undef isnan +#endif +#ifdef isnan // check for C99 isnan +#define IS_NAN isnan +#else +#define IS_NAN(x) (((*(int *)&x) & (255<<23)) == (255<<23)) +#endif #ifndef VECTOR_H #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) diff --git a/game_libs/common/mathlib.h b/game_libs/common/mathlib.h index fea78b324..baef753b1 100644 --- a/game_libs/common/mathlib.h +++ b/game_libs/common/mathlib.h @@ -26,9 +26,15 @@ struct mplane_s; extern vec3_t vec3_origin; -extern int nanmask; -#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) +#ifdef XASH_IRIX +#undef isnan +#endif +#ifdef isnan // check for C99 isnan +#define IS_NAN isnan +#else +#define IS_NAN(x) (((*(int *)&x) & (255<<23)) == (255<<23)) +#endif void VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc); diff --git a/game_libs/pm_shared/pm_math.c b/game_libs/pm_shared/pm_math.c index 4bb4b93fa..e52db9cd9 100644 --- a/game_libs/pm_shared/pm_math.c +++ b/game_libs/pm_shared/pm_math.c @@ -1,9 +1,9 @@ /*** * * Copyright (c) 1996-2002, Valve LLC. All rights reserved. -* -* This product contains software technology licensed from Id -* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. * All Rights Reserved. * * Use, distribution, and modification of this source code and/or resulting @@ -23,14 +23,13 @@ // left / right #define YAW 1 // fall over -#define ROLL 2 +#define ROLL 2 #ifdef _MSC_VER #pragma warning(disable : 4244) #endif vec3_t vec3_origin = { 0,0,0 }; -int nanmask = 255 << 23; float anglemod( float a ) { @@ -77,7 +76,7 @@ void AngleVectorsTranspose( const vec3_t angles, vec3_t forward, vec3_t right, v { float angle; float sr, sp, sy, cr, cp, cy; - + angle = angles[YAW] * ( M_PI * 2 / 360 ); sy = sin( angle ); cy = cos( angle ); @@ -214,7 +213,7 @@ void InterpolateAngles( float *start, float *end, float *output, float frac ) d -= 360; } else if( d < -180 ) - { + { d += 360; } @@ -370,11 +369,11 @@ void VectorMatrix( vec3_t forward, vec3_t right, vec3_t up ) if( forward[0] == 0 && forward[1] == 0 ) { - right[0] = 1; - right[1] = 0; + right[0] = 1; + right[1] = 0; right[2] = 0; - up[0] = -forward[2]; - up[1] = 0; + up[0] = -forward[2]; + up[1] = 0; up[2] = 0; return; } From 3fbe6d128dea8b757ed72ab753e93bab0cc8df5e Mon Sep 17 00:00:00 2001 From: Jonathan Poncelet Date: Fri, 7 Apr 2023 12:01:31 +0100 Subject: [PATCH 121/121] More damn aliasing issues --- game_libs/cl_dll/com_weapons.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/game_libs/cl_dll/com_weapons.cpp b/game_libs/cl_dll/com_weapons.cpp index 91aa20b30..d4ee2c45d 100644 --- a/game_libs/cl_dll/com_weapons.cpp +++ b/game_libs/cl_dll/com_weapons.cpp @@ -245,9 +245,20 @@ UTIL_SharedRandomFloat */ float UTIL_SharedRandomFloat( unsigned int seed, float low, float high ) { + union FloatInt + { + float f; + int i; + }; + unsigned int range; + FloatInt lowVal; + FloatInt highVal; + + lowVal.f = low; + highVal.f = high; - U_Srand( (int)seed + *(int *)&low + *(int *)&high ); + U_Srand( (int)seed + lowVal.i + highVal.i ); U_Random(); U_Random();