From: Steinar H. Gunderson Date: Sat, 19 Feb 2005 16:01:57 +0000 (+0000) Subject: Hit the group-fetching code so it compiles. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=f40fa6f12fb246c09e925e97bcd7c40f8d2fa59c Hit the group-fetching code so it compiles. --- diff --git a/bigscreen/Makefile b/bigscreen/Makefile index 76d280d..aca8243 100644 --- a/bigscreen/Makefile +++ b/bigscreen/Makefile @@ -4,7 +4,7 @@ CPPFLAGS=-I/usr/include/postgresql $(shell freetype-config --cflags) -Itinyptc/ 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 diff --git a/bigscreen/ccbs_bigscreen.cpp b/bigscreen/ccbs_bigscreen.cpp index 9db87c8..f509912 100644 --- a/bigscreen/ccbs_bigscreen.cpp +++ b/bigscreen/ccbs_bigscreen.cpp @@ -8,10 +8,11 @@ #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 active_groups; +std::vector active_groups; unsigned char framebuf[800 * 600 * 4]; void init(pqxx::connection &conn) @@ -24,9 +25,13 @@ void init(pqxx::connection &conn) } else { std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id); - for (std::vector::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) { + for (std::vector::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()); } } } diff --git a/bigscreen/fetch_group.cpp b/bigscreen/fetch_group.cpp index 7e131c4..e1d0112 100644 --- a/bigscreen/fetch_group.cpp +++ b/bigscreen/fetch_group.cpp @@ -5,7 +5,7 @@ FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, G 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) + " " + @@ -18,16 +18,16 @@ void FetchGroup::operator() (pqxx::transaction<> &t) // 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 @@ -40,10 +40,10 @@ void FetchGroup::operator() (pqxx::transaction<> &t) 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); } } diff --git a/bigscreen/fetch_list_of_active_groups.cpp b/bigscreen/fetch_list_of_active_groups.cpp index 1df6758..c2d587b 100644 --- a/bigscreen/fetch_list_of_active_groups.cpp +++ b/bigscreen/fetch_list_of_active_groups.cpp @@ -1,6 +1,6 @@ #include "fetch_list_of_active_groups.h" -FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector *active) : active(active) {} +FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector *active) : active(active) {} void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t) { // make sure we start with an empty list @@ -8,7 +8,7 @@ void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t) 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); diff --git a/bigscreen/fetch_list_of_active_groups.h b/bigscreen/fetch_list_of_active_groups.h index 113160d..b1039d3 100644 --- a/bigscreen/fetch_list_of_active_groups.h +++ b/bigscreen/fetch_list_of_active_groups.h @@ -4,17 +4,17 @@ #include #include -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 *active; + std::vector *active; public: - FetchListOfActiveGroups(std::vector *active); + FetchListOfActiveGroups(std::vector *active); void operator() (pqxx::transaction<> &t); }; diff --git a/bigscreen/group.h b/bigscreen/group.h index 6961a90..f6348c0 100644 --- a/bigscreen/group.h +++ b/bigscreen/group.h @@ -13,11 +13,11 @@ struct Score { Song song; bool chosen; unsigned score; -}: +}; struct Player { unsigned id; widestring nick; - unsigned score, rank; + unsigned total, rank; std::vector scores; };