added amb1383 - data value to filter functions
authorDavid Anderson <dvander@alliedmods.net>
Tue Jan 22 17:18:15 2008 +0000 (2008-01-22)
changeset 18557871fb255eb5
parent 1854 91f2e0437e12
child 1856 4e4cff94766a
added amb1383 - data value to filter functions
extensions/sdktools/trnatives.cpp
plugins/include/sdktools_trace.inc
     1.1 --- a/extensions/sdktools/trnatives.cpp	Tue Jan 22 17:04:59 2008 +0000
     1.2 +++ b/extensions/sdktools/trnatives.cpp	Tue Jan 22 17:18:15 2008 +0000
     1.3 @@ -41,16 +41,19 @@
     1.4  		edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity));
     1.5  		m_pFunc->PushCell(engine->IndexOfEdict(pEdict));
     1.6  		m_pFunc->PushCell(contentsMask);
     1.7 +		m_pFunc->PushCell(m_Data);
     1.8  		m_pFunc->Execute(&res);
     1.9  
    1.10  		return (res) ? true : false;
    1.11  	}
    1.12 -	void SetFunctionPtr(IPluginFunction *pFunc)
    1.13 +	void SetFunctionPtr(IPluginFunction *pFunc, cell_t data)
    1.14  	{
    1.15  		m_pFunc = pFunc;
    1.16 +		m_Data = data;
    1.17  	}
    1.18  private:
    1.19  	IPluginFunction *m_pFunc;
    1.20 +	cell_t m_Data;
    1.21  };
    1.22  
    1.23  /* Used for the global trace version */
    1.24 @@ -105,13 +108,24 @@
    1.25  {
    1.26  	cell_t *startaddr, *endaddr;
    1.27  	IPluginFunction *pFunc;
    1.28 +	cell_t data;
    1.29  
    1.30  	pFunc = pContext->GetFunctionById(params[5]);
    1.31  	if (!pFunc)
    1.32  	{
    1.33  		return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
    1.34  	}
    1.35 -	g_SMTraceFilter.SetFunctionPtr(pFunc);
    1.36 +
    1.37 +	if (params[0] >= 6)
    1.38 +	{
    1.39 +		data = params[6];
    1.40 +	}
    1.41 +	else
    1.42 +	{
    1.43 +		data = 0;
    1.44 +	}
    1.45 +
    1.46 +	g_SMTraceFilter.SetFunctionPtr(pFunc, data);
    1.47  	pContext->LocalToPhysAddr(params[1], &startaddr);
    1.48  	pContext->LocalToPhysAddr(params[2], &endaddr);
    1.49  
    1.50 @@ -192,6 +206,7 @@
    1.51  {
    1.52  	IPluginFunction *pFunc;
    1.53  	cell_t *startaddr, *endaddr;
    1.54 +	cell_t data;
    1.55  
    1.56  	pFunc = pContext->GetFunctionById(params[5]);
    1.57  	if (!pFunc)
    1.58 @@ -205,7 +220,16 @@
    1.59  	CSMTraceFilter smfilter;
    1.60  	Ray_t ray;
    1.61  
    1.62 -	smfilter.SetFunctionPtr(pFunc);
    1.63 +	if (params[0] >= 6)
    1.64 +	{
    1.65 +		data = params[6];
    1.66 +	}
    1.67 +	else
    1.68 +	{
    1.69 +		data = 0;
    1.70 +	}
    1.71 +
    1.72 +	smfilter.SetFunctionPtr(pFunc, data);
    1.73  	StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
    1.74  
    1.75  	switch (params[4])
     2.1 --- a/plugins/include/sdktools_trace.inc	Tue Jan 22 17:04:59 2008 +0000
     2.2 +++ b/plugins/include/sdktools_trace.inc	Tue Jan 22 17:18:15 2008 +0000
     2.3 @@ -44,9 +44,9 @@
     2.4  #define	CONTENTS_WATER			0x20
     2.5  #define	CONTENTS_MIST			0x40
     2.6  #define CONTENTS_OPAQUE			0x80		/**< things that cannot be seen through (may be non-solid though). */
     2.7 -#define	LAST_VISIBLE_CONTENTS		0x80
     2.8 -#define ALL_VISIBLE_CONTENTS 		(LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
     2.9 -#define CONTENTS_TESTFOGVOLUME		0x100
    2.10 +#define	LAST_VISIBLE_CONTENTS	0x80
    2.11 +#define ALL_VISIBLE_CONTENTS 	(LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
    2.12 +#define CONTENTS_TESTFOGVOLUME	0x100
    2.13  #define CONTENTS_UNUSED5		0x200
    2.14  #define CONTENTS_UNUSED6		0x4000
    2.15  #define CONTENTS_TEAM1			0x800		/**< per team contents used to differentiate collisions. */
    2.16 @@ -55,17 +55,17 @@
    2.17  #define CONTENTS_MOVEABLE		0x4000		/**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */
    2.18  #define	CONTENTS_AREAPORTAL		0x8000		/**< remaining contents are non-visible, and don't eat brushes. */
    2.19  #define	CONTENTS_PLAYERCLIP		0x10000
    2.20 -#define	CONTENTS_MONSTERCLIP		0x20000
    2.21 +#define	CONTENTS_MONSTERCLIP	0x20000
    2.22  
    2.23  /**
    2.24   * @section currents can be added to any other contents, and may be mixed
    2.25   */
    2.26  #define	CONTENTS_CURRENT_0		0x40000
    2.27  #define	CONTENTS_CURRENT_90		0x80000
    2.28 -#define	CONTENTS_CURRENT_180		0x100000
    2.29 -#define	CONTENTS_CURRENT_270		0x200000
    2.30 +#define	CONTENTS_CURRENT_180	0x100000
    2.31 +#define	CONTENTS_CURRENT_270	0x200000
    2.32  #define	CONTENTS_CURRENT_UP		0x400000
    2.33 -#define	CONTENTS_CURRENT_DOWN		0x800000
    2.34 +#define	CONTENTS_CURRENT_DOWN	0x800000
    2.35  
    2.36  /**
    2.37   * @endsection
    2.38 @@ -75,30 +75,30 @@
    2.39  #define	CONTENTS_MONSTER		0x2000000	/**< should never be on a brush, only in game. */
    2.40  #define	CONTENTS_DEBRIS			0x4000000
    2.41  #define	CONTENTS_DETAIL			0x8000000	/**< brushes to be added after vis leafs. */
    2.42 -#define	CONTENTS_TRANSLUCENT		0x10000000	/**< auto set if any surface has trans. */
    2.43 +#define	CONTENTS_TRANSLUCENT	0x10000000	/**< auto set if any surface has trans. */
    2.44  #define	CONTENTS_LADDER			0x20000000
    2.45  #define CONTENTS_HITBOX			0x40000000	/**< use accurate hitboxes on trace. */
    2.46  
    2.47  /**
    2.48   * @section Trace masks.
    2.49   */
    2.50 -#define	MASK_ALL			(0xFFFFFFFF)
    2.51 -#define	MASK_SOLID			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 			/**< everything that is normally solid */
    2.52 +#define	MASK_ALL				(0xFFFFFFFF)
    2.53 +#define	MASK_SOLID				(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 			/**< everything that is normally solid */
    2.54  #define	MASK_PLAYERSOLID		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 	/**< everything that blocks player movement */
    2.55  #define	MASK_NPCSOLID			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */
    2.56 -#define	MASK_WATER			(CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) 							/**< water physics in these contents */
    2.57 -#define	MASK_OPAQUE			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) 							/**< everything that blocks line of sight for AI, lighting, etc */
    2.58 -#define MASK_OPAQUE_AND_NPCS		(MASK_OPAQUE|CONTENTS_MONSTER)										/**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
    2.59 +#define	MASK_WATER				(CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) 							/**< water physics in these contents */
    2.60 +#define	MASK_OPAQUE				(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) 							/**< everything that blocks line of sight for AI, lighting, etc */
    2.61 +#define MASK_OPAQUE_AND_NPCS	(MASK_OPAQUE|CONTENTS_MONSTER)										/**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
    2.62  #define	MASK_VISIBLE			(MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) 								/**< everything that blocks line of sight for players */
    2.63 -#define MASK_VISIBLE_AND_NPCS		(MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE) 							/**< everything that blocks line of sight for players, but with monsters added. */
    2.64 -#define	MASK_SHOT			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) 	/**< bullets see these as solid */
    2.65 +#define MASK_VISIBLE_AND_NPCS	(MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE) 							/**< everything that blocks line of sight for players, but with monsters added. */
    2.66 +#define	MASK_SHOT				(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) 	/**< bullets see these as solid */
    2.67  #define MASK_SHOT_HULL			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE) 	/**< non-raycasted weapons see this as solid (includes grates) */
    2.68  #define MASK_SHOT_PORTAL		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) 							/**< hits solids (not grates) and passes through everything else */
    2.69 -#define MASK_SOLID_BRUSHONLY		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) 					/**< everything normally solid, except monsters (world+brush only) */
    2.70 +#define MASK_SOLID_BRUSHONLY	(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) 					/**< everything normally solid, except monsters (world+brush only) */
    2.71  #define MASK_PLAYERSOLID_BRUSHONLY	(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE) 			/**< everything normally solid for player movement, except monsters (world+brush only) */
    2.72 -#define MASK_NPCSOLID_BRUSHONLY		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 			/**< everything normally solid for npc movement, except monsters (world+brush only) */
    2.73 +#define MASK_NPCSOLID_BRUSHONLY	(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 			/**< everything normally solid for npc movement, except monsters (world+brush only) */
    2.74  #define MASK_NPCWORLDSTATIC		(CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 					/**< just the world, used for route rebuilding */
    2.75 -#define MASK_SPLITAREAPORTAL		(CONTENTS_WATER|CONTENTS_SLIME) 									/**< These are things that can split areaportals */
    2.76 +#define MASK_SPLITAREAPORTAL	(CONTENTS_WATER|CONTENTS_SLIME) 									/**< These are things that can split areaportals */
    2.77  
    2.78  /**
    2.79   * @endsection
    2.80 @@ -110,21 +110,34 @@
    2.81  	RayType_Infinite	/**< The trace ray will go from the start position to infinity using a direction vector. */
    2.82  };
    2.83  
    2.84 -/**
    2.85 - * Called on entity filtering.
    2.86 - *
    2.87 - * @param entity		Entity index.
    2.88 - * @param contentsMask		Contents Mask.
    2.89 - * @return			True to allow the current entity to be hit, otherwise false.
    2.90 - */
    2.91 -functag TraceEntityFilter bool:public(entity, contentsMask);
    2.92 +funcenum TraceEntityFilter
    2.93 +{
    2.94 +	/**
    2.95 +	 * Called on entity filtering.
    2.96 +	 *
    2.97 +	 * @param entity		Entity index.
    2.98 + 	 * @param contentsMask	Contents Mask.
    2.99 + 	 * @return				True to allow the current entity to be hit, otherwise false.
   2.100 + 	 */
   2.101 +	bool:public(entity, contentsMask),
   2.102 +	
   2.103 +	/**
   2.104 +	 * Called on entity filtering.
   2.105 +	 *
   2.106 +	 * @param entity		Entity index.
   2.107 + 	 * @param contentsMask	Contents Mask.
   2.108 + 	 * @param data			Data value, if used.
   2.109 + 	 * @return				True to allow the current entity to be hit, otherwise false.
   2.110 + 	 */
   2.111 +	bool:public(entity, contentsMask, any:data),
   2.112 +};
   2.113  
   2.114  /**
   2.115   * Get the contents mask and the entity index at the given position.
   2.116   *
   2.117   * @param pos			World position to test.
   2.118   * @param entindex		Entity index found at the given position (by reference).
   2.119 - * @return			Contents mask.
   2.120 + * @return				Contents mask.
   2.121   */
   2.122  native TR_GetPointContents(const Float:pos[3], &entindex=-1);
   2.123  
   2.124 @@ -133,7 +146,7 @@
   2.125   *
   2.126   * @param entindex		Entity index to test.
   2.127   * @param pos			World position.
   2.128 - * @return			Contents mask.
   2.129 + * @return				Contents mask.
   2.130   */
   2.131  native TR_GetPointContentsEnt(entindex, const Float:pos[3]);
   2.132  
   2.133 @@ -151,14 +164,23 @@
   2.134  /**
   2.135   * Starts up a new trace ray using a global trace result and a customized trace ray filter.
   2.136   *
   2.137 + * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is 
   2.138 + * currently not allowed and may not work.
   2.139 + *
   2.140   * @param pos			Starting position of the ray.
   2.141   * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
   2.142   * @param flags			Trace flags.
   2.143   * @param rtype			Method to calculate the ray direction.
   2.144   * @param filter		Function to use as a filter.
   2.145 + * @param data			Arbitrary data value to pass through to the filter function.
   2.146   * @noreturn
   2.147   */
   2.148 -native TR_TraceRayFilter(const Float:pos[3], const Float:vec[3], flags, RayType:rtype, TraceEntityFilter:filter);
   2.149 +native TR_TraceRayFilter(const Float:pos[3],
   2.150 +						 const Float:vec[3],
   2.151 +						 flags,
   2.152 +						 RayType:rtype,
   2.153 +						 TraceEntityFilter:filter,
   2.154 +						 any:data=0);
   2.155  
   2.156  /**
   2.157   * Starts up a new trace ray using a new trace result.
   2.158 @@ -167,30 +189,37 @@
   2.159   * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
   2.160   * @param flags			Trace flags.
   2.161   * @param rtype			Method to calculate the ray direction.
   2.162 - * @return			Ray trace handle.
   2.163 - * @note Traces are closed with CloseHandle().
   2.164 + * @return				Ray trace handle, which must be closed via CloseHandle().
   2.165   */
   2.166  native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
   2.167  
   2.168  /**
   2.169   * Starts up a new trace ray using a new trace result and a customized trace ray filter.
   2.170   *
   2.171 + * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is 
   2.172 + * currently not allowed and may not work.
   2.173 + *
   2.174   * @param pos			Starting position of the ray.
   2.175   * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
   2.176   * @param flags			Trace flags.
   2.177   * @param rtype			Method to calculate the ray direction.
   2.178   * @param filter		Function to use as a filter.
   2.179 - * @return			Ray trace handle.
   2.180 - * @note Traces are closed with CloseHandle().
   2.181 + * @param data			Arbitrary data value to pass through to the filter function.
   2.182 + * @return				Ray trace handle, which must be closed via CloseHandle().
   2.183   */
   2.184 -native Handle:TR_TraceRayFilterEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype, TraceEntityFilter:filter);
   2.185 +native Handle:TR_TraceRayFilterEx(const Float:pos[3], 
   2.186 +								  const Float:vec[3],
   2.187 +								  flags, 
   2.188 +								  RayType:rtype, 
   2.189 +								  TraceEntityFilter:filter,
   2.190 +								  any:data=0);
   2.191  
   2.192  /**
   2.193   * Returns the time fraction from a trace result (1.0 means no collision).
   2.194   *
   2.195   * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   2.196 - * @return			Time fraction value of the trace.
   2.197 - * @error			Invalid Handle.
   2.198 + * @return				Time fraction value of the trace.
   2.199 + * @error				Invalid Handle.
   2.200   */
   2.201  native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE);
   2.202  
   2.203 @@ -200,7 +229,7 @@
   2.204   * @param pos			Vector buffer to store data in.
   2.205   * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   2.206   * @noreturn
   2.207 - * @error			Invalid Handle.
   2.208 + * @error				Invalid Handle.
   2.209   */
   2.210  native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE);
   2.211  
   2.212 @@ -208,8 +237,8 @@
   2.213   * Returns the entity index that collided with the trace.
   2.214   *
   2.215   * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   2.216 - * @return			Entity index or -1 for no collision.
   2.217 - * @error			Invalid Handle.
   2.218 + * @return				Entity index or -1 for no collision.
   2.219 + * @error				Invalid Handle.
   2.220   */
   2.221  native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE);
   2.222  
   2.223 @@ -217,8 +246,8 @@
   2.224   * Returns if there was any kind of collision along the trace ray.
   2.225   *
   2.226   * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   2.227 - * @return			True if any collision found, otherwise false.
   2.228 - * @error			Invalid Handle.
   2.229 + * @return				True if any collision found, otherwise false.
   2.230 + * @error				Invalid Handle.
   2.231   */
   2.232  native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE);
   2.233  
   2.234 @@ -226,7 +255,7 @@
   2.235   * Returns in which body hit group the trace collided if any.
   2.236   *
   2.237   * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   2.238 - * @return			Body hit group.
   2.239 - * @error			Invalid Handle.
   2.240 + * @return				Body hit group.
   2.241 + * @error				Invalid Handle.
   2.242   */
   2.243  native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE);