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.

77 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Encapsultes the job system's version of time (which is != to wall clock time)
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. namespace GCSDK
  10. {
  11. uint64 CJobTime::sm_lTimeCur = 0;
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Constructor
  14. //-----------------------------------------------------------------------------
  15. CJobTime::CJobTime()
  16. {
  17. m_lTime = sm_lTimeCur;
  18. }
  19. //----------------------------------------------------------------------------
  20. // Purpose: Sets our value to the current time
  21. //-----------------------------------------------------------------------------
  22. void CJobTime::SetToJobTime()
  23. {
  24. m_lTime = sm_lTimeCur;
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Sets our value as an offset from the current time
  28. //-----------------------------------------------------------------------------
  29. void CJobTime::SetFromJobTime( int64 dMicroSecOffset )
  30. {
  31. m_lTime = sm_lTimeCur + dMicroSecOffset;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Returns the amount of time that's passed between our time and the
  35. // current time.
  36. // Output: Time that's passed between our time and the current time
  37. //-----------------------------------------------------------------------------
  38. int64 CJobTime::CServerMicroSecsPassed() const
  39. {
  40. return( sm_lTimeCur - m_lTime );
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Updates our current time value. We only
  44. // update the time once per frame-- the rest of the time, we just
  45. // access a cached copy of the time. On the server, we use an arbitrary
  46. // time value beginning at 0, and incremented by 50 milliseconds every
  47. // frame.
  48. // NOTE: This should only be called once per frame.
  49. //-----------------------------------------------------------------------------
  50. void CJobTime::UpdateJobTime( int cMicroSecPerShellFrame )
  51. {
  52. sm_lTimeCur += cMicroSecPerShellFrame; // force a 50 msec clock
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Stomps the current clock with the specified time
  56. // Input : lCurrentTime - new current time
  57. //-----------------------------------------------------------------------------
  58. void CJobTime::SetCurrentJobTime( uint64 lCurrentTime )
  59. {
  60. sm_lTimeCur = lCurrentTime;
  61. }
  62. } // namespace GCSDK