ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Kernel/OVR_Timer.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,99 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   OVR
     1.7 +Filename    :   OVR_Timer.h
     1.8 +Content     :   Provides static functions for precise timing
     1.9 +Created     :   September 19, 2012
    1.10 +Notes       : 
    1.11 +
    1.12 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.13 +
    1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.16 +which is provided at the time of installation or download, or which 
    1.17 +otherwise accompanies this software in either electronic or hard copy form.
    1.18 +
    1.19 +You may obtain a copy of the License at
    1.20 +
    1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.22 +
    1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.24 +distributed under the License is distributed on an "AS IS" BASIS,
    1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.26 +See the License for the specific language governing permissions and
    1.27 +limitations under the License.
    1.28 +
    1.29 +************************************************************************************/
    1.30 +
    1.31 +#ifndef OVR_Timer_h
    1.32 +#define OVR_Timer_h
    1.33 +
    1.34 +#include "OVR_Types.h"
    1.35 +
    1.36 +namespace OVR {
    1.37 +    
    1.38 +//-----------------------------------------------------------------------------------
    1.39 +// ***** Timer
    1.40 +
    1.41 +// Timer class defines a family of static functions used for application
    1.42 +// timing and profiling.
    1.43 +
    1.44 +class Timer
    1.45 +{
    1.46 +public:
    1.47 +    enum {
    1.48 +        MsPerSecond     = 1000,                  // Milliseconds in one second.
    1.49 +        MksPerSecond    = 1000 * 1000,           // Microseconds in one second.
    1.50 +        NanosPerSecond  = 1000 * 1000 * 1000,    // Nanoseconds in one second.
    1.51 +    };
    1.52 +
    1.53 +    // ***** Timing APIs for Application    
    1.54 +
    1.55 +    // These APIs should be used to guide animation and other program functions
    1.56 +    // that require precision.
    1.57 +
    1.58 +    // Returns global high-resolution application timer in seconds.
    1.59 +    static double  OVR_STDCALL GetSeconds();    
    1.60 +
    1.61 +    // Returns time in Nanoseconds, using highest possible system resolution.
    1.62 +    static uint64_t  OVR_STDCALL GetTicksNanos();
    1.63 +
    1.64 +    // Kept for compatibility.
    1.65 +    // Returns ticks in milliseconds, as a 32-bit number. May wrap around every 49.2 days.
    1.66 +    // Use either time difference of two values of GetTicks to avoid wrap-around.
    1.67 +    static uint32_t  OVR_STDCALL GetTicksMs()
    1.68 +    { return  uint32_t(GetTicksNanos() / 1000000); }
    1.69 +
    1.70 +    // for recorded data playback
    1.71 +    static void SetFakeSeconds(double fakeSeconds, bool enable = true) 
    1.72 +    { 
    1.73 +        FakeSeconds = fakeSeconds; 
    1.74 +        useFakeSeconds = enable; 
    1.75 +    }
    1.76 +
    1.77 +private:
    1.78 +    friend class System;
    1.79 +    // System called during program startup/shutdown.
    1.80 +    static void initializeTimerSystem();
    1.81 +    static void shutdownTimerSystem();
    1.82 +
    1.83 +    // for recorded data playback
    1.84 +    static double FakeSeconds;
    1.85 +    static bool   useFakeSeconds;
    1.86 +    
    1.87 +    #if defined(OVR_OS_ANDROID)
    1.88 +        // Android-specific data
    1.89 +    #elif defined (OVR_OS_MS)
    1.90 +        // Microsoft-specific data
    1.91 +    #elif defined(OVR_OS_MAC)
    1.92 +        static double TimeConvertFactorNanos;     // Conversion factor for GetTicksNanos
    1.93 +        static double TimeConvertFactorSeconds;   // Conversion factor for GetSeconds.
    1.94 +    #else
    1.95 +        static bool MonotonicClockAvailable;      // True if clock_gettime supports CLOCK_MONOTONIC
    1.96 +    #endif
    1.97 +};
    1.98 +
    1.99 +
   1.100 +} // OVR::Timer
   1.101 +
   1.102 +#endif