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.

148 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Clones a physics object by use of shadows
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PHYSICSSHADOWCLONE_H
  8. #define PHYSICSSHADOWCLONE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vphysics_interface.h"
  13. #include "BaseEntity.h"
  14. #include "baseanimating.h"
  15. class CPhysicsShadowClone;
  16. struct PhysicsObjectCloneLink_t
  17. {
  18. IPhysicsObject *pSource;
  19. IPhysicsShadowController *pShadowController;
  20. IPhysicsObject *pClone;
  21. };
  22. struct CPhysicsShadowCloneLL
  23. {
  24. CPhysicsShadowClone *pClone;
  25. CPhysicsShadowCloneLL *pNext;
  26. };
  27. #define FVPHYSICS_IS_SHADOWCLONE 0x4000
  28. class CPhysicsShadowClone : public CBaseAnimating
  29. {
  30. DECLARE_CLASS( CPhysicsShadowClone, CBaseAnimating );
  31. private:
  32. EHANDLE m_hClonedEntity; //the entity we're supposed to be cloning the physics of
  33. VMatrix m_matrixShadowTransform; //all cloned coordinates and angles will be run through this matrix before being applied
  34. VMatrix m_matrixShadowTransform_Inverse;
  35. CUtlVector<PhysicsObjectCloneLink_t> m_CloneLinks; //keeps track of which of our physics objects are linked to the source's objects
  36. bool m_bShadowTransformIsIdentity; //the shadow transform doesn't update often, so we can cache this
  37. bool m_bImmovable; //cloning a track train or door, something that doesn't really work on a force-based level
  38. bool m_bInAssumedSyncState;
  39. void FullSyncClonedPhysicsObjects( bool bTeleport );
  40. void SyncEntity( bool bPullChanges );
  41. IPhysicsEnvironment *m_pOwnerPhysEnvironment; //clones exist because of multi-environment situations
  42. public:
  43. CPhysicsShadowClone( void );
  44. virtual ~CPhysicsShadowClone( void );
  45. bool m_bShouldUpSync;
  46. DBG_CODE_NOSCOPE( const char *m_szDebugMarker; );
  47. //do the thing with the stuff, you know, the one that goes WooooWooooWooooWooooWoooo
  48. virtual void Spawn( void );
  49. //crush, kill, DESTROY!!!!!
  50. void Free( void );
  51. //syncs to the source entity in every way possible, assumed sync does some rudimentary tests to see if the object is in sync, and if so, skips the update
  52. void FullSync( bool bAllowAssumedSync = false );
  53. //syncs just the physics objects, bPullChanges should be true when this clone should match it's source, false when it should force differences onto the source entity
  54. void PartialSync( bool bPullChanges );
  55. //virtual bool CreateVPhysics( void );
  56. virtual void VPhysicsDestroyObject( void );
  57. virtual int VPhysicsGetObjectList( IPhysicsObject **pList, int listMax );
  58. virtual int ObjectCaps( void );
  59. virtual void UpdateOnRemove( void );
  60. //routing to the source entity for cloning goodness
  61. virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
  62. //avoid blocking traces that are supposed to hit our source entity
  63. virtual bool TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  64. //is this clone occupying the exact same space as the object it's cloning?
  65. inline bool IsUntransformedClone( void ) const { return m_bShadowTransformIsIdentity; };
  66. void SetCloneTransformationMatrix( const matrix3x4_t &matTransform );
  67. inline bool IsInAssumedSyncState( void ) const { return m_bInAssumedSyncState; }
  68. inline IPhysicsEnvironment *GetOwnerEnvironment( void ) const { return m_pOwnerPhysEnvironment; }
  69. //what entity are we cloning?
  70. void SetClonedEntity( EHANDLE hEntToClone );
  71. EHANDLE GetClonedEntity( void );
  72. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  73. //damage relays to source entity if anything ever hits the clone
  74. virtual bool PassesDamageFilter( const CTakeDamageInfo &info );
  75. virtual bool CanBeHitByMeleeAttack( CBaseEntity *pAttacker );
  76. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  77. virtual int TakeHealth( float flHealth, int bitsDamageType );
  78. virtual void Event_Killed( const CTakeDamageInfo &info );
  79. static CPhysicsShadowClone *CreateShadowClone( IPhysicsEnvironment *pInPhysicsEnvironment, EHANDLE hEntToClone, const char *szDebugMarker, const matrix3x4_t *pTransformationMatrix = NULL );
  80. //given a physics object that is part of this clone, tells you which physics object in the source
  81. IPhysicsObject *TranslatePhysicsToClonedEnt( const IPhysicsObject *pPhysics );
  82. static bool IsShadowClone( const CBaseEntity *pEntity );
  83. static CPhysicsShadowCloneLL *GetClonesOfEntity( const CBaseEntity *pEntity );
  84. static void FullSyncAllClones( void );
  85. static CUtlVector<CPhysicsShadowClone *> const &g_ShadowCloneList;
  86. friend void DrawDebugOverlayForShadowClone( CPhysicsShadowClone *pClone );
  87. //only really necessary to call for entities that create custom collideables.
  88. static void NotifyDestroy( IPhysicsObject *pDestroyingPhys, CBaseEntity *pOwningEntity = NULL ); //passing in the original owner entity just makes the search faster
  89. static void NotifyDestroy( CPhysCollide *pDestroyingCollide, CBaseEntity *pOwningEntity = NULL ); //passing in the original owner entity just makes the search faster
  90. private:
  91. void DestroyClonedPhys( IPhysicsObject *pPhys );
  92. void DestroyClonedCollideable( CPhysCollide *pCollide );
  93. };
  94. class CTraceFilterTranslateClones : public CTraceFilter //give it another filter, and it'll translate shadow clones into their source entity for tests
  95. {
  96. ITraceFilter *m_pActualFilter; //the filter that tests should be forwarded to after translating clones
  97. public:
  98. CTraceFilterTranslateClones( ITraceFilter *pOtherFilter ) : m_pActualFilter(pOtherFilter) {};
  99. virtual bool ShouldHitEntity( IHandleEntity *pEntity, int contentsMask );
  100. virtual TraceType_t GetTraceType() const;
  101. };
  102. #endif //#ifndef PHYSICSSHADOWCLONE_H