From 6e8d9dfb752bcca928f66e46dae33dec8fed9d4a Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 6 Feb 2015 16:52:21 +0100 Subject: [PATCH] Windows now uses standard C++ timer. I assume we weren't using it before because it wasn't present on older versions of Visual Studio? Moved timer code to header. --- library/PolyVoxCore/CMakeLists.txt | 2 +- .../include/PolyVoxCore/Impl/Timer.h | 42 ++++--- library/PolyVoxCore/source/Impl/Timer.cpp | 107 ------------------ 3 files changed, 29 insertions(+), 122 deletions(-) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 2e2cb8b0..51ed0841 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -87,7 +87,7 @@ SET(IMPL_SRC_FILES #source/Impl/MarchingCubesTables.cpp #source/Impl/RandomUnitVectors.cpp #source/Impl/RandomVectors.cpp - source/Impl/Timer.cpp + #source/Impl/Timer.cpp source/Impl/Utility.cpp ) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h index d53feb79..9ad25bc6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Timer.h @@ -26,33 +26,47 @@ freely, subject to the following restrictions: #include -#ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied. -#include -#else #include -#endif //_MSC_VER namespace PolyVox { class Timer { public: - Timer(bool bAutoStart = true); + Timer(bool bAutoStart = true) + { + if (bAutoStart) + { + start(); + } + } - void start(void); + void start(void) + { + m_start = clock::now(); + } - float elapsedTimeInSeconds(void); - uint32_t elapsedTimeInMilliSeconds(void); - uint32_t elapsedTimeInMicroSeconds(void); + float elapsedTimeInSeconds(void) + { + std::chrono::duration elapsed_seconds = clock::now() - m_start; + return elapsed_seconds.count(); + } + + uint32_t elapsedTimeInMilliSeconds(void) + { + std::chrono::duration elapsed_milliseconds = clock::now() - m_start; + return elapsed_milliseconds.count(); + } + + uint32_t elapsedTimeInMicroSeconds(void) + { + std::chrono::duration elapsed_microseconds = clock::now() - m_start; + return elapsed_microseconds.count(); + } private: -#if defined(_MSC_VER) - double m_fPCFreq; - __int64 m_iStartTime; -#else //_MSC_VER typedef std::chrono::system_clock clock; std::chrono::time_point m_start; -#endif //_MSC_VER }; } diff --git a/library/PolyVoxCore/source/Impl/Timer.cpp b/library/PolyVoxCore/source/Impl/Timer.cpp index a0d3c102..e69de29b 100644 --- a/library/PolyVoxCore/source/Impl/Timer.cpp +++ b/library/PolyVoxCore/source/Impl/Timer.cpp @@ -1,107 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-20013 David Williams and Matthew Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "PolyVoxCore/Impl/Timer.h" - -#include "PolyVoxCore/Impl/ErrorHandling.h" - -#include - -namespace PolyVox -{ -#if defined(_MSC_VER) - Timer::Timer(bool bAutoStart) - :m_fPCFreq(0.0) - ,m_iStartTime(0) - { - if(bAutoStart) - { - start(); - } - } - - void Timer::start(void) - { - LARGE_INTEGER li; - if(!QueryPerformanceFrequency(&li)) - { - POLYVOX_LOG_WARNING("QueryPerformanceFrequency failed!"); - m_fPCFreq = 1.0f; - } - - m_fPCFreq = double(li.QuadPart); - - QueryPerformanceCounter(&li); - m_iStartTime = li.QuadPart; - } - - float Timer::elapsedTimeInSeconds(void) - { - LARGE_INTEGER li; - QueryPerformanceCounter(&li); - double fDifference = static_cast(li.QuadPart-m_iStartTime); - return static_cast(fDifference / m_fPCFreq); - } - - uint32_t Timer::elapsedTimeInMilliSeconds(void) - { - return static_cast(elapsedTimeInSeconds() * 1000.0f); - } - - uint32_t Timer::elapsedTimeInMicroSeconds(void) - { - return static_cast(elapsedTimeInSeconds() * 1000000.0f); - } -#else //_MSC_VER - Timer::Timer(bool bAutoStart) - { - if(bAutoStart) - { - start(); - } - } - - void Timer::start(void) - { - m_start = clock::now(); - } - - float Timer::elapsedTimeInSeconds(void) - { - std::chrono::duration elapsed_seconds = clock::now() - m_start; - return elapsed_seconds.count(); - } - - uint32_t Timer::elapsedTimeInMilliSeconds(void) - { - std::chrono::duration elapsed_milliseconds = clock::now() - m_start; - return elapsed_milliseconds.count(); - } - - uint32_t Timer::elapsedTimeInMicroSeconds(void) - { - std::chrono::duration elapsed_microseconds = clock::now() - m_start; - return elapsed_microseconds.count(); - } -#endif //_MSC_VER -}