Refactoring: Port back some code changes from Mesen-S

This commit is contained in:
Sour 2020-02-15 14:27:36 -05:00
parent 1ebd943f3a
commit 42c1c76f43
3 changed files with 19 additions and 84 deletions

View file

@ -7,7 +7,7 @@
#include "MemoryManager.h" #include "MemoryManager.h"
#include "MemoryDumper.h" #include "MemoryDumper.h"
#include "DebuggerTypes.h" #include "DebuggerTypes.h"
#include "Cpu.h" #include "CPU.h"
static constexpr int32_t ResetFunctionIndex = -1; static constexpr int32_t ResetFunctionIndex = -1;

View file

@ -1,42 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#include "Timer.h" #include "Timer.h"
#ifndef LIBRETRO
#include <thread> #include <thread>
#include <chrono>
#ifdef _WIN32 using namespace std::chrono;
#include <Windows.h>
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()
{ {
@ -45,24 +13,16 @@ Timer::Timer()
void Timer::Reset() void Timer::Reset()
{ {
timespec start; _start = high_resolution_clock::now();
clock_gettime(CLOCK_MONOTONIC, &start);
_start = start.tv_sec * 1000000000 + start.tv_nsec;
} }
double Timer::GetElapsedMS() double Timer::GetElapsedMS()
{ {
timespec end; high_resolution_clock::time_point end = high_resolution_clock::now();
clock_gettime(CLOCK_MONOTONIC, &end); duration<double> span = duration_cast<duration<double>>(end - _start);
return span.count() * 1000.0;
uint64_t currentTime = end.tv_sec * 1000000000 + end.tv_nsec;
return (double)(currentTime - _start) / 1000000.0;
} }
#endif
void Timer::WaitUntil(double targetMillisecond) void Timer::WaitUntil(double targetMillisecond)
{ {
if(targetMillisecond > 0) { if(targetMillisecond > 0) {
@ -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

View file

@ -1,18 +1,16 @@
#pragma once #pragma once
#include "stdafx.h" #include "stdafx.h"
#include <chrono>
using namespace std::chrono;
class Timer class Timer
{ {
private: private:
#ifndef LIBRETRO high_resolution_clock::time_point _start;
#ifdef _WIN32
double _frequency = 0.0; public:
#endif Timer();
uint64_t _start; void Reset();
#endif double GetElapsedMS();
public: void WaitUntil(double targetMillisecond);
Timer();
void Reset();
double GetElapsedMS();
void WaitUntil(double targetMillisecond);
}; };