Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reduced FPS hit from multiplayer client list window. #2720

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum MsgType
MSG_GUI_CLOSE_MENU_REQUESTED,
MSG_GUI_OPEN_SELECTOR_REQUESTED, //!< Payload = LoaderType* (owner), Description = GUID | empty
MSG_GUI_CLOSE_SELECTOR_REQUESTED,
MSG_GUI_MP_CLIENTS_REFRESH,
// Editing
MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED, //!< Payload = ground_model_t* (weak)
MSG_EDI_ENTER_TERRN_EDITOR_REQUESTED,
Expand Down
1 change: 1 addition & 0 deletions source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ GUI::TopMenubar* GUIManager::GetTopMenubar() { return &m_impl-
GUI::SurveyMap* GUIManager::GetSurveyMap() { return &m_impl->panel_SurveyMap ; }
GUI::SimActorStats* GUIManager::GetSimActorStats() { return &m_impl->panel_SimActorStats ; }
GUI::DirectionArrow* GUIManager::GetDirectionArrow() { return &m_impl->panel_DirectionArrow ; }
GUI::MpClientList* GUIManager::GetMpClientList() { return &m_impl->panel_MpClientList ; }

GUIManager::GUIManager()
{
Expand Down
1 change: 1 addition & 0 deletions source/main/gui/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class GUIManager: public ZeroedMemoryAllocator
GUI::SurveyMap* GetSurveyMap();
GUI::SimActorStats* GetSimActorStats();
GUI::DirectionArrow* GetDirectionArrow();
GUI::MpClientList* GetMpClientList();

// GUI manipulation
void ShowMessageBox(const char* title, const char* text, bool allow_close = true, const char* btn1_text = "OK", const char* btn2_text = nullptr);
Expand Down
17 changes: 11 additions & 6 deletions source/main/gui/panels/GUI_MultiplayerClientList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ using namespace RoR;
using namespace GUI;
using namespace Ogre;

void MpClientList::UpdateClients()
{
m_users = App::GetNetwork()->GetUserInfos();
m_users.insert(m_users.begin(), App::GetNetwork()->GetLocalUserData());
}

void MpClientList::Draw()
{
GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme();
Expand All @@ -53,15 +59,14 @@ void MpClientList::Draw()
ImGui::GetIO().DisplaySize.x - (content_width + (2*ImGui::GetStyle().WindowPadding.x) + theme.screen_edge_padding.x),
theme.screen_edge_padding.y));

std::vector<RoRnet::UserInfo> users = App::GetNetwork()->GetUserInfos();
users.insert(users.begin(), App::GetNetwork()->GetLocalUserData());
int y = 20 + (ImGui::GetTextLineHeightWithSpacing() * users.size());
int y = 20 + (ImGui::GetTextLineHeightWithSpacing() * m_users.size());

ImGui::SetNextWindowSize(ImVec2((content_width + (2*ImGui::GetStyle().WindowPadding.x)), y));
ImGui::PushStyleColor(ImGuiCol_WindowBg, theme.semitransparent_window_bg);
ImGui::Begin("Peers", nullptr, flags);

for (RoRnet::UserInfo const& user: users)
const RoRnet::UserInfo& local_user = m_users[0]; // See `UpdateClients()`
for (RoRnet::UserInfo const& user: m_users)
{
// Icon sizes: flag(16x11), auth(16x16), up(16x16), down(16x16)
bool hovered = false;
Expand All @@ -71,7 +76,7 @@ void MpClientList::Draw()
Ogre::TexturePtr up_tex;

// Stream state indicators
if (user.uniqueid != App::GetNetwork()->GetLocalUserData().uniqueid &&
if (user.uniqueid != local_user.uniqueid &&
App::app_state->GetEnum<AppState>() != AppState::MAIN_MENU)
{
switch (App::GetGameContext()->GetActorManager()->CheckNetworkStreamsOk(user.uniqueid))
Expand Down Expand Up @@ -155,7 +160,7 @@ void MpClientList::Draw()
ImGui::Text("%s", App::GetNetwork()->UserAuthToStringLong(user).c_str());

// Stream state
if (user.uniqueid != App::GetNetwork()->GetLocalUserData().uniqueid &&
if (user.uniqueid != local_user.uniqueid &&
App::app_state->GetEnum<AppState>() != AppState::MAIN_MENU)
{
ImGui::Separator();
Expand Down
6 changes: 6 additions & 0 deletions source/main/gui/panels/GUI_MultiplayerClientList.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#pragma once

#include "RoRnet.h"

#include <Ogre.h>
#include <imgui.h>

Expand All @@ -37,9 +39,13 @@ class MpClientList
{
public:
void Draw();
void UpdateClients();

private:
Ogre::TexturePtr FetchIcon(const char* name);
bool DrawIcon(Ogre::TexturePtr tex, ImVec2 reference_box); // Returns true if hovered

std::vector<RoRnet::UserInfo> m_users; // only updated on demand to reduce mutex locking and vector allocating overhead.
};

} // namespace GUI
Expand Down
5 changes: 5 additions & 0 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "GUI_LoadingWindow.h"
#include "GUI_MainSelector.h"
#include "GUI_MultiplayerSelector.h"
#include "GUI_MultiplayerClientList.h"
#include "GUI_SimActorStats.h"
#include "InputEngine.h"
#include "Language.h"
Expand Down Expand Up @@ -646,6 +647,10 @@ int main(int argc, char *argv[])
App::GetGuiManager()->GetMainSelector()->Close();
break;

case MSG_GUI_MP_CLIENTS_REFRESH:
App::GetGuiManager()->GetMpClientList()->UpdateClients();
break;

// -- Editing events --

case MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED:
Expand Down
4 changes: 4 additions & 0 deletions source/main/network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ void Network::RecvThread()

bool was_kick = (std::strstr(buffer, "disconnected on request") == nullptr); // FIXME: Add a reason code to MSG2_USER_LEAVE, this is ugly!
PushNetMessage((was_kick) ? MSG_NET_SERVER_KICK : MSG_NET_USER_DISCONNECT, msg.str());
App::GetGameContext()->PushMessage(Message(MSG_GUI_MP_CLIENTS_REFRESH));

Message m((was_kick) ? MSG_NET_USER_DISCONNECT : MSG_NET_SERVER_KICK);
}
Expand All @@ -313,6 +314,7 @@ void Network::RecvThread()
Str<300> text;
text << _L("left the game");
App::GetConsole()->putNetMessage(user->uniqueid, Console::CONSOLE_SYSTEM_NOTICE, text.ToCStr());
App::GetGameContext()->PushMessage(Message(MSG_GUI_MP_CLIENTS_REFRESH));
LOG_THREAD(text);

m_disconnected_users.push_back(*user); // Copy
Expand All @@ -328,6 +330,7 @@ void Network::RecvThread()
memcpy(&m_userdata, buffer, sizeof(RoRnet::UserInfo));
m_authlevel = m_userdata.authstatus;
m_username = Ogre::UTFString(m_userdata.username);
App::GetGameContext()->PushMessage(Message(MSG_GUI_MP_CLIENTS_REFRESH));
// TODO: Update the global variable 'mp_player_name' in a threadsafe way.
}
else
Expand All @@ -346,6 +349,7 @@ void Network::RecvThread()
// NB: Console is threadsafe
App::GetConsole()->putNetMessage(
user_info.uniqueid, Console::CONSOLE_SYSTEM_NOTICE, text.ToCStr());
App::GetGameContext()->PushMessage(Message(MSG_GUI_MP_CLIENTS_REFRESH));
// Lock and update userlist
std::lock_guard<std::mutex> lock(m_users_mutex);
m_users.push_back(user_info);
Expand Down