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.

176 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef GAMETRACE_H
  7. #define GAMETRACE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cmodel.h"
  12. #include "utlvector.h"
  13. #include "ihandleentity.h"
  14. #include "ispatialpartition.h"
  15. #if defined( CLIENT_DLL )
  16. class C_BaseEntity;
  17. #else
  18. class CBaseEntity;
  19. #endif
  20. //-----------------------------------------------------------------------------
  21. // Purpose: A trace is returned when a box is swept through the world
  22. // NOTE: eventually more of this class should be moved up into the base class!!
  23. //-----------------------------------------------------------------------------
  24. class CGameTrace : public CBaseTrace
  25. {
  26. public:
  27. // Returns true if hEnt points at the world entity.
  28. // If this returns true, then you can't use GetHitBoxIndex().
  29. bool DidHitWorld() const;
  30. // Returns true if we hit something and it wasn't the world.
  31. bool DidHitNonWorldEntity() const;
  32. // Gets the entity's network index if the trace has hit an entity.
  33. // If not, returns -1.
  34. int GetEntityIndex() const;
  35. // Returns true if there was any kind of impact at all
  36. bool DidHit() const;
  37. // The engine doesn't know what a CBaseEntity is, so it has a backdoor to
  38. // let it get at the edict.
  39. #if defined( ENGINE_DLL )
  40. void SetEdict( edict_t *pEdict );
  41. edict_t* GetEdict() const;
  42. #endif
  43. public:
  44. float fractionleftsolid; // time we left a solid, only valid if we started in solid
  45. csurface_t surface; // surface hit (impact surface)
  46. int hitgroup; // 0 == generic, non-zero is specific body part
  47. short physicsbone; // physics bone hit by trace in studio
  48. #if defined( CLIENT_DLL )
  49. C_BaseEntity *m_pEnt;
  50. #else
  51. CBaseEntity *m_pEnt;
  52. #endif
  53. // NOTE: this member is overloaded.
  54. // If hEnt points at the world entity, then this is the static prop index.
  55. // Otherwise, this is the hitbox index.
  56. int hitbox; // box hit by trace in studio
  57. CGameTrace() {}
  58. private:
  59. // No copy constructors allowed
  60. CGameTrace(const CGameTrace& vOther);
  61. };
  62. //-----------------------------------------------------------------------------
  63. // Returns true if there was any kind of impact at all
  64. //-----------------------------------------------------------------------------
  65. inline bool CGameTrace::DidHit() const
  66. {
  67. return fraction < 1 || allsolid || startsolid;
  68. }
  69. typedef CGameTrace trace_t;
  70. //=============================================================================
  71. #define TLD_DEF_LEAF_MAX 256
  72. #define TLD_DEF_ENTITY_MAX 1024
  73. class CTraceListData : public IPartitionEnumerator
  74. {
  75. public:
  76. CTraceListData( int nLeafMax = TLD_DEF_LEAF_MAX, int nEntityMax = TLD_DEF_ENTITY_MAX )
  77. {
  78. MEM_ALLOC_CREDIT();
  79. m_nLeafCount = 0;
  80. m_aLeafList.SetSize( nLeafMax );
  81. m_nEntityCount = 0;
  82. m_aEntityList.SetSize( nEntityMax );
  83. }
  84. ~CTraceListData()
  85. {
  86. m_nLeafCount = 0;
  87. m_aLeafList.RemoveAll();
  88. m_nEntityCount = 0;
  89. m_aEntityList.RemoveAll();
  90. }
  91. void Reset( void )
  92. {
  93. m_nLeafCount = 0;
  94. m_nEntityCount = 0;
  95. }
  96. bool IsEmpty( void ) const { return ( m_nLeafCount == 0 && m_nEntityCount == 0 ); }
  97. int LeafCount( void ) const { return m_nLeafCount; }
  98. int LeafCountMax( void ) const { return m_aLeafList.Count(); }
  99. void LeafCountReset( void ) { m_nLeafCount = 0; }
  100. int EntityCount( void ) const { return m_nEntityCount; }
  101. int EntityCountMax( void ) const { return m_aEntityList.Count(); }
  102. void EntityCountReset( void ) { m_nEntityCount = 0; }
  103. // For leaves...
  104. void AddLeaf( int iLeaf )
  105. {
  106. if ( m_nLeafCount >= m_aLeafList.Count() )
  107. {
  108. DevMsg( "CTraceListData: Max leaf count along ray exceeded!\n" );
  109. m_aLeafList.AddMultipleToTail( m_aLeafList.Count() );
  110. }
  111. m_aLeafList[m_nLeafCount] = iLeaf;
  112. m_nLeafCount++;
  113. }
  114. // For entities...
  115. IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
  116. {
  117. if ( m_nEntityCount >= m_aEntityList.Count() )
  118. {
  119. DevMsg( "CTraceListData: Max entity count along ray exceeded!\n" );
  120. m_aEntityList.AddMultipleToTail( m_aEntityList.Count() );
  121. }
  122. m_aEntityList[m_nEntityCount] = pHandleEntity;
  123. m_nEntityCount++;
  124. return ITERATION_CONTINUE;
  125. }
  126. public:
  127. int m_nLeafCount;
  128. CUtlVector<int> m_aLeafList;
  129. int m_nEntityCount;
  130. CUtlVector<IHandleEntity*> m_aEntityList;
  131. };
  132. #endif // GAMETRACE_H