From 119bc8cf0d13fabc29aeeb8001ae796057a18715 Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 14 Apr 2021 00:24:32 +0200 Subject: [PATCH] Scoreboard: fix broken player sorting by fields after the primary and secondary ones; also optimize code by avoid repeating the same score comparisons multiple times --- qcsrc/client/hud/panel/scoreboard.qc | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index fd765ed112..0ac5b8d2c0 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -163,6 +163,8 @@ string Label_getInfo(string label, int mode) void PrintScoresLabels() { Label_getInfo(string_null, 1); } string TranslateScoresLabel(string label) { return Label_getInfo(label, 0); } +#define SB_EXTRA_SORTING_FIELDS 5 +PlayerScoreField sb_extra_sorting_field[SB_EXTRA_SORTING_FIELDS]; void Scoreboard_InitScores() { int i, f; @@ -175,6 +177,13 @@ void Scoreboard_InitScores() ps_primary = it; if(f == SFL_SORT_PRIO_SECONDARY) ps_secondary = it; + if(ps_primary == it || ps_secondary == it) + continue; + if (scores_label(it) == "kills") sb_extra_sorting_field[0] = it; + if (scores_label(it) == "deaths") sb_extra_sorting_field[1] = it; + if (scores_label(it) == "suicides") sb_extra_sorting_field[2] = it; + if (scores_label(it) == "dmg") sb_extra_sorting_field[3] = it; + if (scores_label(it) == "dmgtaken") sb_extra_sorting_field[4] = it; }); if(ps_secondary == NULL) ps_secondary = ps_primary; @@ -261,18 +270,25 @@ float Scoreboard_ComparePlayerScores(entity left, entity right) return false; } - r = Scoreboard_CompareScore(left.scores(ps_primary), right.scores(ps_primary), scores_flags(ps_primary)); - if (r >= 0) - return r; - - r = Scoreboard_CompareScore(left.scores(ps_secondary), right.scores(ps_secondary), scores_flags(ps_secondary)); - if (r >= 0) - return r; + entity fld = NULL; + for (int i = -2; i < SB_EXTRA_SORTING_FIELDS; ++i) + { + if (i < 0) + { + if (!fld) fld = ps_primary; + else if (ps_secondary == ps_primary) continue; + else fld = ps_secondary; + } + else + { + fld = sb_extra_sorting_field[i]; + if (fld == ps_primary || fld == ps_secondary) continue; + } + if (!fld) continue; - FOREACH(Scores, true, { - r = Scoreboard_CompareScore(left.scores(it), right.scores(it), scores_flags(it)); + r = Scoreboard_CompareScore(left.scores(fld), right.scores(fld), scores_flags(fld)); if (r >= 0) return r; - }); + } if (left.sv_entnum < right.sv_entnum) return true; -- 2.39.2