Implement Timer for C++11
This uses std::chrono::system_clock
This commit is contained in:
parent
55dc066a3f
commit
f81b42747b
@ -28,11 +28,12 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied.
|
#ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied.
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
|
#include <chrono>
|
||||||
#endif //_MSC_VER
|
#endif //_MSC_VER
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER)
|
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -44,21 +45,14 @@ namespace PolyVox
|
|||||||
uint32_t elapsedTimeInMilliSeconds(void);
|
uint32_t elapsedTimeInMilliSeconds(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if defined(_MSC_VER)
|
||||||
double m_fPCFreq;
|
double m_fPCFreq;
|
||||||
__int64 m_iStartTime;
|
__int64 m_iStartTime;
|
||||||
};
|
|
||||||
#else //_MSC_VER
|
#else //_MSC_VER
|
||||||
class Timer
|
typedef std::chrono::system_clock clock;
|
||||||
{
|
std::chrono::time_point<clock> m_start;
|
||||||
public:
|
|
||||||
Timer(bool bAutoStart = true);
|
|
||||||
|
|
||||||
void start(void);
|
|
||||||
|
|
||||||
float elapsedTimeInSeconds(void);
|
|
||||||
uint32_t elapsedTimeInMilliSeconds(void);
|
|
||||||
};
|
|
||||||
#endif //_MSC_VER
|
#endif //_MSC_VER
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //__PolyVox_Timer_H__
|
#endif //__PolyVox_Timer_H__
|
@ -78,16 +78,19 @@ namespace PolyVox
|
|||||||
|
|
||||||
void Timer::start(void)
|
void Timer::start(void)
|
||||||
{
|
{
|
||||||
|
m_start = clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Timer::elapsedTimeInSeconds(void)
|
float Timer::elapsedTimeInSeconds(void)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
std::chrono::duration<float> elapsed_seconds = clock::now() - m_start;
|
||||||
|
return elapsed_seconds.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Timer::elapsedTimeInMilliSeconds(void)
|
uint32_t Timer::elapsedTimeInMilliSeconds(void)
|
||||||
{
|
{
|
||||||
return 0;
|
std::chrono::duration<float, std::milli> elapsed_milliseconds = clock::now() - m_start;
|
||||||
|
return elapsed_milliseconds.count();
|
||||||
}
|
}
|
||||||
#endif //_MSC_VER
|
#endif //_MSC_VER
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user