mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 20:16:10 +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,
|
ConCommand( const char *pName, FnCommandCallback_t callback,
|
||||||
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
|
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,
|
ConCommand( const char *pName, ICommandCallback *pCallback,
|
||||||
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
|
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
|
||||||
|
|
||||||
@ -321,8 +325,6 @@ private:
|
|||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
FnCommandCallbackV1_t m_fnCommandCallbackV1;
|
|
||||||
FnCommandCallbackV2_t m_fnCommandCallbackV2;
|
|
||||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||||
ICommandCompletionCallback *m_pCommandCompletionCallback;
|
ICommandCompletionCallback *m_pCommandCompletionCallback;
|
||||||
};
|
};
|
||||||
@ -335,13 +337,16 @@ private:
|
|||||||
// Call this function when executing the command
|
// Call this function when executing the command
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
void *m_fnCallbackAny;
|
||||||
FnCommandCallback_t m_fnCommandCallback;
|
FnCommandCallback_t m_fnCommandCallback;
|
||||||
|
FnCommandCallbackV1_t m_fnCommandCallbackV1;
|
||||||
FnCommandCallbackV2_t m_fnCommandCallbackV2;
|
FnCommandCallbackV2_t m_fnCommandCallbackV2;
|
||||||
ICommandCallback *m_pCommandCallback;
|
ICommandCallback *m_pCommandCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool m_bUsingCommandCallbackInterface : 1;
|
bool m_bUsingCommandCallbackInterface : 1;
|
||||||
bool m_bUsingOldCommandCallback : 1;
|
bool m_bUsingOldCommandCallback : 1;
|
||||||
|
bool m_bUsingV1CommandCallback : 1;
|
||||||
bool m_bUsingV2CommandCallback : 1;
|
bool m_bUsingV2CommandCallback : 1;
|
||||||
};
|
};
|
||||||
CUtlVector<ConCommandCB> m_Callbacks;
|
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*/ )
|
ConCommand::ConCommand( const char *pName, FnCommandCallback_t callback, const char *pHelpString /*= 0*/, int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/ )
|
||||||
{
|
{
|
||||||
// Set the callback
|
// Add the callback
|
||||||
ConCommandCB cb;
|
if (callback)
|
||||||
cb.m_fnCommandCallback = callback;
|
{
|
||||||
cb.m_bUsingOldCommandCallback = false;
|
ConCommandCB cb;
|
||||||
cb.m_bUsingCommandCallbackInterface = false;
|
cb.m_fnCommandCallback = callback;
|
||||||
m_Callbacks.AddToTail(cb);
|
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_fnCompletionCallback = completionFunc ? completionFunc : DefaultCompletionFunc;
|
||||||
m_bHasCompletionCallback = completionFunc != 0 ? true : false;
|
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 );
|
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*/ )
|
ConCommand::ConCommand( const char *pName, ICommandCallback *pCallback, const char *pHelpString /*= 0*/, int flags /*= 0*/, ICommandCompletionCallback *pCompletionCallback /*= 0*/ )
|
||||||
{
|
{
|
||||||
// Set the callback
|
// Add the callback iface
|
||||||
ConCommandCB cb;
|
if (pCallback)
|
||||||
cb.m_pCommandCallback = pCallback;
|
{
|
||||||
cb.m_bUsingOldCommandCallback = false;
|
ConCommandCB cb;
|
||||||
cb.m_bUsingCommandCallbackInterface = true;
|
cb.m_pCommandCallback = pCallback;
|
||||||
m_Callbacks.AddToTail(cb);
|
cb.m_bUsingOldCommandCallback = false;
|
||||||
|
cb.m_bUsingV1CommandCallback = false;
|
||||||
|
cb.m_bUsingV2CommandCallback = false;
|
||||||
|
cb.m_bUsingCommandCallbackInterface = true;
|
||||||
|
m_Callbacks.AddToTail(cb);
|
||||||
|
}
|
||||||
|
|
||||||
m_pCommandCompletionCallback = pCompletionCallback;
|
m_pCommandCompletionCallback = pCompletionCallback;
|
||||||
m_bHasCompletionCallback = ( pCompletionCallback != 0 );
|
m_bHasCompletionCallback = ( pCompletionCallback != 0 );
|
||||||
@ -575,37 +633,28 @@ void ConCommand::Dispatch( const CCommandContext &context, const CCommand &comma
|
|||||||
FOR_EACH_VEC(m_Callbacks, i)
|
FOR_EACH_VEC(m_Callbacks, i)
|
||||||
{
|
{
|
||||||
ConCommandCB cb = 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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
else if (cb.m_bUsingCommandCallbackInterface)
|
||||||
else if (cb.m_bUsingCommandCallbackInterface)
|
|
||||||
{
|
|
||||||
if (cb.m_pCommandCallback)
|
|
||||||
{
|
{
|
||||||
cb.m_pCommandCallback->CommandCallback(context, command);
|
cb.m_pCommandCallback->CommandCallback(context, command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
else if (cb.m_bUsingV1CommandCallback)
|
||||||
else if (cb.m_bUsingV2CommandCallback)
|
{
|
||||||
{
|
(*cb.m_fnCommandCallbackV1)(context);
|
||||||
if (cb.m_bUsingV2CommandCallback)
|
return;
|
||||||
|
}
|
||||||
|
else if (cb.m_bUsingV2CommandCallback)
|
||||||
{
|
{
|
||||||
cb.m_fnCommandCallbackV2(context, command);
|
cb.m_fnCommandCallbackV2(context, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (cb.m_fnCommandCallback)
|
|
||||||
{
|
|
||||||
(*cb.m_fnCommandCallback)(command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command without callback!!!
|
// Command without callback!!!
|
||||||
AssertMsg(0, ("Encountered ConCommand without a callback!\n"));
|
AssertMsg(0, ("Encountered ConCommand without a callback!\n"));
|
||||||
|
Reference in New Issue
Block a user