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.

188 lines
8.2 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. #ifndef RUBIKON_INTERSECTION_ATTRIBUTES_HDR
  3. #define RUBIKON_INTERSECTION_ATTRIBUTES_HDR
  4. static const uint32 INTERSECTION_ENTITY_ID_NONE = 0xFFFFFFFF;
  5. enum BuiltInCollisionGroup_t
  6. {
  7. // Default layer, always collides with everything.
  8. COLLISION_GROUP_ALWAYS = 0, // "always"
  9. // This is how you turn off all collisions for an object - move it to this group
  10. COLLISION_GROUP_NONPHYSICAL = 1, // "never"
  11. // Trigger layer, never collides with anything, only triggers/interacts. Use when querying for interaction layers.
  12. COLLISION_GROUP_TRIGGER = 2, // "trigger"
  13. // Conditionally solid means that the collision response will be zero or as defined in the table when there are matching interactions
  14. COLLISION_GROUP_CONDITIONALLY_SOLID = 3, // needs interactions
  15. // First unreserved collision layer index.
  16. COLLISION_GROUP_FIRST_USER = 4,
  17. // Hard limit of 254 due to memory layout, and these are never visible to scene queries.
  18. COLLISION_GROUPS_MAX_ALLOWED = 64,
  19. };
  20. enum BuiltInInteractionLayer_t
  21. {
  22. // Slow path for generating interactions when INTERSECTION_INTERACTION_LAYER_MAX is hit.
  23. // Set by default on every m_interactsAs, but not any m_interactsWith.
  24. INTERACTION_LAYER_ALWAYS = 0, // "always"
  25. // Indicates that the query will have to recurse into a hitbox model.
  26. INTERACTION_LAYER_HITBOXES = 1,
  27. // Might as well hard-code "trigger" as generic interaction layer. Character Controllers add it by default.
  28. INTERACTION_LAYER_TRIGGER = 2,
  29. // First unreserved interaction layer index.
  30. INTERACTION_LAYER_SKY = 3,
  31. INTERACTION_LAYER_FIRST_USER = 4,
  32. INTERACTION_LAYER_NOT_FOUND = -1,
  33. // Number of scene query interaction layers limited by storing these in a 64-bit uint mask
  34. INTERACTION_LAYERS_MAX_ALLOWED = 64,
  35. };
  36. enum IntersectionPairFlags_t
  37. {
  38. INTERSECTION_PAIR_RESOLVE_CONTACTS = (1<<0),
  39. INTERSECTION_PAIR_NOTIFY_TOUCH_FOUND = (1<<2),
  40. INTERSECTION_PAIR_NOTIFY_TOUCH_PERSISTS = (1<<3),
  41. INTERSECTION_PAIR_NOTIFY_TOUCH_LOST = (1<<4),
  42. INTERSECTION_PAIR_TRIGGER = INTERSECTION_PAIR_NOTIFY_TOUCH_FOUND | INTERSECTION_PAIR_NOTIFY_TOUCH_LOST,
  43. INTERSECTION_PAIR_DEFAULT_COLLISION = INTERSECTION_PAIR_RESOLVE_CONTACTS,
  44. INTERSECTION_NOTIFICATION_ANY = INTERSECTION_PAIR_NOTIFY_TOUCH_FOUND | INTERSECTION_PAIR_NOTIFY_TOUCH_PERSISTS | INTERSECTION_PAIR_NOTIFY_TOUCH_LOST
  45. };
  46. enum IntersectionQueryResult_t
  47. {
  48. INTERSECTION_QUERY_RESULT_FLAGS_NONE = 0,
  49. INTERSECTION_QUERY_RESULT_FLAGS_BLOCK = 1,
  50. };
  51. enum CollisionFunctionMask_t
  52. {
  53. FCOLLISION_FUNC_ENABLE_SOLID_CONTACT = 1<<0,
  54. FCOLLISION_FUNC_ENABLE_TRACE_QUERY = 1<<1,
  55. FCOLLISION_FUNC_ENABLE_TOUCH_EVENT = 1<<2,
  56. FCOLLISION_FUNC_ENABLE_SHOULD_COLLIDE_CALLBACK = 1<<3,
  57. FCOLLISION_FUNC_IGNORE_FOR_HITBOX_TEST = 1<<4,
  58. };
  59. enum RnMassPriorityEnum_t
  60. {
  61. MASS_PRIORITY_DEFAULT = 0,
  62. MASS_PRIORITY_TRIGGER = -1 // triggers never have mass that affects other physics objects
  63. };
  64. // Volume queries: Let's you decide between broadphase proxy and shape overlaps
  65. enum OverlapTest_t
  66. {
  67. OVERLAP_TEST_PROXY, // This will only test the shapes broadphase proxy and not the shape itself
  68. OVERLAP_TEST_SHAPE // This will first find all overlapping proxies inside the broadphase and then test the actual shape for overlap
  69. };
  70. // these are on by default
  71. #define FCOLLISION_FUNC_DEFAULT (FCOLLISION_FUNC_ENABLE_SOLID_CONTACT | FCOLLISION_FUNC_ENABLE_TRACE_QUERY | FCOLLISION_FUNC_ENABLE_TOUCH_EVENT)
  72. extern CUtlString IntersectionPairFlagsToString( uint16 nPairFlags );
  73. // TODO: Currently these flags are stored in a table as 16-bits per-pair. Once we have
  74. // TODO: identified the desired permutations of flags, the per-pair data will be
  75. // TODO: palletized down to a 4-bit index into a lookup table.
  76. // ==================================================================================================
  77. typedef int32 IntersectionLayerIndex;
  78. typedef int32 CollisionGroupIndex;
  79. typedef uint16 IntersectionLayerPairFlags;
  80. typedef uint16 CollisionGroupPairFlags;
  81. struct RnCollisionAttr_t
  82. {
  83. public:
  84. //uintp m_nOwner;
  85. // Which interaction layers do I represent? (e.g. I am a INTERACTION_LAYER_PLAYERCLIP volume)
  86. // NOTE: This is analogous to "contents" in source 1 (bit mask of CONTENTS_* or 1<<INTERACTION_LAYER_*)
  87. uint64 m_nInteractsAs;
  88. // Which interaction layers do I interact or collide with? (e.g. I collide with INTERACTION_LAYER_PASSBULLETS because I am not a bullet)
  89. // NOTE: This is analogous to the "solid mask" or "trace mask" in source 1 (bit mask of CONTENTS_* or 1<<INTERACTION_LAYER_*)
  90. uint64 m_nInteractsWith;
  91. // Which interaction layers do I _not_ interact or collide with? If my exclusion layers match m_nInteractsAs on the other object then no interaction happens.
  92. uint64 m_nInteractsExclude;
  93. uint32 m_nEntityId; // this is the ID of the game entity
  94. uint16 m_nHierarchyId; // this is an ID for the hierarchy of game entities (used to disable collision among objects in a hierarchy)
  95. uint8 m_nCollisionGroup; // one of the registered collision groups
  96. uint8 m_nCollisionFunctionMask; // set of CollisionFunctionMask_t bits
  97. public:
  98. inline RnCollisionAttr_t()
  99. {
  100. m_nInteractsAs = 0; //1 << INTERACTION_LAYER_ALWAYS;
  101. m_nInteractsWith = 0;
  102. m_nInteractsExclude = 0;
  103. m_nCollisionGroup = COLLISION_GROUP_ALWAYS;
  104. m_nCollisionFunctionMask = FCOLLISION_FUNC_DEFAULT;
  105. m_nEntityId = 0;
  106. m_nHierarchyId = 0;
  107. }
  108. uint64 GetUsedLayerMask() const { return m_nInteractsAs | m_nInteractsWith | m_nInteractsExclude; }
  109. uint64 GetUsedGroupMask() const { return 1ull << m_nCollisionGroup; }
  110. uint8 GetCollisionFunctionMask() const { return m_nCollisionFunctionMask; }
  111. void SetCollisionFunctionMask( uint8 nCollisionFunctionMask ) { m_nCollisionFunctionMask = nCollisionFunctionMask; }
  112. inline bool AddCollisionFunctionMask( uint8 nAddMask );
  113. inline bool RemoveCollisionFunctionMask( uint8 nRemoveMask );
  114. inline void SetCollisionGroup( int nGroup ) { m_nCollisionGroup = nGroup; }
  115. bool IsSolidContactEnabled() const { return (GetCollisionFunctionMask() & FCOLLISION_FUNC_ENABLE_SOLID_CONTACT) != 0; }
  116. bool IsTraceAndQueryEnabled() const { return (GetCollisionFunctionMask() & FCOLLISION_FUNC_ENABLE_TRACE_QUERY) != 0; }
  117. bool IsTouchEventEnabled() const { return (GetCollisionFunctionMask() & FCOLLISION_FUNC_ENABLE_TOUCH_EVENT) != 0; }
  118. bool IsShouldCollideCallbackEnabled() const { return (GetCollisionFunctionMask() & FCOLLISION_FUNC_ENABLE_SHOULD_COLLIDE_CALLBACK) != 0; }
  119. bool ShouldIgnoreForHitboxTest() const { return (GetCollisionFunctionMask() & FCOLLISION_FUNC_IGNORE_FOR_HITBOX_TEST) != 0; }
  120. inline bool HasInteractsAsLayer( int nLayerIndex ) const { return ( m_nInteractsAs & ( 1ull << nLayerIndex ) ) != 0; }
  121. inline bool HasInteractsWithLayer( int nLayerIndex ) const { return ( m_nInteractsWith & ( 1ull << nLayerIndex ) ) != 0; }
  122. inline bool HasInteractsExcludeLayer( int nLayerIndex ) const { return ( m_nInteractsExclude & ( 1ull << nLayerIndex ) ) != 0; }
  123. inline void EnableInteractsAsLayer( int nLayer ) { m_nInteractsAs |= ( 1ull << nLayer ); }
  124. inline void EnableInteractsWithLayer( int nLayer ) { m_nInteractsWith |= ( 1ull << nLayer ); }
  125. inline void EnableInteractsExcludeLayer( int nLayer ) { m_nInteractsExclude |= ( 1ull << nLayer ); }
  126. inline void DisableInteractsAsLayer( int nLayer ) { m_nInteractsAs &= ~( 1ull << nLayer ); }
  127. inline void DisableInteractsWithLayer( int nLayer ) { m_nInteractsWith &= ~( 1ull << nLayer ); }
  128. inline void DisableInteractsExcludeLayer( int nLayer ) { m_nInteractsExclude &= ~( 1ull << nLayer ); }
  129. inline uint32 GetEntityId() const { return m_nEntityId; }
  130. inline uint32 GetHierarchyId() const { return m_nHierarchyId; }
  131. };
  132. inline bool RnCollisionAttr_t::AddCollisionFunctionMask( uint8 nAddMask )
  133. {
  134. if ( (m_nCollisionFunctionMask & nAddMask) != nAddMask )
  135. {
  136. m_nCollisionFunctionMask |= nAddMask;
  137. return true;
  138. }
  139. return false;
  140. }
  141. inline bool RnCollisionAttr_t::RemoveCollisionFunctionMask( uint8 nRemoveMask )
  142. {
  143. if ( (m_nCollisionFunctionMask & nRemoveMask) != 0 )
  144. {
  145. m_nCollisionFunctionMask &= ~nRemoveMask;
  146. return true;
  147. }
  148. return false;
  149. }
  150. #endif