Add a notifications mutex to the overlay.

merge-requests/30/head
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);
} }
} }
@ -582,6 +585,15 @@ void Steam_Overlay::BuildNotifications(int width, int height)
}), 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()
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();

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;