VideoCommon/OnScreenDisplay: Take Message's std::string parameter by value

Allows callers to std::move strings into the functions (or automatically
assume the move constructor/move assignment operator for rvalue
references, potentially avoiding copies altogether.
This commit is contained in:
Lioncash 2019-07-28 22:46:08 -04:00
parent 50b240fcbd
commit c212310fbe
7 changed files with 18 additions and 17 deletions

View File

@ -150,7 +150,7 @@ std::string StopMessage(bool main_thread, const std::string& message)
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())
return;
@ -162,8 +162,8 @@ void DisplayMessage(const std::string& message, int time_in_ms)
return;
}
OSD::AddMessage(message, time_in_ms);
Host_UpdateTitle(message);
OSD::AddMessage(std::move(message), time_in_ms);
}
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);
// 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 OnFrameEnd();

View File

@ -17,7 +17,7 @@ namespace DSP::Host
{
u8 ReadHostMemory(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 IsWiiHost();
void InterruptRequest();

View File

@ -36,9 +36,9 @@ void WriteHostMemory(u8 value, u32 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()

View File

@ -27,8 +27,8 @@ constexpr float WINDOW_PADDING = 4.0f; // Pixels between subsequent OSD message
struct Message
{
Message() = default;
Message(const std::string& text_, u32 timestamp_, u32 color_)
: text(text_), timestamp(timestamp_), color(color_)
Message(std::string text_, u32 timestamp_, u32 color_)
: text(std::move(text_)), timestamp(timestamp_), color(color_)
{
}
std::string text;
@ -79,18 +79,18 @@ static float DrawMessage(int index, const Message& msg, const ImVec2& position,
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);
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);
s_messages.emplace(MessageType::Typeless,
Message(message, Common::Timer::GetTimeMs() + ms, rgba));
Message(std::move(message), Common::Timer::GetTimeMs() + ms, rgba));
}
void DrawMessages()

View File

@ -37,10 +37,11 @@ constexpr u32 VERY_LONG = 10000;
}; // namespace Duration
// On-screen message display (colored yellow by default)
void AddMessage(const std::string& message, u32 ms = Duration::SHORT, u32 rgba = Color::YELLOW);
void AddTypedMessage(MessageType type, const std::string& message, u32 ms = Duration::SHORT,
void AddMessage(std::string message, u32 ms = Duration::SHORT, u32 rgba = Color::YELLOW);
void AddTypedMessage(MessageType type, std::string message, u32 ms = Duration::SHORT,
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();
} // 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::OSD_AddMessage(const std::string& str, u32 ms)
void DSP::Host::OSD_AddMessage(std::string str, u32 ms)
{
}
bool DSP::Host::OnThread()