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.
This commit is contained in:
David Williams 2015-02-06 16:52:21 +01:00
parent 8cff2bb2da
commit 6e8d9dfb75
3 changed files with 29 additions and 122 deletions

View File

@ -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
)

View File

@ -26,33 +26,47 @@ freely, subject to the following restrictions:
#include <cstdint>
#ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied.
#include <Windows.h>
#else
#include <chrono>
#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<float> elapsed_seconds = clock::now() - m_start;
return elapsed_seconds.count();
}
uint32_t elapsedTimeInMilliSeconds(void)
{
std::chrono::duration<float, std::milli> elapsed_milliseconds = clock::now() - m_start;
return elapsed_milliseconds.count();
}
uint32_t elapsedTimeInMicroSeconds(void)
{
std::chrono::duration<float, std::micro> 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<clock> m_start;
#endif //_MSC_VER
};
}

View File

@ -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 <iostream>
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<double>(li.QuadPart-m_iStartTime);
return static_cast<float>(fDifference / m_fPCFreq);
}
uint32_t Timer::elapsedTimeInMilliSeconds(void)
{
return static_cast<uint32_t>(elapsedTimeInSeconds() * 1000.0f);
}
uint32_t Timer::elapsedTimeInMicroSeconds(void)
{
return static_cast<uint32_t>(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<float> elapsed_seconds = clock::now() - m_start;
return elapsed_seconds.count();
}
uint32_t Timer::elapsedTimeInMilliSeconds(void)
{
std::chrono::duration<float, std::milli> elapsed_milliseconds = clock::now() - m_start;
return elapsed_milliseconds.count();
}
uint32_t Timer::elapsedTimeInMicroSeconds(void)
{
std::chrono::duration<float, std::micro> elapsed_microseconds = clock::now() - m_start;
return elapsed_microseconds.count();
}
#endif //_MSC_VER
}