core/systems/ForwardSys.cpp
changeset 186 eebc5de63141
parent 183 78488edd8873
child 187 b93ea22fafe4
     1.1 --- a/core/systems/ForwardSys.cpp	Mon Nov 13 13:55:44 2006 +0000
     1.2 +++ b/core/systems/ForwardSys.cpp	Tue Nov 14 08:45:21 2006 +0000
     1.3 @@ -2,6 +2,8 @@
     1.4  #include "ForwardSys.h"
     1.5  #include "PluginSys.h"
     1.6  
     1.7 +CForwardManager g_Forwards;
     1.8 +
     1.9  /**
    1.10   * Gensis turns to its source, reduction occurs stepwise although the essence is all one.
    1.11   * End of line.  FTL system check.
    1.12 @@ -12,7 +14,7 @@
    1.13   * NORMAL FUNCTIONS:
    1.14   * X Push cells
    1.15   * X Push cells byref (copyback tested = yes)
    1.16 - * - Push floats (copyback tested = ??)
    1.17 + * - Push floats
    1.18   * - Push floats byref (copyback tested = ??)
    1.19   * - Push arrays  (copyback tested = ??)
    1.20   * - Push strings (copyback tested = ??)
    1.21 @@ -26,6 +28,98 @@
    1.22   * - Push vararg strings (copyback tested = ??)
    1.23   */
    1.24  
    1.25 +IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned int num_params, ParamType *types, ...)
    1.26 +{
    1.27 +	CForward *fwd;
    1.28 +	va_list ap;
    1.29 +	va_start(ap, types);
    1.30 +	
    1.31 +	fwd = CForward::CreateForward(name, et, num_params, types, ap);
    1.32 +
    1.33 +	va_end(ap);
    1.34 +
    1.35 +	return fwd;
    1.36 +}
    1.37 +
    1.38 +IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType et, int num_params, ParamType *types, ...)
    1.39 +{
    1.40 +	CForward *fwd;
    1.41 +	va_list ap;
    1.42 +	va_start(ap, types);
    1.43 +
    1.44 +	fwd = CForward::CreateForward(name, et, num_params, types, ap);
    1.45 +
    1.46 +	va_end(ap);
    1.47 +
    1.48 +	return fwd;
    1.49 +}
    1.50 +
    1.51 +IForward *CForwardManager::FindForward(const char *name, IChangeableForward **ifchng)
    1.52 +{
    1.53 +	List<CForward *>::iterator iter;
    1.54 +	CForward *fwd;
    1.55 +
    1.56 +	for (iter=m_managed.begin(); iter!=m_managed.end(); iter++)
    1.57 +	{
    1.58 +		fwd = (*iter);
    1.59 +		if (strcmp(fwd->GetForwardName(), name) == 0)
    1.60 +		{
    1.61 +			if (ifchng)
    1.62 +			{
    1.63 +				*ifchng = NULL;
    1.64 +			}
    1.65 +			return fwd;
    1.66 +		}
    1.67 +	}
    1.68 +
    1.69 +	for (iter=m_unmanaged.begin(); iter!=m_unmanaged.end(); iter++)
    1.70 +	{
    1.71 +		fwd = (*iter);
    1.72 +		if (strcmp(fwd->GetForwardName(), name) == 0)
    1.73 +		{
    1.74 +			if (ifchng)
    1.75 +			{
    1.76 +				*ifchng = fwd;
    1.77 +			}
    1.78 +			return fwd;
    1.79 +		}
    1.80 +	}
    1.81 +
    1.82 +	if (ifchng)
    1.83 +	{
    1.84 +		*ifchng = NULL;
    1.85 +	}
    1.86 +
    1.87 +	return NULL;
    1.88 +}
    1.89 +
    1.90 +void CForwardManager::ReleaseForward(IForward *forward)
    1.91 +{
    1.92 +	ForwardFree(static_cast<CForward *>(forward));
    1.93 +}
    1.94 +
    1.95 +void CForwardManager::ForwardFree(CForward *fwd)
    1.96 +{
    1.97 +	m_FreeForwards.push(fwd);
    1.98 +}
    1.99 +
   1.100 +CForward *CForwardManager::ForwardMake()
   1.101 +{
   1.102 +	CForward *fwd;
   1.103 +	if (m_FreeForwards.empty())
   1.104 +	{
   1.105 +		fwd = new CForward;
   1.106 +	} else {
   1.107 +		fwd = m_FreeForwards.front();
   1.108 +		m_FreeForwards.pop();
   1.109 +	}
   1.110 +	return fwd;
   1.111 +}
   1.112 +
   1.113 +/*************************************
   1.114 + * ACTUAL FORWARD API IMPLEMENTATION *
   1.115 + *************************************/
   1.116 +
   1.117  CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int num_params, ParamType *types, va_list ap)
   1.118  {
   1.119  	ParamType _types[SP_MAX_EXEC_PARAMS];
   1.120 @@ -62,7 +156,7 @@
   1.121  		return NULL;
   1.122  	}
   1.123  
   1.124 -	CForward *pForward = new CForward;
   1.125 +	CForward *pForward = g_Forwards.ForwardMake();
   1.126  	pForward->m_curparam = 0;
   1.127  	pForward->m_ExecType = et;
   1.128  	snprintf(pForward->m_name, FORWARDS_NAME_MAX, "%s", name ? name : "");