Browse Source

engine: common: move host cvars to static allocation

pull/2/head
Alibek Omarov 2 years ago
parent
commit
214fc7e827
  1. 4
      engine/client/cl_demo.c
  2. 2
      engine/client/cl_main.c
  3. 4
      engine/common/cmd.c
  4. 7
      engine/common/common.h
  5. 6
      engine/common/con_utils.c
  6. 4
      engine/common/cvar.c
  7. 51
      engine/common/host.c
  8. 6
      engine/server/sv_cmds.c
  9. 2
      engine/server/sv_frame.c
  10. 4
      engine/server/sv_main.c

4
engine/client/cl_demo.c

@ -372,7 +372,7 @@ void CL_WriteDemoHeader( const char *name ) @@ -372,7 +372,7 @@ void CL_WriteDemoHeader( const char *name )
demo.header.id = IDEMOHEADER;
demo.header.dem_protocol = DEMO_PROTOCOL;
demo.header.net_protocol = cls.legacymode ? PROTOCOL_LEGACY_VERSION : PROTOCOL_VERSION;
demo.header.host_fps = bound( MIN_FPS, host_maxfps->value, MAX_FPS );
demo.header.host_fps = bound( MIN_FPS, host_maxfps.value, MAX_FPS );
Q_strncpy( demo.header.mapname, clgame.mapname, sizeof( demo.header.mapname ));
Q_strncpy( demo.header.comment, clgame.maptitle, sizeof( demo.header.comment ));
Q_strncpy( demo.header.gamedir, FS_Gamedir(), sizeof( demo.header.gamedir ));
@ -1468,7 +1468,7 @@ void CL_PlayDemo_f( void ) @@ -1468,7 +1468,7 @@ void CL_PlayDemo_f( void )
{
int c, neg = false;
demo.header.host_fps = host_maxfps->value;
demo.header.host_fps = host_maxfps.value;
while(( c = FS_Getc( cls.demofile )) != '\n' )
{

2
engine/client/cl_main.c

@ -726,7 +726,7 @@ void CL_WritePacket( void ) @@ -726,7 +726,7 @@ void CL_WritePacket( void )
// In single player, send commands as fast as possible
// Otherwise, only send when ready and when not choking bandwidth
if( cl.maxclients == 1 || ( NET_IsLocalAddress( cls.netchan.remote_address ) && !host_limitlocal->value ))
if( cl.maxclients == 1 || ( NET_IsLocalAddress( cls.netchan.remote_address ) && !host_limitlocal.value ))
send_command = true;
if(( host.realtime >= cls.nextcmdtime ) && Netchan_CanPacket( &cls.netchan, true ))

4
engine/common/cmd.c

@ -996,7 +996,7 @@ static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPr @@ -996,7 +996,7 @@ static void Cmd_ExecuteStringWithPrivilegeCheck( const char *text, qboolean isPr
cmd_condlevel = 0;
// cvar value substitution
if( CVAR_TO_BOOL( cmd_scripting ) && isPrivileged )
if( cmd_scripting.value && isPrivileged )
{
while( *text )
{
@ -1357,7 +1357,7 @@ inserts escape sequences @@ -1357,7 +1357,7 @@ inserts escape sequences
void Cmd_Escape( char *newCommand, const char *oldCommand, int len )
{
int c;
int scripting = CVAR_TO_BOOL( cmd_scripting );
int scripting = cmd_scripting.value;
while( (c = *oldCommand++) && len > 1 )
{

7
engine/common/common.h

@ -156,13 +156,12 @@ void DBG_AssertFunction( qboolean fExpr, const char* szExpr, const char* szFile, @@ -156,13 +156,12 @@ void DBG_AssertFunction( qboolean fExpr, const char* szExpr, const char* szFile,
extern convar_t gl_vsync;
extern convar_t scr_loading;
extern convar_t scr_download;
extern convar_t *cmd_scripting;
extern convar_t cmd_scripting;
extern convar_t *sv_maxclients;
extern convar_t cl_allow_levelshots;
extern convar_t host_developer;
extern convar_t *host_limitlocal;
extern convar_t *host_framerate;
extern convar_t *host_maxfps;
extern convar_t host_limitlocal;
extern convar_t host_maxfps;
extern convar_t sys_timescale;
extern convar_t cl_filterstuffcmd;
extern convar_t rcon_password;

6
engine/common/con_utils.c

@ -18,7 +18,7 @@ GNU General Public License for more details. @@ -18,7 +18,7 @@ GNU General Public License for more details.
#include "const.h"
#include "kbutton.h"
extern convar_t *con_gamemaps;
extern convar_t con_gamemaps;
#define CON_MAXCMDS 4096 // auto-complete intermediate list
@ -76,7 +76,7 @@ int Cmd_ListMaps( search_t *t, char *lastmapname, size_t len ) @@ -76,7 +76,7 @@ int Cmd_ListMaps( search_t *t, char *lastmapname, size_t len )
compiler[0] = '\0';
generator[0] = '\0';
f = FS_Open( t->filenames[i], "rb", con_gamemaps->value );
f = FS_Open( t->filenames[i], "rb", con_gamemaps.value );
if( f )
{
@ -190,7 +190,7 @@ qboolean Cmd_GetMapList( const char *s, char *completedname, int length ) @@ -190,7 +190,7 @@ qboolean Cmd_GetMapList( const char *s, char *completedname, int length )
string matchbuf;
int i, nummaps;
t = FS_Search( va( "maps/%s*.bsp", s ), true, con_gamemaps->value );
t = FS_Search( va( "maps/%s*.bsp", s ), true, con_gamemaps.value );
if( !t ) return false;
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));

4
engine/common/cvar.c

@ -19,7 +19,7 @@ GNU General Public License for more details. @@ -19,7 +19,7 @@ GNU General Public License for more details.
#include "eiface.h" // ARRAYSIZE
convar_t *cvar_vars = NULL; // head of list
convar_t *cmd_scripting;
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
@ -1240,7 +1240,7 @@ void Cvar_Init( void ) @@ -1240,7 +1240,7 @@ void Cvar_Init( void )
{
cvar_vars = NULL;
cvar_active_filter_quirks = NULL;
cmd_scripting = Cvar_Get( "cmd_scripting", "0", FCVAR_ARCHIVE|FCVAR_PRIVILEGED, "enable simple condition checking and variable operations" );
Cvar_RegisterVariable( &cmd_scripting );
Cvar_RegisterVariable( &host_developer ); // early registering for dev
Cvar_RegisterVariable( &cl_filterstuffcmd );
Cmd_AddRestrictedCommand( "setgl", Cvar_SetGL_f, "change the value of a opengl variable" ); // OBSOLETE

51
engine/common/host.c

@ -54,15 +54,14 @@ CVAR_DEFINE( host_developer, "developer", "0", FCVAR_FILTERABLE, "engine is in d @@ -54,15 +54,14 @@ CVAR_DEFINE( host_developer, "developer", "0", FCVAR_FILTERABLE, "engine is in d
CVAR_DEFINE_AUTO( sys_timescale, "1.0", FCVAR_CHEAT|FCVAR_FILTERABLE, "scale frame time" );
CVAR_DEFINE_AUTO( sys_ticrate, "100", 0, "framerate in dedicated mode" );
convar_t *host_serverstate;
convar_t *host_gameloaded;
convar_t *host_clientloaded;
convar_t *host_limitlocal;
convar_t *host_maxfps;
convar_t *host_framerate;
convar_t *host_sleeptime;
convar_t *con_gamemaps;
convar_t *build, *ver;
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" );
CVAR_DEFINE_AUTO( host_limitlocal, "0", 0, "apply cl_cmdrate and rate to loopback connection" );
CVAR_DEFINE( host_maxfps, "fps_max", "72", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "host fps upper limit" );
static CVAR_DEFINE_AUTO( host_framerate, "0", FCVAR_FILTERABLE, "locks frame timing to this value in seconds" );
static CVAR_DEFINE( host_sleeptime, "sleeptime", "1", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "milliseconds to sleep for each frame. higher values reduce fps accuracy" );
CVAR_DEFINE( con_gamemaps, "con_mapfilter", "1", FCVAR_ARCHIVE, "when true show only maps in game folder" );
void Sys_PrintUsage( void )
{
@ -285,20 +284,20 @@ static int Host_CalcSleep( void ) @@ -285,20 +284,20 @@ static int Host_CalcSleep( void )
if( Host_IsDedicated() )
{
// let the dedicated server some sleep
return host_sleeptime->value;
return host_sleeptime.value;
}
switch( host.status )
{
case HOST_NOFOCUS:
if( SV_Active() && CL_IsInGame())
return host_sleeptime->value;
return host_sleeptime.value;
// fallthrough
case HOST_SLEEP:
return 20;
}
return host_sleeptime->value;
return host_sleeptime.value;
}
void Host_NewInstance( const char *name, const char *finalmsg )
@ -600,13 +599,13 @@ double Host_CalcFPS( void ) @@ -600,13 +599,13 @@ double Host_CalcFPS( void )
else if( Host_IsLocalGame( ))
{
if( !gl_vsync.value )
fps = host_maxfps->value;
fps = host_maxfps.value;
}
else
{
if( !gl_vsync.value )
{
fps = host_maxfps->value;
fps = host_maxfps.value;
if( fps == 0.0 ) fps = MAX_FPS;
fps = bound( MIN_FPS, fps, MAX_FPS );
}
@ -681,8 +680,8 @@ qboolean Host_FilterTime( float time ) @@ -681,8 +680,8 @@ qboolean Host_FilterTime( float time )
oldtime = host.realtime;
// NOTE: allow only in singleplayer while demos are not active
if( host_framerate->value > 0.0f && Host_IsLocalGame() && !CL_IsPlaybackDemo() && !CL_IsRecordDemo( ))
host.frametime = bound( MIN_FRAMETIME, host_framerate->value * scale, MAX_FRAMETIME );
if( host_framerate.value > 0.0f && Host_IsLocalGame() && !CL_IsPlaybackDemo() && !CL_IsRecordDemo( ))
host.frametime = bound( MIN_FRAMETIME, host_framerate.value * scale, MAX_FRAMETIME );
else host.frametime = bound( MIN_FRAMETIME, host.frametime, MAX_FRAMETIME );
return true;
@ -1164,18 +1163,18 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa @@ -1164,18 +1163,18 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa
Cmd_AddRestrictedCommand ( "crash", Host_Crash_f, "a way to force a bus error for development reasons");
}
host_serverstate = Cvar_Get( "host_serverstate", "0", FCVAR_READ_ONLY, "displays current server state" );
host_maxfps = Cvar_Get( "fps_max", "72", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "host fps upper limit" );
host_framerate = Cvar_Get( "host_framerate", "0", FCVAR_FILTERABLE, "locks frame timing to this value in seconds" );
host_sleeptime = Cvar_Get( "sleeptime", "1", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "milliseconds to sleep for each frame. higher values reduce fps accuracy" );
host_gameloaded = Cvar_Get( "host_gameloaded", "0", FCVAR_READ_ONLY, "inidcates a loaded game.dll" );
host_clientloaded = Cvar_Get( "host_clientloaded", "0", FCVAR_READ_ONLY, "inidcates a loaded client.dll" );
host_limitlocal = Cvar_Get( "host_limitlocal", "0", 0, "apply cl_cmdrate and rate to loopback connection" );
con_gamemaps = Cvar_Get( "con_mapfilter", "1", FCVAR_ARCHIVE, "when true show only maps in game folder" );
Cvar_RegisterVariable( &host_serverstate );
Cvar_RegisterVariable( &host_maxfps );
Cvar_RegisterVariable( &host_framerate );
Cvar_RegisterVariable( &host_sleeptime );
Cvar_RegisterVariable( &host_gameloaded );
Cvar_RegisterVariable( &host_clientloaded );
Cvar_RegisterVariable( &host_limitlocal );
Cvar_RegisterVariable( &con_gamemaps );
Cvar_RegisterVariable( &sys_timescale );
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( "buildnum", FCVAR_READ_ONLY, "returns a current build number", "%i", Q_buildnum_compat());
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 );

6
engine/server/sv_cmds.c

@ -16,7 +16,7 @@ GNU General Public License for more details. @@ -16,7 +16,7 @@ GNU General Public License for more details.
#include "common.h"
#include "server.h"
extern convar_t *con_gamemaps;
extern convar_t con_gamemaps;
/*
=================
@ -321,8 +321,8 @@ void SV_NextMap_f( void ) @@ -321,8 +321,8 @@ void SV_NextMap_f( void )
int i, next;
search_t *t;
t = FS_Search( "maps\\*.bsp", true, CVAR_TO_BOOL( con_gamemaps )); // only in gamedir
if( !t ) t = FS_Search( "maps/*.bsp", true, CVAR_TO_BOOL( con_gamemaps )); // only in gamedir
t = FS_Search( "maps\\*.bsp", true, con_gamemaps.value ); // only in gamedir
if( !t ) t = FS_Search( "maps/*.bsp", true, con_gamemaps.value ); // only in gamedir
if( !t )
{

2
engine/server/sv_frame.c

@ -863,7 +863,7 @@ void SV_SendClientMessages( void ) @@ -863,7 +863,7 @@ void SV_SendClientMessages( void )
continue;
}
if( !host_limitlocal->value && NET_IsLocalAddress( cl->netchan.remote_address ))
if( !host_limitlocal.value && NET_IsLocalAddress( cl->netchan.remote_address ))
SetBits( cl->flags, FCL_SEND_NET_MESSAGE );
if( cl->state == cs_spawned )

4
engine/server/sv_main.c

@ -422,7 +422,7 @@ void SV_ReadPackets( void ) @@ -422,7 +422,7 @@ void SV_ReadPackets( void )
if( Netchan_Process( &cl->netchan, &net_message ))
{
if(( svs.maxclients == 1 && !host_limitlocal->value ) || ( cl->state != cs_spawned ))
if(( svs.maxclients == 1 && !host_limitlocal.value ) || ( cl->state != cs_spawned ))
SetBits( cl->flags, FCL_SEND_NET_MESSAGE ); // reply at end of frame
// this is a valid, sequenced packet, so process it
@ -441,7 +441,7 @@ void SV_ReadPackets( void ) @@ -441,7 +441,7 @@ void SV_ReadPackets( void )
{
MSG_Init( &net_message, "ClientPacket", net_message_buffer, curSize );
if(( svs.maxclients == 1 && !host_limitlocal->value ) || ( cl->state != cs_spawned ))
if(( svs.maxclients == 1 && !host_limitlocal.value ) || ( cl->state != cs_spawned ))
SetBits( cl->flags, FCL_SEND_NET_MESSAGE ); // reply at end of frame
// this is a valid, sequenced packet, so process it

Loading…
Cancel
Save