From 30cc3dff3f38de0c97aa72870b0735598f97daca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 2 Dec 2021 17:07:40 +0200 Subject: [PATCH] Implement Timer class --- src/openrct2/core/Timer.hpp | 34 ++++++++++++++++++++++++++++++++ src/openrct2/libopenrct2.vcxproj | 1 + 2 files changed, 35 insertions(+) create mode 100644 src/openrct2/core/Timer.hpp diff --git a/src/openrct2/core/Timer.hpp b/src/openrct2/core/Timer.hpp new file mode 100644 index 0000000000..0812d2e17d --- /dev/null +++ b/src/openrct2/core/Timer.hpp @@ -0,0 +1,34 @@ +/***************************************************************************** + * Copyright (c) 2014-2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include + +namespace OpenRCT2 +{ + class Timer + { + using Clock = std::chrono::high_resolution_clock; + using Timepoint = Clock::time_point; + + Timepoint _tp = Clock::now(); + + public: + void Restart() noexcept + { + _tp = Clock::now(); + } + + float GetElapsed() const noexcept + { + auto elapsed = std::chrono::duration_cast(Clock::now() - _tp); + return static_cast(static_cast(elapsed.count()) / 1'000'000.0); + } + }; + +} // namespace OpenRCT2 diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 3eb744c77c..7059938a80 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -187,6 +187,7 @@ +