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.

164 lines
5.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef RAGDOLL_SHARED_H
  7. #define RAGDOLL_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class IPhysicsObject;
  12. class IPhysicsConstraint;
  13. class IPhysicsConstraintGroup;
  14. class IPhysicsCollision;
  15. class IPhysicsEnvironment;
  16. class IPhysicsSurfaceProps;
  17. struct matrix3x4_t;
  18. struct vcollide_t;
  19. struct studiohdr_t;
  20. class CStudioHdr;
  21. class CBoneAccessor;
  22. #include "mathlib/vector.h"
  23. #include "bone_accessor.h"
  24. #include "vcollide_parse.h"
  25. // UNDONE: Remove and make dynamic?
  26. #define RAGDOLL_MAX_ELEMENTS 24
  27. #define RAGDOLL_INDEX_BITS 5 // NOTE 1<<RAGDOLL_INDEX_BITS >= RAGDOLL_MAX_ELEMENTS
  28. #define CORE_DISSOLVE_FADE_START 0.2f
  29. #define CORE_DISSOLVE_MODEL_FADE_START 0.1f
  30. #define CORE_DISSOLVE_MODEL_FADE_LENGTH 0.05f
  31. #define CORE_DISSOLVE_FADEIN_LENGTH 0.1f
  32. struct ragdollelement_t
  33. {
  34. Vector originParentSpace;
  35. IPhysicsObject *pObject; // all valid elements have an object
  36. IPhysicsConstraint *pConstraint; // all valid elements have a constraint (except the root)
  37. int parentIndex;
  38. };
  39. struct ragdoll_t
  40. {
  41. int listCount;
  42. bool allowStretch;
  43. bool unused;
  44. IPhysicsConstraintGroup *pGroup;
  45. // store these in separate arrays for save/load
  46. ragdollelement_t list[RAGDOLL_MAX_ELEMENTS];
  47. int boneIndex[RAGDOLL_MAX_ELEMENTS];
  48. ragdollanimatedfriction_t animfriction;
  49. };
  50. struct ragdollparams_t
  51. {
  52. void *pGameData;
  53. vcollide_t *pCollide;
  54. CStudioHdr *pStudioHdr;
  55. int modelIndex;
  56. Vector forcePosition;
  57. Vector forceVector;
  58. int forceBoneIndex;
  59. const matrix3x4_t *pCurrentBones;
  60. float jointFrictionScale;
  61. bool allowStretch;
  62. bool fixedConstraints;
  63. };
  64. class CRagdollEntry
  65. {
  66. public:
  67. CRagdollEntry( CBaseAnimating *pRagdoll, float flForcedRetireTime ) : m_hRagdoll( pRagdoll ), m_flForcedRetireTime( flForcedRetireTime )
  68. {
  69. }
  70. CBaseAnimating* Get() { return m_hRagdoll.Get(); }
  71. float GetForcedRetireTime() { return m_flForcedRetireTime; }
  72. private:
  73. CHandle<CBaseAnimating> m_hRagdoll;
  74. float m_flForcedRetireTime;
  75. };
  76. //-----------------------------------------------------------------------------
  77. // This hooks the main game systems callbacks to allow the AI system to manage memory
  78. //-----------------------------------------------------------------------------
  79. class CRagdollLRURetirement : public CAutoGameSystemPerFrame
  80. {
  81. public:
  82. CRagdollLRURetirement( char const *name ) : CAutoGameSystemPerFrame( name )
  83. {
  84. }
  85. // Methods of IGameSystem
  86. virtual void Update( float frametime );
  87. virtual void FrameUpdatePostEntityThink( void );
  88. // Move it to the top of the LRU
  89. void MoveToTopOfLRU( CBaseAnimating *pRagdoll, bool bImportant = false, float flForcedRetireTime = 0.0f );
  90. void SetMaxRagdollCount( int iMaxCount ){ m_iMaxRagdolls = iMaxCount; }
  91. virtual void LevelInitPreEntity( void );
  92. int CountRagdolls( bool bOnlySimulatingRagdolls ) { return bOnlySimulatingRagdolls ? m_iSimulatedRagdollCount : m_iRagdollCount; }
  93. private:
  94. typedef CHandle<CBaseAnimating> CRagdollHandle;
  95. CUtlLinkedList< CRagdollEntry > m_LRU;
  96. CUtlLinkedList< CRagdollEntry > m_LRUImportantRagdolls;
  97. int m_iMaxRagdolls;
  98. int m_iSimulatedRagdollCount;
  99. int m_iRagdollCount;
  100. };
  101. extern CRagdollLRURetirement s_RagdollLRU;
  102. // Manages ragdolls fading for the low violence versions
  103. class CRagdollLowViolenceManager
  104. {
  105. public:
  106. CRagdollLowViolenceManager(){ m_bLowViolence = false; }
  107. // Turn the low violence ragdoll stuff off if we're in the HL2 Citadel maps because
  108. // the player has the super gravity gun and fading ragdolls will break things.
  109. void SetLowViolence( const char *pMapName );
  110. bool IsLowViolence( void ){ return m_bLowViolence; }
  111. private:
  112. bool m_bLowViolence;
  113. };
  114. extern CRagdollLowViolenceManager g_RagdollLVManager;
  115. bool RagdollCreate( ragdoll_t &ragdoll, const ragdollparams_t &params, IPhysicsEnvironment *pPhysEnv );
  116. void RagdollActivate( ragdoll_t &ragdoll, vcollide_t *pCollide, int modelIndex, bool bForceWake = true );
  117. void RagdollSetupCollisions( ragdoll_t &ragdoll, vcollide_t *pCollide, int modelIndex );
  118. void RagdollDestroy( ragdoll_t &ragdoll );
  119. // Gets the bone matrix for a ragdoll object
  120. // NOTE: This is different than the object's position because it is
  121. // forced to be rigidly attached in parent space
  122. bool RagdollGetBoneMatrix( const ragdoll_t &ragdoll, CBoneAccessor &pBoneToWorld, int objectIndex );
  123. // Parse the ragdoll and obtain the mapping from each physics element index to a bone index
  124. // returns num phys elements
  125. int RagdollExtractBoneIndices( int *boneIndexOut, CStudioHdr *pStudioHdr, vcollide_t *pCollide );
  126. // computes an exact bbox of the ragdoll's physics objects
  127. void RagdollComputeExactBbox( const ragdoll_t &ragdoll, const Vector &origin, Vector &outMins, Vector &outMaxs );
  128. void RagdollComputeApproximateBbox( const ragdoll_t &ragdoll, const Vector &origin, Vector &outMins, Vector &outMaxs );
  129. bool RagdollIsAsleep( const ragdoll_t &ragdoll );
  130. void RagdollSetupAnimatedFriction( IPhysicsEnvironment *pPhysEnv, ragdoll_t *ragdoll, int iModelIndex );
  131. void RagdollApplyAnimationAsVelocity( ragdoll_t &ragdoll, const matrix3x4_t *pBoneToWorld );
  132. void RagdollApplyAnimationAsVelocity( ragdoll_t &ragdoll, const matrix3x4_t *pPrevBones, const matrix3x4_t *pCurrentBones, float dt );
  133. void RagdollSolveSeparation( ragdoll_t &ragdoll, CBaseEntity *pEntity );
  134. #endif // RAGDOLL_SHARED_H