From f81b42747bdb89a562b76e854c403878260b6f88 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Thu, 22 Aug 2013 20:40:45 +0100 Subject: [PATCH] Implement Timer for C++11 This uses std::chrono::system_clock --- .../include/PolyVoxCore/Impl/Timer.h | 24 +++++++------------ library/PolyVoxCore/source/Impl/Timer.cpp | 7 ++++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h index 6ce9c328..88ccee45 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h @@ -28,37 +28,31 @@ freely, subject to the following restrictions: #ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied. #include +#else +#include #endif //_MSC_VER namespace PolyVox { -#if defined(_MSC_VER) class Timer { public: Timer(bool bAutoStart = true); - + void start(void); - + float elapsedTimeInSeconds(void); uint32_t elapsedTimeInMilliSeconds(void); - + private: +#if defined(_MSC_VER) double m_fPCFreq; __int64 m_iStartTime; - }; #else //_MSC_VER - class Timer - { - public: - Timer(bool bAutoStart = true); - - void start(void); - - float elapsedTimeInSeconds(void); - uint32_t elapsedTimeInMilliSeconds(void); - }; + typedef std::chrono::system_clock clock; + std::chrono::time_point m_start; #endif //_MSC_VER + }; } #endif //__PolyVox_Timer_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/source/Impl/Timer.cpp b/library/PolyVoxCore/source/Impl/Timer.cpp index 49ec9a11..32190aa8 100644 --- a/library/PolyVoxCore/source/Impl/Timer.cpp +++ b/library/PolyVoxCore/source/Impl/Timer.cpp @@ -78,16 +78,19 @@ namespace PolyVox void Timer::start(void) { + m_start = clock::now(); } float Timer::elapsedTimeInSeconds(void) { - return 0.0f; + std::chrono::duration elapsed_seconds = clock::now() - m_start; + return elapsed_seconds.count(); } uint32_t Timer::elapsedTimeInMilliSeconds(void) { - return 0; + std::chrono::duration elapsed_milliseconds = clock::now() - m_start; + return elapsed_milliseconds.count(); } #endif //_MSC_VER }