Remove the forward cache and simplify CForward construction.
This commit is contained in:
parent
dcc192ee0d
commit
632c7d05dd
@ -32,22 +32,13 @@
|
|||||||
#include "DebugReporter.h"
|
#include "DebugReporter.h"
|
||||||
#include "common_logic.h"
|
#include "common_logic.h"
|
||||||
#include <bridge/include/IScriptManager.h>
|
#include <bridge/include/IScriptManager.h>
|
||||||
|
#include <amtl/am-string.h>
|
||||||
|
|
||||||
CForwardManager g_Forwards;
|
CForwardManager g_Forwards;
|
||||||
|
|
||||||
// Genesis turns to its source, reduction occurs stepwise although the essence
|
// Genesis turns to its source, reduction occurs stepwise although the essence
|
||||||
// is all one. End of line. FTL system check.
|
// is all one. End of line. FTL system check.
|
||||||
|
|
||||||
CForwardManager::~CForwardManager()
|
|
||||||
{
|
|
||||||
CStack<CForward *>::iterator iter;
|
|
||||||
for (iter=m_FreeForwards.begin(); iter!=m_FreeForwards.end(); iter++)
|
|
||||||
{
|
|
||||||
delete (*iter);
|
|
||||||
}
|
|
||||||
m_FreeForwards.popall();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CForwardManager::OnSourceModAllInitialized()
|
void CForwardManager::OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
scripts->AddPluginsListener(this);
|
scripts->AddPluginsListener(this);
|
||||||
@ -166,34 +157,12 @@ IForward *CForwardManager::FindForward(const char *name, IChangeableForward **if
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CForwardManager::ReleaseForward(IForward *forward)
|
void CForwardManager::ReleaseForward(IForward *aForward)
|
||||||
{
|
{
|
||||||
ForwardFree(static_cast<CForward *>(forward));
|
CForward *fwd = static_cast<CForward *>(aForward);
|
||||||
}
|
|
||||||
|
|
||||||
void CForwardManager::ForwardFree(CForward *fwd)
|
|
||||||
{
|
|
||||||
if (fwd == NULL)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_FreeForwards.push(fwd);
|
|
||||||
m_managed.remove(fwd);
|
m_managed.remove(fwd);
|
||||||
m_unmanaged.remove(fwd);
|
m_unmanaged.remove(fwd);
|
||||||
}
|
delete fwd;
|
||||||
|
|
||||||
CForward *CForwardManager::ForwardMake()
|
|
||||||
{
|
|
||||||
CForward *fwd;
|
|
||||||
if (m_FreeForwards.empty())
|
|
||||||
{
|
|
||||||
fwd = new CForward;
|
|
||||||
} else {
|
|
||||||
fwd = m_FreeForwards.front();
|
|
||||||
m_FreeForwards.pop();
|
|
||||||
}
|
|
||||||
return fwd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
|
void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
|
||||||
@ -221,6 +190,28 @@ void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
|
|||||||
* ACTUAL FORWARD API IMPLEMENTATION *
|
* ACTUAL FORWARD API IMPLEMENTATION *
|
||||||
*************************************/
|
*************************************/
|
||||||
|
|
||||||
|
CForward::CForward(ExecType et, const char *name, const ParamType *types, unsigned num_params)
|
||||||
|
: m_IterGuard(nullptr),
|
||||||
|
m_numparams(0),
|
||||||
|
m_varargs(0),
|
||||||
|
m_ExecType(et),
|
||||||
|
m_curparam(0),
|
||||||
|
m_errstate(SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
ke::SafeStrcpy(m_name, sizeof(m_name), name ? name : "");
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < num_params; i++)
|
||||||
|
m_types[i] = types[i];
|
||||||
|
|
||||||
|
if (num_params && types[num_params - 1] == Param_VarArgs) {
|
||||||
|
m_varargs = num_params;
|
||||||
|
m_numparams = num_params - 1;
|
||||||
|
} else {
|
||||||
|
m_varargs = 0;
|
||||||
|
m_numparams = num_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, va_list ap)
|
CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, const ParamType *types, va_list ap)
|
||||||
{
|
{
|
||||||
ParamType _types[SP_MAX_EXEC_PARAMS];
|
ParamType _types[SP_MAX_EXEC_PARAMS];
|
||||||
@ -258,30 +249,7 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CForward *pForward = g_Forwards.ForwardMake();
|
return new CForward(et, name, _types, num_params);
|
||||||
pForward->m_IterGuard = NULL;
|
|
||||||
pForward->m_curparam = 0;
|
|
||||||
pForward->m_ExecType = et;
|
|
||||||
snprintf(pForward->m_name, FORWARDS_NAME_MAX, "%s", name ? name : "");
|
|
||||||
|
|
||||||
for (unsigned int i=0; i<num_params; i++)
|
|
||||||
{
|
|
||||||
pForward->m_types[i] = _types[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num_params && _types[num_params-1] == Param_VarArgs)
|
|
||||||
{
|
|
||||||
pForward->m_varargs = num_params--;
|
|
||||||
} else {
|
|
||||||
pForward->m_varargs = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pForward->m_numparams = num_params;
|
|
||||||
pForward->m_errstate = SP_ERROR_NONE;
|
|
||||||
|
|
||||||
pForward->m_functions.clear();
|
|
||||||
|
|
||||||
return pForward;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <IPluginSys.h>
|
#include <IPluginSys.h>
|
||||||
#include "common_logic.h"
|
#include "common_logic.h"
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_stack.h>
|
|
||||||
#include "ISourceMod.h"
|
#include "ISourceMod.h"
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
@ -116,6 +115,9 @@ public:
|
|||||||
va_list ap);
|
va_list ap);
|
||||||
bool IsFunctionRegistered(IPluginFunction *func);
|
bool IsFunctionRegistered(IPluginFunction *func);
|
||||||
private:
|
private:
|
||||||
|
CForward(ExecType et, const char *name,
|
||||||
|
const ParamType *types, unsigned num_params);
|
||||||
|
|
||||||
void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
|
void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
|
||||||
void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
|
void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
|
||||||
inline int SetError(int err)
|
inline int SetError(int err)
|
||||||
@ -150,8 +152,6 @@ class CForwardManager :
|
|||||||
public SMGlobalClass
|
public SMGlobalClass
|
||||||
{
|
{
|
||||||
friend class CForward;
|
friend class CForward;
|
||||||
public:
|
|
||||||
~CForwardManager();
|
|
||||||
public: //IForwardManager
|
public: //IForwardManager
|
||||||
IForward *CreateForward(const char *name,
|
IForward *CreateForward(const char *name,
|
||||||
ExecType et,
|
ExecType et,
|
||||||
@ -171,11 +171,7 @@ public: //IPluginsListener
|
|||||||
void OnPluginPauseChange(IPlugin *plugin, bool paused);
|
void OnPluginPauseChange(IPlugin *plugin, bool paused);
|
||||||
public: //SMGlobalClass
|
public: //SMGlobalClass
|
||||||
void OnSourceModAllInitialized();
|
void OnSourceModAllInitialized();
|
||||||
protected:
|
|
||||||
CForward *ForwardMake();
|
|
||||||
void ForwardFree(CForward *fwd);
|
|
||||||
private:
|
private:
|
||||||
CStack<CForward *> m_FreeForwards;
|
|
||||||
List<CForward *> m_managed;
|
List<CForward *> m_managed;
|
||||||
List<CForward *> m_unmanaged;
|
List<CForward *> m_unmanaged;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user