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