mirror of https://github.com/OpenRCT2/OpenRCT2.git
Implement Timer class
This commit is contained in:
parent
cb6d7418c5
commit
30cc3dff3f
|
@ -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 <chrono>
|
||||
|
||||
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<std::chrono::microseconds>(Clock::now() - _tp);
|
||||
return static_cast<float>(static_cast<double>(elapsed.count()) / 1'000'000.0);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace OpenRCT2
|
|
@ -187,6 +187,7 @@
|
|||
<ClInclude Include="core\String.hpp" />
|
||||
<ClInclude Include="core\StringBuilder.h" />
|
||||
<ClInclude Include="core\StringReader.h" />
|
||||
<ClInclude Include="core\Timer.hpp" />
|
||||
<ClInclude Include="core\Zip.h" />
|
||||
<ClInclude Include="core\ZipStream.hpp" />
|
||||
<ClInclude Include="Date.h" />
|
||||
|
|
Loading…
Reference in New Issue