You can subscribe to this list here.
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(25) |
Jul
(288) |
Aug
(119) |
Sep
(31) |
Oct
(59) |
Nov
(458) |
Dec
(359) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
(268) |
Feb
(26) |
Mar
(36) |
Apr
(48) |
May
(119) |
Jun
(37) |
Jul
(173) |
Aug
(429) |
Sep
(137) |
Oct
(156) |
Nov
(59) |
Dec
(45) |
| 2011 |
Jan
(398) |
Feb
(257) |
Mar
(49) |
Apr
(5) |
May
(34) |
Jun
(11) |
Jul
(38) |
Aug
(12) |
Sep
(1) |
Oct
(49) |
Nov
(5) |
Dec
(10) |
| 2012 |
Jan
(21) |
Feb
(32) |
Mar
(20) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(173) |
Aug
|
Sep
(25) |
Oct
(6) |
Nov
(44) |
Dec
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:50:10
|
Module: performous Branch: master Commit: 0d183b3ce1783b96619e5f9e3d57169e91020102 Author: Markus Raab <un...@ma...> Date: Thu Nov 12 11:46:21 2009 +0100 Merge branch 'master' of git://git.performous.org/gitroot/performous/performous --- |
|
From: Markus R. <god...@us...> - 2009-11-12 12:50:05
|
Module: performous
Branch: master
Commit: 20b425ffd6a6eaa119c125b675ea3164233b9acf
Author: Markus Raab <un...@ma...>
Date: Thu Nov 12 10:52:21 2009 +0100
Query Interface for Database
it is now possible to query the global hiscore
and hiscores per songs and player.
in test program you can now enter song too and query is used
more const correctness (queries are const)
assign_id_internal regression fixed
---
game/database.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++++-----
game/database.hh | 9 ++++++-
game/hiscore.cc | 30 ++++++++++++++++++++++++--
game/hiscore.hh | 9 +++++++-
game/players.cc | 10 ++++++++-
game/players.hh | 9 ++++++-
game/songitems.cc | 14 ++++++++++-
game/songitems.hh | 5 ++++
8 files changed, 128 insertions(+), 17 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index d9906dc..d0f2bba 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -76,17 +76,54 @@ void Database::addHiscore (boost::shared_ptr<Song> s) {
m_hiscores.addHiscore(score, playerid, songid);
}
-bool Database::reachedHiscore (boost::shared_ptr<Song> s) {
+bool Database::reachedHiscore (boost::shared_ptr<Song> s) const {
int score = m_players.scores.front();
int songid = m_songs.lookup(s);
+
return m_hiscores.reachedHiscore(score, songid);
}
-int test(std::string const& name, int score) {
+void Database::queryOverallHiscore (std::ostream & os, std::string const& track) const {
+ std::vector<HiscoreItem> hi = m_hiscores.queryHiscore (10, -1, -1, track);
+ for (size_t i=0; i<hi.size(); ++i)
+ {
+ os << i+1 << ".\t"
+ << m_players.lookup(hi[i].playerid) << "\t"
+ << m_songs.lookup(hi[i].songid) << "\t"
+ // << hi[i].track << "\t"
+ << hi[i].score << "\n";
+ }
+}
+
+void Database::queryPerSongHiscore (std::ostream & os, boost::shared_ptr<Song> s, std::string const& track) const {
+ int songid = m_songs.lookup(s);
+ std::vector<HiscoreItem> hi = m_hiscores.queryHiscore(10, -1, songid, track);
+ for (size_t i=0; i<hi.size(); ++i)
+ {
+ os << i+1 << ".\t"
+ << m_players.lookup(hi[i].playerid) << "\t"
+ // << hi[i].track << "\t"
+ << hi[i].score << "\n";
+ }
+}
+
+void Database::queryPerPlayerHiscore (std::ostream & os, std::string const& track) const {
+ int playerid = m_players.lookup(m_players.current().name);
+ std::vector<HiscoreItem> hi = m_hiscores.queryHiscore(10, playerid, -1, track);
+ for (size_t i=0; i<hi.size(); ++i)
+ {
+ os << i+1 << ".\t"
+ << m_songs.lookup(hi[i].songid) << "\t"
+ // << hi[i].track << "\t"
+ << hi[i].score << "\n";
+ }
+}
+
+int test(std::string const& name, std::string const& song, int score) {
Database d("database.xml");
// d.addPlayer("Markus", "m.jpg");
- boost::shared_ptr<Song> s(new Song("/usr/share/songs/ABBA/ABBA - Dancing Queen/", "ABBA - Dancing Queen.txt"));
+ boost::shared_ptr<Song> s(new Song("/usr/share/songs/ABBA/ABBA - " + song + "/", "ABBA - " + song + ".txt"));
d.addSong(s);
PlayerItem pi;
@@ -100,6 +137,15 @@ int test(std::string const& name, int score) {
d.addHiscore(s);
}
+ std::cout << " --- Overall Hiscore ---" << std::endl;
+ d.queryOverallHiscore(std::cout);
+
+ std::cout << " --- Player Hiscore ---" << std::endl;
+ d.queryPerPlayerHiscore(std::cout);
+
+ std::cout << " --- Song Hiscore ---" << std::endl;
+ d.queryPerSongHiscore(std::cout, s);
+
return 0;
}
@@ -107,10 +153,11 @@ int test(std::string const& name, int score) {
int main(int argc, char**argv) {
- if (argc < 3) return 3;
+ if (argc < 4) return 3;
std::string name = argv[1];
- int score = boost::lexical_cast<int>(argv[2]);
+ std::string song = argv[2];
+ int score = boost::lexical_cast<int>(argv[3]);
- return test(name, score);
+ return test(name, song, score);
}
diff --git a/game/database.hh b/game/database.hh
index 1adec0a..c884944 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -1,6 +1,7 @@
#pragma once
#include <string>
+#include <ostream>
#include "players.hh"
#include "hiscore.hh"
@@ -64,9 +65,13 @@ class Database
Queries if the current player with current score has reached a new hiscore
for the song s.
*/
- bool reachedHiscore (boost::shared_ptr<Song> s);
+ bool reachedHiscore (boost::shared_ptr<Song> s) const;
- friend int test(std::string const&, int);
+ void queryOverallHiscore (std::ostream & os, std::string const& track = "") const;
+ void queryPerSongHiscore (std::ostream & os, boost::shared_ptr<Song> s, std::string const& track = "") const;
+ void queryPerPlayerHiscore (std::ostream & os, std::string const& track = "") const;
+
+ friend int test(std::string const&, std::string const&, int);
private:
fs::path m_filename;
diff --git a/game/hiscore.cc b/game/hiscore.cc
index a74ec5e..4c0bcae 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -10,7 +10,7 @@
Hiscore::Hiscore()
{}
-bool Hiscore::reachedHiscore(int score, int songid, std::string const& track) {
+bool Hiscore::reachedHiscore(int score, int songid, std::string const& track) const {
if (score < 0) throw HiscoreException("Score negativ overflow");
if (score > 10000) throw HiscoreException("Score positive overflow");
@@ -46,6 +46,31 @@ void Hiscore::addHiscore(int score, int playerid, int songid, std::string const&
m_hiscore.insert(hi);
}
+Hiscore::HiscoreVector Hiscore::queryHiscore(int max, int playerid, int songid, std::string const& track) const {
+ HiscoreVector hv;
+ for (hiscore_t::const_iterator it = m_hiscore.begin(); it != m_hiscore.end(); ++it) {
+ if (playerid != -1)
+ {
+ if (playerid != it->playerid) continue;
+ }
+ if (songid != -1)
+ {
+ if (songid != it->songid) continue;
+ }
+ if (!track.empty())
+ {
+ if (track != it->track) continue;
+ }
+ if (max != -1)
+ {
+ if (max == 0) break;
+ --max;
+ }
+ hv.push_back(*it);
+ }
+ return hv;
+}
+
void Hiscore::load(xmlpp::NodeSet const& n) {
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
@@ -72,8 +97,7 @@ void Hiscore::load(xmlpp::NodeSet const& n) {
}
void Hiscore::save(xmlpp::Element *hiscores) {
- for (hiscore_t::const_iterator it = m_hiscore.begin(); it != m_hiscore.end(); ++it)
- {
+ for (hiscore_t::const_iterator it = m_hiscore.begin(); it != m_hiscore.end(); ++it) {
xmlpp::Element* hiscore = hiscores->add_child("hiscore");
hiscore->set_attribute("playerid", boost::lexical_cast<std::string>(it->playerid));
hiscore->set_attribute("songid", boost::lexical_cast<std::string>(it->songid));
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 951fe16..704fe61 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -51,7 +51,7 @@ class Hiscore
@return true if the score make it into the top.
@return false if addNewHiscore does not make sense
for that score.*/
- bool reachedHiscore(int score, int songid, std::string const& track = "vocals");
+ bool reachedHiscore(int score, int songid, std::string const& track = "vocals") const;
/**Add a specific highscore into the list.
@@ -65,6 +65,13 @@ class Hiscore
HiscoreException will be raised.
*/
void addHiscore(int score, int playerid, int songid, std::string const& track = "vocals");
+
+ typedef std::vector<HiscoreItem> HiscoreVector;
+ /**This queries the database for a sorted vector of highscores.
+ The defaults mean to query everything.
+ @param max limits the number of elements returned.
+ */
+ HiscoreVector queryHiscore(int max = -1, int playerid = -1, int songid = -1, std::string const& track = "") const;
private:
typedef std::multiset<HiscoreItem>hiscore_t;
diff --git a/game/players.cc b/game/players.cc
index 1a0a764..9919ac4 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -62,7 +62,7 @@ void Players::update() {
if (m_dirty) filter_internal();
}
-int Players::lookup(std::string const& name) {
+int Players::lookup(std::string const& name) const {
for (players_t::const_iterator it = m_players.begin(); it != m_players.end(); ++it) {
if (it->name == name) return it->id;
}
@@ -70,6 +70,14 @@ int Players::lookup(std::string const& name) {
return -1;
}
+std::string Players::lookup(int id) const {
+ PlayerItem pi;
+ pi.id = id;
+ players_t::iterator it = m_players.find(pi);
+ if (it == m_players.end()) return "Unkown Player";
+ else return it->name;
+}
+
void Players::addPlayer (std::string const& name, std::string const& picture, int id) {
PlayerItem pi;
pi.id = id;
diff --git a/game/players.hh b/game/players.hh
index e739b0f..2e67199 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -54,7 +54,7 @@ class Players: boost::noncopyable {
bool m_dirty;
- friend int test(std::string const&, int);
+ friend int test(std::string const&, std::string const&, int);
public:
cur_players_t cur;
@@ -70,7 +70,12 @@ class Players: boost::noncopyable {
void update();
/// lookup a playerid using the players name
- int lookup(std::string const& name);
+ int lookup(std::string const& name) const;
+
+ /** lookup a players name using the playerid.
+ @return the players name or "Unkown Player"
+ */
+ std::string lookup(int id) const;
/// add a player with a displayed name and an optional picture; if no id is given one will be assigned
void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
diff --git a/game/songitems.cc b/game/songitems.cc
index d4d44a1..8e78ae0 100644
--- a/game/songitems.cc
+++ b/game/songitems.cc
@@ -83,8 +83,18 @@ int SongItems::lookup(boost::shared_ptr<Song> song) const {
return -1;
}
+std::string SongItems::lookup (int id) const {
+ SongItem si;
+ si.id = id;
+ songs_t::iterator it = m_songs.find(si);
+ if (it == m_songs.end()) return "Unkown Song";
+ else if (!it->song) return it->artist + " - " + it->title;
+ else return it->song->artist + " - " + it->song->title;
+}
+
int SongItems::assign_id_internal() const {
- songs_t::const_iterator it = m_songs.begin();
- if (it != m_songs.end()) return it->id+1;
+ // use the last one with highest id
+ songs_t::const_reverse_iterator it = m_songs.rbegin();
+ if (it != m_songs.rend()) return it->id+1;
else return 1; // empty set
}
diff --git a/game/songitems.hh b/game/songitems.hh
index a71f100..4575c45 100644
--- a/game/songitems.hh
+++ b/game/songitems.hh
@@ -83,6 +83,11 @@ struct SongItems
@return -1 if no song found.*/
int lookup(boost::shared_ptr<Song> song) const;
+ /**Lookup the artist + title for a specific song.
+ @return "Unknown Song" if nothing is found.
+ */
+ std::string lookup (int id) const;
+
private:
int assign_id_internal() const;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:50:03
|
Module: performous
Branch: master
Commit: a785edf51deeaa576cb7b2df263d29ec5d456f04
Author: Markus Raab <un...@ma...>
Date: Thu Nov 12 11:45:56 2009 +0100
in the middle of work
reason: to pull from master
---
game/CMakeLists.txt | 3 +--
game/database.cc | 5 +++++
game/database.hh | 2 +-
game/main.cc | 8 ++++----
game/players.hh | 2 --
game/screen_hiscore.hh | 2 +-
game/screen_players.hh | 2 +-
game/screen_sing.hh | 11 ++++++-----
game/songs.cc | 3 ++-
game/songs.hh | 4 +++-
10 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 4f48dfa..3b191fa 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 2.6)
-# FILE(GLOB SOURCE_FILES "*.cc")
-SET(SOURCE_FILES hiscore.cc database.cc players.cc configuration.cc fs.cc unicode.cc songitems.cc song.cc notes.cc songparser-ini.cc songparser-txt.cc midifile.cc)
+FILE(GLOB SOURCE_FILES "*.cc")
FILE(GLOB HEADER_FILES "*.hh")
set(SOURCES ${SOURCE_FILES} ${HEADER_FILES})
diff --git a/game/database.cc b/game/database.cc
index d0f2bba..a7bb9ac 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -118,7 +118,11 @@ void Database::queryPerPlayerHiscore (std::ostream & os, std::string const& trac
<< hi[i].score << "\n";
}
}
+bool Database::noPlayers() const {
+ return m_players.cur.empty();
+}
+/*
int test(std::string const& name, std::string const& song, int score) {
Database d("database.xml");
// d.addPlayer("Markus", "m.jpg");
@@ -161,3 +165,4 @@ int main(int argc, char**argv) {
return test(name, song, score);
}
+*/
diff --git a/game/database.hh b/game/database.hh
index c884944..fb7d18f 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -71,7 +71,7 @@ class Database
void queryPerSongHiscore (std::ostream & os, boost::shared_ptr<Song> s, std::string const& track = "") const;
void queryPerPlayerHiscore (std::ostream & os, std::string const& track = "") const;
- friend int test(std::string const&, std::string const&, int);
+ bool noPlayers() const;
private:
fs::path m_filename;
diff --git a/game/main.cc b/game/main.cc
index c444e90..a863bfd 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -142,17 +142,17 @@ void mainLoop() {
Audio audio;
audioSetup(capture, audio);
Backgrounds backgrounds;
- Songs songs(songlist);
Database database(getHomeDir() / ".config" / "performous" / "database.xml");
+ Songs songs(database, songlist);
ScreenManager sm;
Window window(config["graphic/window_width"].i(), config["graphic/window_height"].i(), config["graphic/fullscreen"].b());
sm.addScreen(new ScreenIntro("Intro", audio, capture));
sm.addScreen(new ScreenSongs("Songs", audio, songs));
- sm.addScreen(new ScreenSing("Sing", audio, capture, database.m_players, backgrounds));
+ sm.addScreen(new ScreenSing("Sing", audio, capture, database, backgrounds));
sm.addScreen(new ScreenPractice("Practice", audio, capture));
sm.addScreen(new ScreenConfiguration("Configuration", audio));
- sm.addScreen(new ScreenPlayers("Players", audio, database.m_players));
- sm.addScreen(new ScreenHiscore("Hiscore", audio, database.m_players));
+ sm.addScreen(new ScreenPlayers("Players", audio, database));
+ sm.addScreen(new ScreenHiscore("Hiscore", audio, database));
sm.activateScreen("Intro");
// Main loop
boost::xtime time = now();
diff --git a/game/players.hh b/game/players.hh
index 2e67199..f3aa07b 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -54,8 +54,6 @@ class Players: boost::noncopyable {
bool m_dirty;
- friend int test(std::string const&, std::string const&, int);
-
public:
cur_players_t cur;
cur_scores_t scores;
diff --git a/game/screen_hiscore.hh b/game/screen_hiscore.hh
index 14e10a6..0e0ff5f 100644
--- a/game/screen_hiscore.hh
+++ b/game/screen_hiscore.hh
@@ -37,7 +37,7 @@ class ScreenHiscore : public Screen {
Audio& m_audio;
Players& m_players;
boost::shared_ptr<Song> m_song; /// Pointer to the current song
- boost::scoped_ptr<SongHiscore> m_highscore;
+ boost::scoped_ptr<Hiscore> m_highscore;
boost::scoped_ptr<Surface> m_songbg;
boost::scoped_ptr<Video> m_video;
boost::scoped_ptr<ThemeSongs> theme;
diff --git a/game/screen_players.hh b/game/screen_players.hh
index 5015c09..18cb58e 100644
--- a/game/screen_players.hh
+++ b/game/screen_players.hh
@@ -32,7 +32,7 @@ class ScreenPlayers : public Screen {
Audio& m_audio;
Players& m_players;
boost::shared_ptr<Song> m_song; /// Pointer to the current song
- boost::scoped_ptr<SongHiscore> m_highscore;
+ boost::scoped_ptr<Hiscore> m_highscore;
boost::scoped_ptr<Surface> m_songbg;
boost::scoped_ptr<Video> m_video;
boost::scoped_ptr<ThemeSongs> theme;
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index 98d3fb5..17d1d69 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -14,6 +14,7 @@
#include "surface.hh"
#include "opengl_text.hh"
#include "progressbar.hh"
+#include "database.hh"
#include "screen_players.hh"
@@ -25,12 +26,12 @@ class Capture;
class ScoreWindow {
public:
/// constructor
- ScoreWindow(Engine & e, Players & players);
+ ScoreWindow(Engine & e, Database & database);
/// draws ScoreWindow
void draw();
- bool empty() { return m_players.cur.empty(); }
+ bool empty() { return m_database.noPlayers(); }
private:
- Players & m_players;
+ Database & m_database;
AnimValue m_pos;
Surface m_bg;
ProgressBar m_scoreBar;
@@ -43,8 +44,8 @@ class ScoreWindow {
class ScreenSing: public Screen {
public:
/// constructor
- ScreenSing(std::string const& name, Audio& audio, Capture& capture, Players& players, Backgrounds& bgs):
- Screen(name), m_audio(audio), m_capture(capture), m_players(players), m_backgrounds(bgs), m_latencyAV()
+ ScreenSing(std::string const& name, Audio& audio, Capture& capture, Database& database, Backgrounds& bgs):
+ Screen(name), m_audio(audio), m_capture(capture), m_database(database), m_backgrounds(bgs), m_latencyAV()
{}
void enter();
void exit();
diff --git a/game/songs.cc b/game/songs.cc
index 65bce0c..51afd2f 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -14,7 +14,7 @@
#include <stdexcept>
#include <cstdlib>
-Songs::Songs(std::string const& songlist): m_songlist(songlist), math_cover(), m_order(), m_dirty(false), m_loading(false), m_needShuffle(false) {
+Songs::Songs(Database & database, std::string const& songlist): m_songlist(songlist), math_cover(), m_order(), m_dirty(false), m_loading(false), m_needShuffle(false), m_database(database) {
reload();
}
@@ -72,6 +72,7 @@ void Songs::reload_internal(fs::path const& parent) {
Song* s = new Song(path, name);
s->randomIdx = ++randomIdx; // Not so random during loading, they are shuffled after load is finished
boost::mutex::scoped_lock l(m_mutex);
+ database.addSong(s);
m_songs.push_back(boost::shared_ptr<Song>(s));
m_dirty = true;
} catch (SongParserException& e) {
diff --git a/game/songs.hh b/game/songs.hh
index a5c44ad..ee5028b 100644
--- a/game/songs.hh
+++ b/game/songs.hh
@@ -3,6 +3,7 @@
#include "animvalue.hh"
#include "fs.hh"
#include "song.hh"
+#include "database.hh"
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/thread/mutex.hpp>
@@ -14,7 +15,7 @@
class Songs: boost::noncopyable {
public:
/// constructor
- Songs(std::string const& songlist = std::string());
+ Songs(Database & database, std::string const& songlist = std::string());
~Songs();
/// updates filtered songlist
void update();
@@ -70,6 +71,7 @@ class Songs: boost::noncopyable {
SongVector m_songs, m_filtered;
AnimAcceleration math_cover;
std::string m_filter;
+ Database & m_database;
int m_order;
void dumpSongs_internal() const;
void reload_internal();
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:59
|
Module: performous
Branch: master
Commit: c17639f9cbadd3c1503dcbdbe0d9784f243d2544
Author: Markus Raab <un...@ma...>
Date: Thu Nov 12 09:29:49 2009 +0100
a pointer to song is stored
(for more complete information, e.g. artist)
---
game/songitems.cc | 34 ++++++++++++++++++++++++++--------
game/songitems.hh | 26 +++++++++++++++++++++-----
2 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/game/songitems.cc b/game/songitems.cc
index 99b4eba..d4d44a1 100644
--- a/game/songitems.cc
+++ b/game/songitems.cc
@@ -38,7 +38,7 @@ void SongItems::save(xmlpp::Element *songs) {
}
}
-void SongItems::addSongItem(std::string const& artist, std::string const& title, int id) {
+int SongItems::addSongItem(std::string const& artist, std::string const& title, int id) {
SongItem si;
if (id==-1) id = assign_id_internal();
si.id = id;
@@ -51,22 +51,40 @@ void SongItems::addSongItem(std::string const& artist, std::string const& title,
si.id = assign_id_internal();
m_songs.insert(si); // now do the insert with the fresh id
}
+ return si.id;
}
void SongItems::addSong(boost::shared_ptr<Song> song) {
- if (lookup(song) == -1) addSongItem(song->artist, song->title);
+ int id = lookup(song);
+ if (id == -1)
+ {
+ id = addSongItem(song->artist, song->title);
+ }
+
+ SongItem si;
+ si.id = id;
+ songs_t::iterator it = m_songs.find(si);
+ if (it == m_songs.end()) throw SongItemsException("Cant find song which was added just before");
+ // it->song.reset(song); // does not work, it is a read only structure...
+
+ // fill up the rest of the information
+ si.artist = it->artist;
+ si.title = it->title;
+ si.song = song;
+
+ m_songs.erase(it);
+ m_songs.insert(si);
}
-int SongItems::lookup(boost::shared_ptr<Song> song) {
- for (songs_t::iterator it = m_songs.begin(); it != m_songs.end(); ++it)
- {
+int SongItems::lookup(boost::shared_ptr<Song> song) const {
+ for (songs_t::const_iterator it = m_songs.begin(); it != m_songs.end(); ++it) {
if (song->collateByArtistOnly == it->artist && song->collateByTitleOnly == it->title) return it->id;
}
return -1;
}
-int SongItems::assign_id_internal() {
- songs_t::const_reverse_iterator it = m_songs.rbegin();
- if (it != m_songs.rend()) return it->id+1;
+int SongItems::assign_id_internal() const {
+ songs_t::const_iterator it = m_songs.begin();
+ if (it != m_songs.end()) return it->id+1;
else return 1; // empty set
}
diff --git a/game/songitems.hh b/game/songitems.hh
index 9b1f2c5..a71f100 100644
--- a/game/songitems.hh
+++ b/game/songitems.hh
@@ -21,11 +21,22 @@ struct SongItemsException: public std::runtime_error {
struct SongItem
{
- int id; // TODO use a PUID instead (LibOFA)
+ int id; ///< The unique id for every song
+ /** This data is stored separate because it is read in before
+ the song is added.
+ A short, but relatively non-ambiguous collate form is used.
+ */
std::string artist;
std::string title;
+ /** This shared pointer is stored to access all song
+ information available.
+ E.g. the full artist information can be accessed using
+ this pointer.
+ */
+ boost::shared_ptr<Song> song;
+
bool operator< (SongItem const& other) const
{
return id < other.id;
@@ -54,10 +65,15 @@ struct SongItems
There will be no check if artist and title already exist - if you
need that you want addSong().
*/
- void addSongItem(std::string const& artist, std::string const& title, int id = -1);
+ int addSongItem(std::string const& artist, std::string const& title, int id = -1);
/**Adds or Links an already existing song with an songitem.
+
The id will be assigned and artist and title will be filled in.
- If there is already a song with the same artist and title nothing will be done.
+ If there is already a song with the same artist and title the existing
+ will be used.
+
+ Afterwards the pointer to the song will be stored for entire available
+ song information.
lookup is used internally to achieve that.
*/
@@ -65,10 +81,10 @@ struct SongItems
/**Lookup a songid for a specific song.
@return -1 if no song found.*/
- int lookup(boost::shared_ptr<Song> song);
+ int lookup(boost::shared_ptr<Song> song) const;
private:
- int assign_id_internal();
+ int assign_id_internal() const;
typedef std::set<SongItem> songs_t;
songs_t m_songs;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:59
|
Module: performous
Branch: master
Commit: 7da4f8864081ce4b74128dced6f6657de9f44cf0
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 18:43:01 2009 +0100
Something like that for path
---
game/players.cc | 15 +--------------
1 files changed, 1 insertions(+), 14 deletions(-)
diff --git a/game/players.cc b/game/players.cc
index 683a1e6..f840ded 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -85,20 +85,7 @@ void Players::addPlayer (std::string const& name, std::string const& picture, in
if (pi.picture != "") // no picture, so don't search path
{
- /* TODO: add again check for pictures
- ConfigItem::StringList const& sl = config["system/path_pictures"].sl();
- typedef std::set<fs::path> dirs;
- dirs d;
- std::transform(sl.begin(), sl.end(), std::inserter(d, d.end()), pathMangle);
-
- for (dirs::const_iterator it = d.begin(); it != d.end(); ++it) {
- if (!fs::exists(*it)) continue; // as long as it does not exists
- pi.path = it->file_string();
- }
-
- if (pi.path != "") std::cout << "Found " << pi.picture << " in " << pi.path << std::endl;
- else std::cout << "Not found " << pi.picture << std::endl;
- */
+ // pi.picture = getXdgPath(fs::path("pictures") / pi.picture);
}
m_dirty = true;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:57
|
Module: performous
Branch: master
Commit: b1b9a58df683e2d4120f0fe9fbb5a4228ac82a53
Author: Markus Raab <un...@ma...>
Date: Thu Nov 12 09:00:06 2009 +0100
track names are lowercase
---
data/database.xml | 2 +-
game/hiscore.cc | 2 +-
game/hiscore.hh | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/data/database.xml b/data/database.xml
index 8116110..725b6e2 100644
--- a/data/database.xml
+++ b/data/database.xml
@@ -10,7 +10,7 @@
</player>
</players>
<hiscores> <!-- a list of highscores -->
- <hiscore songid="123" playerid="123" track="VOCALS">600</hiscore>
+ <hiscore songid="123" playerid="123" track="vocals">600</hiscore>
</hiscores>
</performous>
<!--
diff --git a/game/hiscore.cc b/game/hiscore.cc
index 67f2e3e..a74ec5e 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -64,7 +64,7 @@ void Hiscore::load(xmlpp::NodeSet const& n) {
int score = boost::lexical_cast<int>(tn->get_content());
std::string track;
- if (!a_track) track = "VOCALS";
+ if (!a_track) track = "vocals";
else track = a_track->get_value();
addHiscore(score, playerid, songid, track);
diff --git a/game/hiscore.hh b/game/hiscore.hh
index df673a9..951fe16 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -51,7 +51,7 @@ class Hiscore
@return true if the score make it into the top.
@return false if addNewHiscore does not make sense
for that score.*/
- bool reachedHiscore(int score, int songid, std::string const& track = "VOCALS");
+ bool reachedHiscore(int score, int songid, std::string const& track = "vocals");
/**Add a specific highscore into the list.
@@ -64,7 +64,7 @@ class Hiscore
in its valid interval. If one of this conditions is not net a
HiscoreException will be raised.
*/
- void addHiscore(int score, int playerid, int songid, std::string const& track = "VOCALS");
+ void addHiscore(int score, int playerid, int songid, std::string const& track = "vocals");
private:
typedef std::multiset<HiscoreItem>hiscore_t;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:55
|
Module: performous
Branch: master
Commit: 935780efd7df860689b8eb5849844144bbad7726
Author: Markus Raab <un...@ma...>
Date: Thu Nov 12 08:25:39 2009 +0100
documentation
+ formatting
---
docs/DeveloperReadme.txt | 9 +++++++++
game/database.hh | 31 +++++++++++++++++++++++++++++--
game/hiscore.cc | 12 ++++--------
game/hiscore.hh | 16 ++++++++++++++--
game/players.cc | 9 +++------
5 files changed, 59 insertions(+), 18 deletions(-)
diff --git a/docs/DeveloperReadme.txt b/docs/DeveloperReadme.txt
index 3529a4d..84d2a5a 100644
--- a/docs/DeveloperReadme.txt
+++ b/docs/DeveloperReadme.txt
@@ -47,6 +47,15 @@ their value smoothly over time. This effect is most prominent it the song
browser, but it is used in various other parts of the UI and we also abuse it
as a simple timer in some places.
+The database is the access point to static information. There you can add
+players, songitems and - the reason why it was introduced - hiscores. It is also
+a facade for Players (players.cc/hh), hiscore (hiscore.cc/hh)
+and songitems (songitems.cc/hh). Don't confuse songs with songitems. In fact
+they both hold a shared_ptr to the same song (song.cc/hh), but only the songitems
+have a unique id which is used in the highscore. On the other hand the
+songs (songs.cc/hh) are used for the song browser. There is also the code
+for iterating above all files and call the song-parser.
+
The game logic runs as a separate thread so that slow OpenGL rendering or other
such factors don't disturb it (engine.cc/hh). This engine runs in an endless
loop, polling the audio analyzer code (pitch.cc/hh) for data that it then uses
diff --git a/game/database.hh b/game/database.hh
index eb014c3..1adec0a 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -9,14 +9,25 @@
#include "fs.hh"
/**Access to a database for performous which holds
- Player-, Hiscore-, Song- and Partydata.
+ Player-, Hiscore-, Song-, Track- and (in future)
+ Partydata.
+
+ This is a facade for Players, Hiscore and SongItems.
Will be initialized at the very beginning of
the program.*/
class Database
{
public:
+ /**Will try to load the database.
+ If it does not succeed the error will be ignored.
+ Only some information will be printed on stderr.
+ */
Database (fs::path filename);
+ /**Will try to save the database.
+ This will even be done if the loading failed.
+ It tries to create the directory above the file.
+ */
~Database ();
/**Loads the whole database from xml.
@@ -28,15 +39,31 @@ class Database
@post filled database
*/
void load();
+ /**Saves the whole database to xml.
+ Will write out everything to the file given in the constructor, @see file()
+ */
void save();
+ /**The filename given by the constructor.
+ @returns the filename used for the database.
+ */
std::string file();
- public: // methods for player management
+ public: // methods for database management
+ /**A facade for Players::addPlayer.*/
void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
+ /**A facade for SongItems::addSong.*/
void addSong (boost::shared_ptr<Song> s);
+ /**A facade for Hiscore::addHiscore.
+ The ids will be looked up first by using the songs and current players data.*/
void addHiscore (boost::shared_ptr<Song> s);
+
+ public: // methods for database queries
+ /**A facade for Hiscore::reachedHiscore.
+ Queries if the current player with current score has reached a new hiscore
+ for the song s.
+ */
bool reachedHiscore (boost::shared_ptr<Song> s);
friend int test(std::string const&, int);
diff --git a/game/hiscore.cc b/game/hiscore.cc
index 1c5fb13..67f2e3e 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -10,8 +10,7 @@
Hiscore::Hiscore()
{}
-bool Hiscore::reachedHiscore(int score, int songid, std::string const& track)
-{
+bool Hiscore::reachedHiscore(int score, int songid, std::string const& track) {
if (score < 0) throw HiscoreException("Score negativ overflow");
if (score > 10000) throw HiscoreException("Score positive overflow");
@@ -29,8 +28,7 @@ bool Hiscore::reachedHiscore(int score, int songid, std::string const& track)
return true; // nothing found for that song -> true
}
-void Hiscore::addHiscore(int score, int playerid, int songid, std::string const& track)
-{
+void Hiscore::addHiscore(int score, int playerid, int songid, std::string const& track) {
HiscoreItem hi;
if (score < 0) throw HiscoreException("Score negativ overflow");
if (score > 10000) throw HiscoreException("Score positive overflow");
@@ -48,8 +46,7 @@ void Hiscore::addHiscore(int score, int playerid, int songid, std::string const&
m_hiscore.insert(hi);
}
-void Hiscore::load(xmlpp::NodeSet const& n)
-{
+void Hiscore::load(xmlpp::NodeSet const& n) {
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
@@ -74,8 +71,7 @@ void Hiscore::load(xmlpp::NodeSet const& n)
}
}
-void Hiscore::save(xmlpp::Element *hiscores)
-{
+void Hiscore::save(xmlpp::Element *hiscores) {
for (hiscore_t::const_iterator it = m_hiscore.begin(); it != m_hiscore.end(); ++it)
{
xmlpp::Element* hiscore = hiscores->add_child("hiscore");
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 665854b..df673a9 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -34,7 +34,7 @@ struct HiscoreItem {
class Hiscore
{
-public:
+ public:
Hiscore ();
void load(xmlpp::NodeSet const& n);
@@ -52,8 +52,20 @@ public:
@return false if addNewHiscore does not make sense
for that score.*/
bool reachedHiscore(int score, int songid, std::string const& track = "VOCALS");
+
+ /**Add a specific highscore into the list.
+
+ @pre Hiscore is added.
+
+ There is no check regarding if it is useful to add this hiscore.
+ To check this, use reachedHiscore() first.
+
+ The method will check if all ids are non-negative and the score
+ in its valid interval. If one of this conditions is not net a
+ HiscoreException will be raised.
+ */
void addHiscore(int score, int playerid, int songid, std::string const& track = "VOCALS");
-private:
+ private:
typedef std::multiset<HiscoreItem>hiscore_t;
hiscore_t m_hiscore;
diff --git a/game/players.cc b/game/players.cc
index f840ded..1a0a764 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -25,8 +25,7 @@ Players::~Players()
{ }
void Players::load(xmlpp::NodeSet const& n) {
- for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
- {
+ for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it) {
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
xmlpp::Attribute* a_name = element.get_attribute("name");
if (!a_name) throw PlayersException("Attribute name not found");
@@ -47,8 +46,7 @@ void Players::load(xmlpp::NodeSet const& n) {
}
void Players::save(xmlpp::Element *players) {
- for (players_t::const_iterator it = m_players.begin(); it!=m_players.end(); ++it)
- {
+ for (players_t::const_iterator it = m_players.begin(); it!=m_players.end(); ++it) {
xmlpp::Element* player = players->add_child("player");
player->set_attribute("name", it->name);
player->set_attribute("id", boost::lexical_cast<std::string>(it->id));
@@ -65,8 +63,7 @@ void Players::update() {
}
int Players::lookup(std::string const& name) {
- for (players_t::const_iterator it = m_players.begin(); it != m_players.end(); ++it)
- {
+ for (players_t::const_iterator it = m_players.begin(); it != m_players.end(); ++it) {
if (it->name == name) return it->id;
}
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:52
|
Module: performous
Branch: master
Commit: 7424efe9ca0a05efa246e880d98d8d2636832df6
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 16:51:27 2009 +0100
test program for reaching new hiscore
don't score reverse: score already sorted correctly
---
game/database.cc | 28 +++++++++++++++++++---------
game/database.hh | 2 +-
game/hiscore.cc | 2 +-
game/hiscore.hh | 3 ++-
game/players.hh | 2 +-
5 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index 5b01f36..d9906dc 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -82,25 +82,35 @@ bool Database::reachedHiscore (boost::shared_ptr<Song> s) {
return m_hiscores.reachedHiscore(score, songid);
}
-int test() {
+int test(std::string const& name, int score) {
Database d("database.xml");
- d.addPlayer("Markus", "m.jpg");
+ // d.addPlayer("Markus", "m.jpg");
boost::shared_ptr<Song> s(new Song("/usr/share/songs/ABBA/ABBA - Dancing Queen/", "ABBA - Dancing Queen.txt"));
d.addSong(s);
PlayerItem pi;
- pi.name = "Markus";
+ pi.name = name;
d.m_players.m_filtered.push_back(pi);
- d.m_players.scores.push_back(5000);
+ d.m_players.scores.push_back(score);
- if (d.reachedHiscore(s)) std::cout << "Reached a new Hiscore" << std::endl;
-
- d.addHiscore(s);
+ if (d.reachedHiscore(s))
+ {
+ std::cout << "Reached a new Hiscore" << std::endl;
+ d.addHiscore(s);
+ }
return 0;
}
-int main() {
- return test();
+#include "boost/lexical_cast.hpp"
+
+int main(int argc, char**argv) {
+
+ if (argc < 3) return 3;
+
+ std::string name = argv[1];
+ int score = boost::lexical_cast<int>(argv[2]);
+
+ return test(name, score);
}
diff --git a/game/database.hh b/game/database.hh
index 2018464..eb014c3 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -39,7 +39,7 @@ class Database
void addHiscore (boost::shared_ptr<Song> s);
bool reachedHiscore (boost::shared_ptr<Song> s);
- friend int test();
+ friend int test(std::string const&, int);
private:
fs::path m_filename;
diff --git a/game/hiscore.cc b/game/hiscore.cc
index b38e771..1c5fb13 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -18,7 +18,7 @@ bool Hiscore::reachedHiscore(int score, int songid, std::string const& track)
if (score < 500) return false; // come on, did you even try to sing?
int counter = 0;
- for (hiscore_t::const_reverse_iterator it = m_hiscore.rbegin(); it != m_hiscore.rend(); ++it)
+ for (hiscore_t::const_iterator it = m_hiscore.begin(); it != m_hiscore.end(); ++it)
{
if (it->songid != songid) continue;
if (it->track != track) continue;
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 030b567..665854b 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -24,7 +24,8 @@ struct HiscoreItem {
std::string track;
- /**Operator for sorting by score.*/
+ /**Operator for sorting by score.
+ Reverse order, so that highest is first!*/
bool operator < (HiscoreItem const& other) const
{
return other.score < score;
diff --git a/game/players.hh b/game/players.hh
index 3dff279..e739b0f 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -54,7 +54,7 @@ class Players: boost::noncopyable {
bool m_dirty;
- friend int test();
+ friend int test(std::string const&, int);
public:
cur_players_t cur;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:50
|
Module: performous
Branch: master
Commit: 1ca784a70b8fc4c91695759027eb4fd094b8c662
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 16:31:19 2009 +0100
Forget to close IF in packaging
---
cmake/performous-packaging.cmake | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/cmake/performous-packaging.cmake b/cmake/performous-packaging.cmake
index 256aad1..d987ed5 100644
--- a/cmake/performous-packaging.cmake
+++ b/cmake/performous-packaging.cmake
@@ -64,7 +64,7 @@ if(UNIX)
endif("${LSB_DISTRIB}" MATCHES "Ubuntu9.10")
if("${LSB_DISTRIB}" MATCHES "Debian5.*")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl1.2debian, libcairo2, librsvg2-2, libboost-dev, libavcodec51, libavformat52, libswscale0, libmagick++10, libxml++2.6-2, libglew1.5")
- endif("${LSB_DISTRIB}" MATCHES "Ubuntu9.10")
+ endif("${LSB_DISTRIB}" MATCHES "Debian5.*")
if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
message("WARNING: ${LSB_DISTRIB} not supported yet.\nPlease set deps in cmake/performous-packaging.cmake before packaging.")
endif(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:48
|
Module: performous
Branch: master
Commit: 96e393748946aabe6b875ca0108cd0e1ce65e8de
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 16:29:07 2009 +0100
reached Hiscore
checker if a score is in a new hiscore implemented
warning! contains bugs...
---
game/database.cc | 8 ++++++++
game/database.hh | 1 +
game/hiscore.cc | 19 +++++++++++++++++++
game/hiscore.hh | 12 ++++++++++++
4 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index 305aeda..5b01f36 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -76,6 +76,12 @@ void Database::addHiscore (boost::shared_ptr<Song> s) {
m_hiscores.addHiscore(score, playerid, songid);
}
+bool Database::reachedHiscore (boost::shared_ptr<Song> s) {
+ int score = m_players.scores.front();
+ int songid = m_songs.lookup(s);
+ return m_hiscores.reachedHiscore(score, songid);
+}
+
int test() {
Database d("database.xml");
d.addPlayer("Markus", "m.jpg");
@@ -88,6 +94,8 @@ int test() {
d.m_players.m_filtered.push_back(pi);
d.m_players.scores.push_back(5000);
+ if (d.reachedHiscore(s)) std::cout << "Reached a new Hiscore" << std::endl;
+
d.addHiscore(s);
return 0;
diff --git a/game/database.hh b/game/database.hh
index 714234a..2018464 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -37,6 +37,7 @@ class Database
void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
void addSong (boost::shared_ptr<Song> s);
void addHiscore (boost::shared_ptr<Song> s);
+ bool reachedHiscore (boost::shared_ptr<Song> s);
friend int test();
diff --git a/game/hiscore.cc b/game/hiscore.cc
index ff28b25..b38e771 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -10,6 +10,25 @@
Hiscore::Hiscore()
{}
+bool Hiscore::reachedHiscore(int score, int songid, std::string const& track)
+{
+ if (score < 0) throw HiscoreException("Score negativ overflow");
+ if (score > 10000) throw HiscoreException("Score positive overflow");
+
+ if (score < 500) return false; // come on, did you even try to sing?
+
+ int counter = 0;
+ for (hiscore_t::const_reverse_iterator it = m_hiscore.rbegin(); it != m_hiscore.rend(); ++it)
+ {
+ if (it->songid != songid) continue;
+ if (it->track != track) continue;
+ if (score > it->score) return true; // seems like you are in top 3!
+ else ++counter;
+ if (counter == 3) return false; // not in top 3 -> leave
+ }
+ return true; // nothing found for that song -> true
+}
+
void Hiscore::addHiscore(int score, int playerid, int songid, std::string const& track)
{
HiscoreItem hi;
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 00f33c2..030b567 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -39,6 +39,18 @@ public:
void load(xmlpp::NodeSet const& n);
void save(xmlpp::Element *players);
+ /**Check if you reached a new highscore.
+
+ You must be in TOP 3 of a specific song to enter the highscore list.
+ This is because it will take forever to fill more.
+ And people refuse to enter their names if they are not close to the top.
+
+ @param score is a value between 0 and 10000
+ values below 500 will lead to returning false
+ @return true if the score make it into the top.
+ @return false if addNewHiscore does not make sense
+ for that score.*/
+ bool reachedHiscore(int score, int songid, std::string const& track = "VOCALS");
void addHiscore(int score, int playerid, int songid, std::string const& track = "VOCALS");
private:
typedef std::multiset<HiscoreItem>hiscore_t;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:47
|
Module: performous
Branch: master
Commit: f00652f3e152bd331356bfcc369b1bd7e2e5ac1a
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 16:12:23 2009 +0100
test case added
---
game/database.cc | 14 ++++++++++++--
game/database.hh | 2 ++
game/players.hh | 2 ++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index c8d67b6..305aeda 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -76,13 +76,23 @@ void Database::addHiscore (boost::shared_ptr<Song> s) {
m_hiscores.addHiscore(score, playerid, songid);
}
-// Test program for Database
-int main() {
+int test() {
Database d("database.xml");
d.addPlayer("Markus", "m.jpg");
boost::shared_ptr<Song> s(new Song("/usr/share/songs/ABBA/ABBA - Dancing Queen/", "ABBA - Dancing Queen.txt"));
d.addSong(s);
+ PlayerItem pi;
+ pi.name = "Markus";
+ d.m_players.m_filtered.push_back(pi);
+ d.m_players.scores.push_back(5000);
+
d.addHiscore(s);
+
+ return 0;
+}
+
+int main() {
+ return test();
}
diff --git a/game/database.hh b/game/database.hh
index 851e856..714234a 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -38,6 +38,8 @@ class Database
void addSong (boost::shared_ptr<Song> s);
void addHiscore (boost::shared_ptr<Song> s);
+ friend int test();
+
private:
fs::path m_filename;
diff --git a/game/players.hh b/game/players.hh
index b035926..3dff279 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -54,6 +54,8 @@ class Players: boost::noncopyable {
bool m_dirty;
+ friend int test();
+
public:
cur_players_t cur;
cur_scores_t scores;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:44
|
Module: performous
Branch: master
Commit: ef302080ba5424d521db1dc66d13e87b72a9e537
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 15:46:33 2009 +0100
Database now has the basic add* features
some style correction
check correct values in addHiscore
default track VOCALS
lookup() methods added
collate corrected
---
game/database.cc | 20 ++++++++++++++++++--
game/database.hh | 14 ++++++--------
game/hiscore.cc | 8 ++++++--
game/hiscore.hh | 2 +-
game/players.cc | 12 ++++++++++--
game/players.hh | 16 +++++++++++++++-
game/songitems.cc | 23 +++++++++++------------
game/songitems.hh | 20 +++++++++++++++++++-
8 files changed, 86 insertions(+), 29 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index c71c21f..c8d67b6 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -61,12 +61,28 @@ std::string Database::file() {
return m_filename.string();
}
+void Database::addPlayer (std::string const& name, std::string const& picture, int id) {
+ m_players.addPlayer(name, picture, id);
+}
+
+void Database::addSong (boost::shared_ptr<Song> s) {
+ m_songs.addSong(s);
+}
+
+void Database::addHiscore (boost::shared_ptr<Song> s) {
+ int playerid = m_players.lookup(m_players.current().name);
+ int score = m_players.scores.front();
+ int songid = m_songs.lookup(s);
+ m_hiscores.addHiscore(score, playerid, songid);
+}
+
// Test program for Database
-int main()
-{
+int main() {
Database d("database.xml");
d.addPlayer("Markus", "m.jpg");
boost::shared_ptr<Song> s(new Song("/usr/share/songs/ABBA/ABBA - Dancing Queen/", "ABBA - Dancing Queen.txt"));
d.addSong(s);
+
+ d.addHiscore(s);
}
diff --git a/game/database.hh b/game/database.hh
index fd0f553..851e856 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -15,7 +15,7 @@
the program.*/
class Database
{
-public:
+ public:
Database (fs::path filename);
~Database ();
@@ -32,15 +32,13 @@ public:
std::string file();
-public: // methods for player management
+ public: // methods for player management
- void addPlayer (std::string const& name, std::string const& picture = "", int id = -1)
- { m_players.addPlayer(name, picture, id); }
+ void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
+ void addSong (boost::shared_ptr<Song> s);
+ void addHiscore (boost::shared_ptr<Song> s);
- void addSong (boost::shared_ptr<Song>s)
- { m_songs.addSong(s); }
-
-private:
+ private:
fs::path m_filename;
Players m_players;
diff --git a/game/hiscore.cc b/game/hiscore.cc
index 326e3c3..ff28b25 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -13,11 +13,17 @@ Hiscore::Hiscore()
void Hiscore::addHiscore(int score, int playerid, int songid, std::string const& track)
{
HiscoreItem hi;
+ if (score < 0) throw HiscoreException("Score negativ overflow");
+ if (score > 10000) throw HiscoreException("Score positive overflow");
hi.score = score;
+ if (playerid < 0) throw HiscoreException("No player given");
hi.playerid = playerid;
+
+ if (songid < 0) throw HiscoreException("No song given");
hi.songid = songid;
+ if (track.empty()) throw HiscoreException("No track given");
hi.track = track;
m_hiscore.insert(hi);
@@ -40,8 +46,6 @@ void Hiscore::load(xmlpp::NodeSet const& n)
xmlpp::TextNode* tn = element.get_child_text();
if (!tn) throw HiscoreException("Score not found");
int score = boost::lexical_cast<int>(tn->get_content());
- if (score < 0) throw HiscoreException("Score negativ overflow");
- if (score > 10000) throw HiscoreException("Score positive overflow");
std::string track;
if (!a_track) track = "VOCALS";
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 88261c4..00f33c2 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -39,7 +39,7 @@ public:
void load(xmlpp::NodeSet const& n);
void save(xmlpp::Element *players);
- void addHiscore(int score, int playerid, int songid, std::string const& track);
+ void addHiscore(int score, int playerid, int songid, std::string const& track = "VOCALS");
private:
typedef std::multiset<HiscoreItem>hiscore_t;
diff --git a/game/players.cc b/game/players.cc
index c1d4b50..683a1e6 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -64,6 +64,15 @@ void Players::update() {
if (m_dirty) filter_internal();
}
+int Players::lookup(std::string const& name) {
+ for (players_t::const_iterator it = m_players.begin(); it != m_players.end(); ++it)
+ {
+ if (it->name == name) return it->id;
+ }
+
+ return -1;
+}
+
void Players::addPlayer (std::string const& name, std::string const& picture, int id) {
PlayerItem pi;
pi.id = id;
@@ -107,8 +116,7 @@ void Players::setFilter(std::string const& val) {
filter_internal();
}
-int Players::assign_id_internal()
-{
+int Players::assign_id_internal() {
players_t::const_reverse_iterator it = m_players.rbegin();
if (it != m_players.rend()) return it->id+1;
else return 1; // empty set
diff --git a/game/players.hh b/game/players.hh
index 51fc606..b035926 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -25,7 +25,19 @@ struct PlayersException: public std::runtime_error {
/**A collection of all Players.
The current players plugged in a song can
- be retrieved with Engine::getPlayers().*/
+ be retrieved with Engine::getPlayers().
+
+ There are 3 different views united in that collection.
+ There is a full players list which are used by the
+ database, but also for the filtering.
+
+ The filtered list is used to show players in
+ the screen_players.
+
+ The current lists (Players and scores) are used
+ to pass the information which players have won
+ to the ScoreScreen and then to the players window.
+ */
class Players: boost::noncopyable {
private:
typedef std::set<PlayerItem> players_t;
@@ -55,6 +67,8 @@ class Players: boost::noncopyable {
void update();
+ /// lookup a playerid using the players name
+ int lookup(std::string const& name);
/// add a player with a displayed name and an optional picture; if no id is given one will be assigned
void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
diff --git a/game/songitems.cc b/game/songitems.cc
index 4b1c522..99b4eba 100644
--- a/game/songitems.cc
+++ b/game/songitems.cc
@@ -10,8 +10,7 @@
#include <libxml++/libxml++.h>
-void SongItems::load(xmlpp::NodeSet const& n)
-{
+void SongItems::load(xmlpp::NodeSet const& n) {
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
@@ -29,8 +28,7 @@ void SongItems::load(xmlpp::NodeSet const& n)
}
}
-void SongItems::save(xmlpp::Element *songs)
-{
+void SongItems::save(xmlpp::Element *songs) {
for (songs_t::const_iterator it = m_songs.begin(); it != m_songs.end(); ++it)
{
xmlpp::Element* song = songs->add_child("song");
@@ -40,8 +38,7 @@ void SongItems::save(xmlpp::Element *songs)
}
}
-void SongItems::addSongItem(std::string const& artist, std::string const& title, int id)
-{
+void SongItems::addSongItem(std::string const& artist, std::string const& title, int id) {
SongItem si;
if (id==-1) id = assign_id_internal();
si.id = id;
@@ -56,17 +53,19 @@ void SongItems::addSongItem(std::string const& artist, std::string const& title,
}
}
-void SongItems::addSong(boost::shared_ptr<Song> song)
-{
+void SongItems::addSong(boost::shared_ptr<Song> song) {
+ if (lookup(song) == -1) addSongItem(song->artist, song->title);
+}
+
+int SongItems::lookup(boost::shared_ptr<Song> song) {
for (songs_t::iterator it = m_songs.begin(); it != m_songs.end(); ++it)
{
- if (song->collateByArtistOnly == it->artist && song->collateByTitleOnly == it->title) return;
+ if (song->collateByArtistOnly == it->artist && song->collateByTitleOnly == it->title) return it->id;
}
- addSongItem(song->artist, song->title);
+ return -1;
}
-int SongItems::assign_id_internal()
-{
+int SongItems::assign_id_internal() {
songs_t::const_reverse_iterator it = m_songs.rbegin();
if (it != m_songs.rend()) return it->id+1;
else return 1; // empty set
diff --git a/game/songitems.hh b/game/songitems.hh
index d51c03d..9b1f2c5 100644
--- a/game/songitems.hh
+++ b/game/songitems.hh
@@ -32,6 +32,18 @@ struct SongItem
}
};
+/**A list of songs for the database.
+
+ Every song has a unique id managed by that database.
+ This class was introduced to hide the implementation
+ detail which data structure is used for the list away.
+
+ Currently a std::set is used, which makes both addSongItem()
+ and addSong() slow. The only advantage is that the id is
+ unique and it is cheap to get a new unique id.
+
+ When one of the methods is to slow, it can be optimized
+ easily. */
struct SongItems
{
void load(xmlpp::NodeSet const& n);
@@ -46,10 +58,16 @@ struct SongItems
/**Adds or Links an already existing song with an songitem.
The id will be assigned and artist and title will be filled in.
If there is already a song with the same artist and title nothing will be done.
+
+ lookup is used internally to achieve that.
*/
void addSong(boost::shared_ptr<Song> song);
-private:
+ /**Lookup a songid for a specific song.
+ @return -1 if no song found.*/
+ int lookup(boost::shared_ptr<Song> song);
+
+ private:
int assign_id_internal();
typedef std::set<SongItem> songs_t;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:43
|
Module: performous
Branch: master
Commit: f65ed74215f3747e0f2c47e8a94a20f6ae8ebd05
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 15:15:15 2009 +0100
addSong now works
---
game/database.cc | 3 +++
game/database.hh | 3 +++
game/song.cc | 4 ++++
game/song.hh | 2 ++
game/songitems.cc | 2 +-
5 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index 6190ffb..c71c21f 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -66,4 +66,7 @@ int main()
{
Database d("database.xml");
d.addPlayer("Markus", "m.jpg");
+
+ boost::shared_ptr<Song> s(new Song("/usr/share/songs/ABBA/ABBA - Dancing Queen/", "ABBA - Dancing Queen.txt"));
+ d.addSong(s);
}
diff --git a/game/database.hh b/game/database.hh
index ba74745..fd0f553 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -37,6 +37,9 @@ public: // methods for player management
void addPlayer (std::string const& name, std::string const& picture = "", int id = -1)
{ m_players.addPlayer(name, picture, id); }
+ void addSong (boost::shared_ptr<Song>s)
+ { m_songs.addSong(s); }
+
private:
fs::path m_filename;
diff --git a/game/song.cc b/game/song.cc
index d75d92a..5135535 100644
--- a/game/song.cc
+++ b/game/song.cc
@@ -15,7 +15,9 @@ void Song::reload(bool errorIgnore) {
title.clear();
artist.clear();
collateByTitle.clear();
+ collateByTitleOnly.clear();
collateByArtist.clear();
+ collateByArtistOnly.clear();
text.clear();
creator.clear();
music.clear();
@@ -34,7 +36,9 @@ void Song::reload(bool errorIgnore) {
void Song::collateUpdate() {
collateByTitle = collate(title + artist) + '\0' + filename;
+ collateByTitleOnly = collate(title);
collateByArtist = collate(artist + title) + '\0' + filename;
+ collateByArtistOnly = collate(artist);
}
std::string Song::collate(std::string const& str) {
diff --git a/game/song.hh b/game/song.hh
index f02bf87..983dc3f 100644
--- a/game/song.hh
+++ b/game/song.hh
@@ -60,8 +60,10 @@ class Song: boost::noncopyable {
std::string video; ///< video
/// Variables used for comparisons (sorting)
std::string collateByTitle;
+ std::string collateByTitleOnly;
/// Variables used for comparisons (sorting)
std::string collateByArtist;
+ std::string collateByArtistOnly;
/** Rebuild collate variables from other strings **/
void collateUpdate();
/** Convert a string to its collate form **/
diff --git a/game/songitems.cc b/game/songitems.cc
index db61ff3..4b1c522 100644
--- a/game/songitems.cc
+++ b/game/songitems.cc
@@ -60,7 +60,7 @@ void SongItems::addSong(boost::shared_ptr<Song> song)
{
for (songs_t::iterator it = m_songs.begin(); it != m_songs.end(); ++it)
{
- if (song->artist == it->artist && song->title == it->title) return;
+ if (song->collateByArtistOnly == it->artist && song->collateByTitleOnly == it->title) return;
}
addSongItem(song->artist, song->title);
}
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:42
|
Module: performous
Branch: master
Commit: 24c0972ea4ddc8a59a65a1a6d3680aafb051d236
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 11:58:37 2009 +0100
added songitems
---
game/database.cc | 6 +++++
game/database.hh | 4 ++-
game/players.hh | 3 +-
game/songitems.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
game/songitems.hh | 43 +++++++++++++++++++++++++++++++++++++
5 files changed, 115 insertions(+), 2 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index 2a393ff..6190ffb 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -31,6 +31,9 @@ void Database::load() {
xmlpp::NodeSet hiscores = nodeRoot->find("/performous/hiscores/hiscore");
m_hiscores.load(hiscores);
+
+ xmlpp::NodeSet songs = nodeRoot->find("/performous/songs/song");
+ m_songs.load(songs);
}
void Database::save() {
@@ -43,6 +46,9 @@ void Database::save() {
xmlpp::Element *hiscores = nodeRoot->add_child("hiscores");
m_hiscores.save(hiscores);
+ xmlpp::Element *songs = nodeRoot->add_child("songs");
+ m_songs.save(songs);
+
if (!exists(m_filename.parent_path()) && !m_filename.parent_path().empty())
{
std::cout << "Will create directory: " << m_filename.parent_path() << std::endl;
diff --git a/game/database.hh b/game/database.hh
index 8ceb4d7..ba74745 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -4,6 +4,7 @@
#include "players.hh"
#include "hiscore.hh"
+#include "songitems.hh"
#include "fs.hh"
@@ -23,7 +24,7 @@ public:
@exception xmlpp exceptions may be thrown on any parse errors
@exception PlayersException if some conditions of players fail (e.g. no id)
@exception HiscoreException if some hiscore conditions fail (e.g. score too high)
- @exception SongsExceptions if some songs conditions fail (e.g. no id)
+ @exception SongItemsExceptions if some songs conditions fail (e.g. no id)
@post filled database
*/
void load();
@@ -41,4 +42,5 @@ private:
Players m_players;
Hiscore m_hiscores;
+ SongItems m_songs;
};
diff --git a/game/players.hh b/game/players.hh
index 17cc6d3..51fc606 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -4,12 +4,13 @@
#include <list>
#include <vector>
#include <string>
+#include <stdexcept>
#include <boost/noncopyable.hpp>
+#include "fs.hh"
#include "player.hh"
#include "animvalue.hh"
-#include "fs.hh"
namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet; }
diff --git a/game/songitems.cc b/game/songitems.cc
new file mode 100644
index 0000000..775661c
--- /dev/null
+++ b/game/songitems.cc
@@ -0,0 +1,61 @@
+#include "songitems.hh"
+
+#include <string>
+
+#include <boost/lexical_cast.hpp>
+
+#include <libxml++/libxml++.h>
+
+
+void SongItems::load(xmlpp::NodeSet const& n)
+{
+ for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
+ {
+ xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
+
+ xmlpp::Attribute* a_id = element.get_attribute("id");
+ if (!a_id) throw SongItemsException("No attribute id");
+
+ xmlpp::Attribute* a_artist = element.get_attribute("artist");
+ if (!a_artist) throw SongItemsException("No attribute artist");
+
+ xmlpp::Attribute* a_title = element.get_attribute("title");
+ if (!a_title) throw SongItemsException("No attribute title");
+
+ addSong(a_artist->get_value(), a_title->get_value(), boost::lexical_cast<int>(a_id->get_value()));
+ }
+}
+
+void SongItems::save(xmlpp::Element *songs)
+{
+ for (songs_t::const_iterator it = m_songs.begin(); it != m_songs.end(); ++it)
+ {
+ xmlpp::Element* song = songs->add_child("song");
+ song->set_attribute("id", boost::lexical_cast<std::string>(it->id));
+ song->set_attribute("artist", it->artist);
+ song->set_attribute("title", it->title);
+ }
+}
+
+void SongItems::addSong(std::string const& artist, std::string const& title, int id)
+{
+ SongItem si;
+ if (id==-1) id = assign_id_internal();
+ si.id = id;
+ si.artist = artist;
+ si.title = title;
+
+ std::pair<songs_t::iterator, bool> ret = m_songs.insert(si);
+ if (!ret.second)
+ {
+ si.id = assign_id_internal();
+ m_songs.insert(si); // now do the insert with the fresh id
+ }
+}
+
+int SongItems::assign_id_internal()
+{
+ songs_t::const_reverse_iterator it = m_songs.rbegin();
+ if (it != m_songs.rend()) return it->id+1;
+ else return 1; // empty set
+}
diff --git a/game/songitems.hh b/game/songitems.hh
new file mode 100644
index 0000000..ee089b6
--- /dev/null
+++ b/game/songitems.hh
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <set>
+#include <vector>
+#include <string>
+#include <stdexcept>
+
+namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet; }
+
+/**Exception which will be thrown when loading or
+ saving Players fails.*/
+struct SongItemsException: public std::runtime_error {
+ SongItemsException (std::string const& msg) :
+ runtime_error(msg)
+ {}
+};
+
+struct SongItem
+{
+ int id; // TODO use a PUID instead (LibOFA)
+
+ std::string artist;
+ std::string title;
+
+ bool operator< (SongItem const& other) const
+ {
+ return id < other.id;
+ }
+};
+
+struct SongItems
+{
+ void load(xmlpp::NodeSet const& n);
+ void save(xmlpp::Element *players);
+
+ void addSong(std::string const& artist, std::string const& title, int id = -1);
+
+private:
+ int assign_id_internal();
+
+ typedef std::set<SongItem> songs_t;
+ songs_t m_songs;
+};
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:41
|
Module: performous Branch: master Commit: 90c9cacb0fb89ac1547bca30d2602687594e2871 Author: Markus Raab <un...@ma...> Date: Wed Nov 11 13:00:27 2009 +0100 Merge branch 'master' of git://git.performous.org/gitroot/performous/performous --- |
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:39
|
Module: performous
Branch: master
Commit: 36ddd9d00735ad724aae153c40d05ea9f80b5aa1
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 12:38:01 2009 +0100
performous compiles from now on again
(BUT it is only a small test program for the database)
difference between addSong and addSongItem introduced
---
game/CMakeLists.txt | 3 ++-
game/songitems.cc | 20 ++++++++++++++++----
game/songitems.hh | 16 +++++++++++++++-
3 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 3b191fa..4f48dfa 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.6)
-FILE(GLOB SOURCE_FILES "*.cc")
+# FILE(GLOB SOURCE_FILES "*.cc")
+SET(SOURCE_FILES hiscore.cc database.cc players.cc configuration.cc fs.cc unicode.cc songitems.cc song.cc notes.cc songparser-ini.cc songparser-txt.cc midifile.cc)
FILE(GLOB HEADER_FILES "*.hh")
set(SOURCES ${SOURCE_FILES} ${HEADER_FILES})
diff --git a/game/songitems.cc b/game/songitems.cc
index 775661c..db61ff3 100644
--- a/game/songitems.cc
+++ b/game/songitems.cc
@@ -1,7 +1,10 @@
#include "songitems.hh"
+#include "unicode.hh"
+
#include <string>
+#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <libxml++/libxml++.h>
@@ -22,7 +25,7 @@ void SongItems::load(xmlpp::NodeSet const& n)
xmlpp::Attribute* a_title = element.get_attribute("title");
if (!a_title) throw SongItemsException("No attribute title");
- addSong(a_artist->get_value(), a_title->get_value(), boost::lexical_cast<int>(a_id->get_value()));
+ addSongItem(a_artist->get_value(), a_title->get_value(), boost::lexical_cast<int>(a_id->get_value()));
}
}
@@ -37,13 +40,13 @@ void SongItems::save(xmlpp::Element *songs)
}
}
-void SongItems::addSong(std::string const& artist, std::string const& title, int id)
+void SongItems::addSongItem(std::string const& artist, std::string const& title, int id)
{
SongItem si;
if (id==-1) id = assign_id_internal();
si.id = id;
- si.artist = artist;
- si.title = title;
+ si.artist = unicodeCollate(artist);
+ si.title = unicodeCollate(title);
std::pair<songs_t::iterator, bool> ret = m_songs.insert(si);
if (!ret.second)
@@ -53,6 +56,15 @@ void SongItems::addSong(std::string const& artist, std::string const& title, int
}
}
+void SongItems::addSong(boost::shared_ptr<Song> song)
+{
+ for (songs_t::iterator it = m_songs.begin(); it != m_songs.end(); ++it)
+ {
+ if (song->artist == it->artist && song->title == it->title) return;
+ }
+ addSongItem(song->artist, song->title);
+}
+
int SongItems::assign_id_internal()
{
songs_t::const_reverse_iterator it = m_songs.rbegin();
diff --git a/game/songitems.hh b/game/songitems.hh
index ee089b6..d51c03d 100644
--- a/game/songitems.hh
+++ b/game/songitems.hh
@@ -1,10 +1,14 @@
#pragma once
+#include "song.hh"
+
#include <set>
#include <vector>
#include <string>
#include <stdexcept>
+#include <boost/shared_ptr.hpp>
+
namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet; }
/**Exception which will be thrown when loading or
@@ -33,7 +37,17 @@ struct SongItems
void load(xmlpp::NodeSet const& n);
void save(xmlpp::Element *players);
- void addSong(std::string const& artist, std::string const& title, int id = -1);
+ /**Adds a song item.
+ If the id is not unique or -1 a new one will be assigned.
+ There will be no check if artist and title already exist - if you
+ need that you want addSong().
+ */
+ void addSongItem(std::string const& artist, std::string const& title, int id = -1);
+ /**Adds or Links an already existing song with an songitem.
+ The id will be assigned and artist and title will be filled in.
+ If there is already a song with the same artist and title nothing will be done.
+ */
+ void addSong(boost::shared_ptr<Song> song);
private:
int assign_id_internal();
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:36
|
Module: performous
Branch: master
Commit: ea4bc0ed90f9c65313083d6ce02b33e3f2d38497
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 11:10:33 2009 +0100
remove unused rnd function
(which is implemented in a wrong way)
genious comment added :-)
---
game/songs.cc | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/game/songs.cc b/game/songs.cc
index f98ce87..65bce0c 100644
--- a/game/songs.cc
+++ b/game/songs.cc
@@ -129,6 +129,7 @@ void Songs::randomize() {
void Songs::randomize_internal() {
/* TR1-based random number generation
+ TODO: it is enough that random_device is initialized once and not for every randomize_internal
namespace rnd = std::tr1;
rnd::random_device gendev; // Random number generator (using /dev/urandom usually)
rnd::mt19937 gen(gendev); // Make Mersenne Twister random number generator, seeded with random_device.
@@ -225,10 +226,6 @@ void Songs::sortChange(int diff) {
sort_internal();
}
-namespace {
- int rnd(int n) { return rand() % n; }
-}
-
void Songs::sort_internal() {
switch (m_order) {
case 0: std::stable_sort(m_filtered.begin(), m_filtered.end(), comparator(&Song::randomIdx)); break;
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:34
|
Module: performous
Branch: master
Commit: 3611554238c2940c4ca8c91fd12f04f32daeaf0c
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 10:40:43 2009 +0100
improved error checking
---
game/database.hh | 8 ++++++++
game/hiscore.cc | 12 ++++++++----
game/hiscore.hh | 8 ++------
game/players.cc | 2 ++
game/players.hh | 7 +++++++
5 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/game/database.hh b/game/database.hh
index 64a57b7..8ceb4d7 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -18,6 +18,14 @@ public:
Database (fs::path filename);
~Database ();
+ /**Loads the whole database from xml.
+ @exception bad_cast may be thrown if xml element is not of correct type
+ @exception xmlpp exceptions may be thrown on any parse errors
+ @exception PlayersException if some conditions of players fail (e.g. no id)
+ @exception HiscoreException if some hiscore conditions fail (e.g. score too high)
+ @exception SongsExceptions if some songs conditions fail (e.g. no id)
+ @post filled database
+ */
void load();
void save();
diff --git a/game/hiscore.cc b/game/hiscore.cc
index 2082a60..326e3c3 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -4,7 +4,6 @@
#include <algorithm>
#include <boost/lexical_cast.hpp>
-#include <boost/numeric/conversion/cast.hpp>
#include <libxml++/libxml++.h>
@@ -30,18 +29,23 @@ void Hiscore::load(xmlpp::NodeSet const& n)
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
xmlpp::Attribute* a_playerid = element.get_attribute("playerid");
+ if (!a_playerid) throw HiscoreException("Attribute playerid not found");
xmlpp::Attribute* a_songid = element.get_attribute("songid");
+ if (!a_songid) throw HiscoreException("Attribute songid not found");
xmlpp::Attribute* a_track = element.get_attribute("track");
int playerid = boost::lexical_cast<int>(a_playerid->get_value());
int songid = boost::lexical_cast<int>(a_songid->get_value());
xmlpp::TextNode* tn = element.get_child_text();
+ if (!tn) throw HiscoreException("Score not found");
int score = boost::lexical_cast<int>(tn->get_content());
- if (score < 0) throw boost::numeric::negative_overflow();
- if (score > 10000) throw boost::numeric::positive_overflow();
+ if (score < 0) throw HiscoreException("Score negativ overflow");
+ if (score > 10000) throw HiscoreException("Score positive overflow");
- std::string track = a_track->get_value();
+ std::string track;
+ if (!a_track) track = "VOCALS";
+ else track = a_track->get_value();
addHiscore(score, playerid, songid, track);
}
diff --git a/game/hiscore.hh b/game/hiscore.hh
index a7cbe89..88261c4 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -9,13 +9,9 @@ namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet;
/**Exception which will be thrown when loading or
saving a SongHiscore fails.*/
struct HiscoreException: public std::runtime_error {
- HiscoreException (std::string const& msg, unsigned int linenum) :
- runtime_error(msg), m_linenum(linenum)
+ HiscoreException (std::string const& msg) :
+ runtime_error(msg)
{}
- /**Line information where the problem occured.*/
- unsigned int line() const {return m_linenum;}
- private:
- unsigned int m_linenum;
};
/**This struct holds together information for a
diff --git a/game/players.cc b/game/players.cc
index 51eedae..c1d4b50 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -29,7 +29,9 @@ void Players::load(xmlpp::NodeSet const& n) {
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
xmlpp::Attribute* a_name = element.get_attribute("name");
+ if (!a_name) throw PlayersException("Attribute name not found");
xmlpp::Attribute* a_id = element.get_attribute("id");
+ if (!a_id) throw PlayersException("Attribute id not found");
int id = -1;
try {id = boost::lexical_cast<int>(a_id->get_value());} catch (boost::bad_lexical_cast const&) { }
xmlpp::NodeSet n2 = element.find("picture");
diff --git a/game/players.hh b/game/players.hh
index d8a64d1..17cc6d3 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -13,6 +13,13 @@
namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet; }
+/**Exception which will be thrown when loading or
+ saving Players fails.*/
+struct PlayersException: public std::runtime_error {
+ PlayersException (std::string const& msg) :
+ runtime_error(msg)
+ {}
+};
/**A collection of all Players.
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:32
|
Module: performous
Branch: master
Commit: 285fc2c0c584e13a5594fbe949bb5cc991c03b1f
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 10:25:15 2009 +0100
pass NodeSet by reference
NodeSet is a vector<Node*>, so better avoid copying
---
game/hiscore.cc | 2 +-
game/hiscore.hh | 2 +-
game/players.cc | 2 +-
game/players.hh | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/game/hiscore.cc b/game/hiscore.cc
index 3019f8f..2082a60 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -24,7 +24,7 @@ void Hiscore::addHiscore(int score, int playerid, int songid, std::string const&
m_hiscore.insert(hi);
}
-void Hiscore::load(xmlpp::NodeSet n)
+void Hiscore::load(xmlpp::NodeSet const& n)
{
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 1066f4c..a7cbe89 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -40,7 +40,7 @@ class Hiscore
public:
Hiscore ();
- void load(xmlpp::NodeSet n);
+ void load(xmlpp::NodeSet const& n);
void save(xmlpp::Element *players);
void addHiscore(int score, int playerid, int songid, std::string const& track);
diff --git a/game/players.cc b/game/players.cc
index fab2c76..51eedae 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -24,7 +24,7 @@ Players::Players():
Players::~Players()
{ }
-void Players::load(xmlpp::NodeSet n) {
+void Players::load(xmlpp::NodeSet const& n) {
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
diff --git a/game/players.hh b/game/players.hh
index 5350b6f..d8a64d1 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -42,7 +42,7 @@ class Players: boost::noncopyable {
Players();
~Players();
- void load(xmlpp::NodeSet n);
+ void load(xmlpp::NodeSet const& n);
void save(xmlpp::Element *players);
void update();
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:30
|
Module: performous Branch: master Commit: 7cc26d5f16a37e7f4d47745c81ed1162fb39f7ed Author: Markus Raab <un...@ma...> Date: Wed Nov 11 10:22:49 2009 +0100 loading of hiscore + players works addPlayer in Database added moved old hiscore files (ultrastar format) to unused --- game/database.cc | 16 +++- game/database.hh | 8 ++- game/hiscore.cc | 177 +++++++++--------------------------------------- game/hiscore.hh | 83 +++++------------------ game/unused/hiscore.cc | 171 ++++++++++++++++++++++++++++++++++++++++++++++ game/unused/hiscore.hh | 102 +++++++++++++++++++++++++++ 6 files changed, 340 insertions(+), 217 deletions(-) |
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:29
|
Module: performous
Branch: master
Commit: c14d2035ec6bdb1ba52571502561b738ba00fef6
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 09:01:07 2009 +0100
players now have a unique id
use set for players to ensure unique id and for ordering
assignment of new ids implemented
empty set
---
game/player.hh | 9 +++++++++
game/players.cc | 27 +++++++++++++++++++--------
game/players.hh | 9 +++++++--
3 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/game/player.hh b/game/player.hh
index 6056cc2..ae808ea 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -75,6 +75,15 @@ struct PlayerItem {
std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
*/
+ /**For insertion in set.
+ Provides ordering and ensures id is unique.*/
+ bool operator< (PlayerItem const& pi) const
+ {
+ return id < pi.id;
+ }
+
+ /**Checks if a player has the same name.
+ Used to find a PlayerItem with the same name.*/
bool operator== (PlayerItem const& pi) const
{
return name == pi.name;
diff --git a/game/players.cc b/game/players.cc
index 0097c84..fab2c76 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -69,6 +69,9 @@ void Players::addPlayer (std::string const& name, std::string const& picture, in
pi.picture = picture;
pi.path = "";
+
+ if (pi.id == -1) pi.id = assign_id_internal();
+
if (pi.picture != "") // no picture, so don't search path
{
/* TODO: add again check for pictures
@@ -87,12 +90,13 @@ void Players::addPlayer (std::string const& name, std::string const& picture, in
*/
}
-
- players_t::const_iterator it = std::find(m_players.begin(), m_players.end(), pi);
- if (it != m_players.end()) return; // dont do anything, player exists
-
m_dirty = true;
- m_players.push_back(pi);
+ std::pair<players_t::iterator, bool> ret = m_players.insert(pi);
+ if (!ret.second)
+ {
+ pi.id = assign_id_internal();
+ m_players.insert(pi); // now do the insert with the fresh id
+ }
}
void Players::setFilter(std::string const& val) {
@@ -101,25 +105,32 @@ void Players::setFilter(std::string const& val) {
filter_internal();
}
+int Players::assign_id_internal()
+{
+ players_t::const_reverse_iterator it = m_players.rbegin();
+ if (it != m_players.rend()) return it->id+1;
+ else return 1; // empty set
+}
+
void Players::filter_internal() {
m_dirty = false;
PlayerItem selection = current();
try {
- players_t filtered;
+ fplayers_t filtered;
for (players_t::const_iterator it = m_players.begin(); it != m_players.end(); ++it) {
if (regex_search(it->name, boost::regex(m_filter, boost::regex_constants::icase))) filtered.push_back(*it);
}
m_filtered.swap(filtered);
} catch (...) {
- players_t(m_players.begin(), m_players.end()).swap(m_filtered); // Invalid regex => copy everything
+ fplayers_t(m_players.begin(), m_players.end()).swap(m_filtered); // Invalid regex => copy everything
}
math_cover.reset();
// Restore old selection
int pos = 0;
if (selection.name != "") {
- players_t::iterator it = std::find(m_filtered.begin(), m_filtered.end(), selection);
+ fplayers_t::iterator it = std::find(m_filtered.begin(), m_filtered.end(), selection);
math_cover.setTarget(0, 0);
if (it != m_filtered.end()) pos = it - m_filtered.begin();
}
diff --git a/game/players.hh b/game/players.hh
index 1139603..5350b6f 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -1,5 +1,7 @@
#pragma once
+#include <set>
+#include <list>
#include <vector>
#include <string>
@@ -18,13 +20,14 @@ namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet;
be retrieved with Engine::getPlayers().*/
class Players: boost::noncopyable {
private:
- typedef std::vector<PlayerItem> players_t;
+ typedef std::set<PlayerItem> players_t;
+ typedef std::vector<PlayerItem> fplayers_t;
typedef std::list<Player> cur_players_t;
typedef std::list<int> cur_scores_t;
private:
players_t m_players;
- players_t m_filtered;
+ fplayers_t m_filtered;
std::string m_filter;
AnimAcceleration math_cover;
@@ -44,6 +47,7 @@ class Players: boost::noncopyable {
void update();
+
/// add a player with a displayed name and an optional picture; if no id is given one will be assigned
void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
@@ -80,5 +84,6 @@ class Players: boost::noncopyable {
/// filters playerlist by regular expression
void setFilter(std::string const& regex);
private:
+ int assign_id_internal(); /// returns the next available id
void filter_internal();
};
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:27
|
Module: performous
Branch: master
Commit: 8620976dcd614eb3dcec6d59508de7cf092e23de
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 08:39:09 2009 +0100
preserve id
---
game/player.hh | 4 +++-
game/players.cc | 18 +++++++++++++-----
game/players.hh | 3 ++-
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/game/player.hh b/game/player.hh
index 25f0775..6056cc2 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -65,7 +65,9 @@ struct Player {
Used for Players Management.
*/
struct PlayerItem {
- std::string name; /// unique name, link to highscore
+ int id; /// unique identifier for this PlayerItem, Link to hiscore
+
+ std::string name; /// name displayed and used for searching the player
std::string path; /// a path to a picture shown
std::string picture; /// + the filename for it
/* Future ideas
diff --git a/game/players.cc b/game/players.cc
index 5935dc2..0097c84 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -3,10 +3,13 @@
#include "fs.hh"
#include "configuration.hh"
+#include <set>
#include <fstream>
#include <iostream>
-#include <set>
+
#include <boost/regex.hpp>
+#include <boost/lexical_cast.hpp>
+
#include <libxml++/libxml++.h>
Players::Players():
@@ -25,7 +28,10 @@ void Players::load(xmlpp::NodeSet n) {
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
- xmlpp::Attribute* a = element.get_attribute("name");
+ xmlpp::Attribute* a_name = element.get_attribute("name");
+ xmlpp::Attribute* a_id = element.get_attribute("id");
+ int id = -1;
+ try {id = boost::lexical_cast<int>(a_id->get_value());} catch (boost::bad_lexical_cast const&) { }
xmlpp::NodeSet n2 = element.find("picture");
std::string picture;
if (!n2.empty()) // optional picture element
@@ -34,7 +40,7 @@ void Players::load(xmlpp::NodeSet n) {
xmlpp::TextNode* tn = element2.get_child_text();
picture = tn->get_content();
}
- addPlayer(a->get_value(), picture);
+ addPlayer(a_name->get_value(), picture, id);
}
}
@@ -43,6 +49,7 @@ void Players::save(xmlpp::Element *players) {
{
xmlpp::Element* player = players->add_child("player");
player->set_attribute("name", it->name);
+ player->set_attribute("id", boost::lexical_cast<std::string>(it->id));
if (it->picture != "")
{
xmlpp::Element* picture = player->add_child("picture");
@@ -55,15 +62,16 @@ void Players::update() {
if (m_dirty) filter_internal();
}
-void Players::addPlayer (std::string const& name, std::string const& picture) {
+void Players::addPlayer (std::string const& name, std::string const& picture, int id) {
PlayerItem pi;
+ pi.id = id;
pi.name = name;
pi.picture = picture;
pi.path = "";
if (pi.picture != "") // no picture, so don't search path
{
- /* TODO: add again
+ /* TODO: add again check for pictures
ConfigItem::StringList const& sl = config["system/path_pictures"].sl();
typedef std::set<fs::path> dirs;
dirs d;
diff --git a/game/players.hh b/game/players.hh
index 4c226f0..1139603 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -44,7 +44,8 @@ class Players: boost::noncopyable {
void update();
- void addPlayer (std::string const& name, std::string const& picture = "");
+ /// add a player with a displayed name and an optional picture; if no id is given one will be assigned
+ void addPlayer (std::string const& name, std::string const& picture = "", int id = -1);
/// const array access
PlayerItem operator[](std::size_t pos) const {
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:26
|
Module: performous
Branch: master
Commit: 12a6cc32cd7e931ce8cd41d992534178cb666625
Author: Markus Raab <un...@ma...>
Date: Tue Nov 10 13:30:31 2009 +0100
packaging for debian lenny added
also ignore build32 and build64 folders
ignore database.xml in game folder
---
.gitignore | 2 ++
cmake/performous-packaging.cmake | 3 +++
game/.gitignore | 1 +
3 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 378eac2..4497982 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
build
+build32
+build64
diff --git a/cmake/performous-packaging.cmake b/cmake/performous-packaging.cmake
index acc3027..256aad1 100644
--- a/cmake/performous-packaging.cmake
+++ b/cmake/performous-packaging.cmake
@@ -62,6 +62,9 @@ if(UNIX)
if("${LSB_DISTRIB}" MATCHES "Ubuntu9.10")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl1.2debian, libcairo2, librsvg2-2, libboost-thread1.38.0, libboost-program-options1.38.0, libboost-regex1.38.0, libboost-filesystem1.38.0, libboost-date-time1.38.0, libavcodec52, libavformat52, libswscale0, libmagick++1, libxml++2.6-2, libglew1.5")
endif("${LSB_DISTRIB}" MATCHES "Ubuntu9.10")
+ if("${LSB_DISTRIB}" MATCHES "Debian5.*")
+ set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl1.2debian, libcairo2, librsvg2-2, libboost-dev, libavcodec51, libavformat52, libswscale0, libmagick++10, libxml++2.6-2, libglew1.5")
+ endif("${LSB_DISTRIB}" MATCHES "Ubuntu9.10")
if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
message("WARNING: ${LSB_DISTRIB} not supported yet.\nPlease set deps in cmake/performous-packaging.cmake before packaging.")
endif(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
diff --git a/game/.gitignore b/game/.gitignore
index 314577e..22bc235 100644
--- a/game/.gitignore
+++ b/game/.gitignore
@@ -7,6 +7,7 @@ config.hh
database
performous.xml
+database.xml
highscore
highscore.txt
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:24
|
Module: performous
Branch: master
Commit: b4c3e59b029e5aec08b9e1bd0fffd5d47ad6b174
Author: Markus Raab <un...@ma...>
Date: Tue Nov 10 11:45:19 2009 +0100
reading/writing players database
---
game/database.cc | 22 +++++++++++++++-------
game/players.cc | 3 ++-
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index c3b1422..510807a 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -8,12 +8,17 @@ Database::Database(fs::path filename) :
m_filename(filename)
{
try { load(); }
- catch(...) { std::cerr << "Could not load " << file() << ", will create" << std::endl; }
+ catch(std::exception const& e) {
+ std::cerr << "Could not load " << file() << ": " << e.what() << std::endl;
+ std::cerr << "will try to create" << std::endl;
+ }
}
Database::~Database() {
try { save(); }
- catch (...) { std::cerr << "Could not save players to " << file() << std::endl; }
+ catch (std::exception const& e) {
+ std::cerr << "Could not save " << file() << ": " << e.what() << std::endl;
+ }
}
void Database::load() {
@@ -31,7 +36,11 @@ void Database::save() {
m_players.save(players);
- create_directory(m_filename.parent_path());
+ if (!exists(m_filename.parent_path()) && !m_filename.parent_path().empty())
+ {
+ std::cout << "Will create directory: " << m_filename.parent_path() << std::endl;
+ create_directory(m_filename.parent_path());
+ }
doc.write_to_file_formatted(m_filename.string(), "UTF-8");
}
@@ -39,9 +48,8 @@ std::string Database::file() {
return m_filename.string();
}
-/*
-
// Test program for Database
int main()
-{}
-*/
+{
+ Database ("database.xml");
+}
diff --git a/game/players.cc b/game/players.cc
index 175624e..5935dc2 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -22,7 +22,6 @@ Players::~Players()
{ }
void Players::load(xmlpp::NodeSet n) {
-
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
@@ -64,6 +63,7 @@ void Players::addPlayer (std::string const& name, std::string const& picture) {
if (pi.picture != "") // no picture, so don't search path
{
+ /* TODO: add again
ConfigItem::StringList const& sl = config["system/path_pictures"].sl();
typedef std::set<fs::path> dirs;
dirs d;
@@ -76,6 +76,7 @@ void Players::addPlayer (std::string const& name, std::string const& picture) {
if (pi.path != "") std::cout << "Found " << pi.picture << " in " << pi.path << std::endl;
else std::cout << "Not found " << pi.picture << std::endl;
+ */
}
|
|
From: Markus R. <god...@us...> - 2009-11-12 12:49:22
|
Module: performous
Branch: master
Commit: 1d5f09481ef98bc23f2a3cf456dcd316488fdd4b
Author: Markus Raab <un...@ma...>
Date: Tue Nov 10 10:27:38 2009 +0100
added some old files
---
data/database.xml | 19 ++++++
game/unused/folderview.cpp | 138 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 157 insertions(+), 0 deletions(-)
diff --git a/data/database.xml b/data/database.xml
new file mode 100644
index 0000000..8116110
--- /dev/null
+++ b/data/database.xml
@@ -0,0 +1,19 @@
+<performous>
+ <songs> <!-- a list of songs -->
+ <song id="123" artist="ABBA" title="Dancing Queen">
+ <!-- extra song details -->
+ </song>
+ </songs>
+ <players> <!-- a list of players -->
+ <player id="123" name="Markus">
+ <picture>markus.jpg</picture> <!-- optional picture shown at players selection -->
+ </player>
+ </players>
+ <hiscores> <!-- a list of highscores -->
+ <hiscore songid="123" playerid="123" track="VOCALS">600</hiscore>
+ </hiscores>
+</performous>
+<!--
+id of songs: collateByTitle (?)
+id of players: ?
+-->
diff --git a/game/unused/folderview.cpp b/game/unused/folderview.cpp
new file mode 100644
index 0000000..c2a92f7
--- /dev/null
+++ b/game/unused/folderview.cpp
@@ -0,0 +1,138 @@
+#include <boost/shared_ptr.hpp>
+#include <boost/filesystem.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+namespace fs = boost::filesystem;
+
+class Song
+{
+ public:
+ Song(std::string const& path_, std::string const& filename_ = "") :
+ path(path_), filename(filename_)
+ {}
+
+ std::string path; ///< path of songfile
+ std::string filename; ///< name of songfile
+};
+
+namespace {
+ class IsFolder: public std::unary_function<boost::shared_ptr<Song>,bool> {
+ public:
+ bool operator() (boost::shared_ptr<Song> const song) const
+ {
+ return song->filename.empty();
+ }
+ };
+ class IsDirectBelow: public std::unary_function<boost::shared_ptr<Song>,bool> {
+ public:
+ IsDirectBelow(fs::path path) :
+ m_path(path)
+ {}
+ bool operator() (boost::shared_ptr<Song> const song) const
+ {
+ fs::path base (song->path);
+ base.remove_leaf();
+ // std::cout << "base: " << base << "\tm_path: " << m_path << std::endl;
+ return base == m_path;
+ }
+ private:
+ fs::path m_path;
+ };
+ class IsBelow: public std::unary_function<boost::shared_ptr<Song>,bool> {
+ public:
+ IsBelow(fs::path path) :
+ m_path(path)
+ {}
+ bool operator() (boost::shared_ptr<Song> const song) const
+ {
+ fs::path path (song->path);
+ while (!path.empty())
+ {
+ path.remove_leaf();
+ if (path == m_path) return true;
+ }
+ return false;
+ }
+ private:
+ fs::path m_path;
+ };
+}
+
+class Songs
+{
+ public:
+ typedef std::vector<boost::shared_ptr<Song> > SongVector;
+
+ Songs() :
+ m_songs()
+ {
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/protected")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/protected/Demo", "Demo")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/protected/Great", "Great")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/protected/Sub")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/protected/Sub/Song", "Yeah")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/free")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/free/Demo", "Demo")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/home/songs/free/Great", "Great")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/media/performous")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/media/performous/Internet")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/media/performous/Internet/Song", "Song")));
+ m_songs.push_back(boost::shared_ptr<Song>(new Song("/media/performous/Hits")));
+ }
+ void only_folders()
+ {
+ m_songs.erase(std::remove_if(m_songs.begin(), m_songs.end(), std::not1(IsFolder())), m_songs.end());
+ }
+ void only_songs()
+ {
+ m_songs.erase(std::remove_if(m_songs.begin(), m_songs.end(), IsFolder()), m_songs.end());
+ }
+ void only_path(std::string path)
+ {
+ m_songs.erase(std::remove_if(m_songs.begin(), m_songs.end(), std::not1(IsDirectBelow (path))), m_songs.end());
+ }
+ void only_root()
+ {
+ SongVector::iterator end = m_songs.end();
+ for (SongVector::const_iterator it = m_songs.begin(); it != end; ++it)
+ {
+ std::cout << "Removing below: " << (*it)->path << std::endl;
+ end = std::remove_if(m_songs.begin(), end, IsBelow ((*it)->path));
+ }
+ m_songs.erase(end, m_songs.end());
+ }
+ ~Songs()
+ { }
+ friend std::ostream & operator<< (std::ostream & os, Songs const& s);
+ private:
+ SongVector m_songs;
+
+};
+
+std::ostream & operator<< (std::ostream & os, Songs const& s)
+{
+ for (Songs::SongVector::const_iterator it = s.m_songs.begin(); it!= s.m_songs.end(); ++it)
+ {
+ os << "Song " << (*it)->path << "/ " << (*it)->filename << std::endl;
+ }
+ return os;
+}
+
+class ScreenSongs
+{};
+
+int main(int argc, char**argv)
+{
+ /*
+ if (argc!=2) return 1;
+ std::string path = argv[1];
+ */
+ Songs songs;
+ songs.only_root();
+ // songs.only_path(path);
+ // songs.only_songs();
+ std::cout << songs;
+}
|