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 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_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
all: ccbs-bigscreen
--- /dev/null
+#include "fetch_highscore.h"
+
+FetchHighscore::FetchHighscore(unsigned song, Highscore *hs)
+ : song(song), hs(hs) {}
+
+void FetchHighscore::operator() (pqxx::transaction<> &t)
+{
+ pqxx::result res( t.exec("SELECT score,nick,tournamentname FROM scores NATURAL JOIN players NATURAL JOIN tournaments WHERE song=" + pqxx::to_string(song) + " AND score IS NOT NULL ORDER BY score DESC LIMIT 1") );
+
+ hs->song = song;
+
+ try {
+ pqxx::result::tuple highscore = res.at(0);
+
+ hs->score = highscore["score"].as(hs->score);
+ hs->nick = highscore["nick"].as(hs->nick);
+ hs->tournament_name = highscore["tournamentname"].as(hs->tournament_name);
+ } catch (PGSTD::out_of_range &e) {
+ hs->score = -1;
+ }
+}
--- /dev/null
+#ifndef _FETCH_HIGHSCORE_H
+#define _FETCH_HIGHSCORE_H 1
+
+#include <pqxx/transactor>
+#include "widestring.h"
+
+struct Highscore {
+ unsigned song;
+ int score;
+ widestring nick, tournament_name;
+};
+
+/* A transactor that fetches the all-time high score for a song */
+class FetchHighscore : public pqxx::transactor<> {
+private:
+ unsigned song;
+ Highscore *hs;
+
+public:
+ FetchHighscore(unsigned song, Highscore *hs);
+ void operator() (pqxx::transaction<> &t);
+};
+
+#endif /* !defined(_FETCH_MAX_SCORE_FOR_SONG_H) */
#include "fetch_max_score_for_song.h"
#include "fetch_max_score_for_player.h"
#include "fetch_needs_update.h"
+#include "fetch_highscore.h"
#include "fonts.h"
GroupScreen::GroupScreen(pqxx::connection &conn, unsigned tournament, unsigned round, unsigned parallel)
this_width = my_draw_text(next_song->song.title, NULL, 20.0);
my_draw_text(next_song->song.title, buf, 20.0, 400 - this_width/2, 457);
- // fetch the high score later
- text = widestring("High score: ") + widestring(pqxx::to_string(1234)) +
- widestring(", by dufF in Challenge Cup 1, 2004");
- this_width = my_draw_text(text, NULL, 16.0);
- my_draw_text(text, buf, 16.0, 400 - this_width/2, 487);
+ Highscore hs;
+ conn.perform(FetchHighscore(next_song->song.id, &hs));
+
+ if (hs.score != -1) {
+ text = widestring("High score: ") + widestring(pqxx::to_string(hs.score)) +
+ widestring(", by ") + hs.nick + widestring(" in ") + hs.tournament_name;
+ this_width = my_draw_text(text, NULL, 16.0);
+ my_draw_text(text, buf, 16.0, 400 - this_width/2, 487);
+ }
}
// only show lead/win/qualify for the last song