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.

60 lines
2.0 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. #ifndef JOBTIME_H
  7. #define JOBTIME_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. namespace GCSDK
  12. {
  13. // CJobTime
  14. // This is our primary job time structure. It's similar to the Windows FILETIME structure, but
  15. // with 1/10th the nominal resolution.
  16. // It offers 1 microsecond resolution beginning on January 1, 1601.
  17. // This is NOT wall clock time, it is time based proxy for a frame counter.
  18. // This time PAUSES when you are in the debugger. Most timeout checks (things that don't need to be
  19. // exact time wise should use this );
  20. class CJobTime
  21. {
  22. public:
  23. CJobTime();
  24. void SetToJobTime();
  25. void SetFromJobTime( int64 dMicroSecOffset );
  26. // Amount of time that's passed between this CJobTime and the current time.
  27. int64 CServerMicroSecsPassed() const;
  28. // Time accessors
  29. uint64 LTime() const { return m_lTime; }
  30. void SetLTime( uint64 lTime ) { m_lTime = lTime; }
  31. // Access our cached current time value
  32. static void UpdateJobTime( int cMicroSecPerShellFrame );
  33. static void SetCurrentJobTime( uint64 lCurrentTime );
  34. static uint64 LJobTimeCur() { return sm_lTimeCur; }
  35. bool operator==( const CJobTime &val ) const { return val.m_lTime == m_lTime; }
  36. bool operator!=( const CJobTime &val ) const { return val.m_lTime != m_lTime; }
  37. bool operator<( const CJobTime &val ) const { return m_lTime < val.m_lTime; }
  38. bool operator>( const CJobTime &val ) const { return m_lTime > val.m_lTime; }
  39. const CJobTime& operator+( const int64 &val ) { m_lTime += val; return *this; }
  40. const CJobTime& operator+=( const int64 &val ) { m_lTime += val; return *this; }
  41. private:
  42. uint64 m_lTime; // Our time value (microseconds since 1/1/1601)
  43. static uint64 sm_lTimeCur; // Cached value of the current time (updated each frame)
  44. };
  45. const uint64 k_lJobTimeMaxFuture = (uint64)-1;
  46. }
  47. #endif // JOBTIME_H