UI: Added game timer option (+ code refactoring)

This commit is contained in:
Souryo 2017-05-13 15:43:02 -04:00
parent b0c0efe614
commit 7d1fa8aaaf
23 changed files with 203 additions and 274 deletions

View file

@ -1,8 +1,9 @@
#include "BaseRenderer.h"
#include "stdafx.h"
#include <cmath>
#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<ToastInfo> 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()

View file

@ -29,10 +29,12 @@ protected:
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);
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();
};

View file

@ -411,6 +411,7 @@
<ClInclude Include="ArkanoidController.h" />
<ClInclude Include="Assembler.h" />
<ClInclude Include="AutomaticRomTest.h" />
<ClInclude Include="BaseRenderer.h" />
<ClInclude Include="FceuxMovie.h" />
<ClInclude Include="Mapper174.h" />
<ClInclude Include="Rambo1_158.h" />
@ -771,6 +772,7 @@
<ClCompile Include="ArkanoidController.cpp" />
<ClCompile Include="Assembler.cpp" />
<ClCompile Include="AutomaticRomTest.cpp" />
<ClCompile Include="BaseRenderer.cpp" />
<ClCompile Include="FceuxMovie.cpp" />
<ClCompile Include="RecordedRomTest.cpp" />
<ClCompile Include="AutoSaveManager.cpp" />

View file

@ -1177,6 +1177,9 @@
<ClInclude Include="Mapper174.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="BaseRenderer.h">
<Filter>VideoDecoder</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
@ -1398,5 +1401,8 @@
<ClCompile Include="RewindManager.cpp">
<Filter>Rewinder</Filter>
</ClCompile>
<ClCompile Include="BaseRenderer.cpp">
<Filter>VideoDecoder</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -47,8 +47,9 @@ enum EmulationFlags : uint64_t
UseNes101Hvc101Behavior = 0x100000000,
ShowFrameCounter = 0x200000000,
ShowGameTimer = 0x400000000,
FdsAutoInsertDisk = 0x400000000,
FdsAutoInsertDisk = 0x800000000,
Turbo = 0x2000000000,
InBackground = 0x4000000000,

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -297,7 +297,6 @@
<Control ID="lblRewindSpeed">Rewind Speed:</Control>
<Control ID="tpgAdvanced">Avanzado</Control>
<Control ID="chkShowFrameCounter">Show Frame Counter</Control>
<Control ID="chkUseAlternativeMmc3Irq">Utilizar la versión alternativa de componentes de IRQs de MMC3</Control>
<Control ID="chkAllowInvalidInput">Permitir las entradas inválidas (Arriba+Abajo e Izquierda+Derecha al mismo tiempo)</Control>
<Control ID="lblRamPowerOnState">Estado inicial de la memoria durante el inicio:</Control>
@ -367,7 +366,10 @@
<Control ID="chkAutoSave">Crear una copia de seguridad de cada estado</Control>
<Control ID="lblAutoSave">minutos (Pulse F8 para cargar)</Control>
<Control ID="chkAutoSaveNotify">Mostrar una notificación en pantalla al hacer la copia de seguridad automática</Control>
<Control ID="grpCloudSaves">Copia de seguridad online</Control>
<Control ID="grpCloudSaves">Copia de seguridad online</Control>
<Control ID="chkShowFrameCounter">Show frame counter</Control>
<Control ID="chkShowGameTimer">Show game timer</Control>
<Control ID="lblRewind">Keep rewind data for the last</Control>
<Control ID="lblRewindMinutes">minutes (Memory Usage ≈1MB/min)</Control>

View file

@ -299,7 +299,6 @@
<Control ID="lblRewindSpeed">Vitesse du rembobinage :</Control>
<Control ID="tpgAdvanced">Avancé</Control>
<Control ID="chkShowFrameCounter">Afficher le compteur d'images</Control>
<Control ID="chkUseAlternativeMmc3Irq">Utiliser la version alternative du comportement des IRQs du MMC3</Control>
<Control ID="chkAllowInvalidInput">Permettre les entrées invalides (Bas+Haut ou Gauche+Droite en même temps)</Control>
<Control ID="chkRemoveSpriteLimit">Éliminer la limite de sprites (Réduit le clignotement dans certains jeux)</Control>
@ -362,6 +361,9 @@
<Control ID="chkFdsFastForwardOnLoad">Augmenter la vitesse d'émulation pendant le chargement des jeux FDS</Control>
<Control ID="chkFdsAutoInsertDisk">Insérer le disque demandé automatiquement pour les jeux de FDS</Control>
<Control ID="chkShowFrameCounter">Afficher le compteur d'images</Control>
<Control ID="chkShowGameTimer">Afficher le compteur de temps</Control>
<Control ID="lblRewind">Permettre de rembobiner jusqu'à</Control>
<Control ID="lblRewindMinutes">minutes (Utilise ≈1MB/min)</Control>

View file

