From d0f3b9133f0f2b007ca5c46f9ae50e70a080d353 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 30 Mar 2024 23:17:28 +0100 Subject: [PATCH] Optimize WinningConditionHelper: avoid calling strcpy if strings are the same, reduce number of strcat calls. Also remove redundant ^7 in 3 messages of GameCommand_moveplayer --- qcsrc/server/command/sv_cmd.qc | 9 ++++++--- qcsrc/server/scores.qc | 30 ++++++++++++++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 3fdb1f968..ab360bc35 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1089,7 +1089,8 @@ void GameCommand_moveplayer(int request, int argc) if (team_num == client.team) // already on the destination team { // keep the forcing undone - LOG_INFO("Player #", client_num_str, " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), "^7."); + LOG_INFO("Player #", client_num_str, " (", pl_name, ") is already on the ", + Team_ColoredFullName(team_num), "."); continue; } else if (team_num == 0) // auto team @@ -1119,7 +1120,8 @@ void GameCommand_moveplayer(int request, int argc) } if (!TeamBalance_IsTeamAllowed(balance, team_id)) { - LOG_INFO("Player #", client_num_str, " (", pl_name, ") is not allowed to join the ", Team_ColoredFullName(team_num), "^7."); + LOG_INFO("Player #", client_num_str, " (", pl_name, ") is not allowed to join the ", + Team_ColoredFullName(team_num), "."); TeamBalance_Destroy(balance); continue; } @@ -1130,7 +1132,8 @@ void GameCommand_moveplayer(int request, int argc) if (MoveToTeam(client, team_id, 6)) { successful = strcat(successful, (successful ? ", " : ""), pl_name); - LOG_INFO("Player #", client_num_str, " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7."); + LOG_INFO("Player #", client_num_str, " (", pl_name, ") has been moved to the ", + Team_ColoredFullName(team_num), "."); } else { diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 5e1c8d9db..c067fac8a 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -445,7 +445,6 @@ void WinningConditionHelper(entity this) { float c; string s; - float fullstatus; entity winnerscorekeeper; entity secondscorekeeper; entity sk; @@ -456,16 +455,17 @@ void WinningConditionHelper(entity this) // so to match pure, match for :P0: // to match full, match for :S0: - fullstatus = autocvar_g_full_getstatus_responses; - - s = GetGametype(); - s = strcat(s, ":", autocvar_g_xonoticversion); - s = strcat(s, ":P", ftos(cvar_purechanges_count)); - s = strcat(s, ":S", ftos(nJoinAllowed(this, NULL))); - s = strcat(s, ":F", ftos(serverflags)); - s = strcat(s, ":T", sv_termsofservice_url_escaped); - s = strcat(s, ":M", modname); - s = strcat(s, "::", GetPlayerScoreString(NULL, (fullstatus ? 1 : 2))); + // NOTE can't use a single strcat because strcat concatenates max 8 strings + s = strcat(GetGametype(), + ":", autocvar_g_xonoticversion, + ":P", ftos(cvar_purechanges_count), + ":S", ftos(nJoinAllowed(this, NULL))); + s = strcat(s, + ":F", ftos(serverflags), + ":T", sv_termsofservice_url_escaped, + ":M", modname); + s = strcat(s, + "::", GetPlayerScoreString(NULL, (autocvar_g_full_getstatus_responses ? 1 : 2))); if(teamscores_entities_count) { @@ -578,11 +578,12 @@ void WinningConditionHelper(entity this) } } - strcpy(worldstatus, s); + if (s != worldstatus) + strcpy(worldstatus, s); FOREACH_CLIENT(true, { string s = ""; - if(fullstatus) + if(autocvar_g_full_getstatus_responses) { s = GetPlayerScoreString(it, 1); s = strcat(s, IS_REAL_CLIENT(it) ? ":human" : ":bot"); @@ -597,7 +598,8 @@ void WinningConditionHelper(entity this) s = "-666"; } - strcpy(it.clientstatus, s); + if (s != it.clientstatus) + strcpy(it.clientstatus, s); }); } -- 2.39.2