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