added amb1383 - data value to filter functions

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401861
This commit is contained in:
David Anderson 2008-01-22 17:18:15 +00:00
parent f50509abf0
commit 38012bf3e6
2 changed files with 99 additions and 46 deletions

View File

@ -41,16 +41,19 @@ public:
edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity));
m_pFunc->PushCell(engine->IndexOfEdict(pEdict));
m_pFunc->PushCell(contentsMask);
m_pFunc->PushCell(m_Data);
m_pFunc->Execute(&res);
return (res) ? true : false;
}
void SetFunctionPtr(IPluginFunction *pFunc)
void SetFunctionPtr(IPluginFunction *pFunc, cell_t data)
{
m_pFunc = pFunc;
m_Data = data;
}
private:
IPluginFunction *m_pFunc;
cell_t m_Data;
};
/* Used for the global trace version */
@ -105,13 +108,24 @@ static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *param
{
cell_t *startaddr, *endaddr;
IPluginFunction *pFunc;
cell_t data;
pFunc = pContext->GetFunctionById(params[5]);
if (!pFunc)
{
return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
}
g_SMTraceFilter.SetFunctionPtr(pFunc);
if (params[0] >= 6)
{
data = params[6];
}
else
{
data = 0;
}
g_SMTraceFilter.SetFunctionPtr(pFunc, data);
pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr);
@ -192,6 +206,7 @@ static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *par
{
IPluginFunction *pFunc;
cell_t *startaddr, *endaddr;
cell_t data;
pFunc = pContext->GetFunctionById(params[5]);
if (!pFunc)
@ -205,7 +220,16 @@ static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *par
CSMTraceFilter smfilter;
Ray_t ray;
smfilter.SetFunctionPtr(pFunc);
if (params[0] >= 6)
{
data = params[6];
}
else
{
data = 0;
}
smfilter.SetFunctionPtr(pFunc, data);
StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
switch (params[4])

View File

@ -110,14 +110,27 @@ enum RayType
RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */
};
/**
funcenum TraceEntityFilter
{
/**
* Called on entity filtering.
*
* @param entity Entity index.
* @param contentsMask Contents Mask.
* @return True to allow the current entity to be hit, otherwise false.
*/
functag TraceEntityFilter bool:public(entity, contentsMask);
bool:public(entity, contentsMask),
/**
* Called on entity filtering.
*
* @param entity Entity index.
* @param contentsMask Contents Mask.
* @param data Data value, if used.
* @return True to allow the current entity to be hit, otherwise false.
*/
bool:public(entity, contentsMask, any:data),
};
/**
* Get the contents mask and the entity index at the given position.
@ -151,14 +164,23 @@ native TR_TraceRay(const Float:pos[3], const Float:vec[3], flags, RayType:rtype)
/**
* Starts up a new trace ray using a global trace result and a customized trace ray filter.
*
* Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
* currently not allowed and may not work.
*
* @param pos Starting position of the ray.
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags.
* @param rtype Method to calculate the ray direction.
* @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter function.
* @noreturn
*/
native TR_TraceRayFilter(const Float:pos[3], const Float:vec[3], flags, RayType:rtype, TraceEntityFilter:filter);
native TR_TraceRayFilter(const Float:pos[3],
const Float:vec[3],
flags,
RayType:rtype,
TraceEntityFilter:filter,
any:data=0);
/**
* Starts up a new trace ray using a new trace result.
@ -167,23 +189,30 @@ native TR_TraceRayFilter(const Float:pos[3], const Float:vec[3], flags, RayType:
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags.
* @param rtype Method to calculate the ray direction.
* @return Ray trace handle.
* @note Traces are closed with CloseHandle().
* @return Ray trace handle, which must be closed via CloseHandle().
*/
native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
/**
* Starts up a new trace ray using a new trace result and a customized trace ray filter.
*
* Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
* currently not allowed and may not work.
*
* @param pos Starting position of the ray.
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags.
* @param rtype Method to calculate the ray direction.
* @param filter Function to use as a filter.
* @return Ray trace handle.
* @note Traces are closed with CloseHandle().
* @param data Arbitrary data value to pass through to the filter function.
* @return Ray trace handle, which must be closed via CloseHandle().
*/
native Handle:TR_TraceRayFilterEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype, TraceEntityFilter:filter);
native Handle:TR_TraceRayFilterEx(const Float:pos[3],
const Float:vec[3],
flags,
RayType:rtype,
TraceEntityFilter:filter,
any:data=0);
/**
* Returns the time fraction from a trace result (1.0 means no collision).