ovr_sdk

view LibOVR/Src/Kernel/OVR_Timer.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line source
1 /************************************************************************************
3 PublicHeader: OVR
4 Filename : OVR_Timer.h
5 Content : Provides static functions for precise timing
6 Created : September 19, 2012
7 Notes :
9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
11 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
16 You may obtain a copy of the License at
18 http://www.oculusvr.com/licenses/LICENSE-3.2
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
26 ************************************************************************************/
28 #ifndef OVR_Timer_h
29 #define OVR_Timer_h
31 #include "OVR_Types.h"
33 namespace OVR {
35 //-----------------------------------------------------------------------------------
36 // ***** Timer
38 // Timer class defines a family of static functions used for application
39 // timing and profiling.
41 class Timer
42 {
43 public:
44 enum {
45 MsPerSecond = 1000, // Milliseconds in one second.
46 MksPerSecond = 1000 * 1000, // Microseconds in one second.
47 NanosPerSecond = 1000 * 1000 * 1000, // Nanoseconds in one second.
48 };
50 // ***** Timing APIs for Application
52 // These APIs should be used to guide animation and other program functions
53 // that require precision.
55 // Returns global high-resolution application timer in seconds.
56 static double OVR_STDCALL GetSeconds();
58 // Returns time in Nanoseconds, using highest possible system resolution.
59 static uint64_t OVR_STDCALL GetTicksNanos();
61 // Kept for compatibility.
62 // Returns ticks in milliseconds, as a 32-bit number. May wrap around every 49.2 days.
63 // Use either time difference of two values of GetTicks to avoid wrap-around.
64 static uint32_t OVR_STDCALL GetTicksMs()
65 { return uint32_t(GetTicksNanos() / 1000000); }
67 // for recorded data playback
68 static void SetFakeSeconds(double fakeSeconds, bool enable = true)
69 {
70 FakeSeconds = fakeSeconds;
71 useFakeSeconds = enable;
72 }
74 private:
75 friend class System;
76 // System called during program startup/shutdown.
77 static void initializeTimerSystem();
78 static void shutdownTimerSystem();
80 // for recorded data playback
81 static double FakeSeconds;
82 static bool useFakeSeconds;
84 #if defined(OVR_OS_ANDROID)
85 // Android-specific data
86 #elif defined (OVR_OS_MS)
87 // Microsoft-specific data
88 #elif defined(OVR_OS_MAC)
89 static double TimeConvertFactorNanos; // Conversion factor for GetTicksNanos
90 static double TimeConvertFactorSeconds; // Conversion factor for GetSeconds.
91 #else
92 static bool MonotonicClockAvailable; // True if clock_gettime supports CLOCK_MONOTONIC
93 #endif
94 };
97 } // OVR::Timer
99 #endif