Remove the forward cache and simplify CForward construction.

This commit is contained in:
David Anderson 2015-09-17 19:54:39 -07:00
parent dcc192ee0d
commit 632c7d05dd
2 changed files with 30 additions and 66 deletions

View File

@ -32,22 +32,13 @@
#include "DebugReporter.h"
#include "common_logic.h"
#include <bridge/include/IScriptManager.h>
#include <amtl/am-string.h>
CForwardManager g_Forwards;
// Genesis turns to its source, reduction occurs stepwise although the essence
// 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()
{
scripts->AddPluginsListener(this);
@ -166,34 +157,12 @@ IForward *CForwardManager::FindForward(const char *name, IChangeableForward **if
return NULL;
}
void CForwardManager::ReleaseForward(IForward *forward)
void CForwardManager::ReleaseForward(IForward *aForward)
{
ForwardFree(static_cast<CForward *>(forward));
}
void CForwardManager::ForwardFree(CForward *fwd)
{
if (fwd == NULL)
{
return;
}
m_FreeForwards.push(fwd);
CForward *fwd = static_cast<CForward *>(aForward);
m_managed.remove(fwd);
m_unmanaged.remove(fwd);
}
CForward *CForwardManager::ForwardMake()
{
CForward *fwd;
if (m_FreeForwards.empty())
{
fwd = new CForward;
} else {
fwd = m_FreeForwards.front();
m_FreeForwards.pop();
}
return fwd;
delete fwd;
}
void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
@ -221,6 +190,28 @@ void CForwardManager::OnPluginPauseChange(IPlugin *plugin, bool paused)
* 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)
{
ParamType _types[SP_MAX_EXEC_PARAMS];
@ -258,30 +249,7 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu
return NULL;
}
CForward *pForward = g_Forwards.ForwardMake();
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;
return new CForward(et, name, _types, num_params);
}
int CForward::Execute(cell_t *result, IForwardFilter *filter)

View File

@ -32,7 +32,6 @@
#include <IPluginSys.h>
#include "common_logic.h"
#include <sh_list.h>
#include <sh_stack.h>
#include "ISourceMod.h"
using namespace SourceHook;
@ -116,6 +115,9 @@ public:
va_list ap);
bool IsFunctionRegistered(IPluginFunction *func);
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_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
inline int SetError(int err)
@ -150,8 +152,6 @@ class CForwardManager :
public SMGlobalClass
{
friend class CForward;
public:
~CForwardManager();
public: //IForwardManager
IForward *CreateForward(const char *name,
ExecType et,
@ -171,11 +171,7 @@ public: //IPluginsListener
void OnPluginPauseChange(IPlugin *plugin, bool paused);
public: //SMGlobalClass
void OnSourceModAllInitialized();
protected:
CForward *ForwardMake();
void ForwardFree(CForward *fwd);
private:
CStack<CForward *> m_FreeForwards;
List<CForward *> m_managed;
List<CForward *> m_unmanaged;
};