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.

170 lines
5.9 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef PUSHENTITY_H
  7. #define PUSHENTITY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "movetype_push.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Keeps track of original positions of any entities that are being possibly pushed
  14. // and handles restoring positions for those objects if the push is aborted
  15. //-----------------------------------------------------------------------------
  16. class CPhysicsPushedEntities
  17. {
  18. public:
  19. DECLARE_CLASS_NOBASE( CPhysicsPushedEntities );
  20. CPhysicsPushedEntities( void );
  21. // Purpose: Tries to rotate an entity hierarchy, returns the blocker if any
  22. CBaseEntity *PerformRotatePush( CBaseEntity *pRoot, float movetime );
  23. // Purpose: Tries to linearly push an entity hierarchy, returns the blocker if any
  24. CBaseEntity *PerformLinearPush( CBaseEntity *pRoot, float movetime );
  25. int CountMovedEntities() { return m_rgMoved.Count(); }
  26. void StoreMovedEntities( physicspushlist_t &list );
  27. void BeginPush( CBaseEntity *pRootEntity );
  28. // updates physics for all pushers that moved this tick
  29. void UpdatePusherPhysicsEndOfTick();
  30. void QueueChildUpdate( CBaseEntity *pChild ) { m_rgUpdatedChildren.AddToTail(pChild); }
  31. protected:
  32. // describes the per-frame incremental motion of a rotating MOVETYPE_PUSH
  33. struct RotatingPushMove_t
  34. {
  35. Vector origin;
  36. matrix3x4_t startLocalToWorld;
  37. matrix3x4_t endLocalToWorld;
  38. QAngle amove; // delta orientation
  39. };
  40. // Pushers + their original positions also (for touching triggers)
  41. struct PhysicsPusherInfo_t
  42. {
  43. CBaseEntity *m_pEntity;
  44. Vector m_vecStartAbsOrigin;
  45. };
  46. // Pushed entities + various state related to them being pushed
  47. struct PhysicsPushedInfo_t
  48. {
  49. CBaseEntity *m_pEntity;
  50. Vector m_vecStartAbsOrigin;
  51. trace_t m_Trace;
  52. bool m_bBlocked;
  53. bool m_bPusherIsGround;
  54. };
  55. // Adds the specified entity to the list
  56. void AddEntity( CBaseEntity *ent );
  57. // If a move fails, restores all entities to their original positions
  58. void RestoreEntities( );
  59. // Compute the direction to move the rotation blocker
  60. void ComputeRotationalPushDirection( CBaseEntity *pBlocker, const RotatingPushMove_t &rotPushMove, Vector *pMove, CBaseEntity *pRoot );
  61. // Speculatively checks to see if all entities in this list can be pushed
  62. bool SpeculativelyCheckPush( PhysicsPushedInfo_t &info, const Vector &vecAbsPush, bool bRotationalPush, CBaseEntity *pRoot, bool bIgnoreTeammates = false );
  63. // Speculatively checks to see if all entities in this list can be pushed
  64. virtual bool SpeculativelyCheckRotPush( const RotatingPushMove_t &rotPushMove, CBaseEntity *pRoot = NULL );
  65. // Speculatively checks to see if all entities in this list can be pushed
  66. virtual bool SpeculativelyCheckLinearPush( const Vector &vecAbsPush );
  67. // Registers a blockage
  68. CBaseEntity *RegisterBlockage();
  69. // Some fixup for objects pushed by rotating objects
  70. virtual void FinishRotPushedEntity( CBaseEntity *pPushedEntity, const RotatingPushMove_t &rotPushMove );
  71. // Commits the speculative movement
  72. void FinishPush( bool bIsRotPush = false, const RotatingPushMove_t *pRotPushMove = NULL );
  73. // Generates a list of all entities potentially blocking all pushers
  74. void GenerateBlockingEntityList();
  75. void GenerateBlockingEntityListAddBox( const Vector &vecMoved );
  76. // Purpose: Gets a list of all entities hierarchically attached to the root
  77. void SetupAllInHierarchy( CBaseEntity *pParent );
  78. // Unlink + relink the pusher list so we can actually do the push
  79. void UnlinkPusherList( int *pPusherHandles );
  80. void RelinkPusherList( int *pPusherHandles );
  81. // Causes all entities in the list to touch triggers from their prev position
  82. void FinishPushers();
  83. // Purpose: Rotates the root entity, fills in the pushmove structure
  84. void RotateRootEntity( CBaseEntity *pRoot, float movetime, RotatingPushMove_t &rotation );
  85. // Purpose: Linearly moves the root entity
  86. void LinearlyMoveRootEntity( CBaseEntity *pRoot, float movetime, Vector *pAbsPushVector );
  87. bool IsPushedPositionValid( CBaseEntity *pBlocker, bool bIgnoreTeammates );
  88. void TraceBlockerEntity( CBaseEntity *pBlocker, const Vector& absStart, const Vector& absEnd, bool bIgnoreTeammates, trace_t *pOutTrace );
  89. bool FindValidLocationUpwards( float *pOutLengthUp, CBaseEntity *pBlocker, float maxDist, float slop );
  90. bool FindValidLocationAlongVector( Vector *pOutDelta, CBaseEntity *pBlocker, const Vector &vEndPoint, float slop );
  91. protected:
  92. CUtlVector<PhysicsPusherInfo_t> m_rgPusher;
  93. CUtlVector<PhysicsPushedInfo_t> m_rgMoved;
  94. int m_nBlocker;
  95. bool m_bIsUnblockableByPlayer;
  96. Vector m_rootPusherStartLocalOrigin;
  97. QAngle m_rootPusherStartLocalAngles;
  98. float m_rootPusherStartLocaltime;
  99. float m_flMoveTime;
  100. CUtlVector<PhysicsPusherInfo_t> m_rgUpdatedPushers;
  101. CUtlVector<CBaseEntity *> m_rgUpdatedChildren;
  102. friend class CPushBlockerEnum;
  103. };
  104. class CTraceFilterPushMove : public CTraceFilterSimple
  105. {
  106. DECLARE_CLASS( CTraceFilterPushMove, CTraceFilterSimple );
  107. public:
  108. CTraceFilterPushMove( CBaseEntity *pEntity, int nCollisionGroup )
  109. : CTraceFilterSimple( pEntity, nCollisionGroup )
  110. {
  111. m_pRootParent = pEntity->GetRootMoveParent();
  112. }
  113. bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
  114. {
  115. Assert( dynamic_cast<CBaseEntity*>(pHandleEntity) );
  116. CBaseEntity *pTestEntity = static_cast<CBaseEntity*>(pHandleEntity);
  117. if ( UTIL_EntityHasMatchingRootParent( m_pRootParent, pTestEntity ) )
  118. return false;
  119. if ( pTestEntity->GetMoveType() == MOVETYPE_VPHYSICS &&
  120. pTestEntity->VPhysicsGetObject() && pTestEntity->VPhysicsGetObject()->IsMoveable() )
  121. return false;
  122. return BaseClass::ShouldHitEntity( pHandleEntity, contentsMask );
  123. }
  124. private:
  125. CBaseEntity *m_pRootParent;
  126. };
  127. extern CPhysicsPushedEntities *g_pPushedEntities;
  128. #endif // PUSHENTITY_H