oculus1

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