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
2.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef IPREDICTIONSYSTEM_H
  8. #define IPREDICTIONSYSTEM_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "predictable_entity.h"
  13. class CBaseEntity;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Interfaces derived from this are able to filter out the local player
  16. // when doing prediction on the client, this includes not sending network data to
  17. // the local player from the server if needed.
  18. //-----------------------------------------------------------------------------
  19. class IPredictionSystem
  20. {
  21. public:
  22. IPredictionSystem()
  23. {
  24. m_pNextSystem = g_pPredictionSystems;
  25. g_pPredictionSystems = this;
  26. m_bSuppressEvent = false;
  27. m_pSuppressHost = NULL;
  28. m_nStatusPushed = 0;
  29. };
  30. virtual ~IPredictionSystem() {};
  31. IPredictionSystem *GetNext()
  32. {
  33. return m_pNextSystem;
  34. }
  35. void SetSuppressEvent( bool state )
  36. {
  37. m_bSuppressEvent = state;
  38. }
  39. void SetSuppressHost( CBaseEntity *host )
  40. {
  41. m_pSuppressHost = host;
  42. }
  43. CBaseEntity const *GetSuppressHost( void )
  44. {
  45. if ( DisableFiltering() )
  46. {
  47. return NULL;
  48. }
  49. return m_pSuppressHost;
  50. }
  51. bool CanPredict( void ) const
  52. {
  53. if ( DisableFiltering() )
  54. {
  55. return false;
  56. }
  57. return !m_bSuppressEvent;
  58. }
  59. static IPredictionSystem *g_pPredictionSystems;
  60. static void SuppressEvents( bool state )
  61. {
  62. IPredictionSystem *sys = g_pPredictionSystems;
  63. while ( sys )
  64. {
  65. sys->SetSuppressEvent( state );
  66. sys = sys->GetNext();
  67. }
  68. }
  69. static void SuppressHostEvents( CBaseEntity *host )
  70. {
  71. IPredictionSystem *sys = g_pPredictionSystems;
  72. while ( sys )
  73. {
  74. sys->SetSuppressHost( host );
  75. sys = sys->GetNext();
  76. }
  77. }
  78. private:
  79. static void Push( void )
  80. {
  81. IPredictionSystem *sys = g_pPredictionSystems;
  82. while ( sys )
  83. {
  84. sys->_Push();
  85. sys = sys->GetNext();
  86. }
  87. }
  88. static void Pop( void )
  89. {
  90. IPredictionSystem *sys = g_pPredictionSystems;
  91. while ( sys )
  92. {
  93. sys->_Pop();
  94. sys = sys->GetNext();
  95. }
  96. }
  97. void _Push( void )
  98. {
  99. ++m_nStatusPushed;
  100. }
  101. void _Pop( void )
  102. {
  103. --m_nStatusPushed;
  104. }
  105. bool DisableFiltering( void ) const
  106. {
  107. return ( m_nStatusPushed > 0 ) ? true : false;
  108. }
  109. IPredictionSystem *m_pNextSystem;
  110. bool m_bSuppressEvent;
  111. CBaseEntity *m_pSuppressHost;
  112. int m_nStatusPushed;
  113. friend class CDisablePredictionFiltering;
  114. };
  115. class CDisablePredictionFiltering
  116. {
  117. public:
  118. CDisablePredictionFiltering( bool disable = true )
  119. {
  120. m_bDisabled = disable;
  121. if ( m_bDisabled )
  122. {
  123. IPredictionSystem::Push();
  124. }
  125. }
  126. ~CDisablePredictionFiltering( void )
  127. {
  128. if ( m_bDisabled )
  129. {
  130. IPredictionSystem::Pop();
  131. }
  132. }
  133. private:
  134. bool m_bDisabled;
  135. };
  136. #endif // IPREDICTIONSYSTEM_H