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 fonts.o
+CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fetch_group.o fonts.o
all: ccbs-bigscreen
#include "widestring.h"
#include "fetch_current_tournament.h"
#include "fetch_list_of_active_groups.h"
+#include "fetch_group.h"
#include "fonts.h"
Tournament active_tournament;
-std::vector<Group> active_groups;
+std::vector<SkeletonGroup> active_groups;
unsigned char framebuf[800 * 600 * 4];
void init(pqxx::connection &conn)
} else {
std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
- for (std::vector<Group>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
+ for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
std::fprintf(stderr, "tourn: %u round: %u parallel: %u\n",
i->tournament, i->round, i->parallel);
+
+ Group gr;
+ conn.perform(FetchGroup(i->tournament, i->round, i->parallel, &gr));
+ std::fprintf(stderr, "%u players in group\n", gr.players.size());
}
}
}
void FetchGroup::operator() (pqxx::transaction<> &t)
{
- pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE " +
+ pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE "
"tournament=" + pqxx::to_string(tournament) + " AND " +
"round=" + pqxx::to_string(round) + " AND " +
"parallel=" + pqxx::to_string(parallel) + " " +
// massage the data we get back into a Group object and children
int curr_player = -1;
for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
- if (i["player"] != curr_player) {
+ if (i["player"].as(curr_player) != curr_player) {
Player p;
- p.id = i["player"];
+ p.id = i["player"].as(p.id);
p.nick = i["nick"].as(p.nick);
p.total = 0;
p.rank = 1;
curr_group.players.push_back(p);
- curr_player = i["player"];
+ curr_player = i["player"].as(curr_player);
}
// note: we _will_ get some duplication here (multiple identical Song
so.artist = i["song"].as(so.artist);
sc.song = so;
- sc.chosen = i["chosen"].as(s.chosen);
- sc.score = i["score"].as(s.score);
+ sc.chosen = i["chosen"].as(sc.chosen);
+ sc.score = i["score"].as(sc.score);
- curr_group.players[curr.group.players.size() - 1].scores.push_back(sc);
+ curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);
}
}
#include "fetch_list_of_active_groups.h"
-FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<Group> *active) : active(active) {}
+FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<SkeletonGroup> *active) : active(active) {}
void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t)
{
// make sure we start with an empty list
pqxx::result res( t.exec("SELECT * FROM bigscreen.active_groups") );
for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
- Group g;
+ SkeletonGroup g;
g.tournament = i["tournament"].as(g.tournament);
g.round = i["round"].as(g.round);
#include <pqxx/transactor>
#include <vector>
-struct Group {
+struct SkeletonGroup {
unsigned tournament, round, parallel;
};
/* A transactor that fetches the current list of active groups. */
class FetchListOfActiveGroups : public pqxx::transactor<> {
private:
- std::vector<Group> *active;
+ std::vector<SkeletonGroup> *active;
public:
- FetchListOfActiveGroups(std::vector<Group> *active);
+ FetchListOfActiveGroups(std::vector<SkeletonGroup> *active);
void operator() (pqxx::transaction<> &t);
};
Song song;
bool chosen;
unsigned score;
-}:
+};
struct Player {
unsigned id;
widestring nick;
- unsigned score, rank;
+ unsigned total, rank;
std::vector<Score> scores;
};