From 504bd9300791303f3af88d1ec26e0c67130a26e0 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Thu, 2 Feb 2023 21:35:48 +0300 Subject: [PATCH] rsx: Implement overlay message queue stacking --- rpcs3/Emu/RSX/Overlays/overlay_message.cpp | 39 +++++++++++++++++++++- rpcs3/Emu/RSX/Overlays/overlay_message.h | 14 ++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_message.cpp b/rpcs3/Emu/RSX/Overlays/overlay_message.cpp index f17f9030cc..504f3d2d8f 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_message.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_message.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "overlay_message.h" #include "Emu/RSX/RSXThread.h" +#pragma optimize("", off) namespace rsx { @@ -38,7 +39,7 @@ namespace rsx m_fade_out_animation.duration = 2.f; m_fade_out_animation.active = true; - back_color.a = 0.15; + back_color = 0.25; if (icon) { @@ -61,6 +62,11 @@ namespace rsx return m_refs && *m_refs == 0 ? 0 : m_expiration_time; } + bool message_item::text_matches(const std::u32string& text) const + { + return m_text.text == text; + } + void message_item::set_pos(u16 _x, u16 _y) { rounded_rect::set_pos(_x, _y); @@ -199,5 +205,36 @@ namespace rsx return cr; } + bool message::message_exists(message_pin_location location, localized_string_id id) + { + return message_exists(location, get_localized_u32string(id)); + } + + bool message::message_exists(message_pin_location location, const std::string& msg) + { + return message_exists(location, utf8_to_u32string(msg)); + } + + bool message::message_exists(message_pin_location location, const std::u32string& msg) + { + auto check_list = [&](const std::deque& list) + { + return std::any_of(list.cbegin(), list.cend(), [&](const message_item& item) + { + return item.text_matches(msg); + }); + }; + + switch (location) + { + case message_pin_location::top: + return check_list(m_ready_queue_top) || check_list(m_vis_items_top); + case message_pin_location::bottom: + return check_list(m_ready_queue_bottom) || check_list(m_vis_items_bottom); + default: + fmt::throw_exception("Unreachable"); + } + } + } // namespace overlays } // namespace rsx diff --git a/rpcs3/Emu/RSX/Overlays/overlay_message.h b/rpcs3/Emu/RSX/Overlays/overlay_message.h index 3e0638fb94..b22e1b3c41 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_message.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_message.h @@ -24,6 +24,8 @@ namespace rsx u64 get_expiration() const; compiled_resource& get_compiled() override; + bool text_matches(const std::u32string& text) const; + private: label m_text{}; std::unique_ptr m_icon{}; @@ -62,10 +64,13 @@ namespace rsx { for (auto id : msg_id) { - queue.emplace_back(id, expiration, refs, icon); + if (!message_exists(location, id)) + { + queue.emplace_back(id, expiration, refs, icon); + } } } - else + else if (!message_exists(location, msg_id)) { queue.emplace_back(msg_id, expiration, std::move(refs), std::move(icon)); } @@ -86,6 +91,11 @@ namespace rsx std::deque m_vis_items_bottom; void update_queue(std::deque& vis_set, std::deque& ready_set, message_pin_location origin); + + // Stacking. Extends the lifetime of a message instead of inserting a duplicate + bool message_exists(message_pin_location location, localized_string_id id); + bool message_exists(message_pin_location location, const std::string& msg); + bool message_exists(message_pin_location location, const std::u32string& msg); }; template