From 28031dac1e071011d75aba8adb6678fe32675eef Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Sat, 1 Oct 2016 22:10:37 +0200 Subject: [PATCH] Getting rid of TimerData class --- src/lol/sys/timer.h | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/lol/sys/timer.h b/src/lol/sys/timer.h index cfee3797..80742e9e 100644 --- a/src/lol/sys/timer.h +++ b/src/lol/sys/timer.h @@ -25,15 +25,9 @@ namespace lol * Timer implementation class */ -class TimerData +class Timer { - friend class Timer; - private: - TimerData() - { - (void)GetSeconds(true); - } float GetSeconds(bool reset) { @@ -47,55 +41,43 @@ private: return std::chrono::duration_cast>(tp - tp0).count(); } - static void WaitSeconds(float seconds) - { - if (seconds > 0.0f) - std::this_thread::sleep_for(std::chrono::duration(seconds)); - } - - std::chrono::steady_clock::time_point m_tp; -}; - -class Timer -{ public: Timer() - : data(new TimerData()) + : m_tp() { + (void)GetSeconds(true); } ~Timer() { - delete data; } void Reset() { - (void)data->GetSeconds(true); + (void)GetSeconds(true); } float Get() { - return data->GetSeconds(true); + return GetSeconds(true); } float Poll() { - return data->GetSeconds(false); + return GetSeconds(false); } void Wait(float seconds) { - float secs_elapsed = data->GetSeconds(false); - data->WaitSeconds(seconds - secs_elapsed); + if (seconds > 0.0f) + { + float secs_elapsed = GetSeconds(false); + std::this_thread::sleep_for(std::chrono::duration(seconds - secs_elapsed)); + } } private: - TimerData *data; - - /* Copying timers is forbidden for now. */ - Timer(Timer const &t); - Timer operator =(Timer const &t); + std::chrono::steady_clock::time_point m_tp; }; } /* namespace lol */