00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTTIME_H
00030 #define NVBLASTTIME_H
00031
00032 #include "NvBlastTypes.h"
00033
00034
00035 namespace Nv
00036 {
00037 namespace Blast
00038 {
00039
00040 class Time
00041 {
00042 public:
00043 Time() : m_lastTickCount(getTimeTicks()) {}
00044
00045 int64_t getElapsedTicks()
00046 {
00047 const int64_t lastTickCount = m_lastTickCount;
00048 m_lastTickCount = getTimeTicks();
00049 return m_lastTickCount - lastTickCount;
00050 }
00051
00052 int64_t peekElapsedTicks() const
00053 {
00054 return getTimeTicks() - m_lastTickCount;
00055 }
00056
00057 int64_t getLastTickCount() const
00058 {
00059 return m_lastTickCount;
00060 }
00061
00062 static double seconds(int64_t ticks)
00063 {
00064 return s_secondsPerTick * ticks;
00065 }
00066
00067 private:
00068 int64_t getTimeTicks() const;
00069 static double getTickDuration();
00070
00071 int64_t m_lastTickCount;
00072 static const double s_secondsPerTick;
00073 };
00074
00075 }
00076 }
00077
00078
00080
00081 #if NV_MICROSOFT_FAMILY
00082
00083 #include "NvBlastIncludeWindows.h"
00084
00085 NV_INLINE int64_t Nv::Blast::Time::getTimeTicks() const
00086 {
00087 LARGE_INTEGER a;
00088 QueryPerformanceCounter(&a);
00089 return a.QuadPart;
00090 }
00091
00092 NV_INLINE double Nv::Blast::Time::getTickDuration()
00093 {
00094 LARGE_INTEGER a;
00095 QueryPerformanceFrequency(&a);
00096 return 1.0 / (double)a.QuadPart;
00097 }
00098
00099 #elif NV_UNIX_FAMILY
00100
00101 #include <time.h>
00102
00103 NV_INLINE int64_t Nv::Blast::Time::getTimeTicks() const
00104 {
00105 struct timespec mCurrTimeInt;
00106 clock_gettime(CLOCK_REALTIME, &mCurrTimeInt);
00107 return (static_cast<int64_t>(mCurrTimeInt.tv_sec) * 1000000000) + (static_cast<int64_t>(mCurrTimeInt.tv_nsec));
00108 }
00109
00110 NV_INLINE double Nv::Blast::Time::getTickDuration()
00111 {
00112 return 1.e-9;
00113 }
00114
00115 #elif NV_PS4
00116
00117 #include "ps4/NvBlastTimePS4.h"
00118
00119 #endif
00120
00121 #endif // #ifndef NVBLASTTIME_H