summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorAestek <thib.gilles@gmail.com>2016-02-02 16:35:27 +0100
committerAestek <thib.gilles@gmail.com>2016-07-23 20:58:51 +0200
commit6a0fc4c438dcc827b6ed4e0a22a2e54676682ea0 (patch)
treeb44ade2f80ade233a2e82965af0717b18257e4f6 /Source/Core/VideoCommon
parentaa34e5e20e5f66cfdbace167b98c30c1fedcf522 (diff)
Improve netplay setup dialog UX
* Focus "Hash Code" / "IP address" text box by default in "Connect" * Focus game list in "Host" tab * RETURN keypress now host/join depending on selected tab * Remember last hosted game * Remove PanicAlertT: * Simply log message to netplay window * Remove them when they are useless * Show some netplay message in OSD * Chat messages * Pad buffer changes * Desync alerts * Stop the game consistently when another player disconnects / crashes * Prettify chat textbox * Log netplay ping to OSD Join scenario: * Copy netplay code * Open netplay * Paste code * Press enter Host scenario: * Open netplay * Go to host tab * Press enter
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/OnScreenDisplay.cpp67
-rw-r--r--Source/Core/VideoCommon/OnScreenDisplay.h42
-rw-r--r--Source/Core/VideoCommon/VideoConfig.cpp4
-rw-r--r--Source/Core/VideoCommon/VideoConfig.h2
4 files changed, 86 insertions, 29 deletions
diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp
index 3cc2e823d8..62997cd150 100644
--- a/Source/Core/VideoCommon/OnScreenDisplay.cpp
+++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp
@@ -17,21 +17,30 @@
namespace OSD
{
-struct Message
+static std::multimap<CallbackType, Callback> s_callbacks;
+static std::multimap<MessageType, Message> s_messages;
+static std::mutex s_messages_mutex;
+
+void AddTypedMessage(MessageType type, const std::string& message, u32 ms, u32 rgba)
{
- Message() {}
- Message(const std::string& s, u32 ts, u32 rgba) : m_str(s), m_timestamp(ts), m_rgba(rgba) {}
- std::string m_str;
- u32 m_timestamp;
- u32 m_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));
+}
-static std::multimap<CallbackType, Callback> s_callbacks;
-static std::list<Message> s_msgList;
+void AddMessage(const 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));
+}
-void AddMessage(const std::string& str, u32 ms, u32 rgba)
+void DrawMessage(const Message& msg, int top, int left, int time_left)
{
- s_msgList.emplace_back(str, Common::Timer::GetTimeMs() + ms, rgba);
+ float alpha = std::min(1.0f, std::max(0.0f, time_left / 1024.0f));
+ u32 color = (msg.m_rgba & 0xFFFFFF) | ((u32)((msg.m_rgba >> 24) * alpha) << 24);
+
+ g_renderer->RenderText(msg.m_str, left, top, color);
}
void DrawMessages()
@@ -39,28 +48,32 @@ void DrawMessages()
if (!SConfig::GetInstance().bOnScreenDisplayMessages)
return;
- int left = 25, top = 15;
- auto it = s_msgList.begin();
- while (it != s_msgList.end())
{
- int time_left = (int)(it->m_timestamp - Common::Timer::GetTimeMs());
- float alpha = std::max(1.0f, std::min(0.0f, time_left / 1024.0f));
- u32 color = (it->m_rgba & 0xFFFFFF) | ((u32)((it->m_rgba >> 24) * alpha) << 24);
-
- g_renderer->RenderText(it->m_str, left, top, color);
-
- top += 15;
-
- if (time_left <= 0)
- it = s_msgList.erase(it);
- else
- ++it;
+ std::lock_guard<std::mutex> lock(s_messages_mutex);
+
+ u32 now = Common::Timer::GetTimeMs();
+ int left = 20, top = 35;
+
+ auto it = s_messages.begin();
+ while (it != s_messages.end())
+ {
+ const Message& msg = it->second;
+ int time_left = (int)(msg.m_timestamp - now);
+ DrawMessage(msg, top, left, time_left);
+
+ if (time_left <= 0)
+ it = s_messages.erase(it);
+ else
+ ++it;
+ top += 15;
+ }
}
}
void ClearMessages()
{
- s_msgList.clear();
+ std::lock_guard<std::mutex> lock(s_messages_mutex);
+ s_messages.clear();
}
// On-Screen Display Callbacks
diff --git a/Source/Core/VideoCommon/OnScreenDisplay.h b/Source/Core/VideoCommon/OnScreenDisplay.h
index ab74201bca..a05f4058ef 100644
--- a/Source/Core/VideoCommon/OnScreenDisplay.h
+++ b/Source/Core/VideoCommon/OnScreenDisplay.h
@@ -11,9 +11,47 @@
namespace OSD
{
+struct Message
+{
+ Message() {}
+ Message(const std::string& s, u32 ts, u32 rgba) : m_str(s), m_timestamp(ts), m_rgba(rgba) {}
+ std::string m_str;
+ u32 m_timestamp;
+ u32 m_rgba;
+};
+
+enum class MessageType
+{
+ NetPlayPing,
+ NetPlayBuffer,
+
+ // This entry must be kept last so that persistent typed messages are
+ // displayed before other messages
+ Typeless,
+};
+
+namespace Color
+{
+constexpr u32 CYAN = 0xFF00FFFF;
+constexpr u32 GREEN = 0xFF00FF00;
+constexpr u32 RED = 0xFFFF0000;
+constexpr u32 YELLOW = 0xFFFFFF30;
+};
+
+namespace Duration
+{
+constexpr u32 SHORT = 2000;
+constexpr u32 NORMAL = 5000;
+constexpr u32 VERY_LONG = 10000;
+};
+
// On-screen message display (colored yellow by default)
-void AddMessage(const std::string& str, u32 ms = 2000, u32 rgba = 0xFFFFFF30);
-void DrawMessages(); // draw the current messages on the screen. Only call once per frame.
+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,
+ u32 rgba = Color::YELLOW);
+void DrawMessage(const Message& msg, int top, int left, int time_left); // draw one message
+void DrawMessages(); // draw the current messages on the screen. Only call once
+ // per frame.
void ClearMessages();
// On-screen callbacks
diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp
index c19528d7d9..7f8def5450 100644
--- a/Source/Core/VideoCommon/VideoConfig.cpp
+++ b/Source/Core/VideoCommon/VideoConfig.cpp
@@ -60,6 +60,8 @@ void VideoConfig::Load(const std::string& ini_file)
settings->Get("UseRealXFB", &bUseRealXFB, 0);
settings->Get("SafeTextureCacheColorSamples", &iSafeTextureCache_ColorSamples, 128);
settings->Get("ShowFPS", &bShowFPS, false);
+ settings->Get("ShowNetPlayPing", &bShowNetPlayPing, false);
+ settings->Get("ShowNetPlayMessages", &bShowNetPlayMessages, false);
settings->Get("LogRenderTimeToFile", &bLogRenderTimeToFile, false);
settings->Get("OverlayStats", &bOverlayStats, false);
settings->Get("OverlayProjStats", &bOverlayProjStats, false);
@@ -267,6 +269,8 @@ void VideoConfig::Save(const std::string& ini_file)
settings->Set("UseRealXFB", bUseRealXFB);
settings->Set("SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples);
settings->Set("ShowFPS", bShowFPS);
+ settings->Set("ShowNetPlayPing", bShowNetPlayPing);
+ settings->Set("ShowNetPlayMessages", bShowNetPlayMessages);
settings->Set("LogRenderTimeToFile", bLogRenderTimeToFile);
settings->Set("OverlayStats", bOverlayStats);
settings->Set("OverlayProjStats", bOverlayProjStats);
diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h
index d78c63ba90..9df952a18d 100644
--- a/Source/Core/VideoCommon/VideoConfig.h
+++ b/Source/Core/VideoCommon/VideoConfig.h
@@ -82,6 +82,8 @@ struct VideoConfig final
// Information
bool bShowFPS;
+ bool bShowNetPlayPing;
+ bool bShowNetPlayMessages;
bool bOverlayStats;
bool bOverlayProjStats;
bool bTexFmtOverlayEnable;