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.

299 lines
8.4 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //==========================================================================//
  6. #ifndef PAINT_BLOBS_SHARED_H
  7. #define PAINT_BLOBS_SHARED_H
  8. #include "paint_color_manager.h"
  9. #include "trigger_tractorbeam_shared.h"
  10. enum BlobTraceResult
  11. {
  12. BLOB_TRACE_HIT_NOTHING = 0,
  13. BLOB_TRACE_HIT_PORTAL,
  14. BLOB_TRACE_HIT_WORLD,
  15. BLOB_TRACE_HIT_PAINT_CLEANSER,
  16. BLOB_TRACE_HIT_SOMETHING,
  17. BLOB_TRACE_HIT_PLAYER,
  18. BLOB_TRACE_HIT_TRACTORBEAM,
  19. BLOB_TRACE_HIT_PROP_PORTAL // this flag is for creating ghost blobs to make smooth blobs rendering when blobs go through portal
  20. };
  21. struct BlobCollisionRecord
  22. {
  23. trace_t trace;
  24. Vector targetEndPos;
  25. BlobTraceResult traceResultType;
  26. };
  27. enum PaintBlobMoveState
  28. {
  29. PAINT_BLOB_AIR_MOVE = 0,
  30. PAINT_BLOB_STREAK_MOVE,
  31. PAINT_BLOB_TRACTOR_BEAM_MOVE
  32. };
  33. class CBasePaintBlob
  34. {
  35. public:
  36. CBasePaintBlob( void );
  37. ~CBasePaintBlob( void );
  38. void Init( const Vector &vecOrigin, const Vector &vecVelocity, int paintType, float flMaxStreakTime, float flStreakSpeedDampenRate, CBaseEntity* pOwner, bool bSilent, bool bDrawOnly );
  39. bool IsStreaking( void ) const;
  40. void SetTractorBeam( CTrigger_TractorBeam* pBeam );
  41. const Vector& GetTempEndPosition( void ) const;
  42. void SetTempEndPosition( const Vector &vecTempEndPosition );
  43. const Vector& GetTempEndVelocity( void ) const;
  44. void SetTempEndVelocity( const Vector &vecTempEndVelocity );
  45. const Vector& GetPosition( void ) const;
  46. void SetPosition( const Vector &vecPosition );
  47. const Vector& GetPrevPosition() const;
  48. void SetPrevPosition( const Vector& vPrevPosition );
  49. const Vector& GetVelocity( void ) const;
  50. void SetVelocity( const Vector &vecVelocity );
  51. const Vector& GetStreakDir() const;
  52. PaintPowerType GetPaintPowerType( void ) const;
  53. PaintBlobMoveState GetMoveState( void ) const;
  54. void SetMoveState( PaintBlobMoveState moveState );
  55. float GetAccumulatedTime() const { return m_flAccumulatedTime; }
  56. void SetAccumulatedTime( float flAccumulatedTime ) { m_flAccumulatedTime = flAccumulatedTime; }
  57. // kill this if we don't need fixed time step
  58. float GetLastUpdateTime() const { return m_flLastUpdateTime; }
  59. void SetLastUpdateTime( float flLastUpdateTime ) { m_flLastUpdateTime = flLastUpdateTime; }
  60. float GetVortexDirection() const;
  61. bool ShouldDeleteThis() const;
  62. void SetDeletionFlag( bool bDelete );
  63. float GetLifeTime() const;
  64. void UpdateLifeTime( float flUpdateTime );
  65. void UpdateBlobCollision( float flDeltaTime, const Vector& vecEndPos, Vector& vecEndVelocity );
  66. void UpdateBlobPostCollision( float flDeltaTime );
  67. const Vector& GetContactNormal() const;
  68. float GetStreakTime() const { return m_flStreakTimer; }
  69. float GetStreakSpeedDampenRate() const { return m_flStreakSpeedDampenRate; }
  70. void SetRadiusScale( float flRadiusScale );
  71. float GetRadiusScale( void ) const;
  72. bool ShouldPlayEffect() const;
  73. bool IsSilent() const { return m_bSilent; }
  74. bool IsGhosting() const { return ( m_hPortal != NULL ); }
  75. void GetGhostMatrix( VMatrix& matGhostTransform );
  76. void ResetGhostState() { m_hPortal = NULL; }
  77. CTrigger_TractorBeam* GetCurrentBeam() const;
  78. bool PaintBlobCheckShouldStreak( const trace_t &trace );
  79. void PlayEffect( const Vector& vPosition, const Vector& vNormal );
  80. bool PaintBlobStreakPaint( const Vector &vecBlobStartPos );
  81. virtual void PaintBlobPaint( const trace_t &tr ) = 0;
  82. void SetShouldPlaySound( bool shouldPlaySound );
  83. bool ShouldPlaySound() const;
  84. void SetBlobTeleportedThisFrame( bool bTeleported ) { m_bTeleportedThisFrame = bTeleported; }
  85. bool HasBlobTeleportedThisFrame() const { return m_bTeleportedThisFrame; }
  86. int GetTeleportationCount() const { return m_nTeleportationCount; }
  87. float m_flDestVortexRadius;
  88. float m_flCurrentVortexRadius;
  89. float m_flCurrentVortexSpeed;
  90. float m_flVortexDirection; // -1.f or 1.f
  91. protected:
  92. void PaintBlobMoveThroughPortal( float flDeltaTime, CPortal_Base2D *pInPortal, const Vector &vecStartPos, const Vector &vecTransformedEndPos );
  93. BlobTraceResult BlobHitSolid( CBaseEntity* pHitEntity );
  94. int CheckCollision( BlobCollisionRecord *pCollisions, int maxCollisions, const Vector &vecEndPos );
  95. void CheckCollisionAgainstWorldAndStaticProps( BlobCollisionRecord& solidHitRecord, float& flHitFraction );
  96. int CheckCollisionThroughPortal( BlobCollisionRecord *pCollisions, int maxCollisions, const Vector &vecEndPos );
  97. void ResolveCollision( bool& bDeleted, const BlobCollisionRecord& collision, Vector& targetVelocity, float deltaTime );
  98. void DecayVortexSpeed( float flDeltaTime );
  99. Vector m_vecTempEndPosition;
  100. Vector m_vecTempEndVelocity;
  101. Vector m_vecPosition;
  102. Vector m_vecPrevPosition;
  103. Vector m_vecVelocity;
  104. // this is used for playing paint effect on client and painting surface on server
  105. Vector m_vContactNormal;
  106. PaintPowerType m_paintType;
  107. EHANDLE m_hOwner;
  108. PaintBlobMoveState m_MoveState;
  109. //Timers for the blob
  110. float m_flLifeTime;
  111. //Streaking
  112. Vector m_vecStreakDir;
  113. bool m_bStreakDirChanged;
  114. float m_flStreakTimer;
  115. float m_flStreakSpeedDampenRate;
  116. bool m_bDeleteFlag;
  117. float m_flAccumulatedTime;
  118. float m_flLastUpdateTime;
  119. //The radius scale of the blob for the isosurface rendering
  120. // this is shared so the listen server doesn't have to create blobs on the client dll
  121. float m_flRadiusScale;
  122. bool m_bShouldPlayEffect;
  123. // blob needs to know if hitting beam is the same as the current beam, so it doesn't need to init beam data again
  124. EntityBeamHistory_t m_beamHistory;
  125. bool m_bInTractorBeam;
  126. // HACK: remove this when awesome paint box/sphere feature is done (Bank)
  127. bool m_bSilent;
  128. // portal handle (for ghosting)
  129. EHANDLE m_hPortal;
  130. // optimize trace
  131. bool CheckCollisionBoxAgainstWorldAndStaticProps();
  132. Vector m_vCollisionBoxCenter;
  133. bool m_bCollisionBoxHitSolid;
  134. bool m_bShouldPlaySound;
  135. // if this flag is true, blob won't do effect/sound/paint
  136. bool m_bDrawOnly;
  137. // teleportation counter
  138. bool m_bTeleportedThisFrame;
  139. int m_nTeleportationCount;
  140. };
  141. #ifdef GAME_DLL
  142. class CPaintBlob;
  143. #else
  144. class C_PaintBlob;
  145. typedef C_PaintBlob CPaintBlob;
  146. #endif
  147. typedef CUtlVector<CPaintBlob*> PaintBlobVector_t;
  148. //////////////////////////////////////////////////////////////////////////
  149. // Listen Server Shared Data
  150. //////////////////////////////////////////////////////////////////////////
  151. struct BlobTeleportationHistory_t
  152. {
  153. BlobTeleportationHistory_t() : m_vEnterPosition( vec3_origin ), m_vExitPosition( vec3_origin ), m_flTeleportTime( 0.f )
  154. {
  155. }
  156. BlobTeleportationHistory_t( const VMatrix& matSourceToLinked, const VMatrix& matLinkedToSource, const Vector& vEnter, const Vector& vExit, float flTeleportTime )
  157. {
  158. m_matSourceToLinked = matSourceToLinked;
  159. m_matLinkedToSource = matLinkedToSource;
  160. m_vEnterPosition = vEnter;
  161. m_vExitPosition = vExit;
  162. m_flTeleportTime = flTeleportTime;
  163. }
  164. VMatrix m_matSourceToLinked;
  165. VMatrix m_matLinkedToSource;
  166. Vector m_vEnterPosition;
  167. Vector m_vExitPosition;
  168. float m_flTeleportTime;
  169. };
  170. typedef CUtlVector< BlobTeleportationHistory_t > BlobTeleportationHistoryVector_t;
  171. struct BlobData_t
  172. {
  173. BlobData_t()
  174. {
  175. m_blobID = -1;
  176. m_vPosition = vec3_origin;
  177. m_flScale = 0.f;
  178. m_bTeleportedThisFrame = false;
  179. m_bGhosting = false;
  180. MatrixSetIdentity( m_matGhostTransform );
  181. }
  182. BlobData_t( const BlobData_t& blobData )
  183. {
  184. m_blobID = blobData.m_blobID;
  185. m_vPosition = blobData.m_vPosition;
  186. m_flScale = blobData.m_flScale;
  187. m_bTeleportedThisFrame = blobData.m_bTeleportedThisFrame;
  188. m_bGhosting = blobData.m_bGhosting;
  189. m_matGhostTransform = blobData.m_matGhostTransform;
  190. }
  191. ~BlobData_t()
  192. {
  193. m_teleportationHistory.Purge();
  194. }
  195. int m_blobID;
  196. Vector m_vPosition;
  197. float m_flScale;
  198. // teleportation data
  199. bool m_bTeleportedThisFrame;
  200. BlobTeleportationHistoryVector_t m_teleportationHistory;
  201. // ghosting data
  202. bool m_bGhosting;
  203. VMatrix m_matGhostTransform;
  204. };
  205. typedef CUtlVector< BlobData_t > BlobDataVector_t;
  206. struct BlobInterpolationData_t
  207. {
  208. BlobInterpolationData_t()
  209. {
  210. m_flUpdateTime = 0.f;
  211. }
  212. ~BlobInterpolationData_t()
  213. {
  214. m_blobData.Purge();
  215. }
  216. float m_flUpdateTime;
  217. BlobDataVector_t m_blobData;
  218. };
  219. typedef CUtlVector< BlobInterpolationData_t > BlobInterpolationDataVector_t;
  220. void PaintBlobUpdate( const PaintBlobVector_t& blobList );
  221. #endif //PAINT_BLOBS_SHARED_H