From 7d1fa8aaaf73c82acb8614a880b84b3fce58fefe Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 13 May 2017 15:43:02 -0400 Subject: [PATCH] UI: Added game timer option (+ code refactoring) --- {Linux => Core}/BaseRenderer.cpp | 78 +++++++--- {Linux => Core}/BaseRenderer.h | 12 +- Core/Core.vcxproj | 2 + Core/Core.vcxproj.filters | 6 + Core/EmulationSettings.h | 3 +- Core/IMessageManager.h | 2 + GUI.NET/Config/EmulationInfo.cs | 2 - GUI.NET/Config/PreferenceInfo.cs | 6 + GUI.NET/Dependencies/resources.es.xml | 6 +- GUI.NET/Dependencies/resources.fr.xml | 4 +- GUI.NET/Dependencies/resources.ja.xml | 4 +- GUI.NET/Dependencies/resources.pt.xml | 8 +- GUI.NET/Dependencies/resources.ru.xml | 4 +- GUI.NET/Dependencies/resources.uk.xml | 4 +- .../Config/frmEmulationConfig.Designer.cs | 53 +++---- GUI.NET/Forms/Config/frmEmulationConfig.cs | 1 - .../Forms/Config/frmPreferences.Designer.cs | 90 +++++++---- GUI.NET/Forms/Config/frmPreferences.cs | 3 + GUI.NET/InteropEmu.cs | 3 +- Linux/SdlRenderer.cpp | 12 +- Linux/SdlRenderer.h | 2 +- Windows/Renderer.cpp | 146 ++---------------- Windows/Renderer.h | 26 +--- 23 files changed, 203 insertions(+), 274 deletions(-) rename {Linux => Core}/BaseRenderer.cpp (58%) rename {Linux => Core}/BaseRenderer.h (76%) diff --git a/Linux/BaseRenderer.cpp b/Core/BaseRenderer.cpp similarity index 58% rename from Linux/BaseRenderer.cpp rename to Core/BaseRenderer.cpp index c47638f3..9e8235bf 100644 --- a/Linux/BaseRenderer.cpp +++ b/Core/BaseRenderer.cpp @@ -1,8 +1,9 @@ -#include "BaseRenderer.h" +#include "stdafx.h" #include -#include "../Core/EmulationSettings.h" -#include "../Core/VideoDecoder.h" -#include "../Core/PPU.h" +#include "BaseRenderer.h" +#include "EmulationSettings.h" +#include "VideoDecoder.h" +#include "PPU.h" void BaseRenderer::DisplayMessage(string title, string message) { @@ -87,28 +88,28 @@ void BaseRenderer::DrawToast(shared_ptr toast, int &lastHeight) int lineHeight = 25; string text = "[" + toast->GetToastTitle() + "] " + toast->GetToastMessage(); uint32_t lineCount = 0; - std::wstring wrappedText = WrapText(text, _screenWidth - textLeftMargin * 2 - 20, lineCount); + std::wstring wrappedText = WrapText(text, (float)(_screenWidth - textLeftMargin * 2 - 20), lineCount); lastHeight += lineCount * lineHeight; - DrawString(wrappedText, textLeftMargin, (float)(_screenHeight - lastHeight), opacity, opacity, opacity); + 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) +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); + DrawString(textStr, x, y, r, g, b, opacity); } -void BaseRenderer::ShowFpsCounter() +void BaseRenderer::ShowFpsCounter(int lineNumber) { - double elapsedSeconds = _fpsTimer.GetElapsedMS() / 1000; - if(elapsedSeconds > 1.0) { + int yPos = 13 + 24 * lineNumber; + if(_fpsTimer.GetElapsedMS() > 1000) { //Update fps every sec uint32_t frameCount = VideoDecoder::GetInstance()->GetFrameCount(); - if(frameCount < _lastFrameCount) { + if(frameCount - _lastFrameCount < 0) { _currentFPS = 0; } else { - _currentFPS = (int)(std::round((double)(frameCount - _lastFrameCount) / elapsedSeconds)); - _currentRenderedFPS = (int)(std::round((double)(_renderedFrameCount - _lastRenderedFrameCount) / elapsedSeconds)); + _currentFPS = (int)(std::round((double)(frameCount - _lastFrameCount) / (_fpsTimer.GetElapsedMS() / 1000))); + _currentRenderedFPS = (int)(std::round((double)(_renderedFrameCount - _lastRenderedFrameCount) / (_fpsTimer.GetElapsedMS() / 1000))); } _lastFrameCount = frameCount; _lastRenderedFrameCount = _renderedFrameCount; @@ -123,27 +124,56 @@ void BaseRenderer::ShowFpsCounter() } string fpsString = string("FPS: ") + std::to_string(_currentFPS) + " / " + std::to_string(_currentRenderedFPS); - DrawString(fpsString, (float)(_screenWidth - 125), 13, 250, 235, 215); + DrawString(fpsString, _screenWidth - 125, yPos, 250, 235, 215); } -void BaseRenderer::ShowLagCounter() +void BaseRenderer::ShowGameTimer(int lineNumber) { - float yPos = EmulationSettings::CheckFlag(EmulationFlags::ShowFPS) ? 37.0f : 13.0f; + int yPos = 13 + 24 * lineNumber; + double frameCount = PPU::GetFrameCount(); + double frameRate = Console::GetNesModel() == 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, (float)(_screenWidth - 123), yPos, 250, 235, 215); + DrawString(lagCounter, _screenWidth - 123, yPos, 250, 235, 215); } -void BaseRenderer::ShowFrameCounter() +void BaseRenderer::ShowFrameCounter(int lineNumber) { - float yPos = 13.0f; + int yPos = 13 + 24 * lineNumber; + string lagCounter = MessageManager::Localize("Frame") + ": " + std::to_string(PPU::GetFrameCount()); + DrawString(lagCounter, _screenWidth - 146, yPos, 250, 235, 215); +} + +void BaseRenderer::DrawCounters() +{ + int lineNumber = 0; + if(EmulationSettings::CheckFlag(EmulationFlags::ShowGameTimer)) { + ShowGameTimer(lineNumber++); + } if(EmulationSettings::CheckFlag(EmulationFlags::ShowFPS)) { - yPos += 24.0f; + ShowFpsCounter(lineNumber++); } if(EmulationSettings::CheckFlag(EmulationFlags::ShowLagCounter)) { - yPos += 24.0f; + ShowLagCounter(lineNumber++); + } + if(EmulationSettings::CheckFlag(EmulationFlags::ShowFrameCounter)) { + ShowFrameCounter(lineNumber++); } - string lagCounter = MessageManager::Localize("Frame") + ": " + std::to_string(PPU::GetFrameCount()); - DrawString(lagCounter, (float)(_screenWidth - 146), yPos, 250, 235, 215); } bool BaseRenderer::IsMessageShown() diff --git a/Linux/BaseRenderer.h b/Core/BaseRenderer.h similarity index 76% rename from Linux/BaseRenderer.h rename to Core/BaseRenderer.h index 88bdcd5e..096ee3dc 100644 --- a/Linux/BaseRenderer.h +++ b/Core/BaseRenderer.h @@ -29,10 +29,12 @@ protected: void DrawToasts(); void DrawToast(shared_ptr toast, int &lastHeight); - void DrawString(std::string message, int x, int y, uint8_t r, uint8_t g, uint8_t b); - virtual void DrawString(std::wstring message, int x, int y, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255) = 0; + 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(); - void ShowLagCounter(); - void ShowFrameCounter(); + void ShowFpsCounter(int lineNumber); + void ShowLagCounter(int lineNumber); + void ShowFrameCounter(int lineNumber); + void ShowGameTimer(int lineNumber); + void DrawCounters(); }; diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 83566727..432e2471 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -411,6 +411,7 @@ + @@ -771,6 +772,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 85aa14a8..bcc34346 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1177,6 +1177,9 @@ Nes\Mappers\Unnamed + + VideoDecoder + @@ -1398,5 +1401,8 @@ Rewinder + + VideoDecoder + \ No newline at end of file diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index 4c6e0489..f4166d11 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -47,8 +47,9 @@ enum EmulationFlags : uint64_t UseNes101Hvc101Behavior = 0x100000000, ShowFrameCounter = 0x200000000, + ShowGameTimer = 0x400000000, - FdsAutoInsertDisk = 0x400000000, + FdsAutoInsertDisk = 0x800000000, Turbo = 0x2000000000, InBackground = 0x4000000000, diff --git a/Core/IMessageManager.h b/Core/IMessageManager.h index 59988d38..1069a170 100644 --- a/Core/IMessageManager.h +++ b/Core/IMessageManager.h @@ -50,6 +50,8 @@ public: return (currentTime - _startTime) * 5.0f / 1000.0f; } else if(_endTime - currentTime < 200) { return (_endTime - currentTime) * 5.0f / 1000.0f; + } else if(currentTime >= _endTime) { + return 0.0f; } else { return 1.0f; } diff --git a/GUI.NET/Config/EmulationInfo.cs b/GUI.NET/Config/EmulationInfo.cs index 2eedd522..b7447cca 100644 --- a/GUI.NET/Config/EmulationInfo.cs +++ b/GUI.NET/Config/EmulationInfo.cs @@ -34,7 +34,6 @@ namespace Mesen.GUI.Config public RamPowerOnState RamPowerOnState; public bool ShowLagCounter = false; - public bool ShowFrameCounter = false; [MinMax(0, 500)] public UInt32 EmulationSpeed = 100; [MinMax(0, 500)] public UInt32 TurboSpeed = 300; @@ -55,7 +54,6 @@ namespace Mesen.GUI.Config InteropEmu.SetFlag(EmulationFlags.AllowInvalidInput, emulationInfo.AllowInvalidInput); InteropEmu.SetFlag(EmulationFlags.RemoveSpriteLimit, emulationInfo.RemoveSpriteLimit); InteropEmu.SetFlag(EmulationFlags.ShowLagCounter, emulationInfo.ShowLagCounter); - InteropEmu.SetFlag(EmulationFlags.ShowFrameCounter, emulationInfo.ShowFrameCounter); InteropEmu.SetFlag(EmulationFlags.DisablePpu2004Reads, emulationInfo.DisablePpu2004Reads); InteropEmu.SetFlag(EmulationFlags.DisablePaletteRead, emulationInfo.DisablePaletteRead); InteropEmu.SetFlag(EmulationFlags.DisableOamAddrBug, emulationInfo.DisableOamAddrBug); diff --git a/GUI.NET/Config/PreferenceInfo.cs b/GUI.NET/Config/PreferenceInfo.cs index fae81828..e0211846 100644 --- a/GUI.NET/Config/PreferenceInfo.cs +++ b/GUI.NET/Config/PreferenceInfo.cs @@ -52,6 +52,9 @@ namespace Mesen.GUI.Config public bool DisableGameDatabase = false; + public bool ShowFrameCounter = false; + public bool ShowGameTimer = false; + public UInt32 RewindBufferSize = 300; public PreferenceInfo() @@ -101,6 +104,9 @@ namespace Mesen.GUI.Config InteropEmu.SetFlag(EmulationFlags.PauseWhenInBackground, preferenceInfo.PauseWhenInBackground); InteropEmu.SetFlag(EmulationFlags.DisableGameDatabase, preferenceInfo.DisableGameDatabase); + InteropEmu.SetFlag(EmulationFlags.ShowFrameCounter, preferenceInfo.ShowFrameCounter); + InteropEmu.SetFlag(EmulationFlags.ShowGameTimer, preferenceInfo.ShowGameTimer); + InteropEmu.SetFlag(EmulationFlags.HidePauseOverlay, preferenceInfo.HidePauseOverlay); InteropEmu.SetFlag(EmulationFlags.DisplayMovieIcons, preferenceInfo.DisplayMovieIcons); diff --git a/GUI.NET/Dependencies/resources.es.xml b/GUI.NET/Dependencies/resources.es.xml index 79c97303..e3cb1f8f 100644 --- a/GUI.NET/Dependencies/resources.es.xml +++ b/GUI.NET/Dependencies/resources.es.xml @@ -297,7 +297,6 @@ Rewind Speed: Avanzado - Show Frame Counter Utilizar la versión alternativa de componentes de IRQs de MMC3 Permitir las entradas inválidas (Arriba+Abajo e Izquierda+Derecha al mismo tiempo) Estado inicial de la memoria durante el inicio: @@ -367,7 +366,10 @@ Crear una copia de seguridad de cada estado minutos (Pulse F8 para cargar) Mostrar una notificación en pantalla al hacer la copia de seguridad automática - Copia de seguridad online + Copia de seguridad online + + Show frame counter + Show game timer Keep rewind data for the last minutes (Memory Usage ≈1MB/min) diff --git a/GUI.NET/Dependencies/resources.fr.xml b/GUI.NET/Dependencies/resources.fr.xml index dac76bc0..e5f7af97 100644 --- a/GUI.NET/Dependencies/resources.fr.xml +++ b/GUI.NET/Dependencies/resources.fr.xml @@ -299,7 +299,6 @@ Vitesse du rembobinage : Avancé - Afficher le compteur d'images Utiliser la version alternative du comportement des IRQs du MMC3 Permettre les entrées invalides (Bas+Haut ou Gauche+Droite en même temps) Éliminer la limite de sprites (Réduit le clignotement dans certains jeux) @@ -362,6 +361,9 @@ Augmenter la vitesse d'émulation pendant le chargement des jeux FDS Insérer le disque demandé automatiquement pour les jeux de FDS + Afficher le compteur d'images + Afficher le compteur de temps + Permettre de rembobiner jusqu'à minutes (Utilise ≈1MB/min) diff --git a/GUI.NET/Dependencies/resources.ja.xml b/GUI.NET/Dependencies/resources.ja.xml index 79c2789b..883e2eb9 100644 --- a/GUI.NET/Dependencies/resources.ja.xml +++ b/GUI.NET/Dependencies/resources.ja.xml @@ -299,7 +299,6 @@ 巻き戻しの速度: 詳細設定 - フレームカウンタを表示する MMC3AのIRQ仕様を使う コントローラでは不可能インプットを可能にする (同時に上と下や右と左) スプライトの制限を解除 (点滅を軽減する) @@ -361,6 +360,9 @@ ファミコンディスクシステムのゲームをディスクからロードする時に自動的に最高速度にする ファミコンディスクシステムのゲーム中に自動的に該当するディスクを入れる + フレームカウンタを表示する + ゲームタイマーを表示する + 巻き戻し用データの 分をキープする (メモリの使用量:1分に約1MB) diff --git a/GUI.NET/Dependencies/resources.pt.xml b/GUI.NET/Dependencies/resources.pt.xml index 480c2666..749e01ab 100644 --- a/GUI.NET/Dependencies/resources.pt.xml +++ b/GUI.NET/Dependencies/resources.pt.xml @@ -297,7 +297,6 @@ Rewind Speed: Avançado - Show Frame Counter Utilizar a versão alternativa de componentes de IRQs de MMC3 Permitir as entradas inválidas (Cima+Baixo e Esquerda+Direita ao mesmo tempo) Estado inicial da memória durante o início: @@ -367,8 +366,11 @@ Criar uma cópia de segurança de cada state minutos (Aperte F8 para carregar) Mostrar uma notificação na tela ao fazer a cópia de segurança automática - Cópia de segurança online - + Cópia de segurança online + + Show frame counter + Show game timer + Keep rewind data for the last minutes (Memory Usage ≈1MB/min) diff --git a/GUI.NET/Dependencies/resources.ru.xml b/GUI.NET/Dependencies/resources.ru.xml index 44bddcb3..826276b8 100644 --- a/GUI.NET/Dependencies/resources.ru.xml +++ b/GUI.NET/Dependencies/resources.ru.xml @@ -299,7 +299,6 @@ Rewind Speed: Расширенные - Show Frame Counter Использовать альтернативный IRQ MMC3 Разрешить недопустимые комбинации (Вниз+Вверх и Влево+Вправо) Содержимое ОЗУ при включении : @@ -361,6 +360,9 @@ Использовать быструю загрузку FDS Automatically switch disks for FDS games + Show frame counter + Show game timer + Keep rewind data for the last minutes (Memory Usage ≈1MB/min) diff --git a/GUI.NET/Dependencies/resources.uk.xml b/GUI.NET/Dependencies/resources.uk.xml index b5de7cf1..63da8259 100644 --- a/GUI.NET/Dependencies/resources.uk.xml +++ b/GUI.NET/Dependencies/resources.uk.xml @@ -299,7 +299,6 @@ Швидкість перемотування: Розширені - Показувати Лічильник Кадрів Використовувати альтернативний IRQ MMC3 Дозволити неприпустимі комбінації (Вниз+Вгору і Ліворуч+Вправо) Вміст ОЗУ при включенні : @@ -361,6 +360,9 @@ Використовувати швидке завантаження FDS Автоматичне перемикання дисків для FDS ігор + Показувати Лічильник Кадрів + Show game timer + Зберігати дані перемотування за останні хвилин (Використання Пам'яті ≈1 МБ/хв) diff --git a/GUI.NET/Forms/Config/frmEmulationConfig.Designer.cs b/GUI.NET/Forms/Config/frmEmulationConfig.Designer.cs index cf2ff07c..eb4f7882 100644 --- a/GUI.NET/Forms/Config/frmEmulationConfig.Designer.cs +++ b/GUI.NET/Forms/Config/frmEmulationConfig.Designer.cs @@ -88,7 +88,6 @@ namespace Mesen.GUI.Forms.Config this.chkShowLagCounter = new System.Windows.Forms.CheckBox(); this.btnResetLagCounter = new System.Windows.Forms.Button(); this.tmrUpdateClockRate = new System.Windows.Forms.Timer(this.components); - this.chkShowFrameCounter = new System.Windows.Forms.CheckBox(); this.tabMain.SuspendLayout(); this.tpgGeneral.SuspendLayout(); this.tableLayoutPanel4.SuspendLayout(); @@ -314,22 +313,20 @@ namespace Mesen.GUI.Forms.Config // this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Controls.Add(this.chkEnableOamDecay, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.chkEnableOamDecay, 0, 3); this.tableLayoutPanel1.Controls.Add(this.chkRemoveSpriteLimit, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel8, 0, 10); - this.tableLayoutPanel1.Controls.Add(this.chkDisablePaletteRead, 0, 8); - this.tableLayoutPanel1.Controls.Add(this.chkDisableOamAddrBug, 0, 7); - this.tableLayoutPanel1.Controls.Add(this.chkDisablePpuReset, 0, 5); - this.tableLayoutPanel1.Controls.Add(this.chkDisablePpu2004Reads, 0, 6); - this.tableLayoutPanel1.Controls.Add(this.chkUseNes101Hvc101Behavior, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.chkAllowInvalidInput, 0, 9); - this.tableLayoutPanel1.Controls.Add(this.chkUseAlternativeMmc3Irq, 0, 3); - this.tableLayoutPanel1.Controls.Add(this.chkShowFrameCounter, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel8, 0, 9); + this.tableLayoutPanel1.Controls.Add(this.chkDisablePaletteRead, 0, 7); + this.tableLayoutPanel1.Controls.Add(this.chkDisableOamAddrBug, 0, 6); + this.tableLayoutPanel1.Controls.Add(this.chkDisablePpuReset, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.chkDisablePpu2004Reads, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.chkUseNes101Hvc101Behavior, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.chkAllowInvalidInput, 0, 8); + this.tableLayoutPanel1.Controls.Add(this.chkUseAlternativeMmc3Irq, 0, 2); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 12; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowCount = 11; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -341,6 +338,7 @@ namespace Mesen.GUI.Forms.Config this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(519, 296); this.tableLayoutPanel1.TabIndex = 0; // @@ -348,7 +346,7 @@ namespace Mesen.GUI.Forms.Config // this.chkEnableOamDecay.AutoSize = true; this.chkEnableOamDecay.Checked = false; - this.chkEnableOamDecay.Location = new System.Drawing.Point(0, 92); + this.chkEnableOamDecay.Location = new System.Drawing.Point(0, 69); this.chkEnableOamDecay.Name = "chkEnableOamDecay"; this.chkEnableOamDecay.Size = new System.Drawing.Size(243, 23); this.chkEnableOamDecay.TabIndex = 9; @@ -369,7 +367,7 @@ namespace Mesen.GUI.Forms.Config this.flowLayoutPanel8.Controls.Add(this.lblRamPowerOnState); this.flowLayoutPanel8.Controls.Add(this.cboRamPowerOnState); this.flowLayoutPanel8.Dock = System.Windows.Forms.DockStyle.Fill; - this.flowLayoutPanel8.Location = new System.Drawing.Point(0, 230); + this.flowLayoutPanel8.Location = new System.Drawing.Point(0, 207); this.flowLayoutPanel8.Margin = new System.Windows.Forms.Padding(0); this.flowLayoutPanel8.Name = "flowLayoutPanel8"; this.flowLayoutPanel8.Size = new System.Drawing.Size(519, 27); @@ -398,7 +396,7 @@ namespace Mesen.GUI.Forms.Config // this.chkDisablePaletteRead.AutoSize = true; this.chkDisablePaletteRead.Checked = false; - this.chkDisablePaletteRead.Location = new System.Drawing.Point(0, 184); + this.chkDisablePaletteRead.Location = new System.Drawing.Point(0, 161); this.chkDisablePaletteRead.Name = "chkDisablePaletteRead"; this.chkDisablePaletteRead.Size = new System.Drawing.Size(248, 23); this.chkDisablePaletteRead.TabIndex = 6; @@ -408,7 +406,7 @@ namespace Mesen.GUI.Forms.Config // this.chkDisableOamAddrBug.AutoSize = true; this.chkDisableOamAddrBug.Checked = false; - this.chkDisableOamAddrBug.Location = new System.Drawing.Point(0, 161); + this.chkDisableOamAddrBug.Location = new System.Drawing.Point(0, 138); this.chkDisableOamAddrBug.Name = "chkDisableOamAddrBug"; this.chkDisableOamAddrBug.Size = new System.Drawing.Size(311, 23); this.chkDisableOamAddrBug.TabIndex = 5; @@ -418,7 +416,7 @@ namespace Mesen.GUI.Forms.Config // this.chkDisablePpuReset.AutoSize = true; this.chkDisablePpuReset.Checked = false; - this.chkDisablePpuReset.Location = new System.Drawing.Point(0, 115); + this.chkDisablePpuReset.Location = new System.Drawing.Point(0, 92); this.chkDisablePpuReset.Name = "chkDisablePpuReset"; this.chkDisablePpuReset.Size = new System.Drawing.Size(414, 23); this.chkDisablePpuReset.TabIndex = 7; @@ -428,7 +426,7 @@ namespace Mesen.GUI.Forms.Config // this.chkDisablePpu2004Reads.AutoSize = true; this.chkDisablePpu2004Reads.Checked = false; - this.chkDisablePpu2004Reads.Location = new System.Drawing.Point(0, 138); + this.chkDisablePpu2004Reads.Location = new System.Drawing.Point(0, 115); this.chkDisablePpu2004Reads.Name = "chkDisablePpu2004Reads"; this.chkDisablePpu2004Reads.Size = new System.Drawing.Size(341, 23); this.chkDisablePpu2004Reads.TabIndex = 4; @@ -437,7 +435,7 @@ namespace Mesen.GUI.Forms.Config // chkUseNes101Hvc101Behavior // this.chkUseNes101Hvc101Behavior.AutoSize = true; - this.chkUseNes101Hvc101Behavior.Location = new System.Drawing.Point(3, 49); + this.chkUseNes101Hvc101Behavior.Location = new System.Drawing.Point(3, 26); this.chkUseNes101Hvc101Behavior.Name = "chkUseNes101Hvc101Behavior"; this.chkUseNes101Hvc101Behavior.Size = new System.Drawing.Size(292, 17); this.chkUseNes101Hvc101Behavior.TabIndex = 8; @@ -449,7 +447,7 @@ namespace Mesen.GUI.Forms.Config this.chkAllowInvalidInput.AutoSize = true; this.chkAllowInvalidInput.Checked = false; this.chkAllowInvalidInput.Dock = System.Windows.Forms.DockStyle.Fill; - this.chkAllowInvalidInput.Location = new System.Drawing.Point(0, 207); + this.chkAllowInvalidInput.Location = new System.Drawing.Point(0, 184); this.chkAllowInvalidInput.Name = "chkAllowInvalidInput"; this.chkAllowInvalidInput.Size = new System.Drawing.Size(519, 23); this.chkAllowInvalidInput.TabIndex = 1; @@ -458,7 +456,7 @@ namespace Mesen.GUI.Forms.Config // chkUseAlternativeMmc3Irq // this.chkUseAlternativeMmc3Irq.AutoSize = true; - this.chkUseAlternativeMmc3Irq.Location = new System.Drawing.Point(3, 72); + this.chkUseAlternativeMmc3Irq.Location = new System.Drawing.Point(3, 49); this.chkUseAlternativeMmc3Irq.Name = "chkUseAlternativeMmc3Irq"; this.chkUseAlternativeMmc3Irq.Size = new System.Drawing.Size(197, 17); this.chkUseAlternativeMmc3Irq.TabIndex = 0; @@ -826,16 +824,6 @@ namespace Mesen.GUI.Forms.Config this.tmrUpdateClockRate.Enabled = true; this.tmrUpdateClockRate.Tick += new System.EventHandler(this.tmrUpdateClockRate_Tick); // - // chkShowFrameCounter - // - this.chkShowFrameCounter.AutoSize = true; - this.chkShowFrameCounter.Location = new System.Drawing.Point(3, 26); - this.chkShowFrameCounter.Name = "chkShowFrameCounter"; - this.chkShowFrameCounter.Size = new System.Drawing.Size(125, 17); - this.chkShowFrameCounter.TabIndex = 10; - this.chkShowFrameCounter.Text = "Show Frame Counter"; - this.chkShowFrameCounter.UseVisualStyleBackColor = true; - // // frmEmulationConfig // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -953,6 +941,5 @@ namespace Mesen.GUI.Forms.Config private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel10; private System.Windows.Forms.NumericUpDown nudRewindSpeed; private System.Windows.Forms.Label lblRewindSpeedHint; - private System.Windows.Forms.CheckBox chkShowFrameCounter; } } \ No newline at end of file diff --git a/GUI.NET/Forms/Config/frmEmulationConfig.cs b/GUI.NET/Forms/Config/frmEmulationConfig.cs index b6048592..f36bfb6b 100644 --- a/GUI.NET/Forms/Config/frmEmulationConfig.cs +++ b/GUI.NET/Forms/Config/frmEmulationConfig.cs @@ -25,7 +25,6 @@ namespace Mesen.GUI.Forms.Config AddBinding("TurboSpeed", nudTurboSpeed); AddBinding("RewindSpeed", nudRewindSpeed); - AddBinding("ShowFrameCounter", chkShowFrameCounter); AddBinding("UseAlternativeMmc3Irq", chkUseAlternativeMmc3Irq); AddBinding("AllowInvalidInput", chkAllowInvalidInput); AddBinding("RemoveSpriteLimit", chkRemoveSpriteLimit); diff --git a/GUI.NET/Forms/Config/frmPreferences.Designer.cs b/GUI.NET/Forms/Config/frmPreferences.Designer.cs index e9e21046..78573194 100644 --- a/GUI.NET/Forms/Config/frmPreferences.Designer.cs +++ b/GUI.NET/Forms/Config/frmPreferences.Designer.cs @@ -98,15 +98,17 @@ namespace Mesen.GUI.Forms.Config this.tpgAdvanced = new System.Windows.Forms.TabPage(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.chkDisableGameDatabase = new Mesen.GUI.Controls.ctrlRiskyOption(); + this.chkFdsAutoLoadDisk = new System.Windows.Forms.CheckBox(); + this.chkFdsFastForwardOnLoad = new System.Windows.Forms.CheckBox(); this.chkDisplayTitleBarInfo = new System.Windows.Forms.CheckBox(); this.flowLayoutPanel6 = new System.Windows.Forms.FlowLayoutPanel(); this.lblRewind = new System.Windows.Forms.Label(); this.nudRewindBufferSize = new System.Windows.Forms.NumericUpDown(); this.lblRewindMinutes = new System.Windows.Forms.Label(); - this.tmrSyncDateTime = new System.Windows.Forms.Timer(this.components); - this.chkFdsAutoLoadDisk = new System.Windows.Forms.CheckBox(); - this.chkFdsFastForwardOnLoad = new System.Windows.Forms.CheckBox(); this.chkFdsAutoInsertDisk = new System.Windows.Forms.CheckBox(); + this.tmrSyncDateTime = new System.Windows.Forms.Timer(this.components); + this.chkShowGameTimer = new System.Windows.Forms.CheckBox(); + this.chkShowFrameCounter = new System.Windows.Forms.CheckBox(); this.tlpMain.SuspendLayout(); this.flowLayoutPanel2.SuspendLayout(); this.tabMain.SuspendLayout(); @@ -959,12 +961,16 @@ namespace Mesen.GUI.Forms.Config this.tableLayoutPanel1.Controls.Add(this.chkFdsAutoLoadDisk, 0, 1); this.tableLayoutPanel1.Controls.Add(this.chkFdsFastForwardOnLoad, 0, 2); this.tableLayoutPanel1.Controls.Add(this.chkDisplayTitleBarInfo, 0, 4); - this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel6, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel6, 0, 7); this.tableLayoutPanel1.Controls.Add(this.chkFdsAutoInsertDisk, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.chkShowGameTimer, 0, 6); + this.tableLayoutPanel1.Controls.Add(this.chkShowFrameCounter, 0, 5); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 7; + this.tableLayoutPanel1.RowCount = 9; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -985,6 +991,26 @@ namespace Mesen.GUI.Forms.Config this.chkDisableGameDatabase.TabIndex = 6; this.chkDisableGameDatabase.Text = "Disable built-in game database"; // + // chkFdsAutoLoadDisk + // + this.chkFdsAutoLoadDisk.AutoSize = true; + this.chkFdsAutoLoadDisk.Location = new System.Drawing.Point(3, 26); + this.chkFdsAutoLoadDisk.Name = "chkFdsAutoLoadDisk"; + this.chkFdsAutoLoadDisk.Size = new System.Drawing.Size(303, 17); + this.chkFdsAutoLoadDisk.TabIndex = 3; + this.chkFdsAutoLoadDisk.Text = "Automatically insert disk 1 side A when starting FDS games"; + this.chkFdsAutoLoadDisk.UseVisualStyleBackColor = true; + // + // chkFdsFastForwardOnLoad + // + this.chkFdsFastForwardOnLoad.AutoSize = true; + this.chkFdsFastForwardOnLoad.Location = new System.Drawing.Point(3, 49); + this.chkFdsFastForwardOnLoad.Name = "chkFdsFastForwardOnLoad"; + this.chkFdsFastForwardOnLoad.Size = new System.Drawing.Size(342, 17); + this.chkFdsFastForwardOnLoad.TabIndex = 4; + this.chkFdsFastForwardOnLoad.Text = "Automatically fast forward FDS games when disk or BIOS is loading"; + this.chkFdsFastForwardOnLoad.UseVisualStyleBackColor = true; + // // chkDisplayTitleBarInfo // this.chkDisplayTitleBarInfo.AutoSize = true; @@ -1001,7 +1027,7 @@ namespace Mesen.GUI.Forms.Config this.flowLayoutPanel6.Controls.Add(this.nudRewindBufferSize); this.flowLayoutPanel6.Controls.Add(this.lblRewindMinutes); this.flowLayoutPanel6.Dock = System.Windows.Forms.DockStyle.Fill; - this.flowLayoutPanel6.Location = new System.Drawing.Point(0, 115); + this.flowLayoutPanel6.Location = new System.Drawing.Point(0, 161); this.flowLayoutPanel6.Margin = new System.Windows.Forms.Padding(0); this.flowLayoutPanel6.Name = "flowLayoutPanel6"; this.flowLayoutPanel6.Size = new System.Drawing.Size(473, 23); @@ -1044,31 +1070,6 @@ namespace Mesen.GUI.Forms.Config this.lblRewindMinutes.TabIndex = 2; this.lblRewindMinutes.Text = "minutes (Memory Usage ≈1MB/min)"; // - // tmrSyncDateTime - // - this.tmrSyncDateTime.Enabled = true; - this.tmrSyncDateTime.Tick += new System.EventHandler(this.tmrSyncDateTime_Tick); - // - // chkFdsAutoLoadDisk - // - this.chkFdsAutoLoadDisk.AutoSize = true; - this.chkFdsAutoLoadDisk.Location = new System.Drawing.Point(3, 26); - this.chkFdsAutoLoadDisk.Name = "chkFdsAutoLoadDisk"; - this.chkFdsAutoLoadDisk.Size = new System.Drawing.Size(303, 17); - this.chkFdsAutoLoadDisk.TabIndex = 3; - this.chkFdsAutoLoadDisk.Text = "Automatically insert disk 1 side A when starting FDS games"; - this.chkFdsAutoLoadDisk.UseVisualStyleBackColor = true; - // - // chkFdsFastForwardOnLoad - // - this.chkFdsFastForwardOnLoad.AutoSize = true; - this.chkFdsFastForwardOnLoad.Location = new System.Drawing.Point(3, 49); - this.chkFdsFastForwardOnLoad.Name = "chkFdsFastForwardOnLoad"; - this.chkFdsFastForwardOnLoad.Size = new System.Drawing.Size(342, 17); - this.chkFdsFastForwardOnLoad.TabIndex = 4; - this.chkFdsFastForwardOnLoad.Text = "Automatically fast forward FDS games when disk or BIOS is loading"; - this.chkFdsFastForwardOnLoad.UseVisualStyleBackColor = true; - // // chkFdsAutoInsertDisk // this.chkFdsAutoInsertDisk.AutoSize = true; @@ -1079,6 +1080,31 @@ namespace Mesen.GUI.Forms.Config this.chkFdsAutoInsertDisk.Text = "Automatically switch disks for FDS games"; this.chkFdsAutoInsertDisk.UseVisualStyleBackColor = true; // + // tmrSyncDateTime + // + this.tmrSyncDateTime.Enabled = true; + this.tmrSyncDateTime.Tick += new System.EventHandler(this.tmrSyncDateTime_Tick); + // + // chkShowGameTimer + // + this.chkShowGameTimer.AutoSize = true; + this.chkShowGameTimer.Location = new System.Drawing.Point(3, 141); + this.chkShowGameTimer.Name = "chkShowGameTimer"; + this.chkShowGameTimer.Size = new System.Drawing.Size(107, 17); + this.chkShowGameTimer.TabIndex = 11; + this.chkShowGameTimer.Text = "Show game timer"; + this.chkShowGameTimer.UseVisualStyleBackColor = true; + // + // chkShowFrameCounter + // + this.chkShowFrameCounter.AutoSize = true; + this.chkShowFrameCounter.Location = new System.Drawing.Point(3, 118); + this.chkShowFrameCounter.Name = "chkShowFrameCounter"; + this.chkShowFrameCounter.Size = new System.Drawing.Size(121, 17); + this.chkShowFrameCounter.TabIndex = 12; + this.chkShowFrameCounter.Text = "Show frame counter"; + this.chkShowFrameCounter.UseVisualStyleBackColor = true; + // // frmPreferences // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1220,5 +1246,7 @@ namespace Mesen.GUI.Forms.Config private System.Windows.Forms.CheckBox chkFdsAutoLoadDisk; private System.Windows.Forms.CheckBox chkFdsFastForwardOnLoad; private System.Windows.Forms.CheckBox chkFdsAutoInsertDisk; + private System.Windows.Forms.CheckBox chkShowGameTimer; + private System.Windows.Forms.CheckBox chkShowFrameCounter; } } \ No newline at end of file diff --git a/GUI.NET/Forms/Config/frmPreferences.cs b/GUI.NET/Forms/Config/frmPreferences.cs index bb7fad53..40cbe38c 100644 --- a/GUI.NET/Forms/Config/frmPreferences.cs +++ b/GUI.NET/Forms/Config/frmPreferences.cs @@ -60,6 +60,9 @@ namespace Mesen.GUI.Forms.Config AddBinding("AutoHideMenu", chkAutoHideMenu); AddBinding("DisplayTitleBarInfo", chkDisplayTitleBarInfo); + AddBinding("ShowFrameCounter", chkShowFrameCounter); + AddBinding("ShowGameTimer", chkShowGameTimer); + AddBinding("RewindBufferSize", nudRewindBufferSize); UpdateCloudDisplay(); diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 626c3d94..31b95e93 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -986,8 +986,9 @@ namespace Mesen.GUI UseNes101Hvc101Behavior = 0x100000000, ShowFrameCounter = 0x200000000, + ShowGameTimer = 0x400000000, - FdsAutoInsertDisk = 0x400000000, + FdsAutoInsertDisk = 0x800000000, Turbo = 0x2000000000, InBackground = 0x4000000000, diff --git a/Linux/SdlRenderer.cpp b/Linux/SdlRenderer.cpp index 1fbb5228..6e9c7f84 100755 --- a/Linux/SdlRenderer.cpp +++ b/Linux/SdlRenderer.cpp @@ -127,15 +127,7 @@ void SdlRenderer::Render() if(paused && !EmulationSettings::CheckFlag(EmulationFlags::HidePauseOverlay)) { DrawPauseScreen(); } else if(VideoDecoder::GetInstance()->IsRunning()) { - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFPS)) { - ShowFpsCounter(); - } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowLagCounter)) { - ShowLagCounter(); - } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFrameCounter)) { - ShowFrameCounter(); - } + DrawCounters(); } DrawToasts(); @@ -162,7 +154,7 @@ void SdlRenderer::DrawPauseScreen() _largeFont->DrawString(_sdlRenderer, L"PAUSE", (int)(_screenWidth / 2 - measureF[0] / 2), (int)(_screenHeight / 2 - measureF[1] / 2 - 8), 250, 235, 215); } -void SdlRenderer::DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b) +void SdlRenderer::DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity) { const wchar_t *text = message.c_str(); _spriteFont->DrawString(_sdlRenderer, text, x, y, r, g, b); diff --git a/Linux/SdlRenderer.h b/Linux/SdlRenderer.h index 924ea7f2..b3dda78f 100755 --- a/Linux/SdlRenderer.h +++ b/Linux/SdlRenderer.h @@ -63,5 +63,5 @@ public: void Render(); void Reset(); - void DrawString(std::wstring message, int x, int y, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255); + 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); }; \ No newline at end of file diff --git a/Windows/Renderer.cpp b/Windows/Renderer.cpp index 3b83e852..be0562f4 100644 --- a/Windows/Renderer.cpp +++ b/Windows/Renderer.cpp @@ -354,12 +354,6 @@ namespace NES return shaderResourceView; } - void Renderer::DisplayMessage(string title, string message) - { - shared_ptr toast(new ToastInfo(title, message, 4000)); - _toasts.push_front(toast); - } - void Renderer::DrawString(string message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font) { std::wstring textStr = utf8::utf8::decode(message); @@ -461,57 +455,10 @@ namespace NES DrawString("PAUSE", (float)_screenWidth / 2 - stringDimensions.m128_f32[0] / 2, (float)_screenHeight / 2 - stringDimensions.m128_f32[1] / 2 - 8, Colors::AntiqueWhite, 1.0f, _largeFont.get()); } - void Renderer::ShowFpsCounter() - { - if(_fpsTimer.GetElapsedMS() > 1000) { - //Update fps every sec - uint32_t frameCount = VideoDecoder::GetInstance()->GetFrameCount(); - if(frameCount - _lastFrameCount < 0) { - _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, (float)(_screenWidth - 125), 13, Colors::AntiqueWhite, 1.0f); - } - - void Renderer::ShowLagCounter() - { - float yPos = EmulationSettings::CheckFlag(EmulationFlags::ShowFPS) ? 37.0f : 13.0f; - string lagCounter = MessageManager::Localize("Lag") + ": " + std::to_string(Console::GetLagCounter()); - DrawString(lagCounter, (float)(_screenWidth - 123), yPos, Colors::AntiqueWhite, 1.0f); - } - - void Renderer::ShowFrameCounter() - { - float yPos = 13.0f; - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFPS)) { - yPos += 24.0f; - } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowLagCounter)) { - yPos += 24.0f; - } - string lagCounter = MessageManager::Localize("Frame") + ": " + std::to_string(PPU::GetFrameCount()); - DrawString(lagCounter, (float)(_screenWidth - 146), yPos, Colors::AntiqueWhite, 1.0f); - } - void Renderer::Render() { bool paused = EmulationSettings::IsPaused(); - if(_noUpdateCount > 10 || _frameChanged || paused || !_toasts.empty()) { + if(_noUpdateCount > 10 || _frameChanged || paused || IsMessageShown()) { _noUpdateCount = 0; auto lock = _frameLock.AcquireSafe(); @@ -527,15 +474,7 @@ namespace NES if(paused && !EmulationSettings::CheckFlag(EmulationFlags::HidePauseOverlay)) { DrawPauseScreen(); } else if(VideoDecoder::GetInstance()->IsRunning()) { - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFPS)) { - ShowFpsCounter(); - } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowLagCounter)) { - ShowLagCounter(); - } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFrameCounter)) { - ShowFrameCounter(); - } + DrawCounters(); } DrawToasts(); @@ -557,84 +496,21 @@ namespace NES } } - void Renderer::RemoveOldToasts() + void Renderer::DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity) { - _toasts.remove_if([](shared_ptr toast) { return toast->IsToastExpired(); }); + XMVECTORF32 color = { (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)opacity / 255.0f }; + _font->DrawString(_spriteBatch.get(), message.c_str(), XMFLOAT2((float)x, (float)y), color); } - void Renderer::DrawToasts() + float Renderer::MeasureString(std::wstring text) { - RemoveOldToasts(); - - int counter = 0; - int lastHeight = 5; - for(shared_ptr toast : _toasts) { - if(counter < 6) { - DrawToast(toast, lastHeight); - } else { - break; - } - counter++; - } + XMVECTOR measure = _font->MeasureString(text.c_str()); + float* measureF = (float*)&measure; + return measureF[0]; } - std::wstring Renderer::WrapText(string utf8Text, SpriteFont* font, float maxLineWidth, uint32_t &lineCount) + bool Renderer::ContainsCharacter(wchar_t character) { - using std::wstring; - wstring text = utf8::utf8::decode(utf8Text); - wstring wrappedText; - list words; - wstring currentWord; - for(size_t i = 0, len = text.length(); i < len; i++) { - if(text[i] == L' ' || text[i] == L'\n') { - if(currentWord.length() > 0) { - words.push_back(currentWord); - currentWord.clear(); - } - } else { - currentWord += text[i]; - } - } - if(currentWord.length() > 0) { - words.push_back(currentWord); - } - - lineCount = 1; - float spaceWidth = font->MeasureString(L" ").m128_f32[0]; - float lineWidth = 0.0f; - for(wstring word : words) { - for(unsigned int i = 0; i < word.size(); i++) { - if(!font->ContainsCharacter(word[i])) { - word[i] = L'?'; - } - } - float wordWidth = font->MeasureString(word.c_str()).m128_f32[0]; - - if(lineWidth + wordWidth < maxLineWidth) { - wrappedText += word + L" "; - lineWidth += wordWidth + spaceWidth; - } else { - wrappedText += L"\n" + word + L" "; - lineWidth = wordWidth + spaceWidth; - lineCount++; - } - } - - return wrappedText; - } - - void Renderer::DrawToast(shared_ptr toast, int &lastHeight) - { - //Get opacity for fade in/out effect - float opacity = toast->GetOpacity(); - XMVECTORF32 color = { opacity, opacity, opacity, opacity }; - float textLeftMargin = 4.0f; - - int lineHeight = 25; - string text = "[" + toast->GetToastTitle() + "] " + toast->GetToastMessage(); - uint32_t lineCount = 0; - std::wstring wrappedText = WrapText(text, _font.get(), _screenWidth - textLeftMargin * 2 - 20, lineCount); - lastHeight += lineCount * lineHeight; - DrawString(wrappedText, textLeftMargin, (float)(_screenHeight - lastHeight), color, 1); + return _font->ContainsCharacter(character); } } \ No newline at end of file diff --git a/Windows/Renderer.h b/Windows/Renderer.h index 72092cbf..9dcbd11f 100644 --- a/Windows/Renderer.h +++ b/Windows/Renderer.h @@ -7,6 +7,7 @@ #include "../Utilities/FolderUtilities.h" #include "../Utilities/SimpleLock.h" #include "../Utilities/Timer.h" +#include "../Core/BaseRenderer.h" using namespace DirectX; @@ -16,7 +17,7 @@ namespace DirectX { } namespace NES { - class Renderer : public IRenderingDevice, public IMessageManager + class Renderer : public BaseRenderer, public IRenderingDevice { private: HWND _hWnd = nullptr; @@ -43,21 +44,12 @@ namespace NES { VideoResizeFilter _resizeFilter = VideoResizeFilter::NearestNeighbor; - Timer _fpsTimer; - uint32_t _lastFrameCount = 0; - uint32_t _renderedFrameCount = 0; - uint32_t _lastRenderedFrameCount = 0; - uint32_t _currentFPS = 0; - uint32_t _currentRenderedFPS = 0; - unique_ptr _font; unique_ptr _largeFont; unique_ptr _spriteBatch; const uint32_t _bytesPerPixel = 4; - uint32_t _screenWidth = 0; - uint32_t _screenHeight = 0; uint32_t _screenBufferSize = 0; uint32_t _nesFrameHeight = 0; @@ -66,9 +58,6 @@ namespace NES { uint32_t _noUpdateCount = 0; - list> _toasts; - //ID3D11ShaderResourceView* _toastTexture = nullptr; - HRESULT InitDevice(); void CleanupDevice(); @@ -83,21 +72,16 @@ namespace NES { void DrawString(string message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font = nullptr); void DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font = nullptr); - void DrawToasts(); - void DrawToast(shared_ptr toast, int &lastHeight); - void RemoveOldToasts(); + void DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity); + float MeasureString(std::wstring text); + bool ContainsCharacter(wchar_t character); - void ShowFpsCounter(); - void ShowLagCounter(); - void ShowFrameCounter(); - public: Renderer(HWND hWnd); ~Renderer(); void Reset(); void Render(); - void DisplayMessage(string title, string message); void UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height); };