Mesen-SX/Utilities/Timer.cpp
NovaSquirrel c0e249e993 Revert "Merge branch 'reformat_code'"
This reverts commit daf3b57e89, reversing
changes made to 7a6e0b7d77.
2021-03-10 11:13:28 -05:00

34 lines
694 B
C++

#include "stdafx.h"
#include "Timer.h"
#include <thread>
#include <chrono>
using namespace std::chrono;
Timer::Timer()
{
Reset();
}
void Timer::Reset()
{
_start = high_resolution_clock::now();
}
double Timer::GetElapsedMS()
{
high_resolution_clock::time_point end = high_resolution_clock::now();
duration<double> span = duration_cast<duration<double>>(end - _start);
return span.count() * 1000.0;
}
void Timer::WaitUntil(double targetMillisecond)
{
if(targetMillisecond > 0) {
double elapsedTime = GetElapsedMS();
if(targetMillisecond - elapsedTime > 1) {
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>((int)(targetMillisecond - elapsedTime)));
}
}
}