Skip to content

Commit 075b72b

Browse files
committed
tier1: allow one to implement custom convar register functions
1 parent 7daba24 commit 075b72b

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

public/tier1/convar.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ class ConCommandBase
261261

262262
// ConVars in this executable use this 'global' to access values.
263263
static IConCommandBaseAccessor *s_pAccessor;
264+
265+
public:
266+
inline ConCommandBase* InternalNext() { return m_pNext; };
267+
inline ConCommandBase* InternalConCommandBases() { return s_pConCommandBases; };
268+
inline IConCommandBaseAccessor* InternalBaseAccessor() { return s_pAccessor; };
264269
};
265270

266271

@@ -1055,6 +1060,13 @@ class SplitScreenSlottedConVarRef : public SplitScreenConVarRef
10551060
void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
10561061
void ConVar_Unregister( );
10571062

1063+
//-----------------------------------------------------------------------------
1064+
// Utility methods when implementing your custom ConVar_Register function.
1065+
//-----------------------------------------------------------------------------
1066+
int* ConVar_GetConVarFlag();
1067+
int* ConVar_GetDLLIdentifier();
1068+
bool* ConVar_GetIsRegistered();
1069+
IConCommandBaseAccessor* ConVar_GetDefaultAccessor();
10581070

10591071
//-----------------------------------------------------------------------------
10601072
// Utility methods

tier1/convar.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
#endif
3333

3434
// This enables the l4d style of culling all cvars that are not marked FCVAR_RELEASE :
35-
#define CULL_ALL_CVARS_NOT_FCVAR_RELEASE
35+
// RaphaelIT7: Fk this, why would anyone want this in a SDK.
36+
// #define CULL_ALL_CVARS_NOT_FCVAR_RELEASE
3637

3738
//-----------------------------------------------------------------------------
3839
// Statically constructed list of ConCommandBases,
@@ -44,6 +45,21 @@ static int s_nCVarFlag = 0;
4445
static int s_nDLLIdentifier = -1; // A unique identifier indicating which DLL this convar came from
4546
static bool s_bRegistered = false;
4647

48+
int* ConVar_GetConVarFlag()
49+
{
50+
return &s_nCVarFlag;
51+
}
52+
53+
int* ConVar_GetDLLIdentifier()
54+
{
55+
return &s_nDLLIdentifier;
56+
}
57+
58+
bool* ConVar_GetIsRegistered()
59+
{
60+
return &s_bRegistered;
61+
}
62+
4763
class CDefaultAccessor : public IConCommandBaseAccessor
4864
{
4965
public:
@@ -57,6 +73,12 @@ class CDefaultAccessor : public IConCommandBaseAccessor
5773

5874
static CDefaultAccessor s_DefaultAccessor;
5975

76+
IConCommandBaseAccessor* ConVar_GetDefaultAccessor()
77+
{
78+
return &s_DefaultAccessor;
79+
}
80+
81+
#ifndef TIER0_CUSTOMCONVARREGISTER
6082
//-----------------------------------------------------------------------------
6183
// Called by the framework to register ConCommandBases with the ICVar
6284
//-----------------------------------------------------------------------------
@@ -87,7 +109,9 @@ void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor )
87109

88110
ConCommandBase::s_pConCommandBases = NULL;
89111
}
112+
#endif
90113

114+
#ifndef TIER0_CUSTOMCONVARUNREGISTER
91115
void ConVar_Unregister( )
92116
{
93117
if ( !g_pCVar || !s_bRegistered )
@@ -101,7 +125,7 @@ void ConVar_Unregister( )
101125
s_nDLLIdentifier = -1;
102126
s_bRegistered = false;
103127
}
104-
128+
#endif
105129

106130
//-----------------------------------------------------------------------------
107131
// Purpose: Default constructor

tier1/premake5_create_project.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ group("SourceSDK")
127127
["Header files/*"] = {"../public/tier1/*.h", "../public/*.h", "../common/xbox/*.h"}
128128
})
129129

130+
if TIER0_PROJECTCALLBACK then
131+
TIER0_PROJECTCALLBACK()
132+
end
133+
130134
IncludeSDKCommonInternal()
131135
IncludeSDKLZMA()
132136

0 commit comments

Comments
 (0)