]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Save team count instead of recounting teams every frame multiple times
authorterencehill <piuntn@gmail.com>
Thu, 16 May 2013 08:06:51 +0000 (10:06 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 16 May 2013 08:06:51 +0000 (10:06 +0200)
qcsrc/client/csqcmodel_hooks.qc
qcsrc/client/hud.qc
qcsrc/client/miscfunctions.qc

index 109b83d166f11a8efe597f1173c76c5cda1aef59..ae7b7bf87bb3c2dbee898800626370e033b5494e 100644 (file)
@@ -214,16 +214,11 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer)
                // own team's color is never forced
                float forcecolor_friend = 0;
                float forcecolor_enemy = 0;
-               float teams_count = 0;
                entity tm;
 
-               for(tm = teams.sort_next; tm; tm = tm.sort_next)
-                       if(tm.team != NUM_SPECTATOR)
-                               ++teams_count;
-
                if(autocvar_cl_forcemyplayercolors)
                        forcecolor_friend = 1024 + autocvar_cl_forcemyplayercolors;
-               if(autocvar_cl_forceplayercolors && teams_count == 2)
+               if(autocvar_cl_forceplayercolors && team_count == 2)
                        forcecolor_enemy = 1024 + autocvar__cl_color;
 
                if(forcecolor_enemy && !forcecolor_friend)
index 1ca42657a19809460b301c3d9a169cc24ac706e4..647fa729971d2a4fee78db675d2682077376e52b 100644 (file)
@@ -1997,7 +1997,7 @@ void HUD_Radar(void)
 // Score (#7)
 //
 void HUD_UpdatePlayerTeams();
-void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
+void HUD_Score_Rankings(vector pos, vector mySize, entity me)
 {
        float score;
        entity tm = world, pl;
@@ -2188,7 +2188,7 @@ void HUD_Score(void)
        } else if (!teamplay) { // non-teamgames
                if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
                {
-                       HUD_Score_Rankings(pos, mySize, me, 0);
+                       HUD_Score_Rankings(pos, mySize, me);
                        return;
                }
                // me vector := [team/connected frags id]
@@ -2229,23 +2229,21 @@ void HUD_Score(void)
                drawstring_aspect(pos + eX * 0.75 * mySize_x, distribution_str, eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
                draw_endBoldFont();
        } else { // teamgames
-               float scores_count = 0, row, column, rows = 0, columns = 0;
+               float row, column, rows = 0, columns = 0;
                local noref vector offset = '0 0 0';
                vector score_pos, score_size; //for scores other than myteam
                if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
                {
-                       for(tm = teams.sort_next; tm, tm.team != NUM_SPECTATOR; tm = tm.sort_next)
-                               ++scores_count;
                        if (autocvar_hud_panel_score_rankings)
                        {
-                               HUD_Score_Rankings(pos, mySize, me, scores_count);
+                               HUD_Score_Rankings(pos, mySize, me);
                                return;
                        }
                        rows = mySize_y/mySize_x;
-                       rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
+                       rows = bound(1, floor((sqrt(4 * (3/1) * rows * team_count + rows * rows) + rows + 0.5) / 2), team_count);
                        //                               ^^^ ammo item aspect goes here
 
-                       columns = ceil(scores_count/rows);
+                       columns = ceil(team_count/rows);
 
                        score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
 
@@ -2674,11 +2672,6 @@ void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, float layout, f
 void HUD_Mod_CA(vector myPos, vector mySize)
 {
        mod_active = 1; // required in each mod function that always shows something
-       entity tm;
-       float teams_count = 0;
-       for(tm = teams.sort_next; tm; tm = tm.sort_next)
-               if(tm.team != NUM_SPECTATOR)
-                       ++teams_count;
 
        float layout;
        if(gametype == MAPINFO_TYPE_CA)
@@ -2688,14 +2681,14 @@ void HUD_Mod_CA(vector myPos, vector mySize)
        float rows, columns, aspect_ratio;
        rows = mySize_y/mySize_x;
        aspect_ratio = (layout) ? 2 : 1;
-       rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
-       columns = ceil(teams_count/rows);
+       rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count);
+       columns = ceil(team_count/rows);
 
        int i;
        float row = 0, column = 0;
        vector pos, itemSize;
        itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
-       for(i=0; i<teams_count; ++i)
+       for(i=0; i<team_count; ++i)
        {
                pos = myPos + eX * column * itemSize_x + eY * row * itemSize_y;
 
@@ -3300,24 +3293,19 @@ void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout,
 void HUD_Mod_Dom(vector myPos, vector mySize)
 {
        mod_active = 1; // required in each mod function that always shows something
-       entity tm;
-       float teams_count = 0;
-       for(tm = teams.sort_next; tm; tm = tm.sort_next)
-               if(tm.team != NUM_SPECTATOR)
-                       ++teams_count;
 
        float layout = autocvar_hud_panel_modicons_dom_layout;
        float rows, columns, aspect_ratio;
        rows = mySize_y/mySize_x;
        aspect_ratio = (layout) ? 3 : 1;
-       rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
-       columns = ceil(teams_count/rows);
+       rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count);
+       columns = ceil(team_count/rows);
 
        int i;
        float row = 0, column = 0;
        vector pos, itemSize;
        itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
-       for(i=0; i<teams_count; ++i)
+       for(i=0; i<team_count; ++i)
        {
                pos = myPos + eX * column * itemSize_x + eY * row * itemSize_y;
 
index 7951962e6be9086aeace7b011b83c62852fdddcb..89da2da2ebdb800d11854264ad15edfa83b44e1e 100644 (file)
@@ -1,5 +1,6 @@
 entity players;
 entity teams;
+var float team_count; // real teams
 
 void AuditLists()
 {
@@ -81,6 +82,8 @@ float RegisterTeam(entity Team)
        if(teams.sort_next)
                teams.sort_next.sort_prev = Team;
        teams.sort_next = Team;
+       if(Team.team && Team.team != NUM_SPECTATOR)
+               ++team_count;
        AuditLists();
        return true;
 }
@@ -101,6 +104,8 @@ void RemoveTeam(entity Team)
        parent.sort_next = Team.sort_next;
        if(Team.sort_next)
                Team.sort_next.sort_prev = parent;
+       if(Team.team && Team.team != NUM_SPECTATOR)
+               --team_count;
        AuditLists();
 }