oculus1

view libovr/Src/Kernel/OVR_Timer.h @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
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 2012 Oculus VR, Inc. All Rights reserved.
11 Use of this software is subject to the terms of the Oculus license
12 agreement provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 ************************************************************************************/
17 #ifndef OVR_Timer_h
18 #define OVR_Timer_h
20 #include "OVR_Types.h"
22 namespace OVR {
24 //-----------------------------------------------------------------------------------
25 // ***** Timer
27 // Timer class defines a family of static functions used for application
28 // timing and profiling.
30 class Timer
31 {
32 public:
33 enum {
34 MsPerSecond = 1000, // Milliseconds in one second.
35 MksPerMs = 1000, // Microseconds in one millisecond.
36 MksPerSecond = MsPerSecond * MksPerMs
37 };
40 // ***** Timing APIs for Application
41 // These APIs should be used to guide animation and other program functions
42 // that require precision.
44 // Returns ticks in milliseconds, as a 32-bit number. May wrap around every
45 // 49.2 days. Use either time difference of two values of GetTicks to avoid
46 // wrap-around. GetTicksMs may perform better then GetTicks.
47 static UInt32 OVR_STDCALL GetTicksMs();
49 // GetTicks returns general-purpose high resolution application timer value,
50 // measured in microseconds (mks, or 1/1000000 of a second). The actual precision
51 // is system-specific and may be much lower, such as 1 ms.
52 static UInt64 OVR_STDCALL GetTicks();
55 // ***** Profiling APIs.
56 // These functions should be used for profiling, but may have system specific
57 // artifacts that make them less appropriate for general system use.
58 // On Win32, for example these rely on QueryPerformanceConter may have
59 // problems with thread-core switching and power modes.
61 // Return a hi-res timer value in mks (1/1000000 of a sec).
62 // Generally you want to call this at the start and end of an
63 // operation, and pass the difference to
64 // TicksToSeconds() to find out how long the operation took.
65 static UInt64 OVR_STDCALL GetProfileTicks();
67 // More convenient zero-based profile timer in seconds. First call initializes
68 // the "zero" value; future calls return the difference. Not thread safe for first call.
69 // Due to low precision of Double, may malfunction after long runtime.
70 static double OVR_STDCALL GetProfileSeconds();
72 // Get the raw cycle counter value, providing the maximum possible timer resolution.
73 static UInt64 OVR_STDCALL GetRawTicks();
74 static UInt64 OVR_STDCALL GetRawFrequency();
77 // ***** Tick and time unit conversion.
79 // Convert micro-second ticks value into seconds value.
80 static inline double TicksToSeconds(UInt64 ticks)
81 {
82 return static_cast<double>(ticks) * (1.0 / (double)MksPerSecond);
83 }
84 // Convert Raw or frequency-unit ticks to seconds based on specified frequency.
85 static inline double RawTicksToSeconds(UInt64 rawTicks, UInt64 rawFrequency)
86 {
87 return static_cast<double>(rawTicks) * rawFrequency;
88 }
90 private:
91 friend class System;
92 // System called during program startup/shutdown.
93 static void initializeTimerSystem();
94 static void shutdownTimerSystem();
95 };
98 } // Scaleform::Timer
100 #endif