1 2 3 4 5 6 7 8 9 10 11 12 13 14 #pragma once15 16 17 18 19 #ifdef __EMSCRIPTEN__20 21 22 23 24 #define MATH_TICK_IS_FLOAT25 #include <limits>26 #endif27 28 #include "../Math/MathNamespace.h"29 30 [MATH_BEGIN_NAMESPACE]31 32 33 34 #ifdef MATH_TICK_IS_FLOAT35 typedef double [tick_t];36 const [tick_t] [TICK_INF] = std::numeric_limits<double>::infinity();37 #else38 typedef unsigned long long [tick_t];39 const [tick_t] [TICK_INF] = 0xFFFFFFFFFFFFFFFFULL;40 #endif41 42 43 44 45 46 class [Clock]47 {48 public:49 [Clock]();50 51 52 53 static void [Sleep](int milliseconds);54 55 56 static int [Year]();57 58 59 static int [Month]();60 61 62 static int [Day]();63 64 65 static int [Hour]();66 67 68 static int [Min]();69 70 71 static int [Sec]();72 73 74 static unsigned long [SystemTime]();75 76 77 static unsigned long [Time]();78 79 80 static unsigned long [TickU32]();81 82 83 static [tick_t] [Tick]();84 85 86 static [tick_t] [TicksPerSec]();87 88 static inline [tick_t] [TicksPerMillisecond]() { return [TicksPerSec]() / 1000; }89 90 91 static inline [tick_t] [TicksInBetween]([tick_t] newTick, [tick_t] oldTick)92 {93 return ([tick_t])(newTick - oldTick);94 }95 96 97 static inline bool [IsNewer]([tick_t] newTick, [tick_t] oldTick)98 {99 #ifdef MATH_TICK_IS_FLOAT100 return newTick >= oldTick;101 #else102 return [TicksInBetween](newTick, oldTick) < (([tick_t])(-1) >> 1);103 #endif104 }105 106 static inline float [MillisecondsSinceF]([tick_t] oldTick) { return [TimespanToMillisecondsF](oldTick, [Tick]()); }107 static inline double [MillisecondsSinceD]([tick_t] oldTick) { return [TimespanToMillisecondsD](oldTick, [Tick]()); }108 109 static inline float [SecondsSinceF]([tick_t] oldTick) { return [TimespanToSecondsF](oldTick, [Tick]()); }110 static inline double [SecondsSinceD]([tick_t] oldTick) { return [TimespanToSecondsD](oldTick, [Tick]()); }111 112 static inline float [TicksToMillisecondsF]([tick_t] ticks) { return ticks * 1000.f / [TicksPerSec](); }113 static inline double [TicksToMillisecondsD]([tick_t] ticks) { return ticks * 1000.0 / [TicksPerSec](); }114 115 static inline float [TicksToSecondsF]([tick_t] ticks) { return ticks / (float)[TicksPerSec](); }116 static inline double [TicksToSecondsD]([tick_t] ticks) { return ticks / (double)[TicksPerSec](); }117 118 static inline float [TimespanToMillisecondsF]([tick_t] oldTick, [tick_t] newTick) { return [TicksToMillisecondsF]([TicksInBetween](newTick, oldTick)); }119 static inline double [TimespanToMillisecondsD]([tick_t] oldTick, [tick_t] newTick) { return [TicksToMillisecondsD]([TicksInBetween](newTick, oldTick)); }120 121 static inline float [TimespanToSecondsF]([tick_t] oldTick, [tick_t] newTick) { return [TicksToSecondsF]([TicksInBetween](newTick, oldTick)); }122 static inline double [TimespanToSecondsD]([tick_t] oldTick, [tick_t] newTick) { return [TicksToSecondsD]([TicksInBetween](newTick, oldTick)); }123 124 static unsigned long long [Rdtsc]();125 126 private:127 static [tick_t] appStartTime; 128 129 130 static void InitClockData();131 132 #ifdef WIN32133 134 135 static [u64] ddwTimerFrequency; 136 #endif137 #ifdef __APPLE__138 static [tick_t] ticksPerSecond;139 #endif140 };141 142 [MATH_END_NAMESPACE] Go back to previous page