CCVarIteratorInternal cleanup

* Improve readability.
* Free allocated iterator memory.
* Enforce FCVAR_HIDDEN ConVar's in ImGui console (there are only 17 ConVar's marked 'hidden', and most of these are stryder/platform related stuff. This is usefull for if we ever wish to create a hidden cvar).
This commit is contained in:
Kawe Mazidjatari 2022-08-14 02:51:15 +02:00
parent 61dbda67f7
commit 9f7d4f57d3
4 changed files with 56 additions and 82 deletions

View File

@ -474,46 +474,49 @@ void CConsole::FindFromPartial(void)
if (ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(m_vsvCommandBases[i].m_svName.c_str())) if (ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(m_vsvCommandBases[i].m_svName.c_str()))
{ {
if (!pCommandBase->IsCommand()) if (!pCommandBase->IsFlagSet(FCVAR_HIDDEN))
{ {
ConVar* pConVar = reinterpret_cast<ConVar*>(pCommandBase); if (!pCommandBase->IsCommand())
{
ConVar* pConVar = reinterpret_cast<ConVar*>(pCommandBase);
svValue = " = ["; // Assign default value to string if its a ConVar. svValue = " = ["; // Assign default value to string if its a ConVar.
svValue.append(pConVar->GetString()); svValue.append(pConVar->GetString());
svValue.append("]"); svValue.append("]");
} }
if (con_suggestion_showhelptext->GetBool()) if (con_suggestion_showhelptext->GetBool())
{
if (pCommandBase->GetHelpText())
{ {
string svHelpText = pCommandBase->GetHelpText(); if (pCommandBase->GetHelpText())
if (!svHelpText.empty())
{ {
svValue.append(" - \"" + svHelpText + "\""); string svHelpText = pCommandBase->GetHelpText();
if (!svHelpText.empty())
{
svValue.append(" - \"" + svHelpText + "\"");
}
}
if (pCommandBase->GetUsageText())
{
string svUsageText = pCommandBase->GetUsageText();
if (!svUsageText.empty())
{
svValue.append(" - \"" + svUsageText + "\"");
}
} }
} }
if (pCommandBase->GetUsageText()) if (con_suggestion_showflags->GetBool())
{ {
string svUsageText = pCommandBase->GetUsageText(); if (con_suggestion_flags_realtime->GetBool())
if (!svUsageText.empty())
{ {
svValue.append(" - \"" + svUsageText + "\""); nFlags = pCommandBase->GetFlags();
}
else // Display compile-time flags instead.
{
nFlags = m_vsvCommandBases[i].m_nFlags;
} }
} }
} m_vSuggest.push_back(CSuggest(m_vsvCommandBases[i].m_svName + svValue, nFlags));
if (con_suggestion_showflags->GetBool())
{
if (con_suggestion_flags_realtime->GetBool())
{
nFlags = pCommandBase->GetFlags();
}
else // Display compile-time flags instead.
{
nFlags = m_vsvCommandBases[i].m_nFlags;
}
} }
} }
m_vSuggest.push_back(CSuggest(m_vsvCommandBases[i].m_svName + svValue, nFlags));
} }
} }
} }

View File

@ -70,7 +70,6 @@ bool CModAppSystemGroup::Create(CModAppSystemGroup* pModAppSystemGroup)
if (CommandLine()->CheckParm("-devsdk")) if (CommandLine()->CheckParm("-devsdk"))
{ {
cv->EnableDevCvars(); cv->EnableDevCvars();
cv->EnableHiddenCvars();
} }
#endif // !DEDICATED #endif // !DEDICATED

View File

@ -341,14 +341,11 @@ int CCvarUtilities::CountVariablesWithFlags(int flags)
{ {
int i = 0; int i = 0;
ConCommandBase* var; ConCommandBase* var;
CCvar::CCVarIteratorInternal* itint = g_pCVar->FactoryInternalIterator();
// Loop through cvars... for (itint->SetFirst(); itint->IsValid(); itint->Next()) // Loop through cvars...
CCvar::CCVarIteratorInternal* pFactory = g_pCVar->FactoryInternalIterator();
pFactory->SetFirst();
while (pFactory->IsValid())
{ {
var = pFactory->Get(); var = itint->Get();
if (!var->IsCommand()) if (!var->IsCommand())
{ {
if (var->IsFlagSet(flags)) if (var->IsFlagSet(flags))
@ -356,10 +353,9 @@ int CCvarUtilities::CountVariablesWithFlags(int flags)
i++; i++;
} }
} }
pFactory->Next();
} }
MemAllocSingleton()->Free(itint);
return i; return i;
} }
@ -369,38 +365,16 @@ int CCvarUtilities::CountVariablesWithFlags(int flags)
void CCvarUtilities::EnableDevCvars() void CCvarUtilities::EnableDevCvars()
{ {
// Loop through cvars... // Loop through cvars...
CCvar::CCVarIteratorInternal* pFactory = g_pCVar->FactoryInternalIterator(); CCvar::CCVarIteratorInternal* itint = g_pCVar->FactoryInternalIterator();
pFactory->SetFirst();
while (pFactory->IsValid()) for (itint->SetFirst(); itint->IsValid(); itint->Next())
{ {
// remove flag from all cvars // remove flag from all cvars
ConCommandBase* pCommandBase = pFactory->Get(); ConCommandBase* pCommandBase = itint->Get();
pCommandBase->RemoveFlags(FCVAR_DEVELOPMENTONLY); pCommandBase->RemoveFlags(FCVAR_DEVELOPMENTONLY);
pFactory->Next();
}
}
//-----------------------------------------------------------------------------
// Purpose: Removes the FCVAR_DEVELOPMENTONLY flag from all cvars, making them accessible
//-----------------------------------------------------------------------------
void CCvarUtilities::EnableHiddenCvars()
{
// Loop through cvars...
CCvar::CCVarIteratorInternal* pFactory = g_pCVar->FactoryInternalIterator();
pFactory->SetFirst();
while (pFactory->IsValid())
{
// remove flag from all cvars
ConCommandBase* pCommandBase = pFactory->Get();
pCommandBase->RemoveFlags(FCVAR_HIDDEN);
pFactory->Next();
} }
MemAllocSingleton()->Free(pFactory); MemAllocSingleton()->Free(itint);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -458,14 +432,11 @@ void CCvarUtilities::CvarList(const CCommand& args)
DevMsg(eDLL_T::ENGINE, "cvar list\n--------------\n"); DevMsg(eDLL_T::ENGINE, "cvar list\n--------------\n");
CUtlRBTree< ConCommandBase* > sorted(0, 0, ConCommandBaseLessFunc); CUtlRBTree< ConCommandBase* > sorted(0, 0, ConCommandBaseLessFunc);
CCvar::CCVarIteratorInternal* itint = g_pCVar->FactoryInternalIterator();
// Loop through cvars... for (itint->SetFirst(); itint->IsValid(); itint->Next()) // Loop through all instances.
CCvar::CCVarIteratorInternal* pFactory = g_pCVar->FactoryInternalIterator();
pFactory->SetFirst();
while (pFactory->IsValid())
{ {
var = pFactory->Get(); var = itint->Get();
if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) && if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) &&
!var->IsFlagSet(FCVAR_HIDDEN)) !var->IsFlagSet(FCVAR_HIDDEN))
@ -489,9 +460,10 @@ void CCvarUtilities::CvarList(const CCommand& args)
sorted.Insert(var); sorted.Insert(var);
} }
} }
pFactory->Next();
} }
MemAllocSingleton()->Free(itint);
if (bLogging) if (bLogging)
{ {
PrintListHeader(f); PrintListHeader(f);
@ -560,13 +532,12 @@ void CCvarUtilities::CvarHelp(const CCommand& args)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CCvarUtilities::CvarDifferences(const CCommand& args) void CCvarUtilities::CvarDifferences(const CCommand& args)
{ {
CCvar::CCVarIteratorInternal* pFactory = g_pCVar->FactoryInternalIterator(); CCvar::CCVarIteratorInternal* itint = g_pCVar->FactoryInternalIterator();
pFactory->SetFirst();
int i = 0; int i = 0;
while (pFactory->IsValid()) for (itint->SetFirst(); itint->IsValid(); itint->Next()) // Loop through all instances.
{ {
ConCommandBase* pCommandBase = pFactory->Get(); ConCommandBase* pCommandBase = itint->Get();
if (!pCommandBase->IsCommand() && if (!pCommandBase->IsCommand() &&
!pCommandBase->IsFlagSet(FCVAR_HIDDEN)) !pCommandBase->IsFlagSet(FCVAR_HIDDEN))
@ -582,8 +553,9 @@ void CCvarUtilities::CvarDifferences(const CCommand& args)
} }
} }
} }
pFactory->Next();
} }
MemAllocSingleton()->Free(itint);
DevMsg(eDLL_T::ENGINE, "--------------\n%3i changed convars\n", i); DevMsg(eDLL_T::ENGINE, "--------------\n%3i changed convars\n", i);
} }
@ -609,12 +581,11 @@ void CCvarUtilities::CvarFindFlags_f(const CCommand& args)
ConCommandBase* var; ConCommandBase* var;
// Loop through vars and print out findings // Loop through vars and print out findings
CCvar::CCVarIteratorInternal* pFactory = g_pCVar->FactoryInternalIterator(); CCvar::CCVarIteratorInternal* itint = g_pCVar->FactoryInternalIterator();
pFactory->SetFirst();
while (pFactory->IsValid()) for (itint->SetFirst(); itint->IsValid(); itint->Next())
{ {
var = pFactory->Get(); var = itint->Get();
if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) || !var->IsFlagSet(FCVAR_HIDDEN)) if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) || !var->IsFlagSet(FCVAR_HIDDEN))
{ {
@ -629,9 +600,9 @@ void CCvarUtilities::CvarFindFlags_f(const CCommand& args)
} }
} }
} }
pFactory->Next();
} }
MemAllocSingleton()->Free(itint);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -782,6 +753,8 @@ unordered_map<string, ConCommandBase*> CCvar::DumpToMap(void)
allConVars[pszCommandName] = pCommand; allConVars[pszCommandName] = pCommand;
} }
MemAllocSingleton()->Free(itint);
return allConVars; return allConVars;
} }

View File

@ -180,7 +180,6 @@ public:
// Enable cvars marked with FCVAR_DEVELOPMENTONLY // Enable cvars marked with FCVAR_DEVELOPMENTONLY
void EnableDevCvars(); void EnableDevCvars();
void EnableHiddenCvars();
// Lists cvars to console // Lists cvars to console
void CvarList(const CCommand& args); void CvarList(const CCommand& args);