Skip to content

Commit

Permalink
Merge pull request #8269 from lioncash/osd-move
Browse files Browse the repository at this point in the history
VideoCommon/OnScreenDisplay: Minor cleanup
  • Loading branch information
stenzek committed Aug 8, 2019
2 parents e5a4a86 + c93fffa commit 22ed2c0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/DSPLLE/DSPHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/HotkeyScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void HotkeyScheduler::Run()
OSD::AddMessage("Internal Resolution: Native");
break;
default:
OSD::AddMessage("Internal Resolution: %dx", g_Config.iEFBScale);
OSD::AddMessage(StringFromFormat("Internal Resolution: %dx", g_Config.iEFBScale));
break;
}
};
Expand Down
29 changes: 14 additions & 15 deletions Source/Core/VideoCommon/OnScreenDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// Refer to the license.txt file included.

#include <algorithm>
#include <list>
#include <map>
#include <mutex>
#include <string>

#include "imgui.h"
#include <imgui.h>

#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
Expand All @@ -26,14 +25,14 @@ constexpr float WINDOW_PADDING = 4.0f; // Pixels between subsequent OSD message

struct Message
{
Message() {}
Message(const std::string& text_, u32 timestamp_, u32 color_)
: text(text_), timestamp(timestamp_), color(color_)
Message() = default;
Message(std::string text_, u32 timestamp_, u32 color_)
: text(std::move(text_)), timestamp(timestamp_), color(color_)
{
}
std::string text;
u32 timestamp;
u32 color;
u32 timestamp = 0;
u32 color = 0;
};
static std::multimap<MessageType, Message> s_messages;
static std::mutex s_messages_mutex;
Expand Down Expand Up @@ -79,18 +78,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);
std::lock_guard 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);
std::lock_guard 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()
Expand All @@ -99,7 +98,7 @@ void DrawMessages()
return;

{
std::lock_guard<std::mutex> lock(s_messages_mutex);
std::lock_guard lock{s_messages_mutex};

const u32 now = Common::Timer::GetTimeMs();
float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x;
Expand All @@ -123,7 +122,7 @@ void DrawMessages()

void ClearMessages()
{
std::lock_guard<std::mutex> lock(s_messages_mutex);
std::lock_guard lock{s_messages_mutex};
s_messages.clear();
}
} // namespace OSD
9 changes: 5 additions & 4 deletions Source/Core/VideoCommon/OnScreenDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Source/DSPTool/DSPTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 22ed2c0

Please sign in to comment.