]> git.sesse.net Git - ccbs/commitdiff
Yet more refactoring.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 5 Mar 2005 00:09:06 +0000 (00:09 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 5 Mar 2005 00:09:06 +0000 (00:09 +0000)
bigscreen/groupscreen.cpp
bigscreen/groupscreen.h

index e4f7b4a643bf9f01ddef5c83375671712b457b27..03b61db2f32e38cbf65e99808fee0646d96c943b 100644 (file)
@@ -216,6 +216,28 @@ void GroupScreen::find_column_widths(const Group &group, std::vector<unsigned> &
        }
 }
 
+/* Find the first player with the fewest songs played and part of this machine. */
+const Player *GroupScreen::get_next_player(const Group &group)
+{
+       unsigned min_played_songs = 9999;
+       const Player *next_player = NULL;
+       unsigned m = 0;
+       for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
+               unsigned this_played = 0;
+               for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j) {
+                       if (j->score != -1)
+                               ++this_played;
+               }
+
+               if ((m++ % num_machines == machine) && this_played < min_played_songs) {
+                       min_played_songs = this_played;
+                       next_player = &(*i);
+               }
+       }
+
+       return next_player;
+}
+
 /*
  * At the bottom, for a single player, is "who's playing, what will he/she be
  * playing, and optionally, how much to lead/win and how much to secure
@@ -241,34 +263,28 @@ void GroupScreen::draw_next_up_single(unsigned char *buf, const Group &group, co
 {
         unsigned num_scores = group.players[0].scores.size();
        
-       /* Find the first player with the fewest songs played and part of this machine. */
-       unsigned min_played_songs = 9999, num_random_songs = 0;
-       const Player *next_player = NULL;
-       unsigned m = 0;
-       for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
-               unsigned this_played = 0, this_random_songs = 0;
-               for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j) {
-                       if (j->score != -1)
-                               ++this_played;
-                       if (!j->chosen)
-                               ++this_random_songs;
-               }
-
-               if ((m++ % num_machines == machine) && this_played < min_played_songs) {
-                       min_played_songs = this_played;
-                       next_player = &(*i);
-                       num_random_songs = this_random_songs;  // should be equal for all
-               }
+       // Find out how many random songs there are (equal for all players).
+       unsigned num_random_songs = 0;
+       for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i) {
+               if (!i->chosen)
+                       ++num_random_songs;
        }
 
-       /* Find out what song this player is supposed to play next; try random songs first */ 
+       /* 
+        * Find out which player is next, and what song he she is supposed to play. First
+        * try random songs.
+        */
+       const Player *next_player = get_next_player(group);
        const Score *next_song = NULL;
+       unsigned num_played = 0;  // will not always be completely accurate, but always as accurate as we need it :-)
 
        for (unsigned i = 0; i < num_random_songs; ++i) {
                unsigned j = (i + next_player->position - 1) % num_random_songs;
                if (next_player->scores[j].score == -1) {
                        next_song = &(next_player->scores[j]);
                        break;
+               } else {
+                       ++num_played;
                }
        }
 
@@ -279,6 +295,8 @@ void GroupScreen::draw_next_up_single(unsigned char *buf, const Group &group, co
                        if (next_player->scores[j].score == -1) {
                                next_song = &(next_player->scores[j]);
                                break;
+                       } else {
+                               ++num_played;
                        }
                }
        }
@@ -304,7 +322,7 @@ void GroupScreen::draw_next_up_single(unsigned char *buf, const Group &group, co
                }
 
                // only show lead/win/qualify for the last song
-               if (min_played_songs == num_scores - 1) {
+               if (num_played == num_scores - 1) {
                        /*
                         * Find out how much we need to lead, how much we need to be guaranteed
                         * to win the group, and how much we need to secure qualification. (FIXME:
index 9c32629a7cbc60232a1b7f08d26a8448434df622..09d8d978b039d8ea8e5c8407e45910922daf862f 100644 (file)
@@ -25,6 +25,7 @@ private:
        void draw_main_heading(std::vector<TextDefer> &td);
        void draw_column_headings(std::vector<TextDefer> &td, const Group &group, const std::vector<unsigned> &colwidth);
        void draw_scores(std::vector<TextDefer> &td, const Group &group, const std::vector<unsigned> &colwidth);
+       const Player *get_next_player(const Group &group);
        void draw_next_up_single(unsigned char *buf, const Group &group, const std::vector<unsigned> &colwidth,
                std::map<unsigned, unsigned> &song_scores, std::map<unsigned, unsigned> &player_scores,
                const std::vector<unsigned> &max_score, const std::vector<unsigned> &min_score);