diff --git a/src/lol/sys/timer.h b/src/lol/sys/timer.h index 80742e9e..606ffd19 100644 --- a/src/lol/sys/timer.h +++ b/src/lol/sys/timer.h @@ -1,11 +1,14 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2013 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2016 Sam Hocevar +// © 2016 Guillaume Bittoun +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #pragma once @@ -21,63 +24,50 @@ namespace lol { -/* - * Timer implementation class - */ - class Timer { -private: - - float GetSeconds(bool reset) - { - std::chrono::steady_clock::time_point - tp = std::chrono::steady_clock::now(), - tp0 = m_tp; - - if (reset) - m_tp = tp; - - return std::chrono::duration_cast>(tp - tp0).count(); - } - public: Timer() - : m_tp() - { - (void)GetSeconds(true); - } - - ~Timer() { + (void)get_seconds(true); } void Reset() { - (void)GetSeconds(true); + (void)get_seconds(true); } float Get() { - return GetSeconds(true); + return get_seconds(true); } float Poll() { - return GetSeconds(false); + return get_seconds(false); } void Wait(float seconds) { if (seconds > 0.0f) { - float secs_elapsed = GetSeconds(false); + float secs_elapsed = get_seconds(false); std::this_thread::sleep_for(std::chrono::duration(seconds - secs_elapsed)); } } private: std::chrono::steady_clock::time_point m_tp; + + float get_seconds(bool reset) + { + auto tp = std::chrono::steady_clock::now(), tp0 = m_tp; + + if (reset) + m_tp = tp; + + return std::chrono::duration_cast>(tp - tp0).count(); + } }; } /* namespace lol */