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.

119 lines
3.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef GLOBALVARS_BASE_H
  7. #define GLOBALVARS_BASE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class CSaveRestoreData;
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Global variables used by shared code
  14. //-----------------------------------------------------------------------------
  15. class CGlobalVarsBase
  16. {
  17. public:
  18. CGlobalVarsBase( bool bIsClient );
  19. // This can be used to filter debug output or to catch the client or server in the act.
  20. bool IsClient() const;
  21. inline bool IsRemoteClient() const;
  22. // for encoding m_flSimulationTime, m_flAnimTime
  23. int GetNetworkBase( int nTick, int nEntity );
  24. public:
  25. // Absolute time (per frame still - Use Plat_FloatTime() for a high precision real time
  26. // perf clock, but not that it doesn't obey host_timescale/host_framerate)
  27. float realtime;
  28. // Absolute frame counter - continues to increase even if game is paused
  29. int framecount;
  30. // Non-paused frametime
  31. float absoluteframetime;
  32. float absoluteframestarttimestddev;
  33. // Current time
  34. //
  35. // On the client, this (along with tickcount) takes a different meaning based on what
  36. // piece of code you're in:
  37. //
  38. // - While receiving network packets (like in PreDataUpdate/PostDataUpdate and proxies),
  39. // this is set to the SERVER TICKCOUNT for that packet. There is no interval between
  40. // the server ticks.
  41. // [server_current_Tick * tick_interval]
  42. //
  43. // - While rendering, this is the exact client clock
  44. // [client_current_tick * tick_interval + interpolation_amount]
  45. //
  46. // - During prediction, this is based on the client's current tick:
  47. // [client_current_tick * tick_interval]
  48. float curtime;
  49. // Time spent on last server or client frame (has nothing to do with think intervals)
  50. float frametime;
  51. // current maxplayers setting
  52. int maxClients;
  53. // Simulation ticks - does not increase when game is paused
  54. int tickcount;
  55. // Simulation tick interval
  56. float interval_per_tick;
  57. // interpolation amount ( client-only ) based on fraction of next tick which has elapsed
  58. float interpolation_amount;
  59. int simTicksThisFrame;
  60. int network_protocol;
  61. // current saverestore data
  62. CSaveRestoreData *pSaveData;
  63. private:
  64. // Set to true in client code.
  65. bool m_bClient;
  66. public:
  67. // true if we are a remote clinet (needs prediction & interpolation - server not on this machine) as opposed to split-screen or local
  68. bool m_bRemoteClient;
  69. private:
  70. // 100 (i.e., tickcount is rounded down to this base and then the "delta" from this base is networked
  71. int nTimestampNetworkingBase;
  72. // 32 (entindex() % nTimestampRandomizeWindow ) is subtracted from gpGlobals->tickcount to set the networking basis, prevents
  73. // all of the entities from forcing a new PackedEntity on the same tick (i.e., prevents them from getting lockstepped on this)
  74. int nTimestampRandomizeWindow;
  75. };
  76. inline int CGlobalVarsBase::GetNetworkBase( int nTick, int nEntity )
  77. {
  78. int nEntityMod = nEntity % nTimestampRandomizeWindow;
  79. int nBaseTick = nTimestampNetworkingBase * (int)( ( nTick - nEntityMod ) / nTimestampNetworkingBase );
  80. return nBaseTick;
  81. }
  82. inline CGlobalVarsBase::CGlobalVarsBase( bool bIsClient ) :
  83. m_bClient( bIsClient ),
  84. nTimestampNetworkingBase( 100 ),
  85. nTimestampRandomizeWindow( 32 )
  86. {
  87. }
  88. inline bool CGlobalVarsBase::IsClient() const
  89. {
  90. return m_bClient;
  91. }
  92. inline bool CGlobalVarsBase::IsRemoteClient() const
  93. {
  94. return m_bRemoteClient;
  95. }
  96. #endif // GLOBALVARS_BASE_H