mirror of
https://github.com/libretro/Mesen.git
synced 2025-02-18 15:49:12 +00:00
Remove more code that is unused by the libretro port
This commit is contained in:
parent
a56fd248ec
commit
c4f5912b6b
@ -27,27 +27,6 @@ void BaseRenderer::DisplayMessage(string title, string message)
|
||||
_toasts.push_front(toast);
|
||||
}
|
||||
|
||||
void BaseRenderer::RemoveOldToasts()
|
||||
{
|
||||
_toasts.remove_if([](shared_ptr<ToastInfo> toast) { return toast->IsToastExpired(); });
|
||||
}
|
||||
|
||||
void BaseRenderer::DrawToasts()
|
||||
{
|
||||
RemoveOldToasts();
|
||||
|
||||
int counter = 0;
|
||||
int lastHeight = 5;
|
||||
for(shared_ptr<ToastInfo> toast : _toasts) {
|
||||
if(counter < 6) {
|
||||
DrawToast(toast, lastHeight);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring BaseRenderer::WrapText(string utf8Text, float maxLineWidth, uint32_t &lineCount)
|
||||
{
|
||||
using std::wstring;
|
||||
@ -95,105 +74,8 @@ std::wstring BaseRenderer::WrapText(string utf8Text, float maxLineWidth, uint32_
|
||||
return wrappedText;
|
||||
}
|
||||
|
||||
void BaseRenderer::DrawToast(shared_ptr<ToastInfo> toast, int &lastHeight)
|
||||
{
|
||||
//Get opacity for fade in/out effect
|
||||
uint8_t opacity = (uint8_t)(toast->GetOpacity()*255);
|
||||
int textLeftMargin = 4;
|
||||
|
||||
int lineHeight = 25;
|
||||
string text = "[" + toast->GetToastTitle() + "] " + toast->GetToastMessage();
|
||||
uint32_t lineCount = 0;
|
||||
std::wstring wrappedText = WrapText(text, (float)(_screenWidth - textLeftMargin * 2 - 20), lineCount);
|
||||
lastHeight += lineCount * lineHeight;
|
||||
DrawString(wrappedText, textLeftMargin, _screenHeight - lastHeight, opacity, opacity, opacity, opacity);
|
||||
}
|
||||
|
||||
void BaseRenderer::DrawString(std::string message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity)
|
||||
{
|
||||
std::wstring textStr = utf8::utf8::decode(message);
|
||||
DrawString(textStr, x, y, r, g, b, opacity);
|
||||
}
|
||||
|
||||
void BaseRenderer::ShowFpsCounter(int lineNumber)
|
||||
{
|
||||
int yPos = 13 + 24 * lineNumber;
|
||||
if(_fpsTimer.GetElapsedMS() > 1000) {
|
||||
//Update fps every sec
|
||||
uint32_t frameCount = _console->GetFrameCount();
|
||||
if(_lastFrameCount > frameCount) {
|
||||
_currentFPS = 0;
|
||||
} else {
|
||||
_currentFPS = (int)(std::round((double)(frameCount - _lastFrameCount) / (_fpsTimer.GetElapsedMS() / 1000)));
|
||||
_currentRenderedFPS = (int)(std::round((double)(_renderedFrameCount - _lastRenderedFrameCount) / (_fpsTimer.GetElapsedMS() / 1000)));
|
||||
}
|
||||
_lastFrameCount = frameCount;
|
||||
_lastRenderedFrameCount = _renderedFrameCount;
|
||||
_fpsTimer.Reset();
|
||||
}
|
||||
|
||||
if(_currentFPS > 5000) {
|
||||
_currentFPS = 0;
|
||||
}
|
||||
if(_currentRenderedFPS > 5000) {
|
||||
_currentRenderedFPS = 0;
|
||||
}
|
||||
|
||||
string fpsString = string("FPS: ") + std::to_string(_currentFPS) + " / " + std::to_string(_currentRenderedFPS);
|
||||
DrawString(fpsString, _screenWidth - 125, yPos, 250, 235, 215);
|
||||
}
|
||||
|
||||
void BaseRenderer::ShowGameTimer(int lineNumber)
|
||||
{
|
||||
int yPos = 13 + 24 * lineNumber;
|
||||
double frameCount = _console->GetFrameCount();
|
||||
double frameRate = _console->GetModel() == NesModel::NTSC ? 60.098811862348404716732985230828 : 50.006977968268290848936010226333;
|
||||
//uint32_t milliseconds = (uint32_t)(frameCount / 60.1 * 1000) % 1000;
|
||||
uint32_t seconds = (uint32_t)(frameCount / frameRate) % 60;
|
||||
uint32_t minutes = (uint32_t)(frameCount / frameRate / 60) % 60;
|
||||
uint32_t hours = (uint32_t)(frameCount / frameRate / 3600);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::setw(2) << std::setfill('0') << hours << ":";
|
||||
ss << std::setw(2) << std::setfill('0') << minutes << ":";
|
||||
ss << std::setw(2) << std::setfill('0') << seconds;
|
||||
//ss << "." << std::setw(3) << std::setfill('0') << milliseconds;
|
||||
DrawString(ss.str(), _screenWidth - 95, yPos, 250, 235, 215);
|
||||
}
|
||||
|
||||
void BaseRenderer::ShowLagCounter(int lineNumber)
|
||||
{
|
||||
int yPos = 13 + 24 * lineNumber;
|
||||
string lagCounter = MessageManager::Localize("Lag") + ": " + std::to_string(_console->GetLagCounter());
|
||||
DrawString(lagCounter, _screenWidth - 123, yPos, 250, 235, 215);
|
||||
}
|
||||
|
||||
void BaseRenderer::ShowFrameCounter(int lineNumber)
|
||||
{
|
||||
int yPos = 13 + 24 * lineNumber;
|
||||
string lagCounter = MessageManager::Localize("Frame") + ": " + std::to_string(_console->GetFrameCount());
|
||||
DrawString(lagCounter, _screenWidth - 146, yPos, 250, 235, 215);
|
||||
}
|
||||
|
||||
void BaseRenderer::DrawCounters()
|
||||
{
|
||||
int lineNumber = 0;
|
||||
EmulationSettings* settings = _console->GetSettings();
|
||||
if(settings->CheckFlag(EmulationFlags::ShowGameTimer)) {
|
||||
ShowGameTimer(lineNumber++);
|
||||
}
|
||||
if(settings->CheckFlag(EmulationFlags::ShowFPS)) {
|
||||
ShowFpsCounter(lineNumber++);
|
||||
}
|
||||
if(settings->CheckFlag(EmulationFlags::ShowLagCounter)) {
|
||||
ShowLagCounter(lineNumber++);
|
||||
}
|
||||
if(settings->CheckFlag(EmulationFlags::ShowFrameCounter)) {
|
||||
ShowFrameCounter(lineNumber++);
|
||||
}
|
||||
}
|
||||
|
||||
bool BaseRenderer::IsMessageShown()
|
||||
{
|
||||
return !_toasts.empty();
|
||||
}
|
||||
|
@ -9,13 +9,6 @@ class BaseRenderer : public IMessageManager
|
||||
private:
|
||||
list<shared_ptr<ToastInfo>> _toasts;
|
||||
|
||||
Timer _fpsTimer;
|
||||
uint32_t _lastFrameCount = 0;
|
||||
uint32_t _lastRenderedFrameCount = 0;
|
||||
uint32_t _currentFPS = 0;
|
||||
uint32_t _currentRenderedFPS = 0;
|
||||
|
||||
void RemoveOldToasts();
|
||||
std::wstring WrapText(string utf8Text, float maxLineWidth, uint32_t &lineCount);
|
||||
virtual float MeasureString(std::wstring text) = 0;
|
||||
virtual bool ContainsCharacter(wchar_t character) = 0;
|
||||
@ -23,25 +16,10 @@ private:
|
||||
protected:
|
||||
shared_ptr<Console> _console;
|
||||
|
||||
uint32_t _screenWidth = 0;
|
||||
uint32_t _screenHeight = 0;
|
||||
uint32_t _renderedFrameCount = 0;
|
||||
|
||||
BaseRenderer(shared_ptr<Console> console, bool registerAsMessageManager);
|
||||
virtual ~BaseRenderer();
|
||||
|
||||
bool IsMessageShown();
|
||||
|
||||
void DisplayMessage(string title, string message);
|
||||
void DrawToasts();
|
||||
|
||||
void DrawToast(shared_ptr<ToastInfo> toast, int &lastHeight);
|
||||
void DrawString(std::string message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity = 255);
|
||||
virtual void DrawString(std::wstring message, int x, int y, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255, uint8_t opacity = 255) = 0;
|
||||
|
||||
void ShowFpsCounter(int lineNumber);
|
||||
void ShowLagCounter(int lineNumber);
|
||||
void ShowFrameCounter(int lineNumber);
|
||||
void ShowGameTimer(int lineNumber);
|
||||
void DrawCounters();
|
||||
};
|
||||
|
@ -1,50 +1,2 @@
|
||||
#include "stdafx.h"
|
||||
#include "BaseSoundManager.h"
|
||||
|
||||
void BaseSoundManager::ProcessLatency(uint32_t readPosition, uint32_t writePosition)
|
||||
{
|
||||
//Record latency between read & write cursors once per frame
|
||||
int32_t cursorGap;
|
||||
if(writePosition < readPosition) {
|
||||
cursorGap = writePosition - readPosition + _bufferSize;
|
||||
} else {
|
||||
cursorGap = writePosition - readPosition;
|
||||
}
|
||||
|
||||
_cursorGaps[_cursorGapIndex] = cursorGap;
|
||||
_cursorGapIndex = (_cursorGapIndex + 1) % 60;
|
||||
if(_cursorGapIndex == 0) {
|
||||
_cursorGapFilled = true;
|
||||
}
|
||||
|
||||
if(_cursorGapFilled) {
|
||||
//Once we have 60+ frames worth of data to work with, adjust playback frequency by +/- 0.5%
|
||||
//To speed up or slow down playback in order to reach our latency goal.
|
||||
uint32_t bytesPerSample = _isStereo ? 4 : 2;
|
||||
|
||||
int32_t gapSum = 0;
|
||||
for(int i = 0; i < 60; i++) {
|
||||
gapSum += _cursorGaps[i];
|
||||
}
|
||||
int32_t gapAverage = gapSum / 60;
|
||||
|
||||
_averageLatency = (gapAverage / bytesPerSample) / (double)_sampleRate * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
AudioStatistics BaseSoundManager::GetStatistics()
|
||||
{
|
||||
AudioStatistics stats;
|
||||
stats.AverageLatency = _averageLatency;
|
||||
stats.BufferUnderrunEventCount = _bufferUnderrunEventCount;
|
||||
stats.BufferSize = _bufferSize;
|
||||
return stats;
|
||||
}
|
||||
|
||||
void BaseSoundManager::ResetStats()
|
||||
{
|
||||
_cursorGapIndex = 0;
|
||||
_cursorGapFilled = false;
|
||||
_bufferUnderrunEventCount = 0;
|
||||
_averageLatency = 0;
|
||||
}
|
||||
|
@ -1,23 +1,4 @@
|
||||
#pragma once
|
||||
#include "../Core/IAudioDevice.h"
|
||||
|
||||
class BaseSoundManager : public IAudioDevice
|
||||
{
|
||||
public:
|
||||
void ProcessLatency(uint32_t readPosition, uint32_t writePosition);
|
||||
AudioStatistics GetStatistics() override;
|
||||
|
||||
protected:
|
||||
bool _isStereo;
|
||||
uint32_t _sampleRate = 0;
|
||||
|
||||
double _averageLatency = 0;
|
||||
uint32_t _bufferSize = 0x10000;
|
||||
uint32_t _bufferUnderrunEventCount = 0;
|
||||
|
||||
int32_t _cursorGaps[60];
|
||||
int32_t _cursorGapIndex = 0;
|
||||
bool _cursorGapFilled = false;
|
||||
|
||||
void ResetStats();
|
||||
};
|
||||
class BaseSoundManager : public IAudioDevice { };
|
||||
|
@ -798,19 +798,6 @@ void Console::Run()
|
||||
|
||||
targetTime += delay;
|
||||
|
||||
bool displayDebugInfo = _settings->CheckFlag(EmulationFlags::DisplayDebugInfo);
|
||||
if(displayDebugInfo) {
|
||||
double lastFrameTime = lastFrameTimer.GetElapsedMS();
|
||||
lastFrameTimer.Reset();
|
||||
frameDurations[frameDurationIndex] = lastFrameTime;
|
||||
frameDurationIndex = (frameDurationIndex + 1) % 60;
|
||||
|
||||
DisplayDebugInformation(lastFrameTime, lastFrameMin, lastFrameMax, frameDurations);
|
||||
if(_slave) {
|
||||
_slave->DisplayDebugInformation(lastFrameTime, lastFrameMin, lastFrameMax, frameDurations);
|
||||
}
|
||||
}
|
||||
|
||||
//When sleeping for a long time (e.g <= 25% speed), sleep in small chunks and check to see if we need to stop sleeping between each sleep call
|
||||
while(targetTime - clockTimer.GetElapsedMS() > 50) {
|
||||
clockTimer.WaitUntil(clockTimer.GetElapsedMS() + 40);
|
||||
@ -1556,61 +1543,6 @@ void Console::DebugProcessVramWriteOperation(uint16_t addr, uint8_t & value)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Console::DisplayDebugInformation(double lastFrame, double &lastFrameMin, double &lastFrameMax, double frameDurations[60])
|
||||
{
|
||||
AudioStatistics stats = _soundMixer->GetStatistics();
|
||||
|
||||
int startFrame = _ppu->GetFrameCount();
|
||||
|
||||
_debugHud->DrawRectangle(8, 8, 115, 49, 0x40000000, true, 1, startFrame);
|
||||
_debugHud->DrawRectangle(8, 8, 115, 49, 0xFFFFFF, false, 1, startFrame);
|
||||
|
||||
_debugHud->DrawString(10, 10, "Audio Stats", 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
_debugHud->DrawString(10, 21, "Latency: ", 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
|
||||
int color = (stats.AverageLatency > 0 && std::abs(stats.AverageLatency - _settings->GetAudioLatency()) > 3) ? 0xFF0000 : 0xFFFFFF;
|
||||
std::stringstream ss;
|
||||
ss << std::fixed << std::setprecision(2) << stats.AverageLatency << " ms";
|
||||
_debugHud->DrawString(54, 21, ss.str(), color, 0xFF000000, 1, startFrame);
|
||||
|
||||
_debugHud->DrawString(10, 30, "Underruns: " + std::to_string(stats.BufferUnderrunEventCount), 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
_debugHud->DrawString(10, 39, "Buffer Size: " + std::to_string(stats.BufferSize / 1024) + "kb", 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
_debugHud->DrawString(10, 48, "Rate: " + std::to_string((uint32_t)(_settings->GetSampleRate() * _soundMixer->GetRateAdjustment())) + "Hz", 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
|
||||
_debugHud->DrawRectangle(132, 8, 115, 49, 0x40000000, true, 1, startFrame);
|
||||
_debugHud->DrawRectangle(132, 8, 115, 49, 0xFFFFFF, false, 1, startFrame);
|
||||
_debugHud->DrawString(134, 10, "Video Stats", 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
|
||||
double totalDuration = 0;
|
||||
for(int i = 0; i < 60; i++) {
|
||||
totalDuration += frameDurations[i];
|
||||
}
|
||||
|
||||
ss = std::stringstream();
|
||||
ss << "FPS: " << std::fixed << std::setprecision(4) << (1000 / (totalDuration/60));
|
||||
_debugHud->DrawString(134, 21, ss.str(), 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
|
||||
ss = std::stringstream();
|
||||
ss << "Last Frame: " << std::fixed << std::setprecision(2) << lastFrame << " ms";
|
||||
_debugHud->DrawString(134, 30, ss.str(), 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
|
||||
if(_ppu->GetFrameCount() > 60) {
|
||||
lastFrameMin = (std::min)(lastFrame, lastFrameMin);
|
||||
lastFrameMax = (std::max)(lastFrame, lastFrameMax);
|
||||
} else {
|
||||
lastFrameMin = 9999;
|
||||
lastFrameMax = 0;
|
||||
}
|
||||
|
||||
ss = std::stringstream();
|
||||
ss << "Min Delay: " << std::fixed << std::setprecision(2) << ((lastFrameMin < 9999) ? lastFrameMin : 0.0) << " ms";
|
||||
_debugHud->DrawString(134, 39, ss.str(), 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
|
||||
ss = std::stringstream();
|
||||
ss << "Max Delay: " << std::fixed << std::setprecision(2) << lastFrameMax << " ms";
|
||||
_debugHud->DrawString(134, 48, ss.str(), 0xFFFFFF, 0xFF000000, 1, startFrame);
|
||||
}
|
||||
|
||||
void Console::ExportStub()
|
||||
{
|
||||
//Force the compiler to export the PgoRunTest function - otherwise it seems to be ignored since it is unused
|
||||
|
@ -104,7 +104,6 @@ private:
|
||||
|
||||
void UpdateNesModel(bool sendNotification);
|
||||
double GetFrameDelay();
|
||||
void DisplayDebugInformation(double lastFrame, double &lastFrameMin, double &lastFrameMax, double frameDurations[60]);
|
||||
|
||||
void ExportStub();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user