1
0
forked from 0ad/0ad

Remove unneeded GetMucMessageCount from the XmppClient.

The affected function was imprecise, because it called a playerlist
update whenever a "chat" level message was received instead
of only updating the playerlist if it's actually influencing the
displayed playerlist.
When there is a chat message, lobby subject change or user-role change,
there is no need to update the list.

Differential Revision: https://code.wildfiregames.com/D671
Refs #3386, 8b437a0b1c
Reviewed By: fpre / ffffffff
This was SVN commit r20040.
This commit is contained in:
elexis 2017-08-25 18:51:26 +00:00
parent ce7e727ff0
commit 16b976fc35
6 changed files with 43 additions and 38 deletions

View File

@ -111,20 +111,19 @@ var g_SelectedGamePort = "";
var g_Kicked = false;
/**
* Notifications sent by XmppClient.cpp
* Processing of notifications sent by XmppClient.cpp.
*
* @returns true if the playerlist GUI must be updated.
*/
var g_NetMessageTypes = {
"system": {
// Three cases are handled in prelobby.js
"registered": msg => {
},
"connected": msg => {
},
"registered": msg => false,
"connected": msg => false,
"disconnected": msg => {
updateGameList();
updateLeaderboard();
updatePlayerList();
Engine.GetGUIObjectByName("chatInput").hidden = true;
@ -138,6 +137,7 @@ var g_NetMessageTypes = {
"time": msg.time,
"text": translate("Disconnected.") + " " + msg.text
});
return true;
},
"error": msg => {
addChatMessage({
@ -145,11 +145,13 @@ var g_NetMessageTypes = {
"time": msg.time,
"text": msg.text
});
return false;
}
},
"chat": {
"subject": msg => {
updateSubject(msg.text);
return false;
},
"join": msg => {
addChatMessage({
@ -159,6 +161,7 @@ var g_NetMessageTypes = {
"time": msg.time,
"isSpecial": true
});
return true;
},
"leave": msg => {
addChatMessage({
@ -171,9 +174,10 @@ var g_NetMessageTypes = {
if (msg.text == g_Username)
Engine.DisconnectXmppClient();
return true;
},
"presence": msg => {
},
"presence": msg => true,
"role": msg => {
Engine.GetGUIObjectByName("chatInput").hidden = Engine.LobbyGetPlayerRole(g_Username) == "visitor";
@ -204,6 +208,8 @@ var g_NetMessageTypes = {
if (g_SelectedPlayer == msg.text)
updateUserRoleText(g_SelectedPlayer);
return false;
},
"nick": msg => {
addChatMessage({
@ -214,12 +220,15 @@ var g_NetMessageTypes = {
"time": msg.time,
"isSpecial": true
});
return true;
},
"kicked": msg => {
handleKick(false, msg.text, msg.data || "", msg.time);
return true;
},
"banned": msg => {
handleKick(true, msg.text, msg.data || "", msg.time);
return true;
},
"room-message": msg => {
addChatMessage({
@ -227,6 +236,7 @@ var g_NetMessageTypes = {
"text": escapeText(msg.text),
"time": msg.time
});
return false;
},
"private-message": msg => {
// Announcements and the Message of the Day are sent by the server directly
@ -246,13 +256,25 @@ var g_NetMessageTypes = {
"time": msg.time,
"private" : true
});
return false;
}
},
"game": {
"gamelist": msg => updateGameList(),
"profile": msg => updateProfile(),
"leaderboard": msg => updateLeaderboard(),
"ratinglist": msg => updatePlayerList()
"gamelist": msg => {
updateGameList();
return false;
},
"profile": msg => {
updateProfile();
return false;
},
"leaderboard": msg => {
updateLeaderboard();
return false;
},
"ratinglist": msg => {
return true;
}
}
};
@ -1137,6 +1159,8 @@ function onTick()
{
updateTimers();
let updateList = false;
while (true)
{
let msg = Engine.LobbyGuiPollMessage();
@ -1153,13 +1177,15 @@ function onTick()
warn("Unrecognised message level: " + msg.level);
continue;
}
g_NetMessageTypes[msg.type][msg.level](msg);
// To improve performance, only update the playerlist GUI when
// the last update in the current stack is processed
if (msg.type == "chat" && Engine.LobbyGetMucMessageCount() == 0)
updatePlayerList();
if (g_NetMessageTypes[msg.type][msg.level](msg))
updateList = true;
}
// To improve performance, only update the playerlist GUI when
// the last update in the current stack is processed
if (updateList)
updatePlayerList();
}
/**

View File

@ -50,7 +50,6 @@ public:
virtual void GetSubject(std::string& subject) = 0;
virtual void GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void ClearPresenceUpdates() = 0;
virtual int GetMucMessageCount() = 0;
virtual void GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;

View File

@ -613,18 +613,6 @@ void XmppClient::ClearPresenceUpdates()
), m_GuiMessageQueue.end());
}
/**
* Used in order to update the GUI only once when multiple updates are queued.
*/
int XmppClient::GetMucMessageCount()
{
return std::count_if(m_GuiMessageQueue.begin(), m_GuiMessageQueue.end(),
[](XmppClient::GUIMessage& message)
{
return message.type == L"chat";
});
}
/**
* Handle a room message.
*/

View File

@ -146,7 +146,6 @@ public:
void GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void SendMUCMessage(const std::string& message);
void ClearPresenceUpdates();
int GetMucMessageCount();
protected:
void PushGuiMessage(XmppClient::GUIMessage message);
void CreateGUIMessage(const std::string& type, const std::string& level, const std::string& text = "", const std::string& data = "");

View File

@ -47,7 +47,6 @@ void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList");
scriptInterface.RegisterFunction<void, &JSI_Lobby::LobbyClearPresenceUpdates>("LobbyClearPresenceUpdates");
scriptInterface.RegisterFunction<int, &JSI_Lobby::LobbyGetMucMessageCount>("LobbyGetMucMessageCount");
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetGameList>("GetGameList");
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetBoardList>("GetBoardList");
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetProfile>("GetProfile");
@ -184,11 +183,6 @@ void JSI_Lobby::LobbyClearPresenceUpdates(ScriptInterface::CxPrivate* UNUSED(pCx
g_XmppClient->ClearPresenceUpdates();
}
int JSI_Lobby::LobbyGetMucMessageCount(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
{
return g_XmppClient ? g_XmppClient->GetMucMessageCount() : 0;
}
JS::Value JSI_Lobby::GetGameList(ScriptInterface::CxPrivate* pCxPrivate)
{
if (!g_XmppClient)

View File

@ -44,7 +44,6 @@ namespace JSI_Lobby
void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players);
JS::Value GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate);
void LobbyClearPresenceUpdates(ScriptInterface::CxPrivate* pCxPrivate);
int LobbyGetMucMessageCount(ScriptInterface::CxPrivate* pCxPrivate);
JS::Value GetGameList(ScriptInterface::CxPrivate* pCxPrivate);
JS::Value GetBoardList(ScriptInterface::CxPrivate* pCxPrivate);
JS::Value GetProfile(ScriptInterface::CxPrivate* pCxPrivate);