Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
11 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef ENGINE_IENGINETRACE_H
  9. #define ENGINE_IENGINETRACE_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "basehandle.h"
  14. #include "utlvector.h" //need CUtlVector for IEngineTrace::GetBrushesIn*()
  15. #include "mathlib/vector4d.h"
  16. #include "bspflags.h"
  17. class Vector;
  18. class IHandleEntity;
  19. struct Ray_t;
  20. class CGameTrace;
  21. typedef CGameTrace trace_t;
  22. class ICollideable;
  23. class QAngle;
  24. class ITraceListData;
  25. class CPhysCollide;
  26. struct cplane_t;
  27. struct virtualmeshlist_t;
  28. struct AABB_t;
  29. //-----------------------------------------------------------------------------
  30. // The standard trace filter... NOTE: Most normal traces inherit from CTraceFilter!!!
  31. //-----------------------------------------------------------------------------
  32. enum TraceType_t
  33. {
  34. TRACE_EVERYTHING = 0,
  35. TRACE_WORLD_ONLY, // NOTE: This does *not* test static props!!!
  36. TRACE_ENTITIES_ONLY, // NOTE: This version will *not* test static props
  37. TRACE_EVERYTHING_FILTER_PROPS, // NOTE: This version will pass the IHandleEntity for props through the filter, unlike all other filters
  38. };
  39. abstract_class ITraceFilter
  40. {
  41. public:
  42. virtual bool ShouldHitEntity( IHandleEntity *pEntity, int contentsMask ) = 0;
  43. virtual TraceType_t GetTraceType() const = 0;
  44. };
  45. struct OcclusionTestResults_t
  46. {
  47. VectorAligned vEndMin, vEndMax; // the bounding box enclosing the end of the occlusion test, to be used to extend the bounding box of an object shadow
  48. };
  49. //-----------------------------------------------------------------------------
  50. // Classes are expected to inherit these + implement the ShouldHitEntity method
  51. //-----------------------------------------------------------------------------
  52. // This is the one most normal traces will inherit from
  53. class CTraceFilter : public ITraceFilter
  54. {
  55. public:
  56. virtual TraceType_t GetTraceType() const
  57. {
  58. return TRACE_EVERYTHING;
  59. }
  60. };
  61. class CTraceFilterEntitiesOnly : public ITraceFilter
  62. {
  63. public:
  64. virtual TraceType_t GetTraceType() const
  65. {
  66. return TRACE_ENTITIES_ONLY;
  67. }
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Classes need not inherit from these
  71. //-----------------------------------------------------------------------------
  72. class CTraceFilterWorldOnly : public ITraceFilter
  73. {
  74. public:
  75. bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  76. {
  77. return false;
  78. }
  79. virtual TraceType_t GetTraceType() const
  80. {
  81. return TRACE_WORLD_ONLY;
  82. }
  83. };
  84. class CTraceFilterWorldAndPropsOnly : public ITraceFilter
  85. {
  86. public:
  87. bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  88. {
  89. return false;
  90. }
  91. virtual TraceType_t GetTraceType() const
  92. {
  93. return TRACE_EVERYTHING;
  94. }
  95. };
  96. class CTraceFilterHitAll : public CTraceFilter
  97. {
  98. public:
  99. virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  100. {
  101. return true;
  102. }
  103. };
  104. enum DebugTraceCounterBehavior_t
  105. {
  106. kTRACE_COUNTER_SET = 0,
  107. kTRACE_COUNTER_INC,
  108. };
  109. //-----------------------------------------------------------------------------
  110. // Enumeration interface for EnumerateLinkEntities
  111. //-----------------------------------------------------------------------------
  112. abstract_class IEntityEnumerator
  113. {
  114. public:
  115. // This gets called with each handle
  116. virtual bool EnumEntity( IHandleEntity *pHandleEntity ) = 0;
  117. };
  118. struct BrushSideInfo_t
  119. {
  120. cplane_t plane; // The plane of the brush side
  121. unsigned short bevel; // Bevel plane?
  122. unsigned short thin; // Thin?
  123. };
  124. //something we can easily create on the stack while easily maintaining our data release contract with IEngineTrace
  125. class CBrushQuery
  126. {
  127. public:
  128. CBrushQuery( void )
  129. {
  130. m_iCount = 0;
  131. m_pBrushes = NULL;
  132. m_iMaxBrushSides = 0;
  133. m_pReleaseFunc = NULL;
  134. m_pData = NULL;
  135. }
  136. ~CBrushQuery( void )
  137. {
  138. ReleasePrivateData();
  139. }
  140. void ReleasePrivateData( void )
  141. {
  142. if( m_pReleaseFunc )
  143. {
  144. m_pReleaseFunc( this );
  145. }
  146. m_iCount = 0;
  147. m_pBrushes = NULL;
  148. m_iMaxBrushSides = 0;
  149. m_pReleaseFunc = NULL;
  150. m_pData = NULL;
  151. }
  152. inline int Count( void ) const { return m_iCount; }
  153. inline uint32 *Base( void ) { return m_pBrushes; }
  154. inline uint32 operator[]( int iIndex ) const { return m_pBrushes[iIndex]; }
  155. inline uint32 GetBrushNumber( int iIndex ) const { return m_pBrushes[iIndex]; }
  156. //maximum number of sides of any 1 brush in the query results
  157. inline int MaxBrushSides( void ) const { return m_iMaxBrushSides; }
  158. protected:
  159. int m_iCount;
  160. uint32 *m_pBrushes;
  161. int m_iMaxBrushSides;
  162. void (*m_pReleaseFunc)(CBrushQuery *); //release function is almost always in a different dll than calling code
  163. void *m_pData;
  164. };
  165. //-----------------------------------------------------------------------------
  166. // Interface the engine exposes to the game DLL
  167. //-----------------------------------------------------------------------------
  168. #define INTERFACEVERSION_ENGINETRACE_SERVER "EngineTraceServer004"
  169. #define INTERFACEVERSION_ENGINETRACE_CLIENT "EngineTraceClient004"
  170. abstract_class IEngineTrace
  171. {
  172. public:
  173. // Returns the contents mask + entity at a particular world-space position
  174. virtual int GetPointContents( const Vector &vecAbsPosition, int contentsMask = MASK_ALL, IHandleEntity** ppEntity = NULL ) = 0;
  175. // Returns the contents mask of the world only @ the world-space position (static props are ignored)
  176. virtual int GetPointContents_WorldOnly( const Vector &vecAbsPosition, int contentsMask = MASK_ALL ) = 0;
  177. // Get the point contents, but only test the specific entity. This works
  178. // on static props and brush models.
  179. //
  180. // If the entity isn't a static prop or a brush model, it returns CONTENTS_EMPTY and sets
  181. // bFailed to true if bFailed is non-null.
  182. virtual int GetPointContents_Collideable( ICollideable *pCollide, const Vector &vecAbsPosition ) = 0;
  183. // Traces a ray against a particular entity
  184. virtual void ClipRayToEntity( const Ray_t &ray, unsigned int fMask, IHandleEntity *pEnt, trace_t *pTrace ) = 0;
  185. // Traces a ray against a particular entity
  186. virtual void ClipRayToCollideable( const Ray_t &ray, unsigned int fMask, ICollideable *pCollide, trace_t *pTrace ) = 0;
  187. // A version that simply accepts a ray (can work as a traceline or tracehull)
  188. virtual void TraceRay( const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  189. // A version that sets up the leaf and entity lists and allows you to pass those in for collision.
  190. virtual void SetupLeafAndEntityListRay( const Ray_t &ray, ITraceListData *pTraceData ) = 0;
  191. virtual void SetupLeafAndEntityListBox( const Vector &vecBoxMin, const Vector &vecBoxMax, ITraceListData *pTraceData ) = 0;
  192. virtual void TraceRayAgainstLeafAndEntityList( const Ray_t &ray, ITraceListData *pTraceData, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  193. // A version that sweeps a collideable through the world
  194. // abs start + abs end represents the collision origins you want to sweep the collideable through
  195. // vecAngles represents the collision angles of the collideable during the sweep
  196. virtual void SweepCollideable( ICollideable *pCollide, const Vector &vecAbsStart, const Vector &vecAbsEnd,
  197. const QAngle &vecAngles, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  198. // Enumerates over all entities along a ray
  199. // If triggers == true, it enumerates all triggers along a ray
  200. virtual void EnumerateEntities( const Ray_t &ray, bool triggers, IEntityEnumerator *pEnumerator ) = 0;
  201. // Same thing, but enumerate entitys within a box
  202. virtual void EnumerateEntities( const Vector &vecAbsMins, const Vector &vecAbsMaxs, IEntityEnumerator *pEnumerator ) = 0;
  203. // Convert a handle entity to a collideable. Useful inside enumer
  204. virtual ICollideable *GetCollideable( IHandleEntity *pEntity ) = 0;
  205. // HACKHACK: Temp for performance measurments
  206. virtual int GetStatByIndex( int index, bool bClear ) = 0;
  207. //finds brushes in an AABB, prone to some false positives
  208. virtual void GetBrushesInAABB( const Vector &vMins, const Vector &vMaxs, CBrushQuery &BrushQuery, int iContentsMask = 0xFFFFFFFF, int cmodelIndex = 0 ) = 0;
  209. //Creates a CPhysCollide out of all displacements wholly or partially contained in the specified AABB
  210. virtual CPhysCollide* GetCollidableFromDisplacementsInAABB( const Vector& vMins, const Vector& vMaxs ) = 0;
  211. // gets the number of displacements in the world
  212. virtual int GetNumDisplacements( ) = 0;
  213. // gets a specific diplacement mesh
  214. virtual void GetDisplacementMesh( int nIndex, virtualmeshlist_t *pMeshTriList ) = 0;
  215. //retrieve brush planes and contents, returns zero if the brush doesn't exist,
  216. //returns positive number of sides filled out if the array can hold them all, negative number of slots needed to hold info if the array is too small
  217. virtual int GetBrushInfo( int iBrush, int &ContentsOut, BrushSideInfo_t *pBrushSideInfoOut, int iBrushSideInfoArraySize ) = 0;
  218. virtual bool PointOutsideWorld( const Vector &ptTest ) = 0; //Tests a point to see if it's outside any playable area
  219. // Walks bsp to find the leaf containing the specified point
  220. virtual int GetLeafContainingPoint( const Vector &ptTest ) = 0;
  221. virtual ITraceListData *AllocTraceListData() = 0;
  222. virtual void FreeTraceListData(ITraceListData *) = 0;
  223. /// Used only in debugging: get/set/clear/increment the trace debug counter. See comment below for details.
  224. virtual int GetSetDebugTraceCounter( int value, DebugTraceCounterBehavior_t behavior ) = 0;
  225. //Similar to GetCollidableFromDisplacementsInAABB(). But returns the intermediate mesh data instead of a collideable
  226. virtual int GetMeshesFromDisplacementsInAABB( const Vector& vMins, const Vector& vMaxs, virtualmeshlist_t *pOutputMeshes, int iMaxOutputMeshes ) = 0;
  227. virtual void GetBrushesInCollideable( ICollideable *pCollideable, CBrushQuery &BrushQuery ) = 0;
  228. virtual bool IsFullyOccluded( int nOcclusionKey, const AABB_t &aabb1, const AABB_t &aabb2, const Vector &vShadow ) = 0;
  229. virtual void SuspendOcclusionTests() = 0;
  230. virtual void ResumeOcclusionTests() = 0;
  231. class CAutoSuspendOcclusionTests
  232. {
  233. IEngineTrace *m_pEngineTrace;
  234. public:
  235. CAutoSuspendOcclusionTests( IEngineTrace *pEngineTrace ) : m_pEngineTrace( pEngineTrace ) { pEngineTrace->SuspendOcclusionTests(); }
  236. ~CAutoSuspendOcclusionTests() { m_pEngineTrace->ResumeOcclusionTests(); }
  237. };
  238. virtual void FlushOcclusionQueries() = 0;
  239. };
  240. /// IEngineTrace::GetSetDebugTraceCounter
  241. /// SET to a negative number to disable. SET to a positive number to reset the counter; it'll tick down by
  242. /// one for each trace, and break into the debugger on hitting zero. INC lets you add or subtract from the
  243. /// counter. In each case it will return the value of the counter BEFORE you set or incremented it. INC 0
  244. /// to query. This end-around approach is necessary for security: because only the engine knows when we
  245. /// are in a trace, and only the server knows when we are in a think, data must somehow be shared between
  246. /// them. Simply returning a pointer to an address inside the engine in a retail build is unacceptable,
  247. /// and in the PC there is no way to distinguish between retail and non-retail builds at compile time
  248. /// (there is no #define for it).
  249. /// This may seem redundant with the VPROF_INCREMENT_COUNTER( "TraceRay" ), but it's not, because while
  250. /// that's readable across DLLs, there's no way to trap on its exceeding a certain value, nor can we reset
  251. /// it for each think.
  252. #endif // ENGINE_IENGINETRACE_H