1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Rework ConCommandRegList

This commit is contained in:
Nick Hastings
2023-05-18 23:47:58 -04:00
committed by Nicholas Hastings
parent 311c966f97
commit 2541d89f62

View File

@ -39,39 +39,25 @@ static int64 s_nCVarFlag = 0;
static bool s_bRegistered = false; static bool s_bRegistered = false;
class ConCommandRegList; class ConCommandRegList;
static ConCommandRegList* s_pCmdRegList = nullptr;
class ConCommandRegList class ConCommandRegList
{ {
public: public:
ConCommandRegList() static void RegisterCommand(ConCommand* pCmd)
{ {
} if (s_bConCommandsRegistered)
static void RegisterCommand( ConCommand *pCmd )
{
if ( s_bConCommandsRegistered )
{ {
ConCommandHandle hndl = g_pCVar->RegisterConCommand( pCmd, s_nCVarFlag ); ConCommandHandle hndl = g_pCVar->RegisterConCommand(pCmd, s_nCVarFlag);
if ( !hndl.IsValid() ) if (!hndl.IsValid())
{ {
Plat_FatalErrorFunc( "RegisterConCommand: Unknown error registering con command \"%s\"!\n", pCmd->GetName() ); Plat_FatalErrorFunc("RegisterConCommand: Unknown error registering con command \"%s\"!\n", pCmd->GetName());
DebuggerBreakIfDebugging(); DebuggerBreakIfDebugging();
} }
pCmd->SetHandle( hndl ); pCmd->SetHandle(hndl);
} }
else else
{ {
ConCommandRegList* pList = s_pCmdRegList; s_ConCommandRegList.AddToTail(pCmd);
if ( !pList || pList->m_Vec.Count() == 100 )
{
pList = new ConCommandRegList;
pList->m_pNext = s_pCmdRegList;
s_pCmdRegList = pList;
}
pList->m_Vec.AddToTail(*pCmd);
} }
} }
@ -81,38 +67,28 @@ public:
{ {
s_bConCommandsRegistered = true; s_bConCommandsRegistered = true;
ConCommandRegList* pList = s_pCmdRegList; FOR_EACH_VEC( s_ConCommandRegList, i)
while ( pList != nullptr )
{ {
FOR_EACH_VEC( s_pCmdRegList->m_Vec, i ) ConCommand *pCmd = s_ConCommandRegList[i];
ConCommandHandle hndl = g_pCVar->RegisterConCommand(pCmd, s_nCVarFlag);
pCmd->SetHandle(hndl);
if (!hndl.IsValid())
{ {
ConCommand* pCmd = &pList->m_Vec[i]; Plat_FatalErrorFunc("RegisterConCommand: Unknown error registering con command \"%s\"!\n", pCmd->GetName());
ConCommandHandle hndl = g_pCVar->RegisterConCommand( pCmd, s_nCVarFlag ); DebuggerBreakIfDebugging();
pCmd->SetHandle( hndl );
if ( !hndl.IsValid() )
{
Plat_FatalErrorFunc( "RegisterConCommand: Unknown error registering con command \"%s\"!\n", pCmd->GetName() );
DebuggerBreakIfDebugging();
}
} }
ConCommandRegList* pNext = pList->m_pNext;
delete pList;
pList = pNext;
} }
s_pCmdRegList = nullptr;
} }
} }
private: private:
CUtlVectorFixed<ConCommand, 100> m_Vec; static CUtlVector<ConCommand*> s_ConCommandRegList;
ConCommandRegList* m_pNext = nullptr;
static bool s_bConCommandsRegistered; static bool s_bConCommandsRegistered;
}; };
bool ConCommandRegList::s_bConCommandsRegistered = false; bool ConCommandRegList::s_bConCommandsRegistered = false;
CUtlVector<ConCommand*> ConCommandRegList::s_ConCommandRegList;
#ifdef CONVAR_WORK_FINISHED #ifdef CONVAR_WORK_FINISHED
template <typename ToCheck, std::size_t ExpectedSize, std::size_t RealSize = sizeof(ToCheck)> template <typename ToCheck, std::size_t ExpectedSize, std::size_t RealSize = sizeof(ToCheck)>