Team Fortress 2 Source Code as on 22/4/2020
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.

100 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "baserecordingsessionblockmanager.h"
  5. #include "baserecordingsessionblock.h"
  6. #include "replay/replayutils.h"
  7. #include "replay/ireplaycontext.h"
  8. #include "replay/shared_defs.h"
  9. #include "KeyValues.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //----------------------------------------------------------------------------------------
  13. #define RECORDINGSESSIONBLOCKMANAGER_VERSION 0
  14. //----------------------------------------------------------------------------------------
  15. CBaseRecordingSessionBlockManager::CBaseRecordingSessionBlockManager( IReplayContext *pContext )
  16. : m_pContext( pContext )
  17. {
  18. }
  19. bool CBaseRecordingSessionBlockManager::Init()
  20. {
  21. // Call CGenericPersistentManager::Init() to do setup, but don't actually load any blocks on the server.
  22. return BaseClass::Init( ShouldLoadBlocks() );
  23. }
  24. const char *CBaseRecordingSessionBlockManager::GetRelativeIndexPath() const
  25. {
  26. return Replay_va( "%s%c", SUBDIR_BLOCKS, CORRECT_PATH_SEPARATOR );
  27. }
  28. float CBaseRecordingSessionBlockManager::GetNextThinkTime() const
  29. {
  30. return g_pEngine->GetHostTime() + 0.1f;
  31. }
  32. int CBaseRecordingSessionBlockManager::GetVersion() const
  33. {
  34. return RECORDINGSESSIONBLOCKMANAGER_VERSION;
  35. }
  36. CBaseRecordingSessionBlock *CBaseRecordingSessionBlockManager::GetBlock( ReplayHandle_t hBlock )
  37. {
  38. return Find( hBlock );
  39. }
  40. void CBaseRecordingSessionBlockManager::DeleteBlock( CBaseRecordingSessionBlock *pBlock )
  41. {
  42. Remove( pBlock );
  43. }
  44. void CBaseRecordingSessionBlockManager::UnloadBlock( CBaseRecordingSessionBlock *pBlock )
  45. {
  46. FlagForUnload( pBlock );
  47. }
  48. CBaseRecordingSessionBlock *CBaseRecordingSessionBlockManager::FindBlockForSession( ReplayHandle_t hSession, int iReconstruction )
  49. {
  50. FOR_EACH_OBJ( this, i )
  51. {
  52. CBaseRecordingSessionBlock *pCurBlock = m_vecObjs[ i ];
  53. if ( pCurBlock->m_hSession == hSession && pCurBlock->m_iReconstruction == iReconstruction )
  54. {
  55. return pCurBlock;
  56. }
  57. }
  58. return NULL;
  59. }
  60. const char *CBaseRecordingSessionBlockManager::GetSavePath() const
  61. {
  62. return Replay_va(
  63. "%s%c%s%c%s%c",
  64. SUBDIR_REPLAY, CORRECT_PATH_SEPARATOR,
  65. m_pContext->GetReplaySubDir(), CORRECT_PATH_SEPARATOR,
  66. SUBDIR_BLOCKS, CORRECT_PATH_SEPARATOR
  67. );
  68. }
  69. const char *CBaseRecordingSessionBlockManager::GetBlockPath() const
  70. {
  71. return GetSavePath();
  72. }
  73. void CBaseRecordingSessionBlockManager::LoadBlockFromFileName( const char *pFilename, IRecordingSession *pSession )
  74. {
  75. CBaseRecordingSessionBlock *pBlock;
  76. if ( ReadObjFromFile( pFilename, pBlock, true ) )
  77. {
  78. pSession->AddBlock( pBlock );
  79. }
  80. }
  81. //----------------------------------------------------------------------------------------