Merge pull request #6815 from spycrab/osd_refactor

VideoCommon/RenderBase: Refactor OSD messages
This commit is contained in:
Léo Lam 2018-05-11 18:33:45 +02:00 committed by GitHub
commit b10bbea393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 31 deletions

View File

@ -252,15 +252,20 @@ void HotkeyScheduler::Run()
emit ConnectWiiRemote(wiimote_id); emit ConnectWiiRemote(wiimote_id);
} }
const auto show_msg = [](OSDMessage message) {
if (g_renderer)
g_renderer->ShowOSDMessage(message);
};
// Graphics // Graphics
if (IsHotkey(HK_INCREASE_IR)) if (IsHotkey(HK_INCREASE_IR))
{ {
OSDChoice = 1; show_msg(OSDMessage::IRChanged);
++g_Config.iEFBScale; ++g_Config.iEFBScale;
} }
if (IsHotkey(HK_DECREASE_IR)) if (IsHotkey(HK_DECREASE_IR))
{ {
OSDChoice = 1; show_msg(OSDMessage::IRChanged);
g_Config.iEFBScale = std::max(g_Config.iEFBScale - 1, EFB_SCALE_AUTO_INTEGRAL); g_Config.iEFBScale = std::max(g_Config.iEFBScale - 1, EFB_SCALE_AUTO_INTEGRAL);
} }
@ -269,29 +274,29 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_TOGGLE_AR)) if (IsHotkey(HK_TOGGLE_AR))
{ {
OSDChoice = 2; show_msg(OSDMessage::ARToggled);
g_Config.aspect_mode = g_Config.aspect_mode =
static_cast<AspectMode>((static_cast<int>(g_Config.aspect_mode) + 1) & 3); static_cast<AspectMode>((static_cast<int>(g_Config.aspect_mode) + 1) & 3);
} }
if (IsHotkey(HK_TOGGLE_EFBCOPIES)) if (IsHotkey(HK_TOGGLE_EFBCOPIES))
{ {
OSDChoice = 3; show_msg(OSDMessage::EFBCopyToggled);
g_Config.bSkipEFBCopyToRam = !g_Config.bSkipEFBCopyToRam; g_Config.bSkipEFBCopyToRam = !g_Config.bSkipEFBCopyToRam;
} }
if (IsHotkey(HK_TOGGLE_XFBCOPIES)) if (IsHotkey(HK_TOGGLE_XFBCOPIES))
{ {
OSDChoice = 6; show_msg(OSDMessage::XFBChanged);
g_Config.bSkipXFBCopyToRam = !g_Config.bSkipXFBCopyToRam; g_Config.bSkipXFBCopyToRam = !g_Config.bSkipXFBCopyToRam;
} }
if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB)) if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB))
{ {
OSDChoice = 6; show_msg(OSDMessage::XFBChanged);
g_Config.bImmediateXFB = !g_Config.bImmediateXFB; g_Config.bImmediateXFB = !g_Config.bImmediateXFB;
} }
if (IsHotkey(HK_TOGGLE_FOG)) if (IsHotkey(HK_TOGGLE_FOG))
{ {
OSDChoice = 4; show_msg(OSDMessage::FogToggled);
g_Config.bDisableFog = !g_Config.bDisableFog; g_Config.bDisableFog = !g_Config.bDisableFog;
} }
@ -305,7 +310,7 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_DECREASE_EMULATION_SPEED)) if (IsHotkey(HK_DECREASE_EMULATION_SPEED))
{ {
OSDChoice = 5; show_msg(OSDMessage::SpeedChanged);
auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1; auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1;
speed = (speed <= 0 || (speed >= 0.95 && speed <= 1.05)) ? 1.0 : speed; speed = (speed <= 0 || (speed >= 0.95 && speed <= 1.05)) ? 1.0 : speed;
@ -314,7 +319,7 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_INCREASE_EMULATION_SPEED)) if (IsHotkey(HK_INCREASE_EMULATION_SPEED))
{ {
OSDChoice = 5; show_msg(OSDMessage::SpeedChanged);
auto speed = SConfig::GetInstance().m_EmulationSpeed + 0.1; auto speed = SConfig::GetInstance().m_EmulationSpeed + 0.1;
speed = (speed >= 0.95 && speed <= 1.05) ? 1.0 : speed; speed = (speed >= 0.95 && speed <= 1.05) ? 1.0 : speed;

View File

@ -1417,14 +1417,19 @@ void CFrame::ParseHotkeys()
OnConnectWiimote(evt); OnConnectWiimote(evt);
} }
const auto show_msg = [](OSDMessage message) {
if (g_renderer)
g_renderer->ShowOSDMessage(message);
};
if (IsHotkey(HK_INCREASE_IR)) if (IsHotkey(HK_INCREASE_IR))
{ {
OSDChoice = 1; show_msg(OSDMessage::IRChanged);
Config::SetCurrent(Config::GFX_EFB_SCALE, Config::Get(Config::GFX_EFB_SCALE) + 1); Config::SetCurrent(Config::GFX_EFB_SCALE, Config::Get(Config::GFX_EFB_SCALE) + 1);
} }
if (IsHotkey(HK_DECREASE_IR)) if (IsHotkey(HK_DECREASE_IR))
{ {
OSDChoice = 1; show_msg(OSDMessage::IRChanged);
if (Config::Get(Config::GFX_EFB_SCALE) > EFB_SCALE_AUTO_INTEGRAL) if (Config::Get(Config::GFX_EFB_SCALE) > EFB_SCALE_AUTO_INTEGRAL)
Config::SetCurrent(Config::GFX_EFB_SCALE, Config::Get(Config::GFX_EFB_SCALE) - 1); Config::SetCurrent(Config::GFX_EFB_SCALE, Config::Get(Config::GFX_EFB_SCALE) - 1);
} }
@ -1434,7 +1439,7 @@ void CFrame::ParseHotkeys()
} }
if (IsHotkey(HK_TOGGLE_AR)) if (IsHotkey(HK_TOGGLE_AR))
{ {
OSDChoice = 2; show_msg(OSDMessage::ARToggled);
// Toggle aspect ratio // Toggle aspect ratio
int aspect_ratio = Config::Get(Config::GFX_ASPECT_RATIO); int aspect_ratio = Config::Get(Config::GFX_ASPECT_RATIO);
aspect_ratio = (aspect_ratio + 1) & 3; aspect_ratio = (aspect_ratio + 1) & 3;
@ -1442,28 +1447,28 @@ void CFrame::ParseHotkeys()
} }
if (IsHotkey(HK_TOGGLE_EFBCOPIES)) if (IsHotkey(HK_TOGGLE_EFBCOPIES))
{ {
OSDChoice = 3; show_msg(OSDMessage::EFBCopyToggled);
// Toggle EFB copies between EFB2RAM and EFB2Texture // Toggle EFB copies between EFB2RAM and EFB2Texture
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM,
!Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM)); !Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM));
} }
if (IsHotkey(HK_TOGGLE_XFBCOPIES)) if (IsHotkey(HK_TOGGLE_XFBCOPIES))
{ {
OSDChoice = 6; show_msg(OSDMessage::XFBChanged);
// Toggle XFB copies between XFB2RAM and XFB2Texture // Toggle XFB copies between XFB2RAM and XFB2Texture
Config::SetCurrent(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM, Config::SetCurrent(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM,
!Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM)); !Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM));
} }
if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB)) if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB))
{ {
OSDChoice = 6; show_msg(OSDMessage::XFBChanged);
// Toggle immediate present of xfb // Toggle immediate present of xfb
Config::SetCurrent(Config::GFX_HACK_IMMEDIATE_XFB, Config::SetCurrent(Config::GFX_HACK_IMMEDIATE_XFB,
!Config::Get(Config::GFX_HACK_IMMEDIATE_XFB)); !Config::Get(Config::GFX_HACK_IMMEDIATE_XFB));
} }
if (IsHotkey(HK_TOGGLE_FOG)) if (IsHotkey(HK_TOGGLE_FOG))
{ {
OSDChoice = 4; show_msg(OSDMessage::FogToggled);
Config::SetCurrent(Config::GFX_DISABLE_FOG, !Config::Get(Config::GFX_DISABLE_FOG)); Config::SetCurrent(Config::GFX_DISABLE_FOG, !Config::Get(Config::GFX_DISABLE_FOG));
} }
if (IsHotkey(HK_TOGGLE_DUMPTEXTURES)) if (IsHotkey(HK_TOGGLE_DUMPTEXTURES))
@ -1477,7 +1482,7 @@ void CFrame::ParseHotkeys()
Core::SetIsThrottlerTempDisabled(IsHotkey(HK_TOGGLE_THROTTLE, true)); Core::SetIsThrottlerTempDisabled(IsHotkey(HK_TOGGLE_THROTTLE, true));
if (IsHotkey(HK_DECREASE_EMULATION_SPEED)) if (IsHotkey(HK_DECREASE_EMULATION_SPEED))
{ {
OSDChoice = 5; show_msg(OSDMessage::SpeedChanged);
if (SConfig::GetInstance().m_EmulationSpeed <= 0.0f) if (SConfig::GetInstance().m_EmulationSpeed <= 0.0f)
SConfig::GetInstance().m_EmulationSpeed = 1.0f; SConfig::GetInstance().m_EmulationSpeed = 1.0f;
@ -1492,7 +1497,7 @@ void CFrame::ParseHotkeys()
} }
if (IsHotkey(HK_INCREASE_EMULATION_SPEED)) if (IsHotkey(HK_INCREASE_EMULATION_SPEED))
{ {
OSDChoice = 5; show_msg(OSDMessage::SpeedChanged);
if (SConfig::GetInstance().m_EmulationSpeed > 0.0f) if (SConfig::GetInstance().m_EmulationSpeed > 0.0f)
SConfig::GetInstance().m_EmulationSpeed += 0.1f; SConfig::GetInstance().m_EmulationSpeed += 0.1f;

View File

@ -68,8 +68,6 @@
// TODO: Move these out of here. // TODO: Move these out of here.
int frameCount; int frameCount;
int OSDChoice;
static int OSDTime;
std::unique_ptr<Renderer> g_renderer; std::unique_ptr<Renderer> g_renderer;
@ -85,9 +83,6 @@ Renderer::Renderer(int backbuffer_width, int backbuffer_height)
UpdateDrawRectangle(); UpdateDrawRectangle();
CalculateTargetSize(); CalculateTargetSize();
OSDChoice = 0;
OSDTime = 0;
if (SConfig::GetInstance().bWii) if (SConfig::GetInstance().bWii)
m_aspect_wide = Config::Get(Config::SYSCONF_WIDESCREEN); m_aspect_wide = Config::Get(Config::SYSCONF_WIDESCREEN);
@ -296,13 +291,13 @@ void Renderer::DrawDebugText()
} }
// OSD Menu messages // OSD Menu messages
if (OSDChoice > 0) if (m_osd_message > 0)
{ {
OSDTime = Common::Timer::GetTimeMs() + 3000; m_osd_time = Common::Timer::GetTimeMs() + 3000;
OSDChoice = -OSDChoice; m_osd_message = -m_osd_message;
} }
if ((u32)OSDTime > Common::Timer::GetTimeMs()) if (static_cast<u32>(m_osd_time) > Common::Timer::GetTimeMs())
{ {
std::string res_text; std::string res_text;
switch (g_ActiveConfig.iEFBScale) switch (g_ActiveConfig.iEFBScale)
@ -360,7 +355,7 @@ void Renderer::DrawDebugText()
// The latest changed setting in yellow // The latest changed setting in yellow
for (int i = 0; i != lines_count; ++i) for (int i = 0; i != lines_count; ++i)
{ {
if (OSDChoice == -i - 1) if (m_osd_message == -i - 1)
final_yellow += lines[i]; final_yellow += lines[i];
final_yellow += '\n'; final_yellow += '\n';
} }
@ -368,7 +363,7 @@ void Renderer::DrawDebugText()
// The other settings in cyan // The other settings in cyan
for (int i = 0; i != lines_count; ++i) for (int i = 0; i != lines_count; ++i)
{ {
if (OSDChoice != -i - 1) if (m_osd_message != -i - 1)
final_cyan += lines[i]; final_cyan += lines[i];
final_cyan += '\n'; final_cyan += '\n';
} }
@ -1032,3 +1027,8 @@ std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCom
{ {
return std::make_unique<VideoCommon::AsyncShaderCompiler>(); return std::make_unique<VideoCommon::AsyncShaderCompiler>();
} }
void Renderer::ShowOSDMessage(OSDMessage message)
{
m_osd_message = static_cast<s32>(message);
}

View File

@ -53,9 +53,17 @@ struct EfbPokeData
u32 data; u32 data;
}; };
// TODO: Move these out of here.
extern int frameCount; extern int frameCount;
extern int OSDChoice;
enum class OSDMessage : s32
{
IRChanged = 1,
ARToggled = 2,
EFBCopyToggled = 3,
FogToggled = 4,
SpeedChanged = 5,
XFBChanged = 6
};
// Renderer really isn't a very good name for this class - it's more like "Misc". // Renderer really isn't a very good name for this class - it's more like "Misc".
// The long term goal is to get rid of this class and replace it with others that make // The long term goal is to get rid of this class and replace it with others that make
@ -190,6 +198,8 @@ public:
{ {
} }
void ShowOSDMessage(OSDMessage message);
protected: protected:
std::tuple<int, int> CalculateTargetScale(int x, int y) const; std::tuple<int, int> CalculateTargetScale(int x, int y) const;
bool CalculateTargetSize(); bool CalculateTargetSize();
@ -277,6 +287,9 @@ private:
u32 m_last_xfb_width = MAX_XFB_WIDTH; u32 m_last_xfb_width = MAX_XFB_WIDTH;
u32 m_last_xfb_height = MAX_XFB_HEIGHT; u32 m_last_xfb_height = MAX_XFB_HEIGHT;
s32 m_osd_message = 0;
s32 m_osd_time = 0;
// NOTE: The methods below are called on the framedumping thread. // NOTE: The methods below are called on the framedumping thread.
bool StartFrameDumpToAVI(const FrameDumpConfig& config); bool StartFrameDumpToAVI(const FrameDumpConfig& config);
void DumpFrameToAVI(const FrameDumpConfig& config); void DumpFrameToAVI(const FrameDumpConfig& config);