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.

152 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef REPLAY_RAGDOLL_H
  7. #define REPLAY_RAGDOLL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. //--------------------------------------------------------------------------------
  12. class C_BaseAnimating;
  13. //--------------------------------------------------------------------------------
  14. struct RagdollSimulationFrame_t
  15. {
  16. RagdollSimulationFrame_t() : pPositions(NULL), pAngles(NULL), nTick(-1) {}
  17. static RagdollSimulationFrame_t* Alloc( int nNumBones );
  18. int nTick;
  19. Vector* pPositions;
  20. QAngle* pAngles;
  21. Vector vRootPosition;
  22. QAngle angRootAngles;
  23. };
  24. //--------------------------------------------------------------------------------
  25. struct RagdollSimulationData_t
  26. {
  27. RagdollSimulationData_t( C_BaseAnimating* pEntity = NULL, int nStartTick = 0, int nNumBones = 0 );
  28. void Record();
  29. int m_nEntityIndex;
  30. int m_nStartTick;
  31. int m_nDuration;
  32. int m_nNumBones;
  33. typedef unsigned short Iterator_t;
  34. CUtlLinkedList< RagdollSimulationFrame_t*, Iterator_t > m_lstFrames;
  35. C_BaseAnimating* m_pEntity;
  36. };
  37. //--------------------------------------------------------------------------------
  38. // TODO: Refactor this into an interface and hide implementation in cpp file
  39. class CReplayRagdollRecorder
  40. {
  41. private:
  42. CReplayRagdollRecorder();
  43. ~CReplayRagdollRecorder();
  44. public:
  45. static CReplayRagdollRecorder& Instance();
  46. void Init();
  47. void Shutdown();
  48. void Think();
  49. void AddEntry( C_BaseAnimating* pEntity, int nStartTick, int nNumBones );
  50. void StopRecordingRagdoll( C_BaseAnimating* pEntity );
  51. void CleanupStartupTicksAndDurations( int nStartTick );
  52. bool DumpRagdollsToDisk( char const* pszFilename ) const;
  53. bool IsRecording() const { return m_bIsRecording; }
  54. private:
  55. typedef unsigned short Iterator_t;
  56. void StopRecordingRagdollAtIndex( Iterator_t nIndex );
  57. void StopRecordingSleepingRagdolls();
  58. void RemoveExpiredRagdollEntries();
  59. void Record();
  60. bool FindEntryInRecordingList( C_BaseAnimating* pEntity, Iterator_t& nOutIndex );
  61. CUtlLinkedList< RagdollSimulationData_t*, Iterator_t > m_lstRagdolls;
  62. CUtlLinkedList< RagdollSimulationData_t*, Iterator_t > m_lstRagdollsToRecord; // Contains some of the elements from m_lstRagdolls -
  63. // the ones which are still recording
  64. bool m_bIsRecording;
  65. };
  66. //--------------------------------------------------------------------------------
  67. class CReplayRagdollCache
  68. {
  69. private:
  70. CReplayRagdollCache();
  71. public:
  72. static CReplayRagdollCache& Instance();
  73. bool Init( char const* pszFilename );
  74. void Shutdown();
  75. void Think();
  76. bool IsInitialized() const { return m_bInit; }
  77. //
  78. // Returns false is no frame exists for the given entity at the given tick.
  79. // Otherwise, returns a
  80. //
  81. bool GetFrame( C_BaseAnimating* pEntity, int nTick, bool* pBoneSimulated, CBoneAccessor* pBoneAccessor ) const;
  82. private:
  83. RagdollSimulationData_t* FindRagdollEntry( C_BaseAnimating* pEntity, int nTick );
  84. const RagdollSimulationData_t* FindRagdollEntry( C_BaseAnimating* pEntity, int nTick ) const;
  85. bool FindFrame( RagdollSimulationFrame_t*& pFrameOut, RagdollSimulationFrame_t*& pNextFrameOut,
  86. const RagdollSimulationData_t* pRagdollEntry, int nTick );
  87. bool FindFrame( RagdollSimulationFrame_t*& pFrameOut, RagdollSimulationFrame_t*& pNextFrameOut,
  88. const RagdollSimulationData_t* pRagdollEntry, int nTick ) const;
  89. typedef unsigned short Iterator_t;
  90. bool m_bInit;
  91. CUtlLinkedList< RagdollSimulationData_t*, Iterator_t > m_lstRagdolls;
  92. };
  93. //--------------------------------------------------------------------------------
  94. bool Replay_CacheRagdolls( const char* pFilename, int nStartTick );
  95. //--------------------------------------------------------------------------------
  96. inline const RagdollSimulationData_t* CReplayRagdollCache::FindRagdollEntry( C_BaseAnimating* pEntity, int nTick ) const
  97. {
  98. return const_cast< CReplayRagdollCache* >( this )->FindRagdollEntry( pEntity, nTick );
  99. }
  100. inline bool CReplayRagdollCache::FindFrame( RagdollSimulationFrame_t*& pFrameOut, RagdollSimulationFrame_t*& pNextFrameOut,
  101. const RagdollSimulationData_t* pRagdollEntry, int nTick ) const
  102. {
  103. return const_cast< CReplayRagdollCache* >( this )->FindFrame( pFrameOut, pNextFrameOut, pRagdollEntry, nTick );
  104. }
  105. //--------------------------------------------------------------------------------
  106. #endif // REPLAY_RAGDOLL_H