Team Fortress 2 Source Code as on 22/4/2020
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.

192 lines
6.9 KiB

  1. //========= Copyright 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. class Vector;
  17. class IHandleEntity;
  18. struct Ray_t;
  19. class CGameTrace;
  20. typedef CGameTrace trace_t;
  21. class ICollideable;
  22. class QAngle;
  23. class CTraceListData;
  24. class CPhysCollide;
  25. struct cplane_t;
  26. //-----------------------------------------------------------------------------
  27. // The standard trace filter... NOTE: Most normal traces inherit from CTraceFilter!!!
  28. //-----------------------------------------------------------------------------
  29. enum TraceType_t
  30. {
  31. TRACE_EVERYTHING = 0,
  32. TRACE_WORLD_ONLY, // NOTE: This does *not* test static props!!!
  33. TRACE_ENTITIES_ONLY, // NOTE: This version will *not* test static props
  34. TRACE_EVERYTHING_FILTER_PROPS, // NOTE: This version will pass the IHandleEntity for props through the filter, unlike all other filters
  35. };
  36. abstract_class ITraceFilter
  37. {
  38. public:
  39. virtual bool ShouldHitEntity( IHandleEntity *pEntity, int contentsMask ) = 0;
  40. virtual TraceType_t GetTraceType() const = 0;
  41. };
  42. //-----------------------------------------------------------------------------
  43. // Classes are expected to inherit these + implement the ShouldHitEntity method
  44. //-----------------------------------------------------------------------------
  45. // This is the one most normal traces will inherit from
  46. class CTraceFilter : public ITraceFilter
  47. {
  48. public:
  49. virtual TraceType_t GetTraceType() const
  50. {
  51. return TRACE_EVERYTHING;
  52. }
  53. };
  54. class CTraceFilterEntitiesOnly : public ITraceFilter
  55. {
  56. public:
  57. virtual TraceType_t GetTraceType() const
  58. {
  59. return TRACE_ENTITIES_ONLY;
  60. }
  61. };
  62. //-----------------------------------------------------------------------------
  63. // Classes need not inherit from these
  64. //-----------------------------------------------------------------------------
  65. class CTraceFilterWorldOnly : public ITraceFilter
  66. {
  67. public:
  68. bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  69. {
  70. return false;
  71. }
  72. virtual TraceType_t GetTraceType() const
  73. {
  74. return TRACE_WORLD_ONLY;
  75. }
  76. };
  77. class CTraceFilterWorldAndPropsOnly : public ITraceFilter
  78. {
  79. public:
  80. bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  81. {
  82. return false;
  83. }
  84. virtual TraceType_t GetTraceType() const
  85. {
  86. return TRACE_EVERYTHING;
  87. }
  88. };
  89. class CTraceFilterHitAll : public CTraceFilter
  90. {
  91. public:
  92. virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  93. {
  94. return true;
  95. }
  96. };
  97. //-----------------------------------------------------------------------------
  98. // Enumeration interface for EnumerateLinkEntities
  99. //-----------------------------------------------------------------------------
  100. abstract_class IEntityEnumerator
  101. {
  102. public:
  103. // This gets called with each handle
  104. virtual bool EnumEntity( IHandleEntity *pHandleEntity ) = 0;
  105. };
  106. //-----------------------------------------------------------------------------
  107. // Interface the engine exposes to the game DLL
  108. //-----------------------------------------------------------------------------
  109. #define INTERFACEVERSION_ENGINETRACE_SERVER "EngineTraceServer003"
  110. #define INTERFACEVERSION_ENGINETRACE_CLIENT "EngineTraceClient003"
  111. abstract_class IEngineTrace
  112. {
  113. public:
  114. // Returns the contents mask + entity at a particular world-space position
  115. virtual int GetPointContents( const Vector &vecAbsPosition, IHandleEntity** ppEntity = NULL ) = 0;
  116. // Get the point contents, but only test the specific entity. This works
  117. // on static props and brush models.
  118. //
  119. // If the entity isn't a static prop or a brush model, it returns CONTENTS_EMPTY and sets
  120. // bFailed to true if bFailed is non-null.
  121. virtual int GetPointContents_Collideable( ICollideable *pCollide, const Vector &vecAbsPosition ) = 0;
  122. // Traces a ray against a particular entity
  123. virtual void ClipRayToEntity( const Ray_t &ray, unsigned int fMask, IHandleEntity *pEnt, trace_t *pTrace ) = 0;
  124. // Traces a ray against a particular entity
  125. virtual void ClipRayToCollideable( const Ray_t &ray, unsigned int fMask, ICollideable *pCollide, trace_t *pTrace ) = 0;
  126. // A version that simply accepts a ray (can work as a traceline or tracehull)
  127. virtual void TraceRay( const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  128. // A version that sets up the leaf and entity lists and allows you to pass those in for collision.
  129. virtual void SetupLeafAndEntityListRay( const Ray_t &ray, CTraceListData &traceData ) = 0;
  130. virtual void SetupLeafAndEntityListBox( const Vector &vecBoxMin, const Vector &vecBoxMax, CTraceListData &traceData ) = 0;
  131. virtual void TraceRayAgainstLeafAndEntityList( const Ray_t &ray, CTraceListData &traceData, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  132. // A version that sweeps a collideable through the world
  133. // abs start + abs end represents the collision origins you want to sweep the collideable through
  134. // vecAngles represents the collision angles of the collideable during the sweep
  135. virtual void SweepCollideable( ICollideable *pCollide, const Vector &vecAbsStart, const Vector &vecAbsEnd,
  136. const QAngle &vecAngles, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace ) = 0;
  137. // Enumerates over all entities along a ray
  138. // If triggers == true, it enumerates all triggers along a ray
  139. virtual void EnumerateEntities( const Ray_t &ray, bool triggers, IEntityEnumerator *pEnumerator ) = 0;
  140. // Same thing, but enumerate entitys within a box
  141. virtual void EnumerateEntities( const Vector &vecAbsMins, const Vector &vecAbsMaxs, IEntityEnumerator *pEnumerator ) = 0;
  142. // Convert a handle entity to a collideable. Useful inside enumer
  143. virtual ICollideable *GetCollideable( IHandleEntity *pEntity ) = 0;
  144. // HACKHACK: Temp for performance measurments
  145. virtual int GetStatByIndex( int index, bool bClear ) = 0;
  146. //finds brushes in an AABB, prone to some false positives
  147. virtual void GetBrushesInAABB( const Vector &vMins, const Vector &vMaxs, CUtlVector<int> *pOutput, int iContentsMask = 0xFFFFFFFF ) = 0;
  148. //Creates a CPhysCollide out of all displacements wholly or partially contained in the specified AABB
  149. virtual CPhysCollide* GetCollidableFromDisplacementsInAABB( const Vector& vMins, const Vector& vMaxs ) = 0;
  150. //retrieve brush planes and contents, returns true if data is being returned in the output pointers, false if the brush doesn't exist
  151. virtual bool GetBrushInfo( int iBrush, CUtlVector<Vector4D> *pPlanesOut, int *pContentsOut ) = 0;
  152. virtual bool PointOutsideWorld( const Vector &ptTest ) = 0; //Tests a point to see if it's outside any playable area
  153. // Walks bsp to find the leaf containing the specified point
  154. virtual int GetLeafContainingPoint( const Vector &ptTest ) = 0;
  155. };
  156. #endif // ENGINE_IENGINETRACE_H