overlays: add internal lock for progress bar texts

This commit is contained in:
Megamouse 2023-02-18 10:05:56 +01:00
parent be49a80bc7
commit ebf72eb126
2 changed files with 48 additions and 6 deletions

View File

@ -71,6 +71,23 @@ namespace rsx
return {};
}
if (const auto [dirty, text] = text_guard.get_text(); dirty)
{
u16 text_w, text_h;
text_display.set_pos(90, 364);
text_display.set_text(text);
text_display.measure_text(text_w, text_h);
text_display.translate(0, -(text_h - 16));
}
for (u32 i = 0; i < progress_bars.size(); i++)
{
if (const auto [dirty, text] = ::at32(bar_text_guard, i).get_text(); dirty)
{
::at32(progress_bars, i).set_text(text);
}
}
compiled_resource result;
update_custom_background();
@ -339,11 +356,7 @@ namespace rsx
void message_dialog::set_text(const std::string& text)
{
u16 text_w, text_h;
text_display.set_pos(90, 364);
text_display.set_text(text);
text_display.measure_text(text_w, text_h);
text_display.translate(0, -(text_h - 16));
text_guard.set_text(text);
}
void message_dialog::update_custom_background()
@ -415,7 +428,7 @@ namespace rsx
if (index >= num_progress_bars)
return CELL_MSGDIALOG_ERROR_PARAM;
::at32(progress_bars, index).set_text(msg);
::at32(bar_text_guard, index).set_text(msg);
return CELL_OK;
}

View File

@ -32,6 +32,35 @@ namespace rsx
animation_color_interpolate fade_animation;
struct text_guard_t
{
std::mutex mutex;
std::string text;
bool dirty{false};
void set_text(std::string t)
{
std::lock_guard lock(mutex);
text = std::move(t);
dirty = true;
}
std::pair<bool, std::string> get_text()
{
if (dirty)
{
std::lock_guard lock(mutex);
dirty = false;
return { true, std::move(text) };
}
return { false, {} };
}
};
text_guard_t text_guard{};
std::array<text_guard_t, 2> bar_text_guard{};
public:
message_dialog(bool allow_custom_background = false);