nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: OVR nuclear@0: Filename : OVR_Timer.h nuclear@0: Content : Provides static functions for precise timing nuclear@0: Created : September 19, 2012 nuclear@0: Notes : nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_Timer_h nuclear@0: #define OVR_Timer_h nuclear@0: nuclear@0: #include "OVR_Types.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: //----------------------------------------------------------------------------------- nuclear@0: // ***** Timer nuclear@0: nuclear@0: // Timer class defines a family of static functions used for application nuclear@0: // timing and profiling. nuclear@0: nuclear@0: class Timer nuclear@0: { nuclear@0: public: nuclear@0: enum { nuclear@0: MsPerSecond = 1000, // Milliseconds in one second. nuclear@0: MksPerSecond = 1000 * 1000, // Microseconds in one second. nuclear@0: NanosPerSecond = 1000 * 1000 * 1000, // Nanoseconds in one second. nuclear@0: }; nuclear@0: nuclear@0: // ***** Timing APIs for Application nuclear@0: nuclear@0: // These APIs should be used to guide animation and other program functions nuclear@0: // that require precision. nuclear@0: nuclear@0: // Returns global high-resolution application timer in seconds. nuclear@0: static double OVR_STDCALL GetSeconds(); nuclear@0: nuclear@0: // Returns time in Nanoseconds, using highest possible system resolution. nuclear@0: static uint64_t OVR_STDCALL GetTicksNanos(); nuclear@0: nuclear@0: // Kept for compatibility. nuclear@0: // Returns ticks in milliseconds, as a 32-bit number. May wrap around every 49.2 days. nuclear@0: // Use either time difference of two values of GetTicks to avoid wrap-around. nuclear@0: static uint32_t OVR_STDCALL GetTicksMs() nuclear@0: { return uint32_t(GetTicksNanos() / 1000000); } nuclear@0: nuclear@0: // for recorded data playback nuclear@0: static void SetFakeSeconds(double fakeSeconds, bool enable = true) nuclear@0: { nuclear@0: FakeSeconds = fakeSeconds; nuclear@0: useFakeSeconds = enable; nuclear@0: } nuclear@0: nuclear@0: private: nuclear@0: friend class System; nuclear@0: // System called during program startup/shutdown. nuclear@0: static void initializeTimerSystem(); nuclear@0: static void shutdownTimerSystem(); nuclear@0: nuclear@0: // for recorded data playback nuclear@0: static double FakeSeconds; nuclear@0: static bool useFakeSeconds; nuclear@0: nuclear@0: #if defined(OVR_OS_ANDROID) nuclear@0: // Android-specific data nuclear@0: #elif defined (OVR_OS_MS) nuclear@0: // Microsoft-specific data nuclear@0: #elif defined(OVR_OS_MAC) nuclear@0: static double TimeConvertFactorNanos; // Conversion factor for GetTicksNanos nuclear@0: static double TimeConvertFactorSeconds; // Conversion factor for GetSeconds. nuclear@0: #else nuclear@0: static bool MonotonicClockAvailable; // True if clock_gettime supports CLOCK_MONOTONIC nuclear@0: #endif nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: } // OVR::Timer nuclear@0: nuclear@0: #endif