Refactoring: Port back some code changes from Mesen-S
This commit is contained in:
parent
1ebd943f3a
commit
42c1c76f43
3 changed files with 19 additions and 84 deletions
|
@ -7,7 +7,7 @@
|
|||
#include "MemoryManager.h"
|
||||
#include "MemoryDumper.h"
|
||||
#include "DebuggerTypes.h"
|
||||
#include "Cpu.h"
|
||||
#include "CPU.h"
|
||||
|
||||
static constexpr int32_t ResetFunctionIndex = -1;
|
||||
|
||||
|
|
|
@ -1,69 +1,29 @@
|
|||
#include "stdafx.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#ifndef LIBRETRO
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
using namespace std::chrono;
|
||||
|
||||
Timer::Timer()
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
if(!QueryPerformanceFrequency(&li)) {
|
||||
throw;
|
||||
}
|
||||
|
||||
_frequency = double(li.QuadPart) / 1000.0;
|
||||
|
||||
QueryPerformanceCounter(&li);
|
||||
_start = li.QuadPart;
|
||||
}
|
||||
|
||||
void Timer::Reset()
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
QueryPerformanceCounter(&li);
|
||||
_start = li.QuadPart;
|
||||
}
|
||||
|
||||
double Timer::GetElapsedMS()
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
QueryPerformanceCounter(&li);
|
||||
return double(li.QuadPart - _start) / _frequency;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <time.h>
|
||||
|
||||
Timer::Timer()
|
||||
Timer::Timer()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Timer::Reset()
|
||||
{
|
||||
timespec start;
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
|
||||
_start = start.tv_sec * 1000000000 + start.tv_nsec;
|
||||
_start = high_resolution_clock::now();
|
||||
}
|
||||
|
||||
double Timer::GetElapsedMS()
|
||||
{
|
||||
timespec end;
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
|
||||
uint64_t currentTime = end.tv_sec * 1000000000 + end.tv_nsec;
|
||||
|
||||
return (double)(currentTime - _start) / 1000000.0;
|
||||
high_resolution_clock::time_point end = high_resolution_clock::now();
|
||||
duration<double> span = duration_cast<duration<double>>(end - _start);
|
||||
return span.count() * 1000.0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Timer::WaitUntil(double targetMillisecond)
|
||||
void Timer::WaitUntil(double targetMillisecond)
|
||||
{
|
||||
if(targetMillisecond > 0) {
|
||||
double elapsedTime = GetElapsedMS();
|
||||
|
@ -72,26 +32,3 @@ void Timer::WaitUntil(double targetMillisecond)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//This is not used by Libretro port, remove its dependencies
|
||||
|
||||
Timer::Timer()
|
||||
{
|
||||
}
|
||||
|
||||
void Timer::Reset()
|
||||
{
|
||||
}
|
||||
|
||||
double Timer::GetElapsedMS()
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void Timer::WaitUntil(double targetMillisecond)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,18 +1,16 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include <chrono>
|
||||
using namespace std::chrono;
|
||||
|
||||
class Timer
|
||||
{
|
||||
private:
|
||||
#ifndef LIBRETRO
|
||||
#ifdef _WIN32
|
||||
double _frequency = 0.0;
|
||||
#endif
|
||||
uint64_t _start;
|
||||
#endif
|
||||
public:
|
||||
Timer();
|
||||
void Reset();
|
||||
double GetElapsedMS();
|
||||
void WaitUntil(double targetMillisecond);
|
||||
private:
|
||||
high_resolution_clock::time_point _start;
|
||||
|
||||
public:
|
||||
Timer();
|
||||
void Reset();
|
||||
double GetElapsedMS();
|
||||
void WaitUntil(double targetMillisecond);
|
||||
};
|
Loading…
Add table
Reference in a new issue