From 32d73e62f40cff456d79eec4ee504f52a0e83e64 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 5 Mar 2026 04:51:59 +0500 Subject: [PATCH] engine: minor refactoring, remove host.apply_game_config as it's unused --- engine/client/cl_main.c | 2 +- engine/common/base_cmd.c | 33 ++++++++++++-------------- engine/common/cmd.c | 51 ++++++++++++++++------------------------ engine/common/common.h | 41 ++++++++++++++------------------ engine/common/custom.c | 3 ++- engine/common/cvar.c | 6 ----- 6 files changed, 56 insertions(+), 80 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 4a332261..2220cfc4 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -24,7 +24,6 @@ GNU General Public License for more details. #include "pm_local.h" #include "multi_emulator.h" -#define MAX_CMD_BUFFER 8000 #define CL_CONNECTION_TIMEOUT 15.0f #define CL_CONNECTION_RETRIES 5 #define CL_TEST_RETRIES 5 @@ -759,6 +758,7 @@ Including both the reliable commands and the usercmds */ static void CL_WritePacket( void ) { + enum { MAX_CMD_BUFFER = 8000 }; sizebuf_t buf; byte data[MAX_CMD_BUFFER] = { 0 }; runcmd_t *pcmd; diff --git a/engine/common/base_cmd.c b/engine/common/base_cmd.c index d582fe7b..0295432c 100644 --- a/engine/common/base_cmd.c +++ b/engine/common/base_cmd.c @@ -25,8 +25,8 @@ struct base_command_hashmap_s { base_command_t *basecmd; // base command: cvar, alias or command base_command_hashmap_t *next; - base_command_type_e type; // type for faster searching - char name[]; // key for searching + base_command_type_e type; // type for faster searching + char name[]; // key for searching }; static base_command_hashmap_t *hashed_cmds[HASH_SIZE]; @@ -237,9 +237,9 @@ BaseCmd_Stats_f */ void BaseCmd_Stats_f( void ) { - int i, minsize = 99999, maxsize = -1, empty = 0; + int minsize = 99999, maxsize = -1, empty = 0; - for( i = 0; i < HASH_SIZE; i++ ) + for( int i = 0; i < HASH_SIZE; i++ ) { base_command_hashmap_t *hm; int len = 0; @@ -264,15 +264,15 @@ void BaseCmd_Stats_f( void ) Con_Printf( "min length: %d, max length: %d, empty: %d\n", minsize, maxsize, empty ); } -typedef struct +struct basecmd_test_stats_s { qboolean valid; int lookups; -} basecmd_test_stats_t; +}; static void BaseCmd_CheckCvars( const char *key, const char *value, const void *unused, void *ptr ) { - basecmd_test_stats_t *stats = ptr; + struct basecmd_test_stats_s *stats = ptr; stats->lookups++; if( !BaseCmd_Find( HM_CVAR, key )) @@ -291,16 +291,14 @@ testing order matches cbuf execute */ void BaseCmd_Test_f( void ) { - basecmd_test_stats_t stats; - double start, end, dt; - int i; + struct basecmd_test_stats_s stats = + { + .valid = true, + }; - stats.valid = true; - stats.lookups = 0; + double start = Platform_DoubleTime() * 1000; - start = Platform_DoubleTime() * 1000; - - for( i = 0; i < 1000; i++ ) + for( int i = 0; i < 1000; i++ ) { cmdalias_t *a; void *cmd; @@ -328,9 +326,8 @@ void BaseCmd_Test_f( void ) Cvar_LookupVars( 0, NULL, &stats.valid, (setpair_t)BaseCmd_CheckCvars ); } - end = Platform_DoubleTime() * 1000; - - dt = end - start; + double end = Platform_DoubleTime() * 1000; + double dt = end - start; if( !stats.valid ) Con_Printf( "BaseCmd is valid\n" ); diff --git a/engine/common/cmd.c b/engine/common/cmd.c index d93439e2..b4b6f15e 100644 --- a/engine/common/cmd.c +++ b/engine/common/cmd.c @@ -147,7 +147,7 @@ static void Cbuf_InsertTextToBuffer( cmdbuf_t *buf, const char *text, size_t len } } -void Cbuf_InsertTextLen( const char *text, size_t len, size_t requested_len ) +static void Cbuf_InsertTextLen( const char *text, size_t len, size_t requested_len ) { // sometimes we need to insert more data than we have // but also prevent overflow @@ -932,44 +932,33 @@ static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPr BaseCmd_FindAll( cmd_argv[0], &cmd, &a, &cvar ); - if( !host.apply_game_config ) + // check aliases + if( a ) { - if( a ) - { - size_t len = Q_strlen( a->value ); - Cbuf_InsertTextToBuffer( - isPrivileged ? &cmd_text : &filteredcmd_text, - a->value, len, len ); - return; - } + size_t len = Q_strlen( a->value ); + Cbuf_InsertTextToBuffer( isPrivileged ? &cmd_text : &filteredcmd_text, a->value, len, len ); + return; } - // special mode for restore game.dll archived cvars - if( !host.apply_game_config || !Q_strcmp( cmd_argv[0], "exec" )) + // check functions + if( cmd && cmd->function ) { - // check functions - if( cmd && cmd->function ) + if( Cmd_ShouldAllowCommand( cmd, isPrivileged )) { - if( Cmd_ShouldAllowCommand( cmd, isPrivileged )) - { - cmd_currentCommandIsPrivileged = isPrivileged; - cmd->function(); - cmd_currentCommandIsPrivileged = true; - } - else - { - Con_Printf( S_WARN "Could not execute privileged command %s\n", cmd->name ); - } - - return; + cmd_currentCommandIsPrivileged = isPrivileged; + cmd->function(); + cmd_currentCommandIsPrivileged = true; } + else + { + Con_Printf( S_WARN "Could not execute privileged command %s\n", cmd->name ); + } + return; } // check cvars - if( Cvar_CommandWithPrivilegeCheck( cvar, isPrivileged )) return; - - if( host.apply_game_config ) - return; // don't send nothing to server: we are a server! + if( Cvar_CommandWithPrivilegeCheck( cvar, isPrivileged )) + return; // forward the command line to the server, so the entity DLL can parse it #if !XASH_DEDICATED @@ -1001,7 +990,7 @@ so when they are typed in at the console, they will need to be forwarded. #if !XASH_DEDICATED void Cmd_ForwardToServer( void ) { - char str[MAX_CMD_BUFFER]; + char str[MAX_CMD_BUFFER]; if( cls.demoplayback ) { diff --git a/engine/common/common.h b/engine/common/common.h index 1f149340..62dde79f 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -328,25 +328,22 @@ typedef struct host_parm_s // for CL_{Push,Pop}TraceBounds vec3_t player_mins_backup[MAX_MAP_HULLS]; vec3_t player_maxs_backup[MAX_MAP_HULLS]; - qboolean trace_bounds_pushed; - qboolean allow_console; // allow console in dev-mode or multiplayer game - qboolean allow_console_init; // initial value to allow the console - qboolean key_overstrike; // key overstrike mode - qboolean stuffcmds_pending; // should execute stuff commands - qboolean allow_cheats; // this host will allow cheating - qboolean change_game; // initialize when game is changed - qboolean mouse_visible; // vgui override cursor control (never change outside Platform_SetCursorType!) - qboolean shutdown_issued; // engine is shutting down - qboolean apply_game_config; // when true apply only to game cvars and ignore all other commands - qboolean apply_opengl_config; // when true apply only to opengl cvars and ignore all other commands - qboolean config_executed; // a bit who indicated was config.cfg already executed e.g. from valve.rc - qboolean textmode; - - // some settings were changed and needs to global update - qboolean userinfo_changed; - qboolean movevars_changed; - qboolean renderinfo_changed; + uint trace_bounds_pushed : 1; + uint allow_console : 1; // allow console in dev-mode or multiplayer game + uint allow_console_init : 1; // initial value to allow the console + uint key_overstrike : 1; // key overstrike mode + uint stuffcmds_pending : 1; // should execute stuff commands + uint allow_cheats : 1; // this host will allow cheating + uint change_game : 1; // initialize when game is changed + uint mouse_visible : 1; // vgui override cursor control (never change outside Platform_SetCursorType!) + uint shutdown_issued : 1; // engine is shutting down + uint apply_opengl_config : 1; // when true apply only to opengl cvars and ignore all other commands + uint config_executed : 1; // a bit who indicated was config.cfg already executed e.g. from valve.rc + uint textmode : 1; + uint userinfo_changed : 1; // some settings were changed and needs to global update + uint movevars_changed : 1; + uint renderinfo_changed : 1; // for IN_MouseMove() easy access int window_center_x; @@ -383,8 +380,8 @@ void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline ); void _Mem_EmptyPool( poolhandle_t poolptr, const char *filename, int fileline ); void _Mem_Check( const char *filename, int fileline ); qboolean Mem_IsAllocatedExt( poolhandle_t poolptr, void *data ); -void Mem_PrintList( size_t minallocationsize ); void Mem_PrintStats( void ); +void Mem_Stats_f( void ); #define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ ) #define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ ) @@ -448,9 +445,8 @@ void Cbuf_AddText( const char *text ); void Cbuf_AddTextf( const char *text, ... ) FORMAT_CHECK( 1 ); void Cbuf_AddFilteredText( const char *text ); void Cbuf_InsertText( const char *text ); -void Cbuf_InsertTextLen( const char *text, size_t len, size_t requested_len ); void Cbuf_ExecStuffCmds( void ); -void Cbuf_Execute (void); +void Cbuf_Execute( void ); qboolean Cmd_CurrentCommandIsPrivileged( void ); void Cmd_Init( void ); void Cmd_Shutdown( void ); @@ -475,13 +471,12 @@ static inline int Cmd_AddCommandWithFlags( const char *cmd_name, xcommand_t func void Cmd_RemoveCommand( const char *cmd_name ); cmd_t *Cmd_Exists( const char *cmd_name ); void Cmd_LookupCmds( void *buffer, void *ptr, setpair_t callback ); -int Cmd_ListMaps( search_t *t , char *lastmapname, size_t len, qboolean silent ); +int Cmd_ListMaps( search_t *t, char *lastmapname, size_t len, qboolean silent ); void Cmd_TokenizeString( const char *text ); void Cmd_ExecuteString( const char *text ); void Cmd_ForwardToServer( void ); void Cmd_Escape( char *newCommand, const char *oldCommand, int len ); - // // imagelib // diff --git a/engine/common/custom.c b/engine/common/custom.c index 22f03d6f..a136b014 100644 --- a/engine/common/custom.c +++ b/engine/common/custom.c @@ -27,7 +27,8 @@ static rgbdata_t *CustomDecal_LoadImage( const char *path, void *raw, int size ) testname = "#logo.png"; else if( !Q_stricmp( COM_FileExtension( path ), "wad" )) testname = "#logo.wad"; - else testname = "#logo.bmp"; + else + testname = "#logo.bmp"; Image_SetForceFlags( IL_LOAD_PLAYER_DECAL ); diff --git a/engine/common/cvar.c b/engine/common/cvar.c index dbfdfb2e..9cfc4977 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -1019,12 +1019,6 @@ qboolean Cvar_CommandWithPrivilegeCheck( convar_t *v, qboolean isPrivileged ) return true; } - if( host.apply_game_config ) - { - if( !FBitSet( v->flags, FCVAR_EXTDLL )) - return true; // only game.dll cvars passed - } - if( FBitSet( v->flags, FCVAR_SPONLY ) && CL_GetMaxClients() > 1 ) { Con_Printf( "can't set \"%s\" in multiplayer\n", v->name );