Core: Added frame limiter
This commit is contained in:
parent
b2af226467
commit
66aa5034a0
4 changed files with 64 additions and 0 deletions
|
@ -13,9 +13,11 @@
|
|||
#include "VideoDecoder.h"
|
||||
#include "VideoRenderer.h"
|
||||
#include "DebugHud.h"
|
||||
#include "FrameLimiter.h"
|
||||
#include "MessageManager.h"
|
||||
#include "../Utilities/Timer.h"
|
||||
#include "../Utilities/VirtualFile.h"
|
||||
#include "../Utilities/PlatformUtilities.h"
|
||||
|
||||
void Console::Initialize()
|
||||
{
|
||||
|
@ -49,11 +51,24 @@ void Console::Run()
|
|||
}
|
||||
|
||||
_stopFlag = false;
|
||||
uint32_t previousFrameCount = 0;
|
||||
|
||||
FrameLimiter frameLimiter(16.63926405550947);
|
||||
|
||||
PlatformUtilities::EnableHighResolutionTimer();
|
||||
|
||||
auto lock = _runLock.AcquireSafe();
|
||||
while(!_stopFlag) {
|
||||
_cpu->Exec();
|
||||
|
||||
if(previousFrameCount != _ppu->GetFrameCount()) {
|
||||
frameLimiter.ProcessFrame();
|
||||
frameLimiter.WaitForNextFrame();
|
||||
previousFrameCount = _ppu->GetFrameCount();
|
||||
}
|
||||
}
|
||||
|
||||
PlatformUtilities::RestoreTimerResolution();
|
||||
}
|
||||
|
||||
void Console::Stop()
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
<ClInclude Include="DrawScreenBufferCommand.h" />
|
||||
<ClInclude Include="DrawStringCommand.h" />
|
||||
<ClInclude Include="dsp.h" />
|
||||
<ClInclude Include="FrameLimiter.h" />
|
||||
<ClInclude Include="IAudioDevice.h" />
|
||||
<ClInclude Include="IInputProvider.h" />
|
||||
<ClInclude Include="IInputRecorder.h" />
|
||||
|
|
|
@ -170,6 +170,9 @@
|
|||
<ClInclude Include="ControlManager.h">
|
||||
<Filter>SNES\Input</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FrameLimiter.h">
|
||||
<Filter>SNES</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
|
|
45
Core/FrameLimiter.h
Normal file
45
Core/FrameLimiter.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
#include "../Utilities/Timer.h"
|
||||
|
||||
class FrameLimiter
|
||||
{
|
||||
private:
|
||||
Timer _clockTimer;
|
||||
double _targetTime;
|
||||
double _delay;
|
||||
bool _resetRunTimers;
|
||||
|
||||
public:
|
||||
FrameLimiter(double delay)
|
||||
{
|
||||
_delay = delay;
|
||||
_targetTime = _delay;
|
||||
}
|
||||
|
||||
void SetDelay(double delay)
|
||||
{
|
||||
_delay = delay;
|
||||
_resetRunTimers = true;
|
||||
}
|
||||
|
||||
void ProcessFrame()
|
||||
{
|
||||
if(_resetRunTimers || (_clockTimer.GetElapsedMS() - _targetTime) > 300) {
|
||||
//Reset the timers, this can happen in 3 scenarios:
|
||||
//1) Target frame rate changed
|
||||
//2) The console was reset/power cycled or the emulation was paused (with or without the debugger)
|
||||
//3) As a satefy net, if we overshoot our target by over 300 milliseconds, the timer is reset, too.
|
||||
// This can happen when something slows the emulator down severely (or when breaking execution in VS when debugging Mesen itself, etc.)
|
||||
_clockTimer.Reset();
|
||||
_targetTime = 0;
|
||||
_resetRunTimers = false;
|
||||
}
|
||||
|
||||
_targetTime += _delay;
|
||||
}
|
||||
|
||||
void WaitForNextFrame()
|
||||
{
|
||||
_clockTimer.WaitUntil(_targetTime);
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue