CXXFLAGS=-g -Wall
LDFLAGS=-L/usr/X11R6/lib
LIBS=$(shell freetype-config --libs) $(shell libpq3-config) -lpqxx tinyptc/libtinyptc.a -lX11
-CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fetch_max_score_for_song.o fetch_max_score_for_player.o fetch_group.o fetch_needs_update.o fetch_highscore.o fonts.o groupscreen.o splitscreen.o rotatescreen.o screen.o
+CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fetch_max_score_for_songs.o fetch_max_score_for_player.o fetch_group.o fetch_needs_update.o fetch_highscore.o fonts.o groupscreen.o splitscreen.o rotatescreen.o screen.o
all: ccbs-bigscreen
+++ /dev/null
-#include "fetch_max_score_for_song.h"
-
-FetchMaxScoreForSong::FetchMaxScoreForSong(unsigned tournament, unsigned song, unsigned *score)
- : tournament(tournament), song(song), score(score) {}
-
-void FetchMaxScoreForSong::operator() (pqxx::transaction<> &t)
-{
- pqxx::result res( t.exec("SELECT MAX(feetrating)*1000 AS max_score FROM songratings WHERE song=" +
- pqxx::to_string(song) + " AND machine=( SELECT machine FROM tournaments WHERE tournament=" +
- pqxx::to_string(tournament) + ")") );
-
- *score = res.at(0)["max_score"].as(*score);
-}
+++ /dev/null
-#ifndef _FETCH_MAX_SCORE_FOR_SONG_H
-#define _FETCH_MAX_SCORE_FOR_SONG_H 1
-
-#include <pqxx/transactor>
-
-/* A transactor that fetches the maximum score for a song */
-class FetchMaxScoreForSong : public pqxx::transactor<> {
-private:
- unsigned tournament, song, *score;
-
-public:
- FetchMaxScoreForSong(unsigned tournament, unsigned song, unsigned *score);
- void operator() (pqxx::transaction<> &t);
-};
-
-#endif /* !defined(_FETCH_MAX_SCORE_FOR_SONG_H) */
--- /dev/null
+#include "fetch_max_score_for_songs.h"
+
+FetchMaxScoreForSongs::FetchMaxScoreForSongs(unsigned tournament, std::map<unsigned, unsigned> *score)
+ : tournament(tournament), score(score) {}
+
+void FetchMaxScoreForSongs::operator() (pqxx::transaction<> &t)
+{
+ score->erase(score->begin(), score->end());
+
+ pqxx::result res( t.exec("SELECT song,MAX(feetrating)*1000 AS max_score FROM songratings WHERE "
+ " machine=( SELECT machine FROM tournaments WHERE tournament=" + pqxx::to_string(tournament) + ") GROUP BY song") );
+
+ for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
+ unsigned song, max_score;
+ song = i["song"].as(song);
+ max_score = i["max_score"].as(max_score);
+
+ score->insert(std::make_pair(song, max_score));
+ }
+}
--- /dev/null
+#ifndef _FETCH_MAX_SCORE_FOR_SONGS_H
+#define _FETCH_MAX_SCORE_FOR_SONGS_H 1
+
+#include <pqxx/transactor>
+#include <map>
+
+/* A transactor that fetches the maximum score for all songs */
+class FetchMaxScoreForSongs : public pqxx::transactor<> {
+private:
+ unsigned tournament;
+ std::map<unsigned, unsigned> *score;
+
+public:
+ FetchMaxScoreForSongs(unsigned tournament, std::map<unsigned, unsigned> *score);
+ void operator() (pqxx::transaction<> &t);
+};
+
+#endif /* !defined(_FETCH_MAX_SCORE_FOR_SONGS_H) */
#include <cstdio>
#include <algorithm>
+#include <map>
#include "groupscreen.h"
#include "fetch_group.h"
-#include "fetch_max_score_for_song.h"
+#include "fetch_max_score_for_songs.h"
#include "fetch_max_score_for_player.h"
#include "fetch_needs_update.h"
#include "fetch_highscore.h"
scores_changed.reset_flag();
+ /*
+ * We'll probably need some values from here later on (although not all), just fetch them
+ * all while we're at it.
+ */
+ std::map<unsigned, unsigned> song_scores;
+ conn.perform(FetchMaxScoreForSongs(tournament, &song_scores));
+
Group group;
conn.perform(FetchGroup(tournament, round, parallel, &group));
gettimeofday(&last_updated, NULL);
unsigned max_score_this_song;
if (j->song.id != -1) {
// random song, or we know what song the player picked
- conn.perform(FetchMaxScoreForSong(tournament, j->song.id, &max_score_this_song));
+ max_score_this_song = song_scores[j->song.id];
} else {
conn.perform(FetchMaxScoreForPlayer(tournament, i->id, round, &max_score_this_song));
}
unsigned max_score_this_song;
if (next_song->song.id != -1) {
// random song, or we know what song the player picked
- conn.perform(FetchMaxScoreForSong(tournament, next_song->song.id, &max_score_this_song));
+ max_score_this_song = song_scores[next_song->song.id];
} else {
conn.perform(FetchMaxScoreForPlayer(tournament, next_player->id, round, &max_score_this_song));
}