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.

109 lines
3.2 KiB

  1. //========= Copyright 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. // for encoding m_flSimulationTime, m_flAnimTime
  22. int GetNetworkBase( int nTick, int nEntity );
  23. public:
  24. // Absolute time (per frame still - Use Plat_FloatTime() for a high precision real time
  25. // perf clock, but not that it doesn't obey host_timescale/host_framerate)
  26. float realtime;
  27. // Absolute frame counter
  28. int framecount;
  29. // Non-paused frametime
  30. float absoluteframetime;
  31. // Current time
  32. //
  33. // On the client, this (along with tickcount) takes a different meaning based on what
  34. // piece of code you're in:
  35. //
  36. // - While receiving network packets (like in PreDataUpdate/PostDataUpdate and proxies),
  37. // this is set to the SERVER TICKCOUNT for that packet. There is no interval between
  38. // the server ticks.
  39. // [server_current_Tick * tick_interval]
  40. //
  41. // - While rendering, this is the exact client clock
  42. // [client_current_tick * tick_interval + interpolation_amount]
  43. //
  44. // - During prediction, this is based on the client's current tick:
  45. // [client_current_tick * tick_interval]
  46. float curtime;
  47. // Time spent on last server or client frame (has nothing to do with think intervals)
  48. float frametime;
  49. // current maxplayers setting
  50. int maxClients;
  51. // Simulation ticks
  52. int tickcount;
  53. // Simulation tick interval
  54. float interval_per_tick;
  55. // interpolation amount ( client-only ) based on fraction of next tick which has elapsed
  56. float interpolation_amount;
  57. int simTicksThisFrame;
  58. int network_protocol;
  59. // current saverestore data
  60. CSaveRestoreData *pSaveData;
  61. private:
  62. // Set to true in client code.
  63. bool m_bClient;
  64. // 100 (i.e., tickcount is rounded down to this base and then the "delta" from this base is networked
  65. int nTimestampNetworkingBase;
  66. // 32 (entindex() % nTimestampRandomizeWindow ) is subtracted from gpGlobals->tickcount to set the networking basis, prevents
  67. // all of the entities from forcing a new PackedEntity on the same tick (i.e., prevents them from getting lockstepped on this)
  68. int nTimestampRandomizeWindow;
  69. };
  70. inline int CGlobalVarsBase::GetNetworkBase( int nTick, int nEntity )
  71. {
  72. int nEntityMod = nEntity % nTimestampRandomizeWindow;
  73. int nBaseTick = nTimestampNetworkingBase * (int)( ( nTick - nEntityMod ) / nTimestampNetworkingBase );
  74. return nBaseTick;
  75. }
  76. inline CGlobalVarsBase::CGlobalVarsBase( bool bIsClient ) :
  77. m_bClient( bIsClient ),
  78. nTimestampNetworkingBase( 100 ),
  79. nTimestampRandomizeWindow( 32 )
  80. {
  81. }
  82. inline bool CGlobalVarsBase::IsClient() const
  83. {
  84. return m_bClient;
  85. }
  86. #endif // GLOBALVARS_BASE_H