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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:56
|
Module: performous
Branch: dance
Commit: a7ba20a91ad31c982af182bce2f4105893657db8
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Nov 11 19:12:24 2009 +0200
Rewrite most of the data path code.
Rename getXdgPath to getPath to avoid clutter and confusion.
Make the config file path setting empty by default.
---
data/schema.xml | 4 ---
game/fs.cc | 70 +++++++++++++++++++++++++++++------------------
game/fs.hh | 2 +-
game/guitargraph.cc | 24 ++++++++--------
game/screen_practice.cc | 12 ++++----
5 files changed, 62 insertions(+), 50 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index 93a9dde..4275468 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -237,10 +237,6 @@ to save the current settings to XML.
</locale>
</entry>
<entry name="system/path" type="string_list">
- <stringvalue>/usr/local/share/games/performous/</stringvalue>
- <stringvalue>/usr/share/games/performous/</stringvalue>
- <stringvalue>../</stringvalue><!-- For Windows where the program is started in bin/ -->
- <stringvalue>~/.performous/</stringvalue>
<locale name="C">
<short>System folders</short>
<long>Where to look for performous data.</long>
diff --git a/game/fs.cc b/game/fs.cc
index ee54c24..e1ace89 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -4,6 +4,8 @@
#include <plugin++/execname.hpp>
#include <cstdlib>
#include <iostream>
+#include <list>
+#include <sstream>
fs::path getHomeDir() {
static fs::path dir;
@@ -33,52 +35,66 @@ std::string getThemePath(std::string const& filename) {
if (theme.empty()) throw std::runtime_error("Configuration value game/theme is empty");
// Figure out theme folder (if theme name rather than path was given)
if (theme.find('/') == std::string::npos) {
- return getXdgPath(fs::path("themes") / theme / filename);
+ return getPath(fs::path("themes") / theme / filename);
} else {
if (*theme.rbegin() == '/') theme.erase(theme.size() - 1); // Remove trailing slash
return theme + "/" + filename;
}
}
-std::string getXdgPath(fs::path const& filename) {
- static std::vector<fs::path> dir;
+namespace {
+ bool pathNotExist(fs::path const& p) {
+ if (exists(p)) {
+ std::cout << ">>> Using data path \"" << p.string() << "\"" << std::endl;
+ return false;
+ }
+ std::cout << ">>> Not using \"" << p.string() << "\" (does not exist)" << std::endl;
+ return true;
+ }
+}
+
+std::string getPath(fs::path const& filename) {
+ typedef std::list<fs::path> Dirs;
+ static Dirs dirs;
static bool initialized = false;
if (!initialized) {
initialized = true;
- // Adding PERFORMOUS_DATA_DIR (compatibility)
- char const* env_data_dir = getenv("PERFORMOUS_DATA_DIR");
- if (env_data_dir) {
- dir.push_back(env_data_dir);
+ fs::path shortDir = "performous";
+ fs::path shareDir = "share/games" / shortDir;
+#ifdef _WIN32
+ // Add APPLIC~1 (user-specific application data) FIXME: Not tested
+ {
+ char const* appdata = getenv("APPDATA");
+ if (appdata) dirs.push_back(appdata / shortDir);
}
+#else
// Adding XDG_DATA_HOME
- char const* xdg_data_home = getenv("XDG_DATA_HOME");
- if (xdg_data_home) {
- dir.push_back(fs::path(xdg_data_home) / "performous");
- } else {
- dir.push_back(getHomeDir() / ".local" / "share" / "performous" );
+ {
+ char const* xdg_data_home = getenv("XDG_DATA_HOME");
+ // FIXME: Should this use "games" or not?
+ dirs.push_back(xdg_data_home ? xdg_data_home / shortDir : getHomeDir() / ".local" / shareDir);
}
+#endif
// Adding relative path from executable
- dir.push_back(fs::path(plugin::execname()).parent_path() / ".." / "share" / "performous");
+ dirs.push_back(fs::path(plugin::execname()).parent_path().parent_path() / shareDir);
+#ifndef _WIN32
// Adding XDG_DATA_DIRS
- char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
- if (xdg_data_dirs) {
- // here explode ":"
- } else {
- dir.push_back( "/usr/local/share/performous/" );
- dir.push_back( "/usr/share/performous/" );
+ {
+ char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
+ std::istringstream iss(xdg_data_dirs ? xdg_data_dirs : "/usr/local/share/:/usr/share/");
+ for (std::string p; std::getline(iss, p, ':'); dirs.push_back(p / shortDir)) {}
}
- // Adding some defaults
+#endif
+ // Adding paths from config file
std::vector<std::string> pathes = config["system/path"].sl();
- std::transform(pathes.begin(), pathes.end(), std::inserter(dir, dir.end()), pathMangle);
- // Some output
- for (std::vector<fs::path>::const_iterator it = dir.begin(); it != dir.end(); ++it) {
- std::cout << ">>> Adding XDG search path \"" << it->string() << "\"" << std::endl;
- }
+ std::transform(pathes.begin(), pathes.end(), std::inserter(dirs, dirs.end()), pathMangle);
+ // Check if they actually exist and print debug
+ dirs.remove_if(pathNotExist);
}
- for (std::vector<fs::path>::const_iterator it = dir.begin(); it != dir.end(); ++it) {
+ for (Dirs::const_iterator it = dirs.begin(); it != dirs.end(); ++it) {
fs::path p = *it;
p /= filename;
if( fs::exists(p) ) return p.string();
}
- throw std::runtime_error("Cannot find file \"" + filename.string() + "\" inside XDG data pathes");
+ throw std::runtime_error("Cannot find file \"" + filename.string() + "\" in any of Performous data folders");
}
diff --git a/game/fs.hh b/game/fs.hh
index 4566149..fd63e86 100644
--- a/game/fs.hh
+++ b/game/fs.hh
@@ -15,4 +15,4 @@ fs::path pathMangle(fs::path const& dir);
std::string getThemePath(std::string const& filename);
/** Get full path to a share file **/
-std::string getXdgPath(fs::path const& filename);
+std::string getPath(fs::path const& filename);
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 9d6c996..fde67e5 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -76,18 +76,18 @@ GuitarGraph::GuitarGraph(Audio& audio, Song const& song, std::string track):
}
unsigned int sr = m_audio.getSR();
if (g_samplesD.empty()) {
- g_samplesD.push_back(Sample(getXdgPath("sounds/drum_bass.ogg"), sr));
- g_samplesD.push_back(Sample(getXdgPath("sounds/drum_snare.ogg"), sr));
- g_samplesD.push_back(Sample(getXdgPath("sounds/drum_hi-hat.ogg"), sr));
- g_samplesD.push_back(Sample(getXdgPath("sounds/drum_tom1.ogg"), sr));
- g_samplesD.push_back(Sample(getXdgPath("sounds/drum_cymbal.ogg"), sr));
- //g_samplesD.push_back(Sample(getXdgPath("sounds/drum_tom2.ogg"), sr));
- g_samplesG.push_back(Sample(getXdgPath("sounds/guitar_fail1.ogg"), sr));
- g_samplesG.push_back(Sample(getXdgPath("sounds/guitar_fail2.ogg"), sr));
- g_samplesG.push_back(Sample(getXdgPath("sounds/guitar_fail3.ogg"), sr));
- g_samplesG.push_back(Sample(getXdgPath("sounds/guitar_fail4.ogg"), sr));
- g_samplesG.push_back(Sample(getXdgPath("sounds/guitar_fail5.ogg"), sr));
- g_samplesG.push_back(Sample(getXdgPath("sounds/guitar_fail6.ogg"), sr));
+ g_samplesD.push_back(Sample(getPath("sounds/drum_bass.ogg"), sr));
+ g_samplesD.push_back(Sample(getPath("sounds/drum_snare.ogg"), sr));
+ g_samplesD.push_back(Sample(getPath("sounds/drum_hi-hat.ogg"), sr));
+ g_samplesD.push_back(Sample(getPath("sounds/drum_tom1.ogg"), sr));
+ g_samplesD.push_back(Sample(getPath("sounds/drum_cymbal.ogg"), sr));
+ //g_samplesD.push_back(Sample(getPath("sounds/drum_tom2.ogg"), sr));
+ g_samplesG.push_back(Sample(getPath("sounds/guitar_fail1.ogg"), sr));
+ g_samplesG.push_back(Sample(getPath("sounds/guitar_fail2.ogg"), sr));
+ g_samplesG.push_back(Sample(getPath("sounds/guitar_fail3.ogg"), sr));
+ g_samplesG.push_back(Sample(getPath("sounds/guitar_fail4.ogg"), sr));
+ g_samplesG.push_back(Sample(getPath("sounds/guitar_fail5.ogg"), sr));
+ g_samplesG.push_back(Sample(getPath("sounds/guitar_fail6.ogg"), sr));
}
unsigned int i = 0;
for (TrackMap::const_iterator it = m_song.track_map.begin(); it != m_song.track_map.end(); ++it,++i) {
diff --git a/game/screen_practice.cc b/game/screen_practice.cc
index 505db7b..1dcb9fa 100644
--- a/game/screen_practice.cc
+++ b/game/screen_practice.cc
@@ -21,12 +21,12 @@ void ScreenPractice::enter() {
drums.reset(new input::InputDev(input::DRUMS));
} catch (std::runtime_error&) {drums.reset();}
unsigned int sr = m_audio.getSR();
- m_samples.push_back(Sample(getXdgPath("sounds/drum_bass.ogg"), sr));
- m_samples.push_back(Sample(getXdgPath("sounds/drum_snare.ogg"), sr));
- m_samples.push_back(Sample(getXdgPath("sounds/drum_hi-hat.ogg"), sr));
- m_samples.push_back(Sample(getXdgPath("sounds/drum_tom1.ogg"), sr));
- m_samples.push_back(Sample(getXdgPath("sounds/drum_cymbal.ogg"), sr));
- //m_samples.push_back(Sample(getXdgPath("sounds/drum_tom2.ogg"), sr));
+ m_samples.push_back(Sample(getPath("sounds/drum_bass.ogg"), sr));
+ m_samples.push_back(Sample(getPath("sounds/drum_snare.ogg"), sr));
+ m_samples.push_back(Sample(getPath("sounds/drum_hi-hat.ogg"), sr));
+ m_samples.push_back(Sample(getPath("sounds/drum_tom1.ogg"), sr));
+ m_samples.push_back(Sample(getPath("sounds/drum_cymbal.ogg"), sr));
+ //m_samples.push_back(Sample(getPath("sounds/drum_tom2.ogg"), sr));
}
void ScreenPractice::exit() {
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:55
|
Module: performous
Branch: dance
Commit: 0d1eeed84d2bd95d272f0d14a297bf9eeb9caa8b
Author: Tapio Vierros <tap...@gm...>
Date: Wed Nov 11 17:42:21 2009 +0200
Tweaks to lyrics rank display.
---
game/layout_singer.cc | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/game/layout_singer.cc b/game/layout_singer.cc
index d648f89..8530a46 100644
--- a/game/layout_singer.cc
+++ b/game/layout_singer.cc
@@ -62,21 +62,19 @@ void LayoutSinger::drawScore(Position position) {
if (p->m_prevLineScore > 0.5 && fact > 0) {
std::string prevLineRank;
float fzoom = 3.0 / (2.0 + fact);
- float rank = 0.0f;
- if (p->m_prevLineScore > 0.95) { prevLineRank = "Perfect"; rank = 1.0f; }
- else if (p->m_prevLineScore > 0.9) { prevLineRank = "Excellent"; rank = 0.8f; }
- else if (p->m_prevLineScore > 0.8) { prevLineRank = "Great"; rank = 0.6f; }
- else if (p->m_prevLineScore > 0.6) { prevLineRank = "Good"; rank = 0.3f; }
- else if (p->m_prevLineScore > 0.4) { prevLineRank = "OK"; rank = 0.0f; }
- float base = 0.2f * (1.0f - rank);
- glColor4f(base + r * rank, base + g * rank, base + b * rank, fact);
+ if (p->m_prevLineScore > 0.95) prevLineRank = "Perfect";
+ else if (p->m_prevLineScore > 0.9) prevLineRank = "Excellent";
+ else if (p->m_prevLineScore > 0.8) prevLineRank = "Great";
+ else if (p->m_prevLineScore > 0.6) prevLineRank = "Good";
+ else if (p->m_prevLineScore > 0.4) prevLineRank = "OK";
+ glColor4f(r, g, b, clamp(fact*2.0f));
m_line_rank_text[i%4]->render(prevLineRank);
switch(position) {
case LayoutSinger::BOTTOM:
m_line_rank_text[i%4]->dimensions().middle(-0.350 + 0.01 + 0.25 * i).fixedHeight(0.055*fzoom).screenTop(0.11);
break;
case LayoutSinger::MIDDLE:
- m_line_rank_text[i%4]->dimensions().right(0.45).fixedHeight(0.04*fzoom).screenTop(0.060 + 0.050 * i);
+ m_line_rank_text[i%4]->dimensions().right(0.30).fixedHeight(0.05*fzoom).screenTop(0.025 + 0.050 * i);
break;
}
m_line_rank_text[i%4]->draw();
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:55
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:55
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:53
|
Module: performous
Branch: dance
Commit: 3496c8effa9a95c6e65b6e17c4c4892d0cb36194
Author: Vincent Le Ligeour <yo...@us...>
Date: Wed Nov 11 16:48:48 2009 +0100
Fixed Rockband Beattles drumkit detection
---
data/schema.xml | 2 +-
game/joystick.cc | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index 93a9dde..66a2606 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -81,7 +81,7 @@ to save the current settings to XML.
<entry name="game/instruments" type="string_list">
<!-- Should be SDL_ID:{GUITAR_GUITARHERO|GUITAR_ROCKBAND|DRUMS_GUITARHERO|DRUMS_ROCKBAND}
example:
- <stringvalue>0:GUITAR_GH</stringvalue>
+ <stringvalue>0:GUITAR_GUITARHERO</stringvalue>
-->
<locale name="C">
<short>Joystick configuration</short>
diff --git a/game/joystick.cc b/game/joystick.cc
index b54d2a6..3b0e42e 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -118,7 +118,8 @@ void input::SDL::init() {
continue;
}
input::SDL::sdl_devices[i] = joy;
- std::cout << " Axes: " << SDL_JoystickNumAxes(joy);
+ std::cout << " Id: " << i;
+ std::cout << ", Axes: " << SDL_JoystickNumAxes(joy);
std::cout << ", Balls: " << SDL_JoystickNumBalls(joy);
std::cout << ", Buttons: " << SDL_JoystickNumButtons(joy);
std::cout << ", Hats: " << SDL_JoystickNumHats(joy) << std::endl;
@@ -154,6 +155,9 @@ void input::SDL::init() {
} else if( name.find("Harmonix Drum Kit") != std::string::npos ) {
std::cout << " Detected as: RockBand Drums" << std::endl;
input::Private::devices[i] = input::Private::InputDevPrivate(input::Private::DRUMS_RB);
+ } else if( name.find("Harmonix Drum kit") != std::string::npos ) {
+ std::cout << " Detected as: RockBand Drums" << std::endl;
+ input::Private::devices[i] = input::Private::InputDevPrivate(input::Private::DRUMS_RB);
} else {
std::cout << " Detected as: Unknwown (please report the name, assuming Guitar Hero Drums)" << std::endl;
input::Private::devices[i] = input::Private::InputDevPrivate(input::Private::DRUMS_GH);
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:48
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:46
|
Module: performous
Branch: dance
Commit: 537eba3875c25ebc284b2cf66e8e2f0ea195db09
Author: Tapio Vierros <tap...@gm...>
Date: Wed Nov 11 17:18:39 2009 +0200
Modified instrument's track/difficulty selection layout a bit, so that the texts are visible with three instruments on screen.
---
game/guitargraph.cc | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 9d6c996..ea708b7 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -367,10 +367,10 @@ void GuitarGraph::draw(double time) {
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
// Draw scores
if (time < -0.5) {
- std::string txt;
- txt += m_track_index->first + "\n" + diffv[m_level].name;
- m_text.dimensions.screenBottom(-0.05).middle(-0.1 + offsetX);
- m_text.draw(txt);
+ m_text.dimensions.screenBottom(-0.041).middle(-0.09 + offsetX);
+ m_text.draw(diffv[m_level].name);
+ m_text.dimensions.screenBottom(-0.015).middle(-0.09 + offsetX);
+ m_text.draw(m_track_index->first);
} else {
m_text.dimensions.screenBottom(-0.30).middle(0.32 * dimensions.w() + offsetX);
m_text.draw(boost::lexical_cast<std::string>(unsigned(getScore())));
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:44
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:42
|
Module: performous
Branch: dance
Commit: 9e2f4eb48dbaa475a959e02ce0e20a0326ee38b4
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Nov 11 17:01:41 2009 +0200
Load data from path relative to executable
---
game/fs.cc | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/game/fs.cc b/game/fs.cc
index 30e9b21..ee54c24 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -1,6 +1,7 @@
#include "fs.hh"
#include "configuration.hh"
+#include <plugin++/execname.hpp>
#include <cstdlib>
#include <iostream>
@@ -56,6 +57,8 @@ std::string getXdgPath(fs::path const& filename) {
} else {
dir.push_back(getHomeDir() / ".local" / "share" / "performous" );
}
+ // Adding relative path from executable
+ dir.push_back(fs::path(plugin::execname()).parent_path() / ".." / "share" / "performous");
// Adding XDG_DATA_DIRS
char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
if (xdg_data_dirs) {
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:41
|
Module: performous Branch: dance Commit: 28bc75a875cd352a6c38c3247dea18646961ded7 Author: Lasse Karkkainen <tro...@tr...> Date: Wed Nov 11 16:47:05 2009 +0200 Merge branch 'master' of ssh://tronic@git.performous.org/gitroot/performous/performous --- |
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:39
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:37
|
Module: performous
Branch: dance
Commit: 140e287a502a012dcabd1c396818dd82b0c51dfd
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Nov 11 16:46:14 2009 +0200
Fix missing include
---
game/unicode.cc | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/game/unicode.cc b/game/unicode.cc
index 8c2c73c..fa31716 100644
--- a/game/unicode.cc
+++ b/game/unicode.cc
@@ -2,6 +2,7 @@
#include <glibmm/ustring.h>
#include <glibmm/convert.h>
+#include <sstream>
void convertToUTF8( std::stringstream &_stream, std::string _filename ) {
try {
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:35
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:34
|
Module: performous
Branch: dance
Commit: b649ab6a24e40649cdc3170c62e2cb68ea23c418
Author: Vincent Le Ligeour <yo...@us...>
Date: Wed Nov 11 15:02:47 2009 +0100
Fixed some midi parsing
---
game/midifile.cc | 2 ++
game/songparser-ini.cc | 1 +
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/game/midifile.cc b/game/midifile.cc
index 7f5c74b..a762f47 100644
--- a/game/midifile.cc
+++ b/game/midifile.cc
@@ -275,6 +275,8 @@ void MidiFileParser::process_midi_event(Track& track, uint8_t t, uint8_t arg1, u
}
// special management for lyrics
if (track.name == "PART VOCALS") {
+ // Discard note effects
+ if( arg1 < 20 ) return;
if (t == 8 || (t == 9 && arg2 == 0)) {
// end of note (note off or note on with zero velocity)
if( !m_lyric.empty() ) {
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index a55d489..5184e83 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -156,6 +156,7 @@ void SongParser::iniParse() {
{
char ch = *syl.rbegin();
if (ch == '-') syl.erase(syl.size() - 1);
+ else if (ch == '=') { *syl.rbegin() = '-'; }
else if (ch != '~') syl += ' ';
}
}
|
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:32
|
Module: performous Branch: dance 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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:30
|
Module: performous Branch: dance Commit: 140bb29d018d7d8e662990ae7976c3804c2b2772 Author: Vincent Le Ligeour <yo...@us...> Date: Wed Nov 11 12:40:57 2009 +0100 Rewrote a large part of the path management --- data/schema.xml | 38 +++++++++++------------------- game/3dobject.hh | 2 +- game/configuration.cc | 10 -------- game/fs.cc | 57 +++++++++++++++++++++++++++++++++++----------- game/fs.hh | 5 +--- game/guitargraph.cc | 36 ++++++++++++++-------------- game/joystick.cc | 15 +++++------ game/main.cc | 5 +-- game/notegraph.cc | 10 ++++---- game/screen_practice.cc | 12 +++++----- game/surface.cc | 4 +-- 11 files changed, 98 insertions(+), 96 deletions(-) |
|
From: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:29
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:27
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:25
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:23
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:21
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:20
|
Module: performous Branch: dance 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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:19
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:18
|
Module: performous
Branch: dance
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: Lasse Kärkkäi. <tr...@us...> - 2009-11-14 18:43:14
|
Module: performous
Branch: dance
Commit: d77f87225586462101ca8297b3cd9c536d73694c
Author: Vincent Le Ligeour <yo...@us...>
Date: Tue Nov 10 22:41:18 2009 +0100
Updated path search to primarly search inside performous data directory
---
game/configuration.cc | 8 ++++----
game/fs.cc | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/game/configuration.cc b/game/configuration.cc
index 522393d..b19444c 100644
--- a/game/configuration.cc
+++ b/game/configuration.cc
@@ -337,10 +337,10 @@ void readConfig() {
// Adding some default pathes
char const* env_data_dir = getenv("PERFORMOUS_DATA_DIR");
if (env_data_dir) {
- config["system/path_themes"].sl().push_back(std::string(env_data_dir) + "/themes/");
- config["system/path_songs"].sl().push_back(std::string(env_data_dir) + "/songs/");
- config["system/path_pictures"].sl().push_back(std::string(env_data_dir) + "/pictures/");
- config["system/path_backgrounds"].sl().push_back(std::string(env_data_dir) + "/backgrounds/");
+ config["system/path_themes"].sl().insert(config["system/path_themes"].sl().begin(), std::string(env_data_dir) + "/themes/");
+ config["system/path_songs"].sl().insert(config["system/path_songs"].sl().begin(), std::string(env_data_dir) + "/songs/");
+ config["system/path_pictures"].sl().insert(config["system/path_pictures"].sl().begin(), std::string(env_data_dir) + "/pictures/");
+ config["system/path_backgrounds"].sl().insert(config["system/path_backgrounds"].sl().begin(), std::string(env_data_dir) + "/backgrounds/");
}
}
diff --git a/game/fs.cc b/game/fs.cc
index c9a3039..499830f 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -37,7 +37,7 @@ std::string getThemePath(std::string const& filename) {
p /= theme;
if (fs::is_directory(p)) { theme = p.string(); break; }
}
- }
+ }
if (*theme.rbegin() == '/') theme.erase(theme.size() - 1); // Remove trailing slash
return theme + "/" + filename;
}
|