mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 12:06:07 +08:00
Fix randomish issues with command callbacks.
Also implemented ctors for remaining variants.
This commit is contained in:
@ -296,6 +296,10 @@ public:
|
||||
|
||||
ConCommand( const char *pName, FnCommandCallback_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
||||
ConCommand(const char *pName, FnCommandCallbackV1_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0);
|
||||
ConCommand(const char *pName, FnCommandCallbackV2_t callback,
|
||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0);
|
||||
ConCommand( const char *pName, ICommandCallback *pCallback,
|
||||
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
|
||||
|
||||
@ -321,8 +325,6 @@ private:
|
||||
|
||||
union
|
||||
{
|
||||
FnCommandCallbackV1_t m_fnCommandCallbackV1;
|
||||
FnCommandCallbackV2_t m_fnCommandCallbackV2;
|
||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||
ICommandCompletionCallback *m_pCommandCompletionCallback;
|
||||
};
|
||||
@ -335,13 +337,16 @@ private:
|
||||
// Call this function when executing the command
|
||||
union
|
||||
{
|
||||
void *m_fnCallbackAny;
|
||||
FnCommandCallback_t m_fnCommandCallback;
|
||||
FnCommandCallbackV1_t m_fnCommandCallbackV1;
|
||||
FnCommandCallbackV2_t m_fnCommandCallbackV2;
|
||||
ICommandCallback *m_pCommandCallback;
|
||||
};
|
||||
|
||||
bool m_bUsingCommandCallbackInterface : 1;
|
||||
bool m_bUsingOldCommandCallback : 1;
|
||||
bool m_bUsingV1CommandCallback : 1;
|
||||
bool m_bUsingV2CommandCallback : 1;
|
||||
};
|
||||
CUtlVector<ConCommandCB> m_Callbacks;
|
||||
|
111
tier1/convar.cpp
111
tier1/convar.cpp
@ -514,12 +514,17 @@ int DefaultCompletionFunc( const char *partial, CUtlVector< CUtlString > &comman
|
||||
|
||||
ConCommand::ConCommand( const char *pName, FnCommandCallback_t callback, const char *pHelpString /*= 0*/, int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/ )
|
||||
{
|
||||
// Set the callback
|
||||
ConCommandCB cb;
|
||||
cb.m_fnCommandCallback = callback;
|
||||
cb.m_bUsingOldCommandCallback = false;
|
||||
cb.m_bUsingCommandCallbackInterface = false;
|
||||
m_Callbacks.AddToTail(cb);
|
||||
// Add the callback
|
||||
if (callback)
|
||||
{
|
||||
ConCommandCB cb;
|
||||
cb.m_fnCommandCallback = callback;
|
||||
cb.m_bUsingOldCommandCallback = true;
|
||||
cb.m_bUsingV1CommandCallback = false;
|
||||
cb.m_bUsingV2CommandCallback = false;
|
||||
cb.m_bUsingCommandCallbackInterface = false;
|
||||
m_Callbacks.AddToTail(cb);
|
||||
}
|
||||
|
||||
m_fnCompletionCallback = completionFunc ? completionFunc : DefaultCompletionFunc;
|
||||
m_bHasCompletionCallback = completionFunc != 0 ? true : false;
|
||||
@ -531,14 +536,67 @@ ConCommand::ConCommand( const char *pName, FnCommandCallback_t callback, const c
|
||||
BaseClass::Create( pName, pHelpString, flags );
|
||||
}
|
||||
|
||||
ConCommand::ConCommand(const char *pName, FnCommandCallbackV1_t callback, const char *pHelpString /*= 0*/, int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/)
|
||||
{
|
||||
// Add the callback
|
||||
if (callback)
|
||||
{
|
||||
ConCommandCB cb;
|
||||
cb.m_fnCommandCallbackV1 = callback;
|
||||
cb.m_bUsingOldCommandCallback = false;
|
||||
cb.m_bUsingV1CommandCallback = true;
|
||||
cb.m_bUsingV2CommandCallback = false;
|
||||
cb.m_bUsingCommandCallbackInterface = false;
|
||||
m_Callbacks.AddToTail(cb);
|
||||
}
|
||||
|
||||
m_fnCompletionCallback = completionFunc ? completionFunc : DefaultCompletionFunc;
|
||||
m_bHasCompletionCallback = completionFunc != 0 ? true : false;
|
||||
m_bUsingCommandCompletionInterface = false;
|
||||
|
||||
m_pParent = this;
|
||||
|
||||
// Setup the rest
|
||||
BaseClass::Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
ConCommand::ConCommand(const char *pName, FnCommandCallbackV2_t callback, const char *pHelpString /*= 0*/, int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/)
|
||||
{
|
||||
// Add the callback
|
||||
if (callback)
|
||||
{
|
||||
ConCommandCB cb;
|
||||
cb.m_fnCommandCallbackV2 = callback;
|
||||
cb.m_bUsingOldCommandCallback = false;
|
||||
cb.m_bUsingV1CommandCallback = false;
|
||||
cb.m_bUsingV2CommandCallback = true;
|
||||
cb.m_bUsingCommandCallbackInterface = false;
|
||||
m_Callbacks.AddToTail(cb);
|
||||
}
|
||||
|
||||
m_fnCompletionCallback = completionFunc ? completionFunc : DefaultCompletionFunc;
|
||||
m_bHasCompletionCallback = completionFunc != 0 ? true : false;
|
||||
m_bUsingCommandCompletionInterface = false;
|
||||
|
||||
m_pParent = this;
|
||||
|
||||
// Setup the rest
|
||||
BaseClass::Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
ConCommand::ConCommand( const char *pName, ICommandCallback *pCallback, const char *pHelpString /*= 0*/, int flags /*= 0*/, ICommandCompletionCallback *pCompletionCallback /*= 0*/ )
|
||||
{
|
||||
// Set the callback
|
||||
ConCommandCB cb;
|
||||
cb.m_pCommandCallback = pCallback;
|
||||
cb.m_bUsingOldCommandCallback = false;
|
||||
cb.m_bUsingCommandCallbackInterface = true;
|
||||
m_Callbacks.AddToTail(cb);
|
||||
// Add the callback iface
|
||||
if (pCallback)
|
||||
{
|
||||
ConCommandCB cb;
|
||||
cb.m_pCommandCallback = pCallback;
|
||||
cb.m_bUsingOldCommandCallback = false;
|
||||
cb.m_bUsingV1CommandCallback = false;
|
||||
cb.m_bUsingV2CommandCallback = false;
|
||||
cb.m_bUsingCommandCallbackInterface = true;
|
||||
m_Callbacks.AddToTail(cb);
|
||||
}
|
||||
|
||||
m_pCommandCompletionCallback = pCompletionCallback;
|
||||
m_bHasCompletionCallback = ( pCompletionCallback != 0 );
|
||||
@ -575,37 +633,28 @@ void ConCommand::Dispatch( const CCommandContext &context, const CCommand &comma
|
||||
FOR_EACH_VEC(m_Callbacks, i)
|
||||
{
|
||||
ConCommandCB cb = m_Callbacks[i];
|
||||
if (cb.m_bUsingOldCommandCallback)
|
||||
if (cb.m_fnCallbackAny)
|
||||
{
|
||||
if (m_fnCommandCallbackV1)
|
||||
if (cb.m_bUsingOldCommandCallback)
|
||||
{
|
||||
(*m_fnCommandCallbackV1)(context);
|
||||
(*cb.m_fnCommandCallback)(command);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (cb.m_bUsingCommandCallbackInterface)
|
||||
{
|
||||
if (cb.m_pCommandCallback)
|
||||
else if (cb.m_bUsingCommandCallbackInterface)
|
||||
{
|
||||
cb.m_pCommandCallback->CommandCallback(context, command);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (cb.m_bUsingV2CommandCallback)
|
||||
{
|
||||
if (cb.m_bUsingV2CommandCallback)
|
||||
else if (cb.m_bUsingV1CommandCallback)
|
||||
{
|
||||
(*cb.m_fnCommandCallbackV1)(context);
|
||||
return;
|
||||
}
|
||||
else if (cb.m_bUsingV2CommandCallback)
|
||||
{
|
||||
cb.m_fnCommandCallbackV2(context, command);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cb.m_fnCommandCallback)
|
||||
{
|
||||
(*cb.m_fnCommandCallback)(command);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Command without callback!!!
|
||||
AssertMsg(0, ("Encountered ConCommand without a callback!\n"));
|
||||
|
Reference in New Issue
Block a user