@ -299,7 +299,6 @@
<Control ID="lblRewindSpeed">巻き戻しの速度:</Control>
<Control ID="tpgAdvanced">詳細設定</Control>
<Control ID="chkShowFrameCounter">フレームカウンタを表示する</Control>
<Control ID="chkUseAlternativeMmc3Irq">MMC3AのIRQ仕様を使う</Control>
<Control ID="chkAllowInvalidInput">コントローラでは不可能インプットを可能にする (同時に上と下や右と左)</Control>
<Control ID="chkRemoveSpriteLimit">スプライトの制限を解除 (点滅を軽減する)</Control>
@ -361,6 +360,9 @@
<Control ID="chkFdsFastForwardOnLoad">ファミコンディスクシステムのゲームをディスクからロードする時に自動的に最高速度にする</Control>
<Control ID="chkFdsAutoInsertDisk">ファミコンディスクシステムのゲーム中に自動的に該当するディスクを入れる</Control>
<Control ID="chkShowFrameCounter">フレームカウンタを表示する</Control>
<Control ID="chkShowGameTimer">ゲームタイマーを表示する</Control>
<Control ID="lblRewind">巻き戻し用データの</Control>
<Control ID="lblRewindMinutes">分をキープする (メモリの使用量分に約MB)</Control>

View file

@ -297,7 +297,6 @@
<Control ID="lblRewindSpeed">Rewind Speed:</Control>
<Control ID="tpgAdvanced">Avançado</Control>
<Control ID="chkShowFrameCounter">Show Frame Counter</Control>
<Control ID="chkUseAlternativeMmc3Irq">Utilizar a versão alternativa de componentes de IRQs de MMC3</Control>
<Control ID="chkAllowInvalidInput">Permitir as entradas inválidas (Cima+Baixo e Esquerda+Direita ao mesmo tempo)</Control>
<Control ID="lblRamPowerOnState">Estado inicial da memória durante o início:</Control>
@ -367,8 +366,11 @@
<Control ID="chkAutoSave">Criar uma cópia de segurança de cada state</Control>
<Control ID="lblAutoSave">minutos (Aperte F8 para carregar)</Control>
<Control ID="chkAutoSaveNotify">Mostrar uma notificação na tela ao fazer a cópia de segurança automática</Control>
<Control ID="grpCloudSaves">Cópia de segurança online</Control>
<Control ID="grpCloudSaves">Cópia de segurança online</Control>
<Control ID="chkShowFrameCounter">Show frame counter</Control>
<Control ID="chkShowGameTimer">Show game timer</Control>
<Control ID="lblRewind">Keep rewind data for the last</Control>
<Control ID="lblRewindMinutes">minutes (Memory Usage ≈1MB/min)</Control>

View file

@ -299,7 +299,6 @@
<Control ID="lblRewindSpeed">Rewind Speed:</Control>
<Control ID="tpgAdvanced">Расширенные</Control>
<Control ID="chkShowFrameCounter">Show Frame Counter</Control>
<Control ID="chkUseAlternativeMmc3Irq">Использовать альтернативный IRQ MMC3</Control>
<Control ID="chkAllowInvalidInput">Разрешить недопустимые комбинации (Вниз+Вверх и Влево+Вправо)</Control>
<Control ID="lblRamPowerOnState">Содержимое ОЗУ при включении : </Control>
@ -361,6 +360,9 @@
<Control ID="chkFdsFastForwardOnLoad">Использовать быструю загрузку FDS</Control>
<Control ID="chkFdsAutoInsertDisk">Automatically switch disks for FDS games</Control>
<Control ID="chkShowFrameCounter">Show frame counter</Control>
<Control ID="chkShowGameTimer">Show game timer</Control>
<Control ID="lblRewind">Keep rewind data for the last</Control>
<Control ID="lblRewindMinutes">minutes (Memory Usage ≈1MB/min)</Control>

View file

@ -299,7 +299,6 @@
<Control ID="lblRewindSpeed">Швидкість перемотування:</Control>
<Control ID="tpgAdvanced">Розширені</Control>
<Control ID="chkShowFrameCounter">Показувати Лічильник Кадрів</Control>
<Control ID="chkUseAlternativeMmc3Irq">Використовувати альтернативний IRQ MMC3</Control>
<Control ID="chkAllowInvalidInput">Дозволити неприпустимі комбінації (Вниз+Вгору і Ліворуч+Вправо)</Control>
<Control ID="lblRamPowerOnState">Вміст ОЗУ при включенні : </Control>
@ -361,6 +360,9 @@
<Control ID="chkFdsFastForwardOnLoad">Використовувати швидке завантаження FDS</Control>
<Control ID="chkFdsAutoInsertDisk">Автоматичне перемикання дисків для FDS ігор</Control>
<Control ID="chkShowFrameCounter">Показувати Лічильник Кадрів</Control>
<Control ID="chkShowGameTimer">Show game timer</Control>
<Control ID="lblRewind">Зберігати дані перемотування за останні</Control>
<Control ID="lblRewindMinutes">хвилин (Використання Пам'яті ≈1 МБ/хв)</Control>

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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();

View file

@ -986,8 +986,9 @@ namespace Mesen.GUI
UseNes101Hvc101Behavior = 0x100000000,
ShowFrameCounter = 0x200000000,
ShowGameTimer = 0x400000000,
FdsAutoInsertDisk = 0x400000000,
FdsAutoInsertDisk = 0x800000000,
Turbo = 0x2000000000,
InBackground = 0x4000000000,

View file

@ -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);

View file

@ -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);
};

View file

@ -354,12 +354,6 @@ namespace NES
return shaderResourceView;
}
void Renderer::DisplayMessage(string title, string message)
{
shared_ptr<ToastInfo> 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<ToastInfo> 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<ToastInfo> 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<wstring> 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<ToastInfo> 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);
}
}

View file

@ -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<SpriteFont> _font;
unique_ptr<SpriteFont> _largeFont;
unique_ptr<SpriteBatch> _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<shared_ptr<ToastInfo>> _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<ToastInfo> 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);
};