The prepare*Array functions now have a third "bool copyBack" parameter which defaults to false and specifies whether the array should be copied from plugin space to core / module space after function execution (=whether the original array should be updated)

This commit is contained in:
Pavol Marko 2004-09-18 13:33:21 +00:00
parent 768ea7519f
commit 34abaa1d56
2 changed files with 45 additions and 33 deletions

View File

@ -128,6 +128,8 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
else if (m_ParamTypes[i] == FP_ARRAY)
{
// copy back
if (preparedArrays[params[i]].copyBack)
{
cell *tmp = physAddrs[i];
if (preparedArrays[params[i]].type == Type_Cell)
{
@ -142,6 +144,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
amx_Release(iter->pPlugin->getAMX(), realParams[i]);
}
}
}
// decide what to do (based on exectype and retval)
switch (m_ExecType)
@ -190,6 +193,7 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
{
if (isFree)
return 0;
const int STRINGEX_MAXLENGTH = 128;
cell realParams[FORWARD_MAX_PARAMS];
@ -258,6 +262,8 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
else if (m_ParamTypes[i] == FP_ARRAY)
{
// copy back
if (preparedArrays[params[i]].copyBack)
{
cell *tmp = physAddrs[i];
if (preparedArrays[params[i]].type == Type_Cell)
{
@ -272,6 +278,7 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
amx_Release(m_Amx, realParams[i]);
}
}
}
return retVal;
}
@ -288,11 +295,12 @@ int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int
int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const ForwardParam *paramTypes)
{
int retVal = (m_SPForwards.size() << 1) | 1;
int retVal = -1;
CSPForward *pForward;
if (!m_FreeSPForwards.empty())
{
pForward = m_SPForwards[m_FreeSPForwards.front() >> 1];
retVal = m_FreeSPForwards.front();
pForward = m_SPForwards[retVal >> 1];
pForward->Set(func, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
return -1;
@ -300,6 +308,7 @@ int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const For
}
else
{
retVal = (m_SPForwards.size() << 1) | 1;
pForward = new CSPForward();
if (!pForward)
return -1;
@ -491,22 +500,23 @@ cell executeForwards(int id, ...)
return g_forwards.executeForwards(id, params);
}
cell CForwardMngr::prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type)
cell CForwardMngr::prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type, bool copyBack)
{
m_TmpArrays[m_TmpArraysNum].ptr = ptr;
m_TmpArrays[m_TmpArraysNum].size = size;
m_TmpArrays[m_TmpArraysNum].type = type;
m_TmpArrays[m_TmpArraysNum].copyBack = copyBack;
return m_TmpArraysNum++;
}
cell prepareCellArray(cell *ptr, unsigned int size)
cell prepareCellArray(cell *ptr, unsigned int size, bool copyBack)
{
return g_forwards.prepareArray((void*)ptr, size, Type_Cell);
return g_forwards.prepareArray((void*)ptr, size, Type_Cell, copyBack);
}
cell prepareCharArray(char *ptr, unsigned int size)
cell prepareCharArray(char *ptr, unsigned int size, bool copyBack)
{
return g_forwards.prepareArray((void*)ptr, size, Type_Char);
return g_forwards.prepareArray((void*)ptr, size, Type_Char, copyBack);
}
void unregisterSPForward(int id)

View File

@ -79,6 +79,7 @@ struct ForwardPreparedArray
void *ptr;
ForwardArrayElemType type;
unsigned int size;
bool copyBack;
};
// Normal forward
@ -185,7 +186,8 @@ public:
int getParamsNum(int id) const; // get num of params of a forward
int getFuncsNum(int id) const; // get num of found functions of a forward
ForwardParam getParamType(int id, int paramId) const;
cell prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type); // prepare array
cell prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type,
bool copyBack); // prepare array
};
// (un)register forward
@ -197,8 +199,8 @@ void unregisterSPForward(int id);
// execute forwards
cell executeForwards(int id, ...);
// prepare array
cell prepareCellArray(cell *ptr, unsigned int size);
cell prepareCharArray(char *ptr, unsigned int size);
cell prepareCellArray(cell *ptr, unsigned int size, bool copyBack = false);
cell prepareCharArray(char *ptr, unsigned int size, bool copyBack = false);
#endif