Skip to content

Commit 3887ac5

Browse files
committed
perf: use static ConVarRefs during relatively hot functions
instead of doing a O(n) lookup per frame in some cases, we can just init the ConVarRef once hottest function in R_LoadSkys, other ones are just possible during runtime or called relatively a lot compared to other non-static ConVarRefs
1 parent 75f4224 commit 3887ac5

File tree

12 files changed

+16
-16
lines changed

12 files changed

+16
-16
lines changed

src/common/ServerBrowser/blacklisted_server_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ bool CBlacklistedServerManager::IsServerBlacklisted( uint32 serverIP, int server
223223
{
224224
netadr_t netAdr( serverIP, serverPort );
225225

226-
ConVarRef sb_showblacklists( "sb_showblacklists" );
226+
static ConVarRef sb_showblacklists( "sb_showblacklists" );
227227

228228
for ( int i = 0; i < m_Blacklist.Count(); i++ )
229229
{

src/engine/gl_warp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void R_LoadSkys( void )
165165

166166
char requestedsky[ 128 ];
167167

168-
ConVarRef skyname( "sv_skyname" );
168+
static ConVarRef skyname( "sv_skyname" );
169169
if ( skyname.IsValid() )
170170
{
171171
Q_strncpy( requestedsky, skyname.GetString(), sizeof( requestedsky ) );

src/engine/matsys_interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void ReadMaterialSystemConfigFromRegistry( MaterialSystem_Config_t &confi
412412
config.SetFlag( MATSYS_VIDCFG_FLAGS_WINDOWED, ReadVideoConfigInt( "ScreenWindowed", 0 ) != 0 );
413413
#if defined( USE_SDL ) && !defined( SWDS )
414414
// Read the ScreenDisplayIndex and set sdl_displayindex if it's there.
415-
ConVarRef conVar( "sdl_displayindex" );
415+
static ConVarRef conVar( "sdl_displayindex" );
416416
if ( conVar.IsValid() )
417417
{
418418
int displayIndex = 0;
@@ -531,7 +531,7 @@ static void WriteMaterialSystemConfigToRegistry( const MaterialSystem_Config_t &
531531

532532
#if defined( USE_SDL ) && !defined( SWDS )
533533
// Save sdl_displayindex out to ScreenDisplayIndex.
534-
ConVarRef conVar( "sdl_displayindex" );
534+
static ConVarRef conVar( "sdl_displayindex" );
535535
if ( conVar.IsValid() && !UseVR() )
536536
{
537537
WriteVideoConfigInt( "ScreenDisplayIndex", conVar.GetInt() );
@@ -683,7 +683,7 @@ void OverrideMaterialSystemConfig( MaterialSystem_Config_t &config )
683683
{
684684
// enable/disable flashlight support based on mod (user can also set this explicitly)
685685
// FIXME: this is only here because dxsupport_override.cfg is currently broken
686-
ConVarRef mat_supportflashlight( "mat_supportflashlight" );
686+
static ConVarRef mat_supportflashlight( "mat_supportflashlight" );
687687
if ( mat_supportflashlight.GetInt() == -1 )
688688
{
689689
const char * gameName = COM_GetModDirectory();

src/game/client/in_steamcontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void CInput::ApplySteamControllerCameraMove( QAngle& viewangles, CUserCmd *cmd,
6969
//roll the view angles so roll is 0 (the HL2 assumed state) and mouse adjustments are relative to the screen.
7070
//Assuming roll is unchanging, we want mouse left to translate to screen left at all times (same for right, up, and down)
7171

72-
ConVarRef cl_pitchdown ( "cl_pitchdown" );
73-
ConVarRef cl_pitchup ( "cl_pitchup" );
72+
static ConVarRef cl_pitchdown ( "cl_pitchdown" );
73+
static ConVarRef cl_pitchup ( "cl_pitchup" );
7474

7575
// Scale yaw and pitch inputs by sensitivity, and make sure they are within acceptable limits (important to avoid exploits, e.g. during Demoman charge we must restrict allowed yaw).
7676
float yaw = CAM_CapYaw( sc_yaw_sensitivity.GetFloat() * vecPosition.x );

src/game/client/tf/tf_hud_notification_panel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void CHudNotificationPanel::MsgFunc_HudNotify( bf_read &msg )
140140
void CHudNotificationPanel::MsgFunc_HudNotifyCustom( bf_read &msg )
141141
{
142142
// Ignore notifications in minmode
143-
ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
143+
static ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
144144
if ( cl_hud_minmode.IsValid() && cl_hud_minmode.GetBool() )
145145
return;
146146

src/game/server/effects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void CGibShooter::Spawn( void )
451451

452452
CGib *CGibShooter::CreateGib ( void )
453453
{
454-
ConVarRef violence_hgibs( "violence_hgibs" );
454+
static ConVarRef violence_hgibs( "violence_hgibs" );
455455
if ( violence_hgibs.IsValid() && !violence_hgibs.GetInt() )
456456
return NULL;
457457

src/game/server/env_tonemap_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void CEnvTonemapController::InputSetBloomScaleRange( inputdata_t &inputdata )
178178
void CEnvTonemapController::InputSetTonemapRate( inputdata_t &inputdata )
179179
{
180180
// TODO: There should be a better way to do this.
181-
ConVarRef mat_hdr_manual_tonemap_rate( "mat_hdr_manual_tonemap_rate" );
181+
static ConVarRef mat_hdr_manual_tonemap_rate( "mat_hdr_manual_tonemap_rate" );
182182
if ( mat_hdr_manual_tonemap_rate.IsValid() )
183183
{
184184
float flTonemapRate = inputdata.value.Float();

src/game/server/func_break.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ void CBreakable::Die( void )
10501050
iCount = func_break_max_pieces.GetInt();
10511051
}
10521052

1053-
ConVarRef breakable_disable_gib_limit( "breakable_disable_gib_limit" );
1053+
static ConVarRef breakable_disable_gib_limit( "breakable_disable_gib_limit" );
10541054
if ( !breakable_disable_gib_limit.GetBool() && iCount )
10551055
{
10561056
if ( m_PerformanceMode == PM_NO_GIBS )

src/game/server/triggers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ void CTriggerPush::Activate()
22432243
{
22442244
// Fix problems with triggers pushing too hard under sv_alternateticks.
22452245
// This is somewhat hacky, but it's simple and we're really close to shipping.
2246-
ConVarRef sv_alternateticks( "sv_alternateticks" );
2246+
static ConVarRef sv_alternateticks( "sv_alternateticks" );
22472247
if ( ( m_flAlternateTicksFix != 0 ) && sv_alternateticks.GetBool() )
22482248
{
22492249
m_flPushSpeed = m_flSpeed * m_flAlternateTicksFix;

src/game/shared/achievementmgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ bool CAchievementMgr::CheckAchievementsEnabled()
10951095
return false;
10961096
}
10971097

1098-
ConVarRef tf_bot_offline_practice( "tf_bot_offline_practice" );
1098+
static ConVarRef tf_bot_offline_practice( "tf_bot_offline_practice" );
10991099
// no achievements for offline practice
11001100
if ( tf_bot_offline_practice.GetInt() != 0 )
11011101
{

0 commit comments

Comments
 (0)