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.

212 lines
8.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #ifndef ISPATIALPARTITION_H
  9. #define ISPATIALPARTITION_H
  10. #include "interface.h"
  11. //-----------------------------------------------------------------------------
  12. // forward declarations
  13. //-----------------------------------------------------------------------------
  14. class Vector;
  15. struct Ray_t;
  16. class IHandleEntity;
  17. #define INTERFACEVERSION_SPATIALPARTITION "SpatialPartition001"
  18. //-----------------------------------------------------------------------------
  19. // These are the various partition lists. Note some are server only, some
  20. // are client only
  21. //-----------------------------------------------------------------------------
  22. enum
  23. {
  24. PARTITION_ENGINE_SOLID_EDICTS = (1 << 0), // every edict_t that isn't SOLID_TRIGGER or SOLID_NOT (and static props)
  25. PARTITION_ENGINE_TRIGGER_EDICTS = (1 << 1), // every edict_t that IS SOLID_TRIGGER
  26. PARTITION_CLIENT_SOLID_EDICTS = (1 << 2),
  27. PARTITION_CLIENT_RESPONSIVE_EDICTS = (1 << 3), // these are client-side only objects that respond to being forces, etc.
  28. PARTITION_ENGINE_NON_STATIC_EDICTS = (1 << 4), // everything in solid & trigger except the static props, includes SOLID_NOTs
  29. PARTITION_CLIENT_STATIC_PROPS = (1 << 5),
  30. PARTITION_ENGINE_STATIC_PROPS = (1 << 6),
  31. PARTITION_CLIENT_NON_STATIC_EDICTS = (1 << 7), // everything except the static props
  32. PARTITION_CLIENT_TRIGGER_ENTITIES = (1 << 8), // client side prediction related triggers
  33. PARTITION_CLIENT_IK_ATTACHMENT = (1 << 9), // Can be used as an IK attachment
  34. PARTITION_ENGINE_PUSHABLE = (1 << 10), // everything with a movetype that can be pushed by MOVETYPE_PUSH ents
  35. };
  36. // Use this to look for all client edicts.
  37. #define PARTITION_ALL_CLIENT_EDICTS ( \
  38. PARTITION_CLIENT_NON_STATIC_EDICTS | \
  39. PARTITION_CLIENT_STATIC_PROPS | \
  40. PARTITION_CLIENT_RESPONSIVE_EDICTS | \
  41. PARTITION_CLIENT_SOLID_EDICTS | \
  42. PARTITION_CLIENT_TRIGGER_ENTITIES \
  43. )
  44. // These are the only handles in the spatial partition that the game is controlling (everything but static props)
  45. // These masks are used to handle updating the dirty spatial partition list in each game DLL
  46. #define PARTITION_CLIENT_GAME_EDICTS (PARTITION_ALL_CLIENT_EDICTS & ~PARTITION_CLIENT_STATIC_PROPS)
  47. #define PARTITION_SERVER_GAME_EDICTS (PARTITION_ENGINE_SOLID_EDICTS|PARTITION_ENGINE_TRIGGER_EDICTS|PARTITION_ENGINE_NON_STATIC_EDICTS)
  48. //-----------------------------------------------------------------------------
  49. // Clients that want to know about all elements within a particular
  50. // volume must inherit from this
  51. //-----------------------------------------------------------------------------
  52. enum IterationRetval_t
  53. {
  54. ITERATION_CONTINUE = 0,
  55. ITERATION_STOP,
  56. };
  57. typedef unsigned short SpatialPartitionHandle_t;
  58. // A combination of the PARTITION_ flags above.
  59. typedef int SpatialPartitionListMask_t;
  60. typedef int SpatialTempHandle_t;
  61. //-----------------------------------------------------------------------------
  62. // Any search in the CSpatialPartition must use this to filter out entities it doesn't want.
  63. // You're forced to use listMasks because it can filter by listMasks really fast. Any other
  64. // filtering can be done by EnumElement.
  65. //-----------------------------------------------------------------------------
  66. class IPartitionEnumerator
  67. {
  68. public:
  69. virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity ) = 0;
  70. };
  71. //-----------------------------------------------------------------------------
  72. // Installs a callback to call right before a spatial partition query occurs
  73. //-----------------------------------------------------------------------------
  74. class IPartitionQueryCallback
  75. {
  76. public:
  77. virtual void OnPreQuery( SpatialPartitionListMask_t listMask ) = 0;
  78. virtual void OnPostQuery( SpatialPartitionListMask_t listMask ) = 0;
  79. };
  80. //-----------------------------------------------------------------------------
  81. // This is the spatial partition manager, groups objects into buckets
  82. //-----------------------------------------------------------------------------
  83. enum
  84. {
  85. PARTITION_INVALID_HANDLE = (SpatialPartitionHandle_t)~0
  86. };
  87. abstract_class ISpatialPartition
  88. {
  89. public:
  90. // Create/destroy a handle for this dude in our system. Destroy
  91. // will also remove it from all lists it happens to be in
  92. virtual SpatialPartitionHandle_t CreateHandle( IHandleEntity *pHandleEntity ) = 0;
  93. // A fast method of creating a handle + inserting into the tree in the right place
  94. virtual SpatialPartitionHandle_t CreateHandle( IHandleEntity *pHandleEntity,
  95. SpatialPartitionListMask_t listMask, const Vector& mins, const Vector& maxs ) = 0;
  96. virtual void DestroyHandle( SpatialPartitionHandle_t handle ) = 0;
  97. // Adds, removes an handle from a particular spatial partition list
  98. // There can be multiple partition lists; each has a unique id
  99. virtual void Insert( SpatialPartitionListMask_t listMask,
  100. SpatialPartitionHandle_t handle ) = 0;
  101. virtual void Remove( SpatialPartitionListMask_t listMask,
  102. SpatialPartitionHandle_t handle ) = 0;
  103. // Same as calling Remove() then Insert(). For performance-sensitive areas where you want to save a call.
  104. virtual void RemoveAndInsert( SpatialPartitionListMask_t removeMask, SpatialPartitionListMask_t insertMask,
  105. SpatialPartitionHandle_t handle ) = 0;
  106. // This will remove a particular handle from all lists
  107. virtual void Remove( SpatialPartitionHandle_t handle ) = 0;
  108. // Call this when an entity moves...
  109. virtual void ElementMoved( SpatialPartitionHandle_t handle,
  110. const Vector& mins, const Vector& maxs ) = 0;
  111. // A fast method to insert + remove a handle from the tree...
  112. // This is used to suppress collision of a single model..
  113. virtual SpatialTempHandle_t HideElement( SpatialPartitionHandle_t handle ) = 0;
  114. virtual void UnhideElement( SpatialPartitionHandle_t handle, SpatialTempHandle_t tempHandle ) = 0;
  115. // Installs callbacks to get called right before a query occurs
  116. virtual void InstallQueryCallback( IPartitionQueryCallback *pCallback ) = 0;
  117. virtual void RemoveQueryCallback( IPartitionQueryCallback *pCallback ) = 0;
  118. // Gets all entities in a particular volume...
  119. // if coarseTest == true, it'll return all elements that are in
  120. // spatial partitions that intersect the box
  121. // if coarseTest == false, it'll return only elements that truly intersect
  122. virtual void EnumerateElementsInBox(
  123. SpatialPartitionListMask_t listMask,
  124. const Vector& mins,
  125. const Vector& maxs,
  126. bool coarseTest,
  127. IPartitionEnumerator* pIterator
  128. ) = 0;
  129. virtual void EnumerateElementsInSphere(
  130. SpatialPartitionListMask_t listMask,
  131. const Vector& origin,
  132. float radius,
  133. bool coarseTest,
  134. IPartitionEnumerator* pIterator
  135. ) = 0;
  136. virtual void EnumerateElementsAlongRay(
  137. SpatialPartitionListMask_t listMask,
  138. const Ray_t& ray,
  139. bool coarseTest,
  140. IPartitionEnumerator* pIterator
  141. ) = 0;
  142. virtual void EnumerateElementsAtPoint(
  143. SpatialPartitionListMask_t listMask,
  144. const Vector& pt,
  145. bool coarseTest,
  146. IPartitionEnumerator* pIterator
  147. ) = 0;
  148. // For debugging.... suppress queries on particular lists
  149. virtual void SuppressLists( SpatialPartitionListMask_t nListMask, bool bSuppress ) = 0;
  150. virtual SpatialPartitionListMask_t GetSuppressedLists() = 0;
  151. virtual void RenderAllObjectsInTree( float flTime ) = 0;
  152. virtual void RenderObjectsInPlayerLeafs( const Vector &vecPlayerMin, const Vector &vecPlayerMax, float flTime ) = 0;
  153. virtual void RenderLeafsForRayTraceStart( float flTime ) = 0;
  154. virtual void RenderLeafsForRayTraceEnd( void ) = 0;
  155. virtual void RenderLeafsForHullTraceStart( float flTime ) = 0;
  156. virtual void RenderLeafsForHullTraceEnd( void ) = 0;
  157. virtual void RenderLeafsForBoxStart( float flTime ) = 0;
  158. virtual void RenderLeafsForBoxEnd( void ) = 0;
  159. virtual void RenderLeafsForSphereStart( float flTime ) = 0;
  160. virtual void RenderLeafsForSphereEnd( void ) = 0;
  161. virtual void RenderObjectsInBox( const Vector &vecMin, const Vector &vecMax, float flTime ) = 0;
  162. virtual void RenderObjectsInSphere( const Vector &vecCenter, float flRadius, float flTime ) = 0;
  163. virtual void RenderObjectsAlongRay( const Ray_t& ray, float flTime ) = 0;
  164. virtual void ReportStats( const char *pFileName ) = 0;
  165. };
  166. #endif