Merge pull request #8269 from lioncash/osd-move

VideoCommon/OnScreenDisplay: Minor cleanup
This commit is contained in:
Connor McLaughlin 2019-08-08 12:38:44 +10:00 committed by GitHub
commit 22ed2c0e0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 27 deletions

View File

@ -150,7 +150,7 @@ std::string StopMessage(bool main_thread, const std::string& message)
Common::CurrentThreadId(), message.c_str()); Common::CurrentThreadId(), message.c_str());
} }
void DisplayMessage(const std::string& message, int time_in_ms) void DisplayMessage(std::string message, int time_in_ms)
{ {
if (!IsRunning()) if (!IsRunning())
return; return;
@ -162,8 +162,8 @@ void DisplayMessage(const std::string& message, int time_in_ms)
return; return;
} }
OSD::AddMessage(message, time_in_ms);
Host_UpdateTitle(message); Host_UpdateTitle(message);
OSD::AddMessage(std::move(message), time_in_ms);
} }
bool IsRunning() bool IsRunning()

View File

@ -63,7 +63,7 @@ void SaveScreenShot(const std::string& name, bool wait_for_completion = false);
void Callback_WiimoteInterruptChannel(int number, u16 channel_id, const u8* data, u32 size); void Callback_WiimoteInterruptChannel(int number, u16 channel_id, const u8* data, u32 size);
// This displays messages in a user-visible way. // This displays messages in a user-visible way.
void DisplayMessage(const std::string& message, int time_in_ms); void DisplayMessage(std::string message, int time_in_ms);
void FrameUpdateOnCPUThread(); void FrameUpdateOnCPUThread();
void OnFrameEnd(); void OnFrameEnd();

View File

@ -17,7 +17,7 @@ namespace DSP::Host
{ {
u8 ReadHostMemory(u32 addr); u8 ReadHostMemory(u32 addr);
void WriteHostMemory(u8 value, u32 addr); void WriteHostMemory(u8 value, u32 addr);
void OSD_AddMessage(const std::string& str, u32 ms); void OSD_AddMessage(std::string str, u32 ms);
bool OnThread(); bool OnThread();
bool IsWiiHost(); bool IsWiiHost();
void InterruptRequest(); void InterruptRequest();

View File

@ -36,9 +36,9 @@ void WriteHostMemory(u8 value, u32 addr)
DSP::WriteARAM(value, addr); DSP::WriteARAM(value, addr);
} }
void OSD_AddMessage(const std::string& str, u32 ms) void OSD_AddMessage(std::string str, u32 ms)
{ {
OSD::AddMessage(str, ms); OSD::AddMessage(std::move(str), ms);
} }
bool OnThread() bool OnThread()

View File

@ -337,7 +337,7 @@ void HotkeyScheduler::Run()
OSD::AddMessage("Internal Resolution: Native"); OSD::AddMessage("Internal Resolution: Native");
break; break;
default: default:
OSD::AddMessage("Internal Resolution: %dx", g_Config.iEFBScale); OSD::AddMessage(StringFromFormat("Internal Resolution: %dx", g_Config.iEFBScale));
break; break;
} }
}; };

View File

@ -3,12 +3,11 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm> #include <algorithm>
#include <list>
#include <map> #include <map>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include "imgui.h" #include <imgui.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -26,14 +25,14 @@ constexpr float WINDOW_PADDING = 4.0f; // Pixels between subsequent OSD message
struct Message struct Message
{ {
Message() {} Message() = default;
Message(const std::string& text_, u32 timestamp_, u32 color_) Message(std::string text_, u32 timestamp_, u32 color_)
: text(text_), timestamp(timestamp_), color(color_) : text(std::move(text_)), timestamp(timestamp_), color(color_)
{ {
} }
std::string text; std::string text;
u32 timestamp; u32 timestamp = 0;
u32 color; u32 color = 0;
}; };
static std::multimap<MessageType, Message> s_messages; static std::multimap<MessageType, Message> s_messages;
static std::mutex s_messages_mutex; static std::mutex s_messages_mutex;
@ -79,18 +78,18 @@ static float DrawMessage(int index, const Message& msg, const ImVec2& position,
return window_height; return window_height;
} }
void AddTypedMessage(MessageType type, const std::string& message, u32 ms, u32 rgba) void AddTypedMessage(MessageType type, std::string message, u32 ms, u32 rgba)
{ {
std::lock_guard<std::mutex> lock(s_messages_mutex); std::lock_guard lock{s_messages_mutex};
s_messages.erase(type); s_messages.erase(type);
s_messages.emplace(type, Message(message, Common::Timer::GetTimeMs() + ms, rgba)); s_messages.emplace(type, Message(std::move(message), Common::Timer::GetTimeMs() + ms, rgba));
} }
void AddMessage(const std::string& message, u32 ms, u32 rgba) void AddMessage(std::string message, u32 ms, u32 rgba)
{ {
std::lock_guard<std::mutex> lock(s_messages_mutex); std::lock_guard lock{s_messages_mutex};
s_messages.emplace(MessageType::Typeless, s_messages.emplace(MessageType::Typeless,
Message(message, Common::Timer::GetTimeMs() + ms, rgba)); Message(std::move(message), Common::Timer::GetTimeMs() + ms, rgba));
} }
void DrawMessages() void DrawMessages()
@ -99,7 +98,7 @@ void DrawMessages()
return; return;
{ {
std::lock_guard<std::mutex> lock(s_messages_mutex); std::lock_guard lock{s_messages_mutex};
const u32 now = Common::Timer::GetTimeMs(); const u32 now = Common::Timer::GetTimeMs();
float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x; float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x;
@ -123,7 +122,7 @@ void DrawMessages()
void ClearMessages() void ClearMessages()
{ {
std::lock_guard<std::mutex> lock(s_messages_mutex); std::lock_guard lock{s_messages_mutex};
s_messages.clear(); s_messages.clear();
} }
} // namespace OSD } // namespace OSD

View File

@ -37,10 +37,11 @@ constexpr u32 VERY_LONG = 10000;
}; // namespace Duration }; // namespace Duration
// On-screen message display (colored yellow by default) // On-screen message display (colored yellow by default)
void AddMessage(const std::string& message, u32 ms = Duration::SHORT, u32 rgba = Color::YELLOW); void AddMessage(std::string message, u32 ms = Duration::SHORT, u32 rgba = Color::YELLOW);
void AddTypedMessage(MessageType type, const std::string& message, u32 ms = Duration::SHORT, void AddTypedMessage(MessageType type, std::string message, u32 ms = Duration::SHORT,
u32 rgba = Color::YELLOW); u32 rgba = Color::YELLOW);
void DrawMessages(); // draw the current messages on the screen. Only call once
// per frame. // Draw the current messages on the screen. Only call once per frame.
void DrawMessages();
void ClearMessages(); void ClearMessages();
} // namespace OSD } // namespace OSD

View File

@ -22,7 +22,7 @@ u8 DSP::Host::ReadHostMemory(u32 addr)
void DSP::Host::WriteHostMemory(u8 value, u32 addr) void DSP::Host::WriteHostMemory(u8 value, u32 addr)
{ {
} }
void DSP::Host::OSD_AddMessage(const std::string& str, u32 ms) void DSP::Host::OSD_AddMessage(std::string str, u32 ms)
{ {
} }
bool DSP::Host::OnThread() bool DSP::Host::OnThread()