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

engine: make some global variables static and const, make even more functions static if possible

This commit is contained in:
Alibek Omarov 2024-10-14 19:19:46 +03:00
parent bf8b709372
commit f52c825bf5
22 changed files with 87 additions and 114 deletions

View File

@ -34,10 +34,10 @@ GNU General Public License for more details.
#define MAX_TEXTCHANNELS 8 // must be power of two (GoldSrc uses 4 channels)
#define TEXT_MSGNAME "TextMessage%i"
char cl_textbuffer[MAX_TEXTCHANNELS][2048];
client_textmessage_t cl_textmessage[MAX_TEXTCHANNELS];
static char cl_textbuffer[MAX_TEXTCHANNELS][2048];
static client_textmessage_t cl_textmessage[MAX_TEXTCHANNELS];
static dllfunc_t cdll_exports[] =
static const dllfunc_t cdll_exports[] =
{
{ "Initialize", (void **)&clgame.dllFuncs.pfnInitialize },
{ "HUD_VidInit", (void **)&clgame.dllFuncs.pfnVidInit },
@ -80,7 +80,7 @@ static dllfunc_t cdll_exports[] =
};
// optional exports
static dllfunc_t cdll_new_exports[] = // allowed only in SDK 2.3 and higher
static const dllfunc_t cdll_new_exports[] = // allowed only in SDK 2.3 and higher
{
{ "HUD_GetStudioModelInterface", (void **)&clgame.dllFuncs.pfnGetStudioModelInterface },
{ "HUD_DirectorMessage", (void **)&clgame.dllFuncs.pfnDirectorMessage },

View File

@ -63,9 +63,9 @@ static byte netcolors[NETGRAPH_NET_COLORS+NETGRAPH_LERP_HEIGHT][4] =
// other will be generated through NetGraph_InitColors()
};
static byte sendcolor[4] = { 88, 29, 130, 255 };
static byte holdcolor[4] = { 255, 0, 0, 200 };
static byte extrap_base_color[4] = { 255, 255, 255, 255 };
static const byte sendcolor[4] = { 88, 29, 130, 255 };
static const byte holdcolor[4] = { 255, 0, 0, 200 };
static const byte extrap_base_color[4] = { 255, 255, 255, 255 };
static netbandwidthgraph_t netstat_graph[NET_TIMINGS];
static float packet_loss;
static float packet_choke;
@ -79,7 +79,7 @@ NetGraph_DrawRect
NetGraph_FillRGBA shortcut
==========
*/
static void NetGraph_DrawRect( wrect_t *rect, byte colors[4] )
static void NetGraph_DrawRect( const wrect_t *rect, const byte colors[4] )
{
ref.dllFuncs.Color4ub( colors[0], colors[1], colors[2], colors[3] ); // color for this quad

View File

@ -59,7 +59,7 @@ void GAME_EXPORT CL_PopPMStates( void )
CL_IsPredicted
===============
*/
qboolean CL_IsPredicted( void )
static qboolean CL_IsPredicted( void )
{
if( cl_nopred.value || cl.intermission )
return false;

View File

@ -956,7 +956,6 @@ void CL_SetSolidPlayers( int playernum );
void CL_InitClientMove( void );
void CL_PredictMovement( qboolean repredicting );
void CL_CheckPredictionError( void );
qboolean CL_IsPredicted( void );
int CL_WaterEntity( const float *rgflPos );
cl_entity_t *CL_GetWaterEntity( const float *rgflPos );
pmtrace_t *CL_VisTraceLine( vec3_t start, vec3_t end, int flags );

View File

@ -25,7 +25,7 @@ typedef enum
T_COUNT
} cvartype_t;
const char *cvartypes[] = { NULL, "BOOL", "NUMBER", "LIST", "STRING" };
static const char *const cvartypes[] = { NULL, "BOOL", "NUMBER", "LIST", "STRING" };
typedef struct parserstate_s
{

View File

@ -24,18 +24,27 @@ GNU General Public License for more details.
typedef struct
{
byte *data;
int cursize;
int maxsize;
byte *const data;
const int maxsize;
int cursize;
} cmdbuf_t;
qboolean cmd_wait;
cmdbuf_t cmd_text, filteredcmd_text;
byte cmd_text_buf[MAX_CMD_BUFFER];
byte filteredcmd_text_buf[MAX_CMD_BUFFER];
cmdalias_t *cmd_alias;
uint cmd_condition;
int cmd_condlevel;
static qboolean cmd_wait;
static byte cmd_text_buf[MAX_CMD_BUFFER];
static byte filteredcmd_text_buf[MAX_CMD_BUFFER];
static cmdbuf_t cmd_text =
{
.data = cmd_text_buf,
.maxsize = ARRAYSIZE( cmd_text_buf ),
};
static cmdbuf_t filteredcmd_text =
{
.data = filteredcmd_text_buf,
.maxsize = ARRAYSIZE( filteredcmd_text_buf ),
};
static cmdalias_t *cmd_alias;
static uint cmd_condition;
static int cmd_condlevel;
static qboolean cmd_currentCommandIsPrivileged;
static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPrivileged );
@ -48,20 +57,6 @@ static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPr
=============================================================================
*/
/*
============
Cbuf_Init
============
*/
static void Cbuf_Init( void )
{
cmd_text.data = cmd_text_buf;
filteredcmd_text.data = filteredcmd_text_buf;
filteredcmd_text.maxsize = cmd_text.maxsize = MAX_CMD_BUFFER;
filteredcmd_text.cursize = cmd_text.cursize = 0;
}
/*
============
Cbuf_Clear
@ -1387,8 +1382,6 @@ Cmd_Init
*/
void Cmd_Init( void )
{
Cbuf_Init();
cmd_functions = NULL;
cmd_condition = 0;
cmd_alias = NULL;

View File

@ -23,7 +23,7 @@ GNU General Public License for more details.
#include "client.h"
#include "library.h"
static const char *file_exts[] =
static const char *const file_exts[] =
{
// ban text files that don't make sense as resource
"cfg", "lst", "ini", "log",
@ -843,7 +843,7 @@ int GAME_EXPORT COM_CompareFileTime( const char *filename1, const char *filename
if( ft1 == -1 || ft2 == -1 )
return bRet;
*iCompare = Host_CompareFileTime( ft1, ft2 );
*iCompare = ft1 < ft2 ? -1 : ( ft1 > ft2 ? 1 : 0 );
bRet = 1;
}

View File

@ -168,6 +168,7 @@ extern convar_t sys_timescale;
extern convar_t cl_filterstuffcmd;
extern convar_t rcon_password;
extern convar_t hpk_custom_file;
extern convar_t con_gamemaps;
#define Mod_AllowMaterials() ( host_allow_materials.value != 0.0f && !FBitSet( host.features, ENGINE_DISABLE_HDTEXTURES ))
@ -528,7 +529,6 @@ typedef void( *pfnChangeGame )( const char *progname );
qboolean Host_IsQuakeCompatible( void );
void EXPORT Host_Shutdown( void );
int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGame, pfnChangeGame func );
int Host_CompareFileTime( int ft1, int ft2 );
void Host_EndGame( qboolean abort, const char *message, ... ) _format( 2 );
void Host_AbortCurrentFrame( void ) NORETURN;
void Host_WriteServerConfig( const char *name );

View File

@ -18,8 +18,6 @@ GNU General Public License for more details.
#include "const.h"
#include "kbutton.h"
extern convar_t con_gamemaps;
#define CON_MAXCMDS 4096 // auto-complete intermediate list
typedef struct autocomplete_list_s
@ -1012,7 +1010,7 @@ int GAME_EXPORT Cmd_CheckMapsList( int fRefresh )
return Cmd_CheckMapsList_R( fRefresh, true );
}
autocomplete_list_t cmd_list[] =
static const autocomplete_list_t cmd_list[] =
{
{ "map_background", 1, Cmd_GetMapList },
{ "changelevel2", 1, Cmd_GetMapList },

View File

@ -18,17 +18,17 @@ GNU General Public License for more details.
#include "base_cmd.h"
#include "eiface.h" // ARRAYSIZE
convar_t *cvar_vars = NULL; // head of list
static convar_t *cvar_vars = NULL; // head of list
CVAR_DEFINE_AUTO( cmd_scripting, "0", FCVAR_ARCHIVE|FCVAR_PRIVILEGED, "enable simple condition checking and variable operations" );
#ifdef HACKS_RELATED_HLMODS
typedef struct cvar_filter_quirks_s
{
const char *gamedir; // gamedir to enable for
const char *cvars; // list of cvars should be excluded from filter
} cvar_filter_quirks_t;
static cvar_filter_quirks_t cvar_filter_quirks[] =
#ifdef HACKS_RELATED_HLMODS
static const cvar_filter_quirks_t cvar_filter_quirks[] =
{
// EXAMPLE:
//{
@ -44,10 +44,10 @@ static cvar_filter_quirks_t cvar_filter_quirks[] =
"cl_dodmusic" // Day of Defeat Beta 1.3 cvar
},
};
static cvar_filter_quirks_t *cvar_active_filter_quirks = NULL;
#endif
static const cvar_filter_quirks_t *cvar_active_filter_quirks = NULL;
CVAR_DEFINE_AUTO( cl_filterstuffcmd, "1", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "filter commands coming from server" );
/*
@ -618,7 +618,7 @@ static convar_t *Cvar_Set2( const char *var_name, const char *value )
return Cvar_Get( var_name, value, FCVAR_USER_CREATED, NULL );
}
else
{
{
if( !Cmd_CurrentCommandIsPrivileged( ))
{
if( FBitSet( var->flags, FCVAR_PRIVILEGED ))
@ -974,7 +974,6 @@ static qboolean Cvar_ShouldSetCvar( convar_t *v, qboolean isPrivileged )
if( cl_filterstuffcmd.value <= 0.0f )
return true;
#ifdef HACKS_RELATED_HLMODS
// check if game-specific filter exceptions should be applied
// TODO: for cmd exceptions, make generic function
if( cvar_active_filter_quirks )
@ -1005,7 +1004,6 @@ static qboolean Cvar_ShouldSetCvar( convar_t *v, qboolean isPrivileged )
}
}
}
#endif
if( FBitSet( v->flags, FCVAR_FILTERABLE ))
return false;

View File

@ -40,7 +40,7 @@ GNU General Public License for more details.
#include "render_api.h" // decallist_t
#include "tests.h"
pfnChangeGame pChangeGame = NULL;
static pfnChangeGame pChangeGame = NULL;
host_parm_t host; // host parms
#ifdef XASH_ENGINE_TESTS
@ -49,8 +49,8 @@ struct tests_stats_s tests_stats;
CVAR_DEFINE( host_developer, "developer", "0", FCVAR_FILTERABLE, "engine is in development-mode" );
CVAR_DEFINE_AUTO( sys_timescale, "1.0", FCVAR_FILTERABLE, "scale frame time" );
CVAR_DEFINE_AUTO( sys_ticrate, "100", FCVAR_SERVER, "framerate in dedicated mode" );
static CVAR_DEFINE_AUTO( sys_ticrate, "100", FCVAR_SERVER, "framerate in dedicated mode" );
static CVAR_DEFINE_AUTO( host_serverstate, "0", FCVAR_READ_ONLY, "displays current server state" );
static CVAR_DEFINE_AUTO( host_gameloaded, "0", FCVAR_READ_ONLY, "inidcates a loaded game.dll" );
static CVAR_DEFINE_AUTO( host_clientloaded, "0", FCVAR_READ_ONLY, "inidcates a loaded client.dll" );
@ -69,14 +69,14 @@ typedef struct feature_message_s
const char *arg;
} feature_message_t;
static feature_message_t bugcomp_features[] =
static const feature_message_t bugcomp_features[] =
{
{ BUGCOMP_PENTITYOFENTINDEX_FLAG, "pfnPEntityOfEntIndex bugfix revert", "peoei" },
{ BUGCOMP_MESSAGE_REWRITE_FACILITY_FLAG, "GoldSrc Message Rewrite Facility", "gsmrf" },
{ BUGCOMP_SPATIALIZE_SOUND_WITH_ATTN_NONE, "spatialize sounds with zero attenuation", "sp_attn_none" },
};
static feature_message_t engine_features[] =
static const feature_message_t engine_features[] =
{
{ ENGINE_WRITE_LARGE_COORD, "Big World Support" },
{ ENGINE_QUAKE_COMPATIBLE, "Quake Compatibility" },
@ -200,19 +200,6 @@ static void Sys_PrintUsage( const char *exename )
Sys_Quit();
}
int Host_CompareFileTime( int ft1, int ft2 )
{
if( ft1 < ft2 )
{
return -1;
}
else if( ft1 > ft2 )
{
return 1;
}
return 0;
}
void Host_ShutdownServer( void )
{
SV_Shutdown( "Server was killed\n" );
@ -223,7 +210,7 @@ void Host_ShutdownServer( void )
Host_PrintEngineFeatures
================
*/
static void Host_PrintFeatures( uint32_t flags, const char *s, feature_message_t *features, size_t size )
static void Host_PrintFeatures( uint32_t flags, const char *s, const feature_message_t *features, size_t size )
{
size_t i;

View File

@ -198,7 +198,7 @@ static mlumpinfo_t srclumps[HEADER_LUMPS] =
{ LUMP_MODELS, 1, MAX_MAP_MODELS, sizeof( dmodel_t ), -1, "models", CHECK_OVERFLOW, (const void **)&srcmodel.submodels, &srcmodel.numsubmodels },
};
static mlumpinfo_t extlumps[EXTRA_LUMPS] =
static const mlumpinfo_t extlumps[EXTRA_LUMPS] =
{
{ LUMP_LIGHTVECS, 0, MAX_MAP_LIGHTING, sizeof( byte ), -1, "deluxmaps", USE_EXTRAHEADER, (const void **)&srcmodel.deluxdata, &srcmodel.deluxdatasize },
{ LUMP_FACEINFO, 0, MAX_MAP_FACEINFO, sizeof( dfaceinfo_t ), -1, "faceinfos", CHECK_OVERFLOW|USE_EXTRAHEADER, (const void **)&srcmodel.faceinfo, &srcmodel.numfaceinfo },

View File

@ -25,7 +25,7 @@ GNU General Public License for more details.
// gives a 33% speedup in WriteUBitLong.
static uint32_t BitWriteMasks[32][33];
static uint32_t ExtraMasks[32];
const char *svc_strings[svc_lastmsg+1] =
const char *const svc_strings[svc_lastmsg+1] =
{
"svc_bad",
"svc_nop",
@ -89,7 +89,7 @@ const char *svc_strings[svc_lastmsg+1] =
"svc_exec",
};
const char *svc_legacy_strings[svc_lastmsg+1] =
const char *const svc_legacy_strings[svc_lastmsg+1] =
{
[svc_legacy_changing] = "svc_legacy_changing",
[svc_legacy_ambientsound] = "svc_legacy_ambientsound",
@ -100,7 +100,7 @@ const char *svc_legacy_strings[svc_lastmsg+1] =
[svc_legacy_chokecount] = "svc_legacy_chokecount",
};
const char *svc_goldsrc_strings[svc_lastmsg+1] =
const char *const svc_goldsrc_strings[svc_lastmsg+1] =
{
[svc_goldsrc_version] = "svc_goldsrc_version",
[svc_goldsrc_serverinfo] = "svc_goldsrc_serverinfo",
@ -119,7 +119,7 @@ const char *svc_goldsrc_strings[svc_lastmsg+1] =
[svc_goldsrc_sendcvarvalue2] = "svc_goldsrc_sendcvarvalue2",
};
const char *svc_quake_strings[svc_lastmsg+1] =
const char *const svc_quake_strings[svc_lastmsg+1] =
{
[svc_updatestat] = "svc_quake_updatestat",
[svc_version] = "svc_quake_version",

View File

@ -98,7 +98,7 @@ sizebuf_t net_message;
static poolhandle_t net_mempool;
byte net_message_buffer[NET_MAX_MESSAGE];
const char *ns_strings[NS_COUNT] =
static const char *const ns_strings[NS_COUNT] =
{
"Client",
"Server",

View File

@ -146,7 +146,7 @@ static void NET_ClearLagData( qboolean bClient, qboolean bServer );
NET_ErrorString
====================
*/
static char *NET_ErrorString( void )
static const char *NET_ErrorString( void )
{
#if XASH_WIN32
int err = WSANOTINITIALISED;

View File

@ -277,11 +277,11 @@ GNU General Public License for more details.
#define SU_ARMOR (1<<13)
#define SU_WEAPON (1<<14)
extern const char *svc_strings[svc_lastmsg+1];
extern const char *svc_legacy_strings[svc_lastmsg+1];
extern const char *svc_quake_strings[svc_lastmsg+1];
extern const char *svc_goldsrc_strings[svc_lastmsg+1];
extern const char *clc_strings[clc_lastmsg+1];
extern const char *const svc_strings[svc_lastmsg+1];
extern const char *const svc_legacy_strings[svc_lastmsg+1];
extern const char *const svc_quake_strings[svc_lastmsg+1];
extern const char *const svc_goldsrc_strings[svc_lastmsg+1];
extern const char *const clc_strings[clc_lastmsg+1];
// FWGS extensions
#define NET_EXT_SPLITSIZE (1U<<0) // set splitsize by cl_dlmax

View File

@ -21,7 +21,7 @@ enum soundlst_type_e
SoundList_List
};
static const char *soundlst_groups[SoundList_Groups] =
static const char *const soundlst_groups[SoundList_Groups] =
{
"BouncePlayerShell",
"BounceWeaponShell",
@ -46,7 +46,7 @@ typedef struct soundlst_s
int max; // the string count if type is group
} soundlst_t;
soundlst_t soundlst[SoundList_Groups];
static soundlst_t soundlst[SoundList_Groups];
static void SoundList_Print_f( void );
static void SoundList_Free( soundlst_t *lst )

View File

@ -19,7 +19,7 @@ GNU General Public License for more details.
#include "net_encode.h"
#include "net_api.h"
const char *clc_strings[clc_lastmsg+1] =
const char *const clc_strings[clc_lastmsg+1] =
{
"clc_bad",
"clc_nop",
@ -3035,7 +3035,7 @@ static qboolean SV_EntGetVars_f( sv_client_t *cl )
return true;
}
ucmd_t ucmds[] =
static const ucmd_t ucmds[] =
{
{ "new", SV_New_f },
{ "god", SV_Godmode_f },
@ -3055,7 +3055,7 @@ ucmd_t ucmds[] =
{ NULL, NULL }
};
ucmd_t enttoolscmds[] =
static const ucmd_t enttoolscmds[] =
{
{ "ent_list", SV_EntList_f },
{ "ent_info", SV_EntInfo_f },

View File

@ -16,8 +16,6 @@ GNU General Public License for more details.
#include "common.h"
#include "server.h"
extern convar_t con_gamemaps;
/*
=================
SV_ClientPrintf

View File

@ -25,8 +25,8 @@ typedef struct
byte sended[MAX_EDICTS_BYTES];
} sv_ents_t;
int c_fullsend; // just a debug counter
int c_notsend;
static int c_fullsend; // just a debug counter
static int c_notsend;
/*
=======================

View File

@ -24,8 +24,6 @@ GNU General Public License for more details.
#include "render_api.h" // modelstate_t
#include "ref_common.h" // decals
#define ENTVARS_COUNT ARRAYSIZE( gEntvarsDescription )
// GameAPI functions declarations
static int GAME_EXPORT pfnModelIndex( const char *m );
@ -83,7 +81,7 @@ EntvarsDescription
entavrs table for FindEntityByString
=============
*/
static TYPEDESCRIPTION gEntvarsDescription[] =
static const TYPEDESCRIPTION gEntvarsDescription[] =
{
DEFINE_ENTITY_FIELD( classname, FIELD_STRING ),
DEFINE_ENTITY_FIELD( globalname, FIELD_STRING ),
@ -100,20 +98,6 @@ static TYPEDESCRIPTION gEntvarsDescription[] =
DEFINE_ENTITY_FIELD( noise3, FIELD_SOUNDNAME ),
};
/*
=============
SV_GetEntvarsDescription
entavrs table for FindEntityByString
=============
*/
static TYPEDESCRIPTION *SV_GetEntvarsDescirption( int number )
{
if( number < 0 || number >= ENTVARS_COUNT )
return NULL;
return &gEntvarsDescription[number];
}
/*
=============
SV_SysError
@ -1506,8 +1490,8 @@ SV_FindEntityByString
*/
static edict_t *GAME_EXPORT SV_FindEntityByString( edict_t *pStartEdict, const char *pszField, const char *pszValue )
{
int index = 0, e = 0;
TYPEDESCRIPTION *desc = NULL;
int i = 0, e = 0;
const TYPEDESCRIPTION *desc = NULL;
edict_t *ed;
const char *t;
@ -1516,10 +1500,13 @@ static edict_t *GAME_EXPORT SV_FindEntityByString( edict_t *pStartEdict, const c
if( pStartEdict ) e = NUM_FOR_EDICT( pStartEdict );
while(( desc = SV_GetEntvarsDescirption( index++ )) != NULL )
for( i = 0; i < ARRAYSIZE( gEntvarsDescription ); i++ )
{
if( !Q_strcmp( pszField, desc->fieldName ))
if( !Q_strcmp( pszField, gEntvarsDescription[i].fieldName ))
{
desc = &gEntvarsDescription[i];
break;
}
}
if( desc == NULL )

View File

@ -82,7 +82,7 @@ typedef struct
float time;
} SAVE_LIGHTSTYLE;
void (__cdecl *pfnSaveGameComment)( char *buffer, int max_length ) = NULL;
static void (__cdecl *pfnSaveGameComment)( char *buffer, int max_length ) = NULL;
static TYPEDESCRIPTION gGameHeader[] =
{
@ -218,7 +218,7 @@ static TYPEDESCRIPTION gTempEntvars[] =
DEFINE_ENTITY_GLOBAL_FIELD( globalname, FIELD_STRING ),
};
struct
static const struct
{
const char *mapname;
const char *titlename;
@ -2185,6 +2185,19 @@ qboolean SV_SaveGame( const char *pName )
return SaveGameSlot( savename, comment );
}
static int SV_CompareFileTime( int ft1, int ft2 )
{
if( ft1 < ft2 )
{
return -1;
}
else if( ft1 > ft2 )
{
return 1;
}
return 0;
}
/*
==================
SV_GetLatestSave
@ -2210,7 +2223,7 @@ const char *SV_GetLatestSave( void )
if( ft > 0 )
{
// should we use the matched?
if( !found || Host_CompareFileTime( newest, ft ) < 0 )
if( !found || SV_CompareFileTime( newest, ft ) < 0 )
{
Q_strncpy( savename, t->filenames[i], sizeof( savename ));
newest = ft;