OVR_Timer.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /************************************************************************************
  2. PublicHeader: OVR
  3. Filename : OVR_Timer.h
  4. Content : Provides static functions for precise timing
  5. Created : September 19, 2012
  6. Notes :
  7. Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
  8. Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
  9. you may not use the Oculus VR Rift SDK except in compliance with the License,
  10. which is provided at the time of installation or download, or which
  11. otherwise accompanies this software in either electronic or hard copy form.
  12. You may obtain a copy of the License at
  13. http://www.oculusvr.com/licenses/LICENSE-3.2
  14. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  15. distributed under the License is distributed on an "AS IS" BASIS,
  16. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. See the License for the specific language governing permissions and
  18. limitations under the License.
  19. ************************************************************************************/
  20. #ifndef OVR_Timer_h
  21. #define OVR_Timer_h
  22. #include "OVR_Types.h"
  23. namespace OVR {
  24. //-----------------------------------------------------------------------------------
  25. // ***** Timer
  26. // Timer class defines a family of static functions used for application
  27. // timing and profiling.
  28. class Timer
  29. {
  30. public:
  31. enum {
  32. MsPerSecond = 1000, // Milliseconds in one second.
  33. MksPerSecond = 1000 * 1000, // Microseconds in one second.
  34. NanosPerSecond = 1000 * 1000 * 1000, // Nanoseconds in one second.
  35. };
  36. // ***** Timing APIs for Application
  37. // These APIs should be used to guide animation and other program functions
  38. // that require precision.
  39. // Returns global high-resolution application timer in seconds.
  40. static double OVR_STDCALL GetSeconds();
  41. // This may return a recorded time if Replaying a recording
  42. static double OVR_STDCALL GetVirtualSeconds();
  43. // Returns time in Nanoseconds, using highest possible system resolution.
  44. static uint64_t OVR_STDCALL GetTicksNanos();
  45. // This may return a recorded time if Replaying a recording
  46. static uint64_t OVR_STDCALL GetVirtualTicksNanos();
  47. #ifdef OVR_OS_MS
  48. static double OVR_STDCALL GetPerfFrequencyInverse();
  49. #endif
  50. // Kept for compatibility.
  51. // Returns ticks in milliseconds, as a 32-bit number. May wrap around every 49.2 days.
  52. // Use either time difference of two values of GetTicks to avoid wrap-around.
  53. static uint32_t OVR_STDCALL GetTicksMs()
  54. { return uint32_t(GetTicksNanos() / 1000000); }
  55. // This may return a recorded time if Replaying a recording
  56. static uint32_t OVR_STDCALL GetVirtualTicksMs()
  57. { return uint32_t(GetVirtualTicksNanos() / 1000000); }
  58. // for recorded data playback
  59. static void SetVirtualSeconds(double virtualSeconds, bool enable = true)
  60. {
  61. VirtualSeconds = virtualSeconds;
  62. useVirtualSeconds = enable;
  63. }
  64. private:
  65. friend class System;
  66. // System called during program startup/shutdown.
  67. static void initializeTimerSystem();
  68. static void shutdownTimerSystem();
  69. // for recorded data playback.
  70. static double VirtualSeconds;
  71. static bool useVirtualSeconds;
  72. #if defined(OVR_OS_ANDROID)
  73. // Android-specific data
  74. #elif defined (OVR_OS_MS)
  75. // Microsoft-specific data
  76. #endif
  77. };
  78. } // OVR::Timer
  79. #endif