mirror of
https://github.com/SourMesen/Mesen.git
synced 2025-04-02 10:52:48 -04:00
Moved FPS counter to renderer, instead of emulation core (gained ~20 fps)
This commit is contained in:
parent
e5fe396ffb
commit
c810b4802a
4 changed files with 22 additions and 24 deletions
|
@ -10,7 +10,6 @@
|
|||
|
||||
shared_ptr<Console> Console::Instance(new Console());
|
||||
uint32_t Console::Flags = 0;
|
||||
uint32_t Console::CurrentFPS = 0;
|
||||
|
||||
Console::Console()
|
||||
{
|
||||
|
@ -161,19 +160,12 @@ bool Console::CheckFlag(int flag)
|
|||
return (Console::Flags & flag) == flag;
|
||||
}
|
||||
|
||||
uint32_t Console::GetFPS()
|
||||
{
|
||||
return Console::CurrentFPS;
|
||||
}
|
||||
|
||||
void Console::Run()
|
||||
{
|
||||
Timer clockTimer;
|
||||
Timer fpsTimer;
|
||||
uint32_t lastFrameCount = 0;
|
||||
double elapsedTime = 0;
|
||||
double targetTime = 16.6666666666666666;
|
||||
|
||||
|
||||
_runLock.Acquire();
|
||||
_stopLock.Acquire();
|
||||
|
||||
|
@ -224,17 +216,6 @@ void Console::Run()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(fpsTimer.GetElapsedMS() > 1000) {
|
||||
uint32_t frameCount = PPU::GetFrameCount();
|
||||
if((int32_t)frameCount - (int32_t)lastFrameCount < 0) {
|
||||
Console::CurrentFPS = 0;
|
||||
} else {
|
||||
Console::CurrentFPS = (int)(std::round((double)(frameCount - lastFrameCount) / (fpsTimer.GetElapsedMS() / 1000)));
|
||||
}
|
||||
lastFrameCount = frameCount;
|
||||
fpsTimer.Reset();
|
||||
}
|
||||
}
|
||||
_apu->StopAudio();
|
||||
_stopLock.Release();
|
||||
|
|
|
@ -22,7 +22,6 @@ class Console
|
|||
private:
|
||||
static shared_ptr<Console> Instance;
|
||||
static uint32_t Flags;
|
||||
static uint32_t CurrentFPS;
|
||||
SimpleLock _pauseLock;
|
||||
SimpleLock _runLock;
|
||||
SimpleLock _stopLock;
|
||||
|
@ -71,7 +70,6 @@ class Console
|
|||
static bool CheckFlag(int flag);
|
||||
static void SetFlags(int flags);
|
||||
static void ClearFlags(int flags);
|
||||
static uint32_t GetFPS();
|
||||
|
||||
static shared_ptr<Console> GetInstance();
|
||||
};
|
||||
|
|
|
@ -439,7 +439,19 @@ namespace NES
|
|||
} else {
|
||||
//Draw FPS counter
|
||||
if(CheckFlag(UIFlags::ShowFPS)) {
|
||||
string fpsString = string("FPS: ") + std::to_string(Console::GetFPS());
|
||||
|
||||
if(_fpsTimer.GetElapsedMS() > 1000) {
|
||||
//Update fps every sec
|
||||
if(_frameCount - _lastFrameCount < 0) {
|
||||
_currentFPS = 0;
|
||||
} else {
|
||||
_currentFPS = (int)(std::round((double)(_frameCount - _lastFrameCount) / (_fpsTimer.GetElapsedMS() / 1000)));
|
||||
}
|
||||
_lastFrameCount = _frameCount;
|
||||
_fpsTimer.Reset();
|
||||
}
|
||||
|
||||
string fpsString = string("FPS: ") + std::to_string(_currentFPS);
|
||||
DrawOutlinedString(fpsString, 256 * 4 - 80, 13, Colors::AntiqueWhite, 1.0f);
|
||||
}
|
||||
}
|
||||
|
@ -556,6 +568,8 @@ namespace NES
|
|||
_frameLock.Acquire();
|
||||
memcpy(_nextFrameBuffer, frameBuffer, 256 * 240 * 4);
|
||||
_frameLock.Release();
|
||||
|
||||
_frameCount++;
|
||||
}
|
||||
|
||||
void Renderer::TakeScreenshot(string romFilename)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../Utilities/PNGWriter.h"
|
||||
#include "../Utilities/FolderUtilities.h"
|
||||
#include "../Utilities/SimpleLock.h"
|
||||
#include "../Utilities/Timer.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
||||
|
@ -46,6 +47,10 @@ namespace NES {
|
|||
uint8_t* _nextFrameBuffer = nullptr;
|
||||
SimpleLock _frameLock;
|
||||
|
||||
Timer _fpsTimer;
|
||||
uint32_t _frameCount = 0;
|
||||
uint32_t _lastFrameCount = 0;
|
||||
uint32_t _currentFPS = 0;
|
||||
|
||||
unique_ptr<SpriteFont> _font;
|
||||
unique_ptr<SpriteFont> _smallFont;
|
||||
|
@ -84,7 +89,7 @@ namespace NES {
|
|||
void DrawToasts();
|
||||
void DrawToast(shared_ptr<ToastInfo> toast, int posIndex);
|
||||
void RemoveOldToasts();
|
||||
|
||||
|
||||
public:
|
||||
Renderer(HWND hWnd);
|
||||
~Renderer();
|
||||
|
|
Loading…
Add table
Reference in a new issue