]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/scores.qc
Optimize WinningConditionHelper: avoid calling strcpy if strings are the same, reduce...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / scores.qc
index 2cedc4aded31c9abce24c8fa5bafdcbe92987bac..c067fac8a1287704818121767438d4072e30b776 100644 (file)
@@ -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);
        });
 }
 
@@ -864,7 +866,7 @@ void Score_NicePrint_Team(entity to, float t, float w)
                        {
                                fl = teamscores_flags(i);
                                sc = sk.(teamscores(i));
-                               s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
+                               s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc, 0));
                        }
        }
        else
@@ -912,7 +914,7 @@ void Score_NicePrint_Player(entity to, entity p, float w)
                {
                        fl = scores_flags(it);
                        sc = sk.(scores(it));
-                       s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
+                       s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc, 0)));
                }
     });