|
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;
|