First
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "tl/detail/prologue.h"
|
||||
#include <EASTL/chrono.h>
|
||||
|
||||
namespace tl
|
||||
{
|
||||
using namespace eastl;
|
||||
|
||||
|
||||
namespace chrono
|
||||
{
|
||||
|
||||
using namespace eastl::chrono;
|
||||
|
||||
template <typename Clock>
|
||||
class TL_API chrono final
|
||||
{
|
||||
public:
|
||||
//! Reset the internal time stamp. If you specify an elapsed time offset it will affect directly to getElapsed.
|
||||
void reset(typename Clock::duration elapsed_offset = Clock::duration::zero()) noexcept
|
||||
{
|
||||
m_start_time_point = Clock::now() + elapsed_offset;
|
||||
}
|
||||
|
||||
//! Return the time passed between the last Reset call and now.
|
||||
typename Clock::duration get_elapsed() const noexcept
|
||||
{
|
||||
return Clock::now() - m_start_time_point;
|
||||
}
|
||||
|
||||
//! Return the time passed between the last Reset call and now and then Reset the Clock.
|
||||
typename Clock::duration get_elapsed_and_reset() noexcept
|
||||
{
|
||||
auto now = Clock::now();
|
||||
auto d = now - m_start_time_point;
|
||||
m_start_time_point = now;
|
||||
return d;
|
||||
}
|
||||
|
||||
private:
|
||||
typename Clock::time_point m_start_time_point = Clock::now();
|
||||
};
|
||||
|
||||
using system_chrono = chrono<eastl::chrono::system_clock>;
|
||||
using high_resolution_chrono = chrono<eastl::chrono::high_resolution_clock>;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user