Add a notifications mutex to the overlay.

This commit is contained in:
Mr_Goldberg 2020-01-26 17:24:16 -05:00
parent 92218b08c6
commit 39d1d8dcdf
No known key found for this signature in database
GPG key ID: 8597D87419DEF278
2 changed files with 65 additions and 51 deletions

View file

@ -300,7 +300,7 @@ void Steam_Overlay::FriendDisconnect(Friend _friend)
void Steam_Overlay::AddMessageNotification(std::string const& message) void Steam_Overlay::AddMessageNotification(std::string const& message)
{ {
std::lock_guard<std::recursive_mutex> lock(overlay_mutex); std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications); int id = find_free_notification_id(notifications);
if (id != 0) if (id != 0)
{ {
@ -317,7 +317,7 @@ void Steam_Overlay::AddMessageNotification(std::string const& message)
void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach) void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
{ {
std::lock_guard<std::recursive_mutex> lock(overlay_mutex); std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications); int id = find_free_notification_id(notifications);
if (id != 0) if (id != 0)
{ {
@ -335,7 +335,7 @@ void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
void Steam_Overlay::AddInviteNotification(std::pair<const Friend, friend_window_state>& wnd_state) void Steam_Overlay::AddInviteNotification(std::pair<const Friend, friend_window_state>& wnd_state)
{ {
std::lock_guard<std::recursive_mutex> lock(overlay_mutex); std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications); int id = find_free_notification_id(notifications);
if (id != 0) if (id != 0)
{ {
@ -522,7 +522,10 @@ void Steam_Overlay::BuildNotifications(int width, int height)
int font_size = ImGui::GetFontSize(); int font_size = ImGui::GetFontSize();
std::lock_guard<std::recursive_mutex> lock(overlay_mutex); std::queue<Friend> friend_actions_temp;
{
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
for (auto it = notifications.begin(); it != notifications.end(); ++it, ++i) for (auto it = notifications.begin(); it != notifications.end(); ++it, ++i)
{ {
@ -564,7 +567,7 @@ void Steam_Overlay::BuildNotifications(int width, int height)
ImGui::TextWrapped("%s", it->message.c_str()); ImGui::TextWrapped("%s", it->message.c_str());
if (ImGui::Button("Join")) if (ImGui::Button("Join"))
{ {
has_friend_action.push(it->frd->first); friend_actions_temp.push(it->frd->first);
it->start_time = std::chrono::seconds(0); it->start_time = std::chrono::seconds(0);
} }
} }
@ -580,6 +583,15 @@ void Steam_Overlay::BuildNotifications(int width, int height)
notifications.erase(std::remove_if(notifications.begin(), notifications.end(), [&now](Notification &item) { notifications.erase(std::remove_if(notifications.begin(), notifications.end(), [&now](Notification &item) {
return (now - item.start_time) > Notification::show_time; return (now - item.start_time) > Notification::show_time;
}), notifications.end()); }), notifications.end());
}
if (!friend_actions_temp.empty()) {
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
while (!friend_actions_temp.empty()) {
has_friend_action.push(friend_actions_temp.front());
friend_actions_temp.pop();
}
}
} }
void Steam_Overlay::CreateFonts() void Steam_Overlay::CreateFonts()

View file

@ -92,6 +92,8 @@ class Steam_Overlay
// Callback infos // Callback infos
std::queue<Friend> has_friend_action; std::queue<Friend> has_friend_action;
std::vector<Notification> notifications; std::vector<Notification> notifications;
std::recursive_mutex notifications_mutex;
bool overlay_state_changed; bool overlay_state_changed;
std::recursive_mutex overlay_mutex; std::recursive_mutex overlay_mutex;