gwnavruntime/kernel/SF_Timer.h Source File

SF_Timer.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 /**************************************************************************
8 
9 PublicHeader: None
10 Filename : KY_Timer.h
11 Content : Provides static functions for precise timing
12 Created : June 28, 2005
13 Authors :
14 
15 **************************************************************************/
16 
17 #ifndef INC_KY_Kernel_Timer_H
18 #define INC_KY_Kernel_Timer_H
19 
21 
22 namespace Kaim {
23 
24 //------------------------------------------------------------------------
25 // ***** Timer
26 
27 // Timer class defines a family of static functions used for application
28 // timing and profiling.
29 
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  };
38 
39 
40  // ***** Timing APIs for Application
41  // These APIs should be used to guide animation and other program functions
42  // that require precision.
43 
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 KY_STDCALL GetTicksMs();
48 
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 KY_STDCALL GetTicks();
53 
54 
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.
60 
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 KY_STDCALL GetProfileTicks();
66 
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 KY_STDCALL GetProfileSeconds();
71 
72  // Get the raw cycle counter value, providing the maximum possible timer resolution.
73  static UInt64 KY_STDCALL GetRawTicks();
74  static UInt64 KY_STDCALL GetRawFrequency();
75 
76 
77  // ***** Tick and time unit conversion.
78 
79  // Convert micro-second ticks value into seconds value.
80  static inline Double TicksToSeconds(UInt64 ticks)
81  {
82  return static_cast<Double>(ticks) * ((Double)1.0 / (Double)MksPerSecond);
83  }
84 
85  // ***** Timer implementation overriding.
86  // Setting a non-null override instance will cause all Timer static functions to
87  // use the overridden implementation, instead of the default. This can be used
88  // (for example) to create deterministic timers, instead of wall-clock timers.
89  class TimerOverride
90  {
91  public:
92  virtual ~TimerOverride() {}
93 
94  virtual UInt32 GetTicksMs() = 0;
95  virtual UInt64 GetRawTicks() = 0;
96  virtual UInt64 GetRawFrequency() = 0;
97  };
98  static void KY_STDCALL SetTimerOverride(TimerOverride* instance);
99 
100 private:
101  friend class System;
102  // System called during program startup/shutdown.
103  static void initializeTimerSystem();
104  static void shutdownTimerSystem();
105 };
106 
107 
108 } // Kaim::Timer
109 
110 #endif
Definition: gamekitcrowddispersion.h:20