added implementation to the forward manager
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40191
This commit is contained in:
parent
cda9c6952d
commit
13d61ec39f
core
@ -98,6 +98,10 @@ namespace SourceMod
|
||||
*/
|
||||
class IForward : public ICallable
|
||||
{
|
||||
public:
|
||||
virtual ~IForward()
|
||||
{
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Returns the name of the forward.
|
||||
@ -271,6 +275,13 @@ namespace SourceMod
|
||||
* @return IForward pointer, or NULL if none found matching the name.
|
||||
*/
|
||||
virtual IForward *FindForward(const char *name, IChangeableForward **ifchng) =0;
|
||||
|
||||
/**
|
||||
* @brief Frees and destroys a forward object.
|
||||
*
|
||||
* @param forward An IForward created by CreateForward() or CreateForwardEx().
|
||||
*/
|
||||
virtual void ReleaseForward(IForward *forward) =0;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "ForwardSys.h"
|
||||
#include "PluginSys.h"
|
||||
|
||||
CForwardManager g_Forwards;
|
||||
|
||||
/**
|
||||
* Gensis turns to its source, reduction occurs stepwise although the essence is all one.
|
||||
* End of line. FTL system check.
|
||||
@ -12,7 +14,7 @@
|
||||
* NORMAL FUNCTIONS:
|
||||
* X Push cells
|
||||
* X Push cells byref (copyback tested = yes)
|
||||
* - Push floats (copyback tested = ??)
|
||||
* - Push floats
|
||||
* - Push floats byref (copyback tested = ??)
|
||||
* - Push arrays (copyback tested = ??)
|
||||
* - Push strings (copyback tested = ??)
|
||||
@ -26,6 +28,98 @@
|
||||
* - Push vararg strings (copyback tested = ??)
|
||||
*/
|
||||
|
||||
IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned int num_params, ParamType *types, ...)
|
||||
{
|
||||
CForward *fwd;
|
||||
va_list ap;
|
||||
va_start(ap, types);
|
||||
|
||||
fwd = CForward::CreateForward(name, et, num_params, types, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return fwd;
|
||||
}
|
||||
|
||||
IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType et, int num_params, ParamType *types, ...)
|
||||
{
|
||||
CForward *fwd;
|
||||
va_list ap;
|
||||
va_start(ap, types);
|
||||
|
||||
fwd = CForward::CreateForward(name, et, num_params, types, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return fwd;
|
||||
}
|
||||
|
||||
IForward *CForwardManager::FindForward(const char *name, IChangeableForward **ifchng)
|
||||
{
|
||||
List<CForward *>::iterator iter;
|
||||
CForward *fwd;
|
||||
|
||||
for (iter=m_managed.begin(); iter!=m_managed.end(); iter++)
|
||||
{
|
||||
fwd = (*iter);
|
||||
if (strcmp(fwd->GetForwardName(), name) == 0)
|
||||
{
|
||||
if (ifchng)
|
||||
{
|
||||
*ifchng = NULL;
|
||||
}
|
||||
return fwd;
|
||||
}
|
||||
}
|
||||
|
||||
for (iter=m_unmanaged.begin(); iter!=m_unmanaged.end(); iter++)
|
||||
{
|
||||
fwd = (*iter);
|
||||
if (strcmp(fwd->GetForwardName(), name) == 0)
|
||||
{
|
||||
if (ifchng)
|
||||
{
|
||||
*ifchng = fwd;
|
||||
}
|
||||
return fwd;
|
||||
}
|
||||
}
|
||||
|
||||
if (ifchng)
|
||||
{
|
||||
*ifchng = NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CForwardManager::ReleaseForward(IForward *forward)
|
||||
{
|
||||
ForwardFree(static_cast<CForward *>(forward));
|
||||
}
|
||||
|
||||
void CForwardManager::ForwardFree(CForward *fwd)
|
||||
{
|
||||
m_FreeForwards.push(fwd);
|
||||
}
|
||||
|
||||
CForward *CForwardManager::ForwardMake()
|
||||
{
|
||||
CForward *fwd;
|
||||
if (m_FreeForwards.empty())
|
||||
{
|
||||
fwd = new CForward;
|
||||
} else {
|
||||
fwd = m_FreeForwards.front();
|
||||
m_FreeForwards.pop();
|
||||
}
|
||||
return fwd;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* ACTUAL FORWARD API IMPLEMENTATION *
|
||||
*************************************/
|
||||
|
||||
CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, ParamType *types, va_list ap)
|
||||
{
|
||||
ParamType _types[SP_MAX_EXEC_PARAMS];
|
||||
@ -62,7 +156,7 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CForward *pForward = new CForward;
|
||||
CForward *pForward = g_Forwards.ForwardMake();
|
||||
pForward->m_curparam = 0;
|
||||
pForward->m_ExecType = et;
|
||||
snprintf(pForward->m_name, FORWARDS_NAME_MAX, "%s", name ? name : "");
|
||||
|
@ -81,4 +81,31 @@ protected:
|
||||
int m_errstate;
|
||||
};
|
||||
|
||||
class CForwardManager : public IForwardManager
|
||||
{
|
||||
friend class CForward;
|
||||
public:
|
||||
virtual IForward *CreateForward(const char *name,
|
||||
ExecType et,
|
||||
unsigned int num_params,
|
||||
ParamType *types,
|
||||
...);
|
||||
virtual IChangeableForward *CreateForwardEx(const char *name,
|
||||
ExecType et,
|
||||
int num_params,
|
||||
ParamType *types,
|
||||
...);
|
||||
virtual IForward *FindForward(const char *name, IChangeableForward **ifchng);
|
||||
virtual void ReleaseForward(IForward *forward);
|
||||
protected:
|
||||
CForward *ForwardMake();
|
||||
void ForwardFree(CForward *fwd);
|
||||
private:
|
||||
CStack<CForward *> m_FreeForwards;
|
||||
List<CForward *> m_managed;
|
||||
List<CForward *> m_unmanaged;
|
||||
};
|
||||
|
||||
extern CForwardManager g_Forwards;
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
||||
|
Loading…
Reference in New Issue
Block a user