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-07-29 15:35:40
|
Module: performous Branch: master Commit: 90eb5ea342e01b94904dcf8038590ef2d8ec4132 Author: Markus Raab <un...@ma...> Date: Sat Jul 25 12:37:03 2009 +0200 sort order should be correct now --- game/screen_sing.cc | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/game/screen_sing.cc b/game/screen_sing.cc index 10f6e5e..5614597 100644 --- a/game/screen_sing.cc +++ b/game/screen_sing.cc @@ -252,6 +252,7 @@ ScoreWindow::ScoreWindow(Engine& e, Players & players): ++p; } m_players.scores.sort(); + m_players.scores.reverse(); // top should be first // topScore is also in m_players.scores.front() if (m_players.cur.empty()) m_rank = "No singer!"; |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:40
|
Module: performous
Branch: master
Commit: ce821cfd8c2977fa3dd569094fdc2627eb2bc628
Author: Markus Raab <un...@ma...>
Date: Sat Jul 25 11:41:13 2009 +0200
entry in highscore works
verbose output for debugging
---
game/players.hh | 2 +
game/screen_players.cc | 65 ++++++++++++++++++++++++++++++++++++------------
game/screen_players.hh | 10 ++++++-
game/screen_sing.cc | 36 ++++++++++----------------
game/screen_sing.hh | 3 +-
5 files changed, 75 insertions(+), 41 deletions(-)
diff --git a/game/players.hh b/game/players.hh
index 10f24f9..5937926 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -35,6 +35,7 @@ class Players: boost::noncopyable {
private:
typedef std::vector<PlayerItem> players_t;
typedef std::list<Player> cur_players_t;
+ typedef std::list<int> cur_scores_t;
private:
players_t m_players;
@@ -48,6 +49,7 @@ class Players: boost::noncopyable {
public:
cur_players_t cur;
+ cur_scores_t scores;
public:
Players(std::string filename);
diff --git a/game/screen_players.cc b/game/screen_players.cc
index ceaa6ae..8623b81 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -14,6 +14,13 @@ ScreenPlayers::ScreenPlayers(std::string const& name, Audio& audio, Players& pla
}
void ScreenPlayers::enter() {
+ m_highscore.reset(new HighScore(m_song->path, "High.sco"));
+ try {
+ m_highscore->load();
+ } catch (HighScoreException const& hi) {
+ std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
+ }
+
theme.reset(new ThemeSongs());
m_emptyCover.reset(new Surface(getThemePath("no_cover.svg"))); // TODO use persons head
m_search.text.clear();
@@ -29,20 +36,27 @@ void ScreenPlayers::exit() {
m_songbg.reset();
m_playing.clear();
m_playReq.clear();
+
+ try {
+ m_highscore->save();
+ } catch (HighScoreException const& hi) {
+ std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
+ }
+ m_highscore.reset();
}
void ScreenPlayers::manageEvent(SDL_Event event) {
- ScreenManager* sm = ScreenManager::getSingletonPtr();
- if (event.type != SDL_KEYDOWN) return;
- SDL_keysym keysym = event.key.keysym;
- int key = keysym.sym;
- SDLMod mod = event.key.keysym.mod;
+ScreenManager* sm = ScreenManager::getSingletonPtr();
+if (event.type != SDL_KEYDOWN) return;
+SDL_keysym keysym = event.key.keysym;
+int key = keysym.sym;
+SDLMod mod = event.key.keysym.mod;
- if (key == SDLK_r && mod & KMOD_CTRL) { m_players.reload(); m_players.setFilter(m_search.text); }
- if (m_search.process(keysym)) m_players.setFilter(m_search.text);
- else if (key == SDLK_ESCAPE) {
- if (m_search.text.empty()) sm->activateScreen("Songs");
- else { m_search.text.clear(); m_players.setFilter(m_search.text); }
+if (key == SDLK_r && mod & KMOD_CTRL) { m_players.reload(); m_players.setFilter(m_search.text); }
+if (m_search.process(keysym)) m_players.setFilter(m_search.text);
+else if (key == SDLK_ESCAPE) {
+ if (m_search.text.empty()) sm->activateScreen("Songs");
+ else { m_search.text.clear(); m_players.setFilter(m_search.text); }
}
// The rest are only available when there are songs available
else if (m_players.empty()) return;
@@ -52,10 +66,27 @@ void ScreenPlayers::manageEvent(SDL_Event event) {
if (m_players.empty())
{
m_players.addPlayer(m_search.text);
- m_players.setFilter(m_search.text); // set new Player as current
+ m_players.setFilter(m_search.text);
+ // the current player is the new created one
+ }
+ std::cout << "add new highscore " << m_players.scores.front()
+ << " name: " << m_players.current().name
+ << std::endl;
+ m_highscore->addNewHighscore(m_players.current().name, m_players.scores.front());
+ m_players.scores.pop_front();
+
+ if (m_players.scores.empty() || !m_highscore->reachedNewHighscore(m_players.scores.front()))
+ {
+ // no more highscore, we are now finished
+ // clear the old players lists
+ m_players.scores.clear();
+ m_players.cur.clear();
+ sm->activateScreen("Songs");
+ } else {
+ std::cout << "enter the next highscore" << std::endl;
+ m_search.text.clear();
+ // enter the next highscore
}
- // we are now finished
- sm->activateScreen("Songs");
}
else if (key == SDLK_LEFT) m_players.advance(-1);
else if (key == SDLK_RIGHT) m_players.advance(1);
@@ -85,10 +116,12 @@ void ScreenPlayers::draw() {
oss_order << m_search.text << '\n';
}
} else {
- PlayerItem player = m_players.current();
// Format the player information text
- oss_song << player.name << '\n';
- oss_order << (m_search.text.empty() ? std::string("new player") : m_search.text) << '\n';
+ oss_song << "You reached " << m_players.scores.front() << " points\n";
+ oss_order << "Name: " << m_players.current().name
+ << " Search Text: "
+ << (m_search.text.empty() ? std::string("new player") : m_search.text)
+ << '\n';
oss_order << "(" << m_players.currentId() + 1 << "/" << m_players.size() << ")";
double spos = m_players.currentPosition(); // This needs to be polled to run the animation
diff --git a/game/screen_players.hh b/game/screen_players.hh
index c8294d9..86e68b5 100644
--- a/game/screen_players.hh
+++ b/game/screen_players.hh
@@ -6,10 +6,11 @@
#include "opengl_text.hh"
#include "screen.hh"
#include "surface.hh"
-#include "players.hh"
#include "textinput.hh"
#include "theme.hh"
#include "video.hh"
+#include "players.hh"
+#include "highscore.hh"
class CAudio;
@@ -23,9 +24,16 @@ class ScreenPlayers : public Screen {
void manageEvent(SDL_Event event);
void draw();
+ void setSong (boost::shared_ptr<Song> song_)
+ {
+ m_song = song_;
+ }
+
private:
Audio& m_audio;
Players& m_players;
+ boost::shared_ptr<Song> m_song; /// Pointer to the current song
+ boost::scoped_ptr<HighScore> 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.cc b/game/screen_sing.cc
index 71eac09..795b5b6 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -3,7 +3,6 @@
#include "util.hh"
#include "configuration.hh"
#include "xtime.hh"
-#include "highscore.hh"
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include "songs.hh"
@@ -71,11 +70,14 @@ void ScreenSing::manageEvent(SDL_Event event) {
else if (key == SDLK_RETURN) {
if (m_score_window.get())
{
- // Score window visible -> Enter quits to Songs or Players Screen
- // TODO if (m_players.hasNewHighscore()) sm->activateScreen("Players");
- sm->activateScreen("Songs");
+ // Score window visible -> Enter quits to Players Screen
+ Screen* s = sm->getScreen("Players");
+ ScreenPlayers* ss = dynamic_cast<ScreenPlayers*> (s);
+ assert(ss);
+ ss->setSong(m_song);
+ sm->activateScreen("Players");
}
- else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, *m_song, m_players)); // Song finished, but no score window -> show it
+ else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, m_players)); // Song finished, but no score window -> show it
}
else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
if (m_score_window.get()) return;
@@ -184,7 +186,7 @@ void ScreenSing::draw() {
}
else if (!m_audio.isPlaying() || (status == Song::FINISHED && m_audio.getLength() - time < 3.0)) {
m_quitTimer.setValue(QUIT_TIMEOUT);
- m_score_window.reset(new ScoreWindow(*m_engine, *m_song, m_players));
+ m_score_window.reset(new ScoreWindow(*m_engine, m_players));
}
}
@@ -212,8 +214,7 @@ void ScreenSing::drawScores() {
}
}
-ScoreWindow::ScoreWindow(Engine& e, Song const& song, Players & players):
- m_song(song),
+ScoreWindow::ScoreWindow(Engine& e, Players & players):
m_players(players),
m_pos(0.8, 2.0),
m_bg(getThemePath("score_window.svg")),
@@ -224,27 +225,18 @@ ScoreWindow::ScoreWindow(Engine& e, Song const& song, Players & players):
m_pos.setTarget(0.0);
e.kill(); // kill the engine thread (to avoid consuming memory)
-
- HighScore hi (m_song.path, "High.sco");
- // TODO fallback path if not writeable?
-
- try {
- hi.load();
- } catch (HighScoreException const& hi) {
- std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
- }
+ m_players.scores.clear();
unsigned int topScore = 0;
for (std::list<Player>::iterator p = m_players.cur.begin(); p != m_players.cur.end();) {
unsigned int score = p->getScore();
if (score < 500) { p = m_players.cur.erase(p); continue; }
+ m_players.scores.push_back(score);
if (score > topScore) topScore = score;
++p;
}
- try {
- hi.save();
- } catch (HighScoreException const& hi) {
- std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
- }
+ m_players.scores.sort();
+ // topScore is also in m_players.scores.front()
+
if (m_players.cur.empty()) m_rank = "No singer!";
else if (topScore > 8000) m_rank = "Hit singer";
else if (topScore > 6000) m_rank = "Lead singer";
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index c89ba9d..a096e63 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -21,12 +21,11 @@
class ScoreWindow {
public:
/// constructor
- ScoreWindow(Engine & e, Song const& song, Players & players);
+ ScoreWindow(Engine & e, Players & players);
/// draws ScoreWindow
void draw();
private:
- Song const& m_song;
Players & m_players;
AnimValue m_pos;
Surface m_bg;
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:36
|
Module: performous
Branch: master
Commit: 47b8558e3ab57ae277564e032695feea26aa69e7
Author: Markus Raab <un...@ma...>
Date: Sat Jul 25 12:09:57 2009 +0200
only show highscore when reached
better output
+ more debug
---
game/engine.hh | 4 ++++
game/screen_players.cc | 11 ++++-------
game/screen_sing.cc | 17 +++++++++++++++++
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/game/engine.hh b/game/engine.hh
index 83b247f..19c91ef 100644
--- a/game/engine.hh
+++ b/game/engine.hh
@@ -46,6 +46,10 @@ class Engine {
template <typename FwdIt> Engine(Audio& audio, Song& song, FwdIt anBegin, FwdIt anEnd, Players &players):
m_audio(audio), m_song(song), m_time(), m_quit(), m_players(players)
{
+ // clear old player information
+ m_players.cur.clear();
+ m_players.scores.clear();
+
size_t frames = m_audio.getLength() / Engine::TIMESTEP;
while (anBegin != anEnd) m_players.cur.push_back(Player(song, *anBegin++, frames));
size_t player = 0;
diff --git a/game/screen_players.cc b/game/screen_players.cc
index 8623b81..4b8a59e 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -78,9 +78,6 @@ else if (key == SDLK_ESCAPE) {
if (m_players.scores.empty() || !m_highscore->reachedNewHighscore(m_players.scores.front()))
{
// no more highscore, we are now finished
- // clear the old players lists
- m_players.scores.clear();
- m_players.cur.clear();
sm->activateScreen("Songs");
} else {
std::cout << "enter the next highscore" << std::endl;
@@ -112,14 +109,14 @@ void ScreenPlayers::draw() {
oss_order << "Check players.txt in current\n";
oss_order << "directory for players";
} else {
- oss_song << "press enter to create player";
+ oss_song << "Press enter to create player!";
oss_order << m_search.text << '\n';
}
} else {
// Format the player information text
- oss_song << "You reached " << m_players.scores.front() << " points\n";
- oss_order << "Name: " << m_players.current().name
- << " Search Text: "
+ oss_song << "You reached " << m_players.scores.front() << " points!\n";
+ oss_order << "Name: " << m_players.current().name << '\n'
+ << "Search Text: "
<< (m_search.text.empty() ? std::string("new player") : m_search.text)
<< '\n';
oss_order << "(" << m_players.currentId() + 1 << "/" << m_players.size() << ")";
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 795b5b6..10f6e5e 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -8,6 +8,7 @@
#include "songs.hh"
#include <iostream>
#include <iomanip>
+#include "highscore.hh" // to check if Players have to be shown
namespace {
static const double QUIT_TIMEOUT = 20.0; // Return to songs screen after 20 seconds in score screen
@@ -70,12 +71,28 @@ void ScreenSing::manageEvent(SDL_Event event) {
else if (key == SDLK_RETURN) {
if (m_score_window.get())
{
+ // TODO: multiple loading...
+ HighScore hi(m_song->path, "High.sco");
+ try {
+ hi.load();
+ } catch (HighScoreException const& hi) {
+ std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
+ }
+
+ if (m_players.scores.empty() || !hi.reachedNewHighscore(m_players.scores.front()))
+ {
+ // if no highscore reached..
+ sm->activateScreen("Songs");
+ return;
+ }
+
// Score window visible -> Enter quits to Players Screen
Screen* s = sm->getScreen("Players");
ScreenPlayers* ss = dynamic_cast<ScreenPlayers*> (s);
assert(ss);
ss->setSong(m_song);
sm->activateScreen("Players");
+ return;
}
else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, m_players)); // Song finished, but no score window -> show it
}
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:33
|
Module: performous Branch: master Commit: 95677ef408d5373b540dae72438491bad6092b42 Author: Markus Raab <un...@ma...> Date: Fri Jul 24 16:13:02 2009 +0200 Players screen is shown (It does not find any player yet) --- game/main.cc | 3 + game/players.cc | 33 +++++++++++- game/players.hh | 45 ++++++++++++++++- game/screen_players.cc | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ game/screen_players.hh | 38 ++++++++++++++ game/screen_sing.cc | 5 ++- game/screen_sing.hh | 2 + 7 files changed, 251 insertions(+), 5 deletions(-) |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:33
|
Module: performous Branch: master Commit: 742d2c952e84ecb69fabad4804351a32ce2bd3f5 Author: Markus Raab <un...@ma...> Date: Fri Jul 24 23:37:06 2009 +0200 Pass Players everywhere also current players are now handeled in the Players class Engine has reference to it Engine does not return it anymore (other classes get reference too) --- game/engine.hh | 21 ++++++++------------- game/layout_singer.cc | 8 +++++--- game/layout_singer.hh | 3 ++- game/notegraph.cc | 6 +++--- game/notegraph.hh | 4 ++-- game/players.cc | 3 ++- game/players.hh | 9 ++++++++- game/screen_players.cc | 5 +++-- game/screen_sing.cc | 46 +++++++++++++++++++++------------------------- game/screen_sing.hh | 9 ++++----- 10 files changed, 58 insertions(+), 56 deletions(-) |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:32
|
Module: performous
Branch: master
Commit: 2c28ed836d40f48266c611aa669a3ebefc1fdd0b
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 22:17:11 2009 +0200
sorting by score
---
game/player.hh | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/game/player.hh b/game/player.hh
index 8c49384..6335ec9 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -40,4 +40,9 @@ struct Player {
int getScore() const {
return 10000.0 * m_score;
}
+ /**Operator for sorting by score.*/
+ bool operator < (Player const& other) const
+ {
+ return other.m_score < m_score;
+ }
};
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:32
|
Module: performous
Branch: master
Commit: 15244b3ab9ad86db747e6ad47dc6154ba368ebbf
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 17:00:10 2009 +0200
people are displayed!
very relaxed filtering system
---
game/players.cc | 35 ++++++++++++++++++++++++++---------
game/players.hh | 9 +++++++--
game/screen_players.cc | 11 ++++++++++-
3 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/game/players.cc b/game/players.cc
index 3b70fe1..c9830d3 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -4,11 +4,20 @@
#include <boost/regex.hpp>
Players::Players(std::string filename):
- m_filename(filename)
-{}
+ m_players(),
+ m_filtered(),
+ m_filename(filename),
+ m_filter(),
+ math_cover()
+{
+ load();
+ m_filtered = m_players;
+}
Players::~Players()
-{}
+{
+ save();
+}
void Players::load()
{
@@ -31,10 +40,14 @@ void Players::save()
}
}
-void Players::addPlayer (std::string name)
+void Players::addPlayer (std::string const& name)
{
PlayerItem pi;
pi.name = name;
+
+ 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_players.push_back(pi);
}
@@ -45,6 +58,13 @@ void Players::setFilter(std::string const& val) {
}
void Players::filter_internal() {
+ if (m_filter == "")
+ {
+ // without filter get all names
+ m_filtered = m_players;
+ return;
+ }
+
try {
players_t filtered;
for (players_t::const_iterator it = m_players.begin(); it != m_players.end(); ++it) {
@@ -54,7 +74,7 @@ void Players::filter_internal() {
} catch (...) {
players_t(m_players.begin(), m_players.end()).swap(m_filtered); // Invalid regex => copy everything
}
- // TODO: reset images
+ math_cover.reset();
}
/*
@@ -66,15 +86,12 @@ int main(int argc, char** argv)
std::string filter = argv[1];
Players p("players.txt");
- p.load();
- // p.addPlayer(name);
+ p.addPlayer("hubert");
p.setFilter(filter);
for (size_t i=0; i<p.size(); i++)
{
std::cout << p[i].name << std::endl;
}
-
- p.save();
}
*/
diff --git a/game/players.hh b/game/players.hh
index 3979d3c..e45ea59 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -18,6 +18,11 @@ struct PlayerItem
std::string picture; /// a path to a picture shown
std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
*/
+
+ bool operator== (PlayerItem const& pi) const
+ {
+ return name == pi.name;
+ }
};
/**A collection of all Players.
@@ -47,7 +52,7 @@ class Players
load();
}
void save();
- void addPlayer (std::string name);
+ void addPlayer (std::string const& name);
/// advances to next player
void advance(int diff) {
@@ -61,7 +66,7 @@ class Players
PlayerItem operator[](std::size_t pos) { return m_filtered[pos]; }
PlayerItem operator[](std::size_t pos) const { return m_filtered[pos]; }
/// number of players
- int size() const { return m_filtered.size(); };
+ std::size_t size() const { return m_filtered.size(); };
/// true if empty
int empty() const { return m_filtered.empty(); };
/// filters playerlist by regular expression
diff --git a/game/screen_players.cc b/game/screen_players.cc
index 0a54faa..27166d0 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -11,11 +11,20 @@ ScreenPlayers::ScreenPlayers(std::string const& name, Audio& audio, Players& pla
{
m_players.setAnimMargins(5.0, 5.0);
m_playTimer.setTarget(getInf()); // Using this as a simple timer counting seconds
+
+ // print all names
+ std::cout << "Constructor of ScreenPlayers" << std::endl;
+ for (size_t i=0; i<m_players.size(); i++)
+ {
+ std::cout << "Name " << i << ": " << m_players[i].name << std::endl;
+ }
}
void ScreenPlayers::enter() {
+ std::cout << "Entered ScreenPlayers" << std::endl;
+
theme.reset(new ThemeSongs());
- m_emptyCover.reset(new Surface(getThemePath("no_cover.svg")));
+ m_emptyCover.reset(new Surface(getThemePath("no_cover.svg"))); // TODO use persons head
m_search.text.clear();
m_players.setFilter(m_search.text);
m_audio.fadeout();
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:30
|
Module: performous
Branch: master
Commit: 43dbba757fffda37d8629e84b70b48f517b7f0e4
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 19:15:02 2009 +0200
Now name from Players is taken
BUG: always the first name
independend from selection
---
game/highscore.cc | 3 +++
game/highscore.hh | 4 +++-
game/main.cc | 2 +-
game/screen_sing.cc | 9 +++++----
game/screen_sing.hh | 10 ++++++----
5 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/game/highscore.cc b/game/highscore.cc
index 559aab2..17768f0 100644
--- a/game/highscore.cc
+++ b/game/highscore.cc
@@ -115,6 +115,9 @@ void HighScore::save()
void HighScore::addNewHighscore(std::string name, int score)
{
+ // do not allow invalid name
+ if (name == "") return;
+
HighScoreItem hsi;
hsi.name = name;
hsi.score = score;
diff --git a/game/highscore.hh b/game/highscore.hh
index 032eb14..bed7ab8 100644
--- a/game/highscore.hh
+++ b/game/highscore.hh
@@ -50,7 +50,9 @@ class HighScore {
if (score < 500) return false;
return score > m_scores[2].score;
}
- /**Add a new entry to the highscore.*/
+ /**Add a new entry to the highscore.
+ It will do nothing on empty name.
+ */
void addNewHighscore(std::string name, int score);
private:
static const int m_maxEntries = 10;
diff --git a/game/main.cc b/game/main.cc
index 53744a6..dd7f5be 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -138,7 +138,7 @@ void mainLoop() {
Window window(config["graphic/window_width"].i(), config["graphic/window_height"].i(), config["graphic/fullscreen"].b(), config["graphic/fs_width"].i(), config["graphic/fs_height"].i());
sm.addScreen(new ScreenIntro("Intro", audio, capture));
sm.addScreen(new ScreenSongs("Songs", audio, songs));
- sm.addScreen(new ScreenSing("Sing", audio, capture));
+ sm.addScreen(new ScreenSing("Sing", audio, capture, players));
sm.addScreen(new ScreenPractice("Practice", audio, capture));
sm.addScreen(new ScreenConfiguration("Configuration", audio));
sm.addScreen(new ScreenPlayers("Players", audio, players));
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index bc49fd7..8460735 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -70,7 +70,7 @@ void ScreenSing::manageEvent(SDL_Event event) {
if (key == SDLK_ESCAPE || key == SDLK_q) sm->activateScreen("Songs");
else if (key == SDLK_RETURN) {
if (m_score_window.get()) sm->activateScreen("Songs"); // Score window visible -> Enter quits
- else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, *m_song)); // Song finished, but no score window -> show it
+ else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, *m_song, m_allplayers)); // Song finished, but no score window -> show it
}
else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
if (m_score_window.get()) return;
@@ -179,7 +179,7 @@ void ScreenSing::draw() {
}
else if (!m_audio.isPlaying() || (status == Song::FINISHED && m_audio.getLength() - time < 3.0)) {
m_quitTimer.setValue(QUIT_TIMEOUT);
- m_score_window.reset(new ScoreWindow(*m_engine, *m_song));
+ m_score_window.reset(new ScoreWindow(*m_engine, *m_song, m_allplayers));
}
}
@@ -208,8 +208,9 @@ void ScreenSing::drawScores() {
}
}
-ScoreWindow::ScoreWindow(Engine& e, Song const& song):
+ScoreWindow::ScoreWindow(Engine& e, Song const& song, Players & allplayers):
m_song(song),
+ m_allplayers(allplayers),
m_pos(0.8, 2.0),
m_bg(getThemePath("score_window.svg")),
m_scoreBar(getThemePath("score_bar_bg.svg"), getThemePath("score_bar_fg.svg"), ProgressBar::VERTICAL, 0.0, 0.0, false),
@@ -240,7 +241,7 @@ ScoreWindow::ScoreWindow(Engine& e, Song const& song):
ScreenManager* sm = ScreenManager::getSingletonPtr();
// show the players screen
sm->activateScreen("Players");
- hi.addNewHighscore(getenv ("USER"), score);
+ hi.addNewHighscore(m_allplayers.current().name, score);
}
}
try {
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index 0e55ce7..e5bdda5 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -21,12 +21,13 @@
class ScoreWindow {
public:
/// constructor
- ScoreWindow(Engine & e, Song const& song);
+ ScoreWindow(Engine & e, Song const& song, Players & players);
/// draws ScoreWindow
void draw();
private:
Song const& m_song;
+ Players & m_allplayers;
AnimValue m_pos;
Surface m_bg;
ProgressBar m_scoreBar;
@@ -40,8 +41,8 @@ class ScoreWindow {
class ScreenSing: public Screen {
public:
/// constructor
- ScreenSing(std::string const& name, Audio& audio, Capture& capture):
- Screen(name), m_audio(audio), m_capture(capture), m_latencyAV()
+ ScreenSing(std::string const& name, Audio& audio, Capture& capture, Players & allplayers):
+ Screen(name), m_audio(audio), m_capture(capture), m_allplayers(allplayers), m_latencyAV()
{}
void enter();
void exit();
@@ -56,9 +57,10 @@ class ScreenSing: public Screen {
private:
void drawScores();
Audio& m_audio;
+ Capture& m_capture;
+ Players& m_allplayers;
boost::shared_ptr<Song> m_song; /// Pointer to the current song
boost::scoped_ptr<ScoreWindow> m_score_window;
- Capture& m_capture;
boost::scoped_ptr<ProgressBar> m_progress;
boost::scoped_ptr<Surface> m_background;
boost::scoped_ptr<Video> m_video;
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:29
|
Module: performous
Branch: master
Commit: b2bad5d7d2794d071d001952445f42191eb8e3f9
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 18:58:40 2009 +0200
lots of fixes
dirty implementation
now selection works
you can press enter to quit
(but there song is replayed?,
but score is shown)
---
game/players.cc | 27 ++++++++++++++++++---------
game/players.hh | 37 ++++++++++++++++++++-----------------
game/screen_players.cc | 32 ++++++++++++++++----------------
3 files changed, 54 insertions(+), 42 deletions(-)
diff --git a/game/players.cc b/game/players.cc
index c9830d3..ec2c129 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -8,19 +8,18 @@ Players::Players(std::string filename):
m_filtered(),
m_filename(filename),
m_filter(),
- math_cover()
+ math_cover(),
+ m_dirty(false)
{
load();
m_filtered = m_players;
}
-Players::~Players()
-{
+Players::~Players() {
save();
}
-void Players::load()
-{
+void Players::load() {
std::ifstream in (m_filename.c_str());
std::string str;
@@ -30,8 +29,7 @@ void Players::load()
}
}
-void Players::save()
-{
+void Players::save() {
std::ofstream out (m_filename.c_str());
for (players_t::const_iterator it = m_players.begin(); it!=m_players.end(); ++it)
@@ -40,14 +38,18 @@ void Players::save()
}
}
-void Players::addPlayer (std::string const& name)
-{
+void Players::update() {
+ if (m_dirty) filter_internal();
+}
+
+void Players::addPlayer (std::string const& name) {
PlayerItem pi;
pi.name = name;
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);
}
@@ -57,9 +59,14 @@ void Players::setFilter(std::string const& val) {
filter_internal();
}
+#include <iostream> //TODO remove
+
void Players::filter_internal() {
+ m_dirty = false;
+
if (m_filter == "")
{
+ std::cout << "empty filter" << std::endl; //TODO remove
// without filter get all names
m_filtered = m_players;
return;
@@ -75,8 +82,10 @@ void Players::filter_internal() {
players_t(m_players.begin(), m_players.end()).swap(m_filtered); // Invalid regex => copy everything
}
math_cover.reset();
+ // TODO restore selection
}
+
/*
#include <iostream>
diff --git a/game/players.hh b/game/players.hh
index e45ea59..ca4bf43 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include <string>
+#include <boost/utility.hpp>
#include "animvalue.hh"
@@ -10,8 +11,7 @@
Used for Players Management.
*/
-struct PlayerItem
-{
+struct PlayerItem {
std::string name; /// unique name, link to highscore
/* Future ideas
std::string displayedName; /// artist name, short name, nick (can be changed)
@@ -29,8 +29,7 @@ struct PlayerItem
The current players plugged in a song can
be retrieved with Engine::getPlayers().*/
-class Players
-{
+class Players: boost::noncopyable {
public:
typedef std::vector<PlayerItem> players_t;
private:
@@ -41,6 +40,8 @@ class Players
std::string m_filter;
AnimAcceleration math_cover;
+ bool m_dirty;
+
public:
Players(std::string filename);
~Players();
@@ -52,8 +53,15 @@ class Players
load();
}
void save();
+ void update();
void addPlayer (std::string const& name);
+ /// const array access
+ PlayerItem operator[](std::size_t pos) const { return m_filtered[pos]; }
+ /// number of songs
+ size_t size() const { return m_filtered.size(); };
+ /// true if empty
+ int empty() const { return m_filtered.empty(); };
/// advances to next player
void advance(int diff) {
int size = m_filtered.size();
@@ -62,23 +70,18 @@ class Players
if (_current < 0) _current += m_filtered.size();
math_cover.setTarget(_current,this->size());
}
- /// array access
- PlayerItem operator[](std::size_t pos) { return m_filtered[pos]; }
- PlayerItem operator[](std::size_t pos) const { return m_filtered[pos]; }
- /// number of players
- std::size_t size() const { return m_filtered.size(); };
- /// true if empty
- int empty() const { return m_filtered.empty(); };
- /// filters playerlist by regular expression
- void setFilter(std::string const& regex);
- /// sets margins for animation
- void setAnimMargins(double left, double right) { math_cover.setMargins(left, right); }
- /// @return current PlayerItem (the copy is very cheap at the moment)
- PlayerItem current() const { return m_filtered[math_cover.getTarget()]; }
/// get current id
int currentId() const { return math_cover.getTarget(); }
/// gets current position
double currentPosition() { return math_cover.getValue(); }
+ /// gets current velocity
+ double currentVelocity() const { return math_cover.getVelocity(); }
+ /// sets margins for animation
+ void setAnimMargins(double left, double right) { math_cover.setMargins(left, right); }
+ /// @return current PlayerItem (the copy is very cheap at the moment)
+ PlayerItem current() const { return m_filtered[math_cover.getTarget()]; }
+ /// filters playerlist by regular expression
+ void setFilter(std::string const& regex);
private:
void filter_internal();
};
diff --git a/game/screen_players.cc b/game/screen_players.cc
index 27166d0..5253a17 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -11,18 +11,9 @@ ScreenPlayers::ScreenPlayers(std::string const& name, Audio& audio, Players& pla
{
m_players.setAnimMargins(5.0, 5.0);
m_playTimer.setTarget(getInf()); // Using this as a simple timer counting seconds
-
- // print all names
- std::cout << "Constructor of ScreenPlayers" << std::endl;
- for (size_t i=0; i<m_players.size(); i++)
- {
- std::cout << "Name " << i << ": " << m_players[i].name << std::endl;
- }
}
void ScreenPlayers::enter() {
- std::cout << "Entered ScreenPlayers" << std::endl;
-
theme.reset(new ThemeSongs());
m_emptyCover.reset(new Surface(getThemePath("no_cover.svg"))); // TODO use persons head
m_search.text.clear();
@@ -41,7 +32,7 @@ void ScreenPlayers::exit() {
}
void ScreenPlayers::manageEvent(SDL_Event event) {
- // ScreenManager* sm = ScreenManager::getSingletonPtr();
+ ScreenManager* sm = ScreenManager::getSingletonPtr();
if (event.type != SDL_KEYDOWN) return;
SDL_keysym keysym = event.key.keysym;
int key = keysym.sym;
@@ -50,25 +41,34 @@ void ScreenPlayers::manageEvent(SDL_Event event) {
if (key == SDLK_r && mod & KMOD_CTRL) { m_players.reload(); m_players.setFilter(m_search.text); }
if (m_search.process(keysym)) m_players.setFilter(m_search.text);
else if (key == SDLK_ESCAPE) {
- if (m_search.text.empty())/*TODO*/; // sm->activateScreen("Intro");
+ if (m_search.text.empty()) sm->activateScreen("Sing");
else { m_search.text.clear(); m_players.setFilter(m_search.text); }
}
// The rest are only available when there are songs available
else if (m_players.empty()) return;
else if (key == SDLK_SPACE || (key == SDLK_PAUSE || (key == SDLK_p && mod & KMOD_CTRL))) m_audio.togglePause();
- else if (key == SDLK_RETURN)/*TODO*/; // sm->activateScreen("Score");
+ else if (key == SDLK_RETURN)
+ {
+ if (m_players.empty())
+ {
+ m_players.addPlayer(m_search.text);
+ m_players.setFilter(m_search.text); // set new Player as current
+ }
+ sm->activateScreen("Sing");
+ }
else if (key == SDLK_LEFT) m_players.advance(-1);
else if (key == SDLK_RIGHT) m_players.advance(1);
else if (key == SDLK_PAGEUP) m_players.advance(-10);
else if (key == SDLK_PAGEDOWN) m_players.advance(10);
- // else if (key == SDLK_TAB && !(mod & KMOD_ALT)) m_players.randomize();
}
void ScreenPlayers::draw() {
+ m_players.update(); // Poll for new players
double length = m_audio.getLength();
double time = clamp(m_audio.getPosition() - config["audio/video_delay"].f(), 0.0, length);
if (m_songbg.get()) m_songbg->draw();
if (m_video.get()) m_video->render(time);
+ theme->bg.draw();
std::string music, songbg, video;
double videoGap = 0.0;
std::ostringstream oss_song, oss_order;
@@ -77,10 +77,10 @@ void ScreenPlayers::draw() {
// Format the song information text
if (m_search.text.empty()) {
oss_song << "No players found!";
- oss_order << "Visit performous.org\n";
+ oss_order << "Check players.txt in current\n";
+ oss_order << "directory for players";
} else {
- // TODO: create new player
- oss_song << "no players match search";
+ oss_song << "press enter to create player";
oss_order << m_search.text << '\n';
}
} else {
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:27
|
Module: performous
Branch: master
Commit: 440be91e969bea142095c2d4bbb24c1ab4b169d9
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 09:03:12 2009 +0200
player in separate class
prepare for players
---
game/engine.cc | 20 --------------------
game/engine.hh | 40 +---------------------------------------
game/player.cc | 24 ++++++++++++++++++++++++
game/player.hh | 44 ++++++++++++++++++++++++++++++++++++++++++++
game/players.cc | 7 +++++++
game/players.hh | 16 ++++++++++++++++
6 files changed, 92 insertions(+), 59 deletions(-)
diff --git a/game/engine.cc b/game/engine.cc
index b9e2f53..c774bea 100644
--- a/game/engine.cc
+++ b/game/engine.cc
@@ -2,23 +2,3 @@
const double Engine::TIMESTEP = 0.01;
-void Player::update() {
- if (m_pos == m_pitch.size()) return; // End of song already
- Tone const* t = m_analyzer.findTone();
- if (t) {
- m_activitytimer = 1000;
- double beginTime = Engine::TIMESTEP * m_pos;
- m_pitch[m_pos++] = std::make_pair(t->freq, t->stabledb);
- double endTime = Engine::TIMESTEP * m_pos;
- while (m_scoreIt != m_song.notes.end()) {
- m_score += m_song.m_scoreFactor * m_scoreIt->score(m_song.scale.getNote(t->freq), beginTime, endTime);
- if (endTime < m_scoreIt->end) break;
- ++m_scoreIt;
- }
- m_score = clamp(m_score, 0.0, 1.0);
- } else {
- if (m_activitytimer > 0) --m_activitytimer;
- m_pitch[m_pos++] = std::make_pair(getNaN(), -getInf());
- }
-}
-
diff --git a/game/engine.hh b/game/engine.hh
index d1c2625..ac8c2bd 100644
--- a/game/engine.hh
+++ b/game/engine.hh
@@ -5,52 +5,14 @@
#include "audio.hh"
#include "color.hh"
#include "pitch.hh"
-#include "screen.hh"
#include "songs.hh"
-#include "util.hh"
#include "xtime.hh"
#include "configuration.hh"
+#include "player.hh"
#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
-#include <limits>
#include <list>
-#include <utility>
-
-/// player class
-struct Player {
- /// currently playing song
- Song& m_song;
- /// sound analyzer
- Analyzer& m_analyzer;
- /// player color for bars, waves, scores
- Color m_color;
- /// typedef for pitch
- typedef std::vector<std::pair<double, double> > pitch_t;
- /// player's pitch
- pitch_t m_pitch;
- /// current position in pitch vector (first unused spot)
- size_t m_pos;
- /// score for current song
- double m_score;
- /// activity timer
- unsigned m_activitytimer;
- /// score iterator
- Notes::const_iterator m_scoreIt;
- /// constructor
- Player(Song& song, Analyzer& analyzer, size_t frames): m_song(song), m_analyzer(analyzer), m_pitch(frames, std::make_pair(getNaN(), -getInf())), m_pos(), m_score(), m_activitytimer(), m_scoreIt(m_song.notes.begin()) {}
- /// prepares analyzer
- void prepare() { m_analyzer.process(); }
- /// updates player stats
- void update();
- /// player activity singing
- float activity() const { return m_activitytimer / 300.0; }
- /// get player's score
- int getScore() const {
- return 10000.0 * m_score;
- }
-
-};
namespace {
const Color playerColors[] = {
diff --git a/game/player.cc b/game/player.cc
new file mode 100644
index 0000000..697ad5e
--- /dev/null
+++ b/game/player.cc
@@ -0,0 +1,24 @@
+#include "player.hh"
+
+#include "engine.hh" // just for Engine::TIMESTEP
+
+void Player::update() {
+ if (m_pos == m_pitch.size()) return; // End of song already
+ Tone const* t = m_analyzer.findTone();
+ if (t) {
+ m_activitytimer = 1000;
+ double beginTime = Engine::TIMESTEP * m_pos;
+ m_pitch[m_pos++] = std::make_pair(t->freq, t->stabledb);
+ double endTime = Engine::TIMESTEP * m_pos;
+ while (m_scoreIt != m_song.notes.end()) {
+ m_score += m_song.m_scoreFactor * m_scoreIt->score(m_song.scale.getNote(t->freq), beginTime, endTime);
+ if (endTime < m_scoreIt->end) break;
+ ++m_scoreIt;
+ }
+ m_score = clamp(m_score, 0.0, 1.0);
+ } else {
+ if (m_activitytimer > 0) --m_activitytimer;
+ m_pitch[m_pos++] = std::make_pair(getNaN(), -getInf());
+ }
+}
+
diff --git a/game/player.hh b/game/player.hh
new file mode 100644
index 0000000..a983e51
--- /dev/null
+++ b/game/player.hh
@@ -0,0 +1,44 @@
+#pragma once
+#include "songs.hh"
+#include "color.hh"
+#include "pitch.hh"
+#include "util.hh"
+
+#include <vector>
+#include <limits>
+
+
+/// player class
+struct Player {
+ /// currently playing song
+ Song& m_song;
+ /// sound analyzer
+ Analyzer& m_analyzer;
+ /// player color for bars, waves, scores
+ Color m_color;
+ /// typedef for pitch
+ typedef std::vector<std::pair<double, double> > pitch_t;
+ /// player's pitch
+ pitch_t m_pitch;
+ /// current position in pitch vector (first unused spot)
+ size_t m_pos;
+ /// score for current song
+ double m_score;
+ /// activity timer
+ unsigned m_activitytimer;
+ /// score iterator
+ Notes::const_iterator m_scoreIt;
+ /// constructor
+ Player(Song& song, Analyzer& analyzer, size_t frames): m_song(song), m_analyzer(analyzer), m_pitch(frames, std::make_pair(getNaN(), -getInf())), m_pos(), m_score(), m_activitytimer(), m_scoreIt(m_song.notes.begin()) {}
+ /// prepares analyzer
+ void prepare() { m_analyzer.process(); }
+ /// updates player stats
+ void update();
+ /// player activity singing
+ float activity() const { return m_activitytimer / 300.0; }
+ /// get player's score
+ int getScore() const {
+ return 10000.0 * m_score;
+ }
+
+};
diff --git a/game/players.cc b/game/players.cc
new file mode 100644
index 0000000..e9eb96c
--- /dev/null
+++ b/game/players.cc
@@ -0,0 +1,7 @@
+#include "players.hh"
+
+void Players::load()
+{}
+
+void Players::save()
+{}
diff --git a/game/players.hh b/game/players.hh
new file mode 100644
index 0000000..e400984
--- /dev/null
+++ b/game/players.hh
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "player.hh"
+
+/**A collection of all Players.
+
+ The current players plugged in a song can
+ be retrieved with Engine::getPlayers().*/
+class Players
+{
+ private:
+ std::list<Player> m_players;
+ public:
+ void load();
+ void save();
+};
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:24
|
Module: performous Branch: master Commit: 1e7b8afa48542e6830baf1a8497bbb452557efc8 Author: Markus Raab <un...@ma...> Date: Fri Jul 24 13:24:20 2009 +0200 added pragma once in all header files --- game/cachemap.hh | 1 + game/color.hh | 1 + game/config.cmake.hh | 2 ++ game/dialog.hh | 1 + game/midifile.hh | 1 + game/opengl_text.hh | 1 + game/pitch.hh | 1 + game/screen_intro.hh | 1 + game/screen_practice.hh | 1 + game/screen_songs.hh | 1 + game/singleton.hh | 1 + game/textinput.hh | 1 + game/unused/fftgraph.hh | 1 + game/xtime.hh | 1 + 14 files changed, 15 insertions(+), 0 deletions(-) diff --git a/game/cachemap.hh b/game/cachemap.hh index b20bba7..7a59dc0 100644 --- a/game/cachemap.hh +++ b/game/cachemap.hh @@ -1,3 +1,4 @@ +#pragma once #include <boost/ptr_container/ptr_map.hpp> #include <list> diff --git a/game/color.hh b/game/color.hh index 9559747..57ca3fe 100644 --- a/game/color.hh +++ b/game/color.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef PERFORMOUS_COLOR_HH #define PERFORMOUS_COLOR_HH diff --git a/game/config.cmake.hh b/game/config.cmake.hh index f81e70a..593a7b0 100644 --- a/game/config.cmake.hh +++ b/game/config.cmake.hh @@ -1,3 +1,5 @@ +#pragma once + // CMake uses config.cmake.hh to generate config.hh within the build folder. #ifndef PERFORMOUS_CONFIG_HH #define PERFORMOUS_CONFIG_HH diff --git a/game/dialog.hh b/game/dialog.hh index bec8dce..ce57981 100644 --- a/game/dialog.hh +++ b/game/dialog.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef PERFORMOUS_DIALOG_HH #define PERFORMOUS_DIALOG_HH diff --git a/game/midifile.hh b/game/midifile.hh index 2ce9c46..9ba85f8 100644 --- a/game/midifile.hh +++ b/game/midifile.hh @@ -1,3 +1,4 @@ +#pragma once #include <boost/cstdint.hpp> #include <fstream> #include <map> diff --git a/game/opengl_text.hh b/game/opengl_text.hh index 37c8af1..b2f9e97 100644 --- a/game/opengl_text.hh +++ b/game/opengl_text.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef __OPENGL_THEME_H__ #define __OPENGL_THEME_H__ diff --git a/game/pitch.hh b/game/pitch.hh index 6bc68a5..f64132d 100644 --- a/game/pitch.hh +++ b/game/pitch.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef USNG_PITCH_H_INCLUDED #define USNG_PITCH_H_INCLUDED diff --git a/game/screen_intro.hh b/game/screen_intro.hh index 125462b..9e6c4ac 100644 --- a/game/screen_intro.hh +++ b/game/screen_intro.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef __SCREENINTRO_H__ #define __SCREENINTRO_H__ diff --git a/game/screen_practice.hh b/game/screen_practice.hh index 8c72c16..1816055 100644 --- a/game/screen_practice.hh +++ b/game/screen_practice.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef __SCREENPRACTICE_H__ #define __SCREENPRACTICE_H__ diff --git a/game/screen_songs.hh b/game/screen_songs.hh index 6eefff8..9508227 100644 --- a/game/screen_songs.hh +++ b/game/screen_songs.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef PERFORMOUS_SCREEN_SONGS_HH #define PERFORMOUS_SCREEN_SONGS_HH diff --git a/game/singleton.hh b/game/singleton.hh index a85ce93..75361c0 100644 --- a/game/singleton.hh +++ b/game/singleton.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef __SINGLETON_H__ #define __SINGLETON_H__ diff --git a/game/textinput.hh b/game/textinput.hh index 11156c6..67b36f1 100644 --- a/game/textinput.hh +++ b/game/textinput.hh @@ -1,3 +1,4 @@ +#pragma once #include <SDL.h> #include <string> diff --git a/game/unused/fftgraph.hh b/game/unused/fftgraph.hh index cd38fcb..5f6b8d9 100644 --- a/game/unused/fftgraph.hh +++ b/game/unused/fftgraph.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef PERFORMOUS_FFTGRAPH_HH #define PERFORMOUS_FFTGRAPH_HH diff --git a/game/xtime.hh b/game/xtime.hh index 99a7d63..ff3109b 100644 --- a/game/xtime.hh +++ b/game/xtime.hh @@ -1,3 +1,4 @@ +#pragma once #ifndef USNG_XTIME_H_INCLUDED #define USNG_XTIME_H_INCLUDED |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:22
|
Module: performous
Branch: master
Commit: 10ffe1bca8ff11bc9563bb892bc40e0ca87c452b
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 12:31:27 2009 +0200
a very very basic Players implementation
---
game/.gitignore | 2 ++
game/player.hh | 15 ---------------
game/players.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
game/players.hh | 26 ++++++++++++++++++++++++--
4 files changed, 72 insertions(+), 19 deletions(-)
diff --git a/game/.gitignore b/game/.gitignore
index 179d259..13ba250 100644
--- a/game/.gitignore
+++ b/game/.gitignore
@@ -2,3 +2,5 @@
Makefile
highscore
highscore.txt
+players
+players.txt
diff --git a/game/player.hh b/game/player.hh
index 5d3e7eb..8c49384 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -41,18 +41,3 @@ struct Player {
return 10000.0 * m_score;
}
};
-
-/** Static Information of a player, not
- dependent from current song.
-
- Used for Players Management.
- */
-struct PlayerItem
-{
- std::string name; /// unique name, link to highscore
-/* Future ideas
- std::string displayedName; /// artist name, short name, nick (can be changed)
- std::string picture; /// a path to a picture shown
- std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
-*/
-};
diff --git a/game/players.cc b/game/players.cc
index e9eb96c..eb33f87 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -1,7 +1,51 @@
#include "players.hh"
-void Players::load()
+#include <fstream>
+
+Players::Players(std::string filename):
+ m_filename(filename)
{}
-void Players::save()
+Players::~Players()
{}
+
+void Players::load()
+{
+ std::ifstream in (m_filename.c_str());
+
+ std::string str;
+ while (getline(in, str))
+ {
+ addPlayer(str);
+ }
+}
+
+void Players::save()
+{
+ std::ofstream out (m_filename.c_str());
+
+ for (players_t::const_iterator it = m_players.begin(); it!=m_players.end(); ++it)
+ {
+ out << it->name << std::endl;
+ }
+}
+
+void Players::addPlayer (std::string name)
+{
+ PlayerItem pi;
+ pi.name = name;
+ m_players.push_back(pi);
+}
+
+#include <iostream>
+
+int main(int argc, char** argv)
+{
+ if (argc != 2) return 1;
+
+ std::string name = argv[1];
+ Players p("players.txt");
+ p.load();
+ p.addPlayer(name);
+ p.save();
+}
diff --git a/game/players.hh b/game/players.hh
index 8d3187d..ac94092 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -1,6 +1,22 @@
#pragma once
+#include <list>
+#include <string>
-#include "player.hh"
+
+/** Static Information of a player, not
+ dependent from current song.
+
+ Used for Players Management.
+ */
+struct PlayerItem
+{
+ std::string name; /// unique name, link to highscore
+/* Future ideas
+ std::string displayedName; /// artist name, short name, nick (can be changed)
+ std::string picture; /// a path to a picture shown
+ std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
+*/
+};
/**A collection of all Players.
@@ -8,9 +24,15 @@
be retrieved with Engine::getPlayers().*/
class Players
{
+ public:
+ typedef std::list<PlayerItem> players_t;
private:
- std::list<PlayerItem> m_players;
+ players_t m_players;
+ std::string m_filename;
public:
+ Players(std::string filename);
+ ~Players();
void load();
void save();
+ void addPlayer (std::string name);
};
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:21
|
Module: performous Branch: master Commit: 47973d0500dbaeb1aa289211c2fda114daef35bd Author: Markus Raab <un...@ma...> Date: Fri Jul 24 08:29:11 2009 +0200 only one song is passed to ScreenSing also pass the current Song to ScoreWindow --- game/layout_singer.cc | 6 +++--- game/layout_singer.hh | 4 ++-- game/main.cc | 2 +- game/screen_sing.cc | 33 ++++++++++++++++----------------- game/screen_sing.hh | 14 ++++++++++---- game/screen_songs.cc | 31 ++++++++++++++++++++++--------- game/screen_songs.hh | 1 + game/songs.hh | 2 ++ 8 files changed, 57 insertions(+), 36 deletions(-) |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:21
|
Module: performous
Branch: master
Commit: 54f381e4c47697c1f995b0656dcb5d0150bb3c4d
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 12:06:05 2009 +0200
Introduce PlayerItem
---
game/player.hh | 14 ++++++++++++++
game/players.hh | 2 +-
2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/game/player.hh b/game/player.hh
index a983e51..5d3e7eb 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -40,5 +40,19 @@ struct Player {
int getScore() const {
return 10000.0 * m_score;
}
+};
+
+/** Static Information of a player, not
+ dependent from current song.
+ Used for Players Management.
+ */
+struct PlayerItem
+{
+ std::string name; /// unique name, link to highscore
+/* Future ideas
+ std::string displayedName; /// artist name, short name, nick (can be changed)
+ std::string picture; /// a path to a picture shown
+ std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
+*/
};
diff --git a/game/players.hh b/game/players.hh
index e400984..8d3187d 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -9,7 +9,7 @@
class Players
{
private:
- std::list<Player> m_players;
+ std::list<PlayerItem> m_players;
public:
void load();
void save();
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:17
|
Module: performous
Branch: master
Commit: c2119b87fbf54d136864aa14eb603e007c09b17a
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 08:38:20 2009 +0200
Take path of song
needs songdir writeable to save highscore
---
game/screen_sing.cc | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 7044366..a3f39d1 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -221,8 +221,8 @@ ScoreWindow::ScoreWindow(Engine& e, Song const& song):
e.kill(); // kill the engine thread (to avoid consuming memory)
- // TODO correct path and filename
- HighScore hi ("", "High.sco");
+ HighScore hi (m_song.path, "High.sco");
+ // TODO fallback path if not writeable?
try {
hi.load();
} catch (HighScoreException const& hi) {
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:14
|
Module: performous Branch: master Commit: 761ca1ed6cf6c38700d705cda92bc14bf24001e3 Author: Markus Raab <un...@ma...> Date: Thu Jul 23 17:10:36 2009 +0200 utf8 converting --- game/highscore.cc | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/game/highscore.cc b/game/highscore.cc index ef74176..559aab2 100644 --- a/game/highscore.cc +++ b/game/highscore.cc @@ -34,7 +34,7 @@ void HighScore::load() std::stringstream ss; ss.write(&data[0], size); - // XXX convertToUTF8(ss, m_path + m_filename); + convertToUTF8(ss, m_path + m_filename); // now parse line by line and build up highscore std::string str; |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:13
|
Module: performous
Branch: master
Commit: 03504520d99ebba6d95a6898b4d9be67a45d9d2e
Author: Markus Raab <un...@ma...>
Date: Thu Jul 23 16:53:18 2009 +0200
write highscore after song
---
game/screen_sing.cc | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 3a21b47..2df6466 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -3,6 +3,7 @@
#include "util.hh"
#include "configuration.hh"
#include "xtime.hh"
+#include "highscore.hh"
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include "songs.hh"
@@ -218,13 +219,32 @@ ScoreWindow::ScoreWindow(Engine& e):
m_players(e.getPlayers())
{
m_pos.setTarget(0.0);
- unsigned int topScore = 0;
e.kill(); // kill the engine thread (to avoid consuming memory)
+
+
+ // TODO correct path and filename
+ HighScore hi ("", "High.sco");
+ try {
+ hi.load();
+ } catch (HighScoreException const& hi) {
+ std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
+ }
+ unsigned int topScore = 0;
for (std::list<Player>::iterator p = m_players.begin(); p != m_players.end();) {
unsigned int score = p->getScore();
if (score < 500) { p = m_players.erase(p); continue; }
if (score > topScore) topScore = score;
++p;
+ if (hi.reachedNewHighscore(score))
+ {
+ // TODO ask for name...
+ hi.addNewHighscore(getenv ("USER"), score);
+ }
+ }
+ try {
+ hi.save();
+ } catch (HighScoreException const& hi) {
+ std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
}
if (m_players.empty()) m_rank = "No singer!";
else if (topScore > 8000) m_rank = "Hit singer";
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:13
|
Module: performous
Branch: master
Commit: 7e7937546cee1ef1aaebe1a137584dd9ba10ff3e
Author: Markus Raab <un...@ma...>
Date: Thu Jul 23 10:42:16 2009 +0200
highscore implementation
---
game/.gitignore | 3 ++
game/highscore.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++
game/highscore.hh | 27 ++++++++++++++
3 files changed, 132 insertions(+), 0 deletions(-)
diff --git a/game/.gitignore b/game/.gitignore
new file mode 100644
index 0000000..6899cb8
--- /dev/null
+++ b/game/.gitignore
@@ -0,0 +1,3 @@
+.ctags
+Makefile
+highscore.txt
diff --git a/game/highscore.cc b/game/highscore.cc
new file mode 100644
index 0000000..8c67110
--- /dev/null
+++ b/game/highscore.cc
@@ -0,0 +1,102 @@
+#include "highscore.hh"
+#include <boost/lexical_cast.hpp>
+
+#include "unicode.hh"
+
+#include <fstream>
+#include <sstream>
+
+HighScore::HighScore (std::string const& path_, std::string const& filename_) :
+ m_path(path_),
+ m_filename(filename_)
+{
+ std::ifstream in((m_path + m_filename).c_str());
+
+ if (!in.is_open()) throw HighScoreException("Could not open highscore file", 0);
+
+
+ in.seekg(0, std::ios::end);
+ size_t size = in.tellg();
+ if (size < 10 || size > 100000) throw HighScoreException("Does not look like a highscore file (wrong size)", 1);
+ in.seekg(0);
+
+ std::vector<char> data(size);
+ if (!in.read(&data[0], size)) throw HighScoreException("Unexpected I/O error", 0);
+
+ std::stringstream ss;
+ ss.write(&data[0], size);
+
+ convertToUTF8(ss, m_path + m_filename);
+
+ // now parse line by line and build up highscore
+ std::string str;
+ unsigned int linenum = 0;
+ unsigned int playernum = 0;
+ while (std::getline(ss, str))
+ {
+ if (str == "E") break;
+ linenum++;
+ if (playernum > 9) throw HighScoreException("Not more than 10 highscores expected in file", linenum);
+ if (str.empty()) continue; // ignore empty player lines
+ if (str.length() <= 9) throw HighScoreException("Line not long enough for player information", linenum);
+
+ if (str[0] != '#') throw HighScoreException("No # found at begin of line", linenum);
+ if (str.substr(1,6) != "PLAYER") throw HighScoreException("Expected PLAYER not found", linenum);
+
+ unsigned int nr = str[7];
+ if (nr != playernum + '0') throw HighScoreException("Did not find correct playernum", linenum);
+ if (str[8] != ':') throw HighScoreException("Did not find :", linenum);
+
+ std::string name = str.substr(9, str.length()-9);
+ if (name.empty()) throw HighScoreException("Did not find name", linenum);
+ std::cout << "name: " << name << std::endl;
+ m_names.push_back(name);
+
+ std::getline(ss, str);
+ linenum++;
+ if (str.empty()) throw HighScoreException("Expected Score, but found empty line", linenum);
+ if (str.length() <= 8) throw HighScoreException("Line not long enough for score information", linenum);
+
+ if (str[0] != '#') throw HighScoreException("No # found at begin of line", linenum);
+ if (str.substr(1,5) != "SCORE") throw HighScoreException("Expected SCORE not found", linenum);
+
+ nr = str[6];
+ if (nr != playernum + '0') throw HighScoreException("Did not find correct playernum", linenum);
+ if (str[7] != ':') throw HighScoreException("Did not find :", linenum);
+
+ std::string score = str.substr(8, str.length()-8);
+ if (score.empty()) throw HighScoreException("Did not find score", linenum);
+ std::cout << "score: " << score << std::endl;
+
+ try {
+ double dscore = boost::lexical_cast<int>(score) / 10000.0;
+ if (dscore < 0.0 || dscore > 1.0) throw HighScoreException("Number not between 0 and 10000", linenum);
+ if (playernum>0 && m_scores.back() < dscore) throw HighScoreException("Lower ranked highscore is higher", linenum);
+ m_scores.push_back(dscore);
+ } catch (boost::bad_lexical_cast const& blc)
+ {
+ throw HighScoreException("Did not find valid double number", linenum);
+ }
+
+ playernum++;
+ }
+}
+
+HighScore::~HighScore()
+{}
+
+/*
+#include <iostream> // TODO debug
+
+int main()
+{
+ try {
+ HighScore hi ("", "highscore.txt");
+ } catch (HighScoreException const& hie)
+ {
+ std::cerr << "Exception: " << hie.what()
+ << " at line: " << hie.line()
+ << std::endl;
+ }
+}
+*/
diff --git a/game/highscore.hh b/game/highscore.hh
new file mode 100644
index 0000000..5f4d766
--- /dev/null
+++ b/game/highscore.hh
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include <stdexcept>
+
+struct HighScoreException: public std::runtime_error {
+ HighScoreException (std::string const& msg, unsigned int linenum) :
+ runtime_error(msg), m_linenum(linenum)
+ {}
+ unsigned int line() const {return m_linenum;}
+ private:
+ unsigned int m_linenum;
+};
+
+class HighScore {
+ public:
+ HighScore (std::string const& path_, std::string const& filename_);
+ ~HighScore ();
+
+ void save();
+ private:
+ std::string m_path;
+ std::string m_filename;
+ std::vector <std::string> m_names;
+ std::vector <double> m_scores;
+};
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:12
|
Module: performous
Branch: master
Commit: e7b84f6167e152d3ab84a98b17f89f26ed5d79f5
Author: Markus Raab <un...@ma...>
Date: Thu Jul 23 16:33:20 2009 +0200
highscore is now a int number between 0 and 10000
---
game/highscore.cc | 19 +++++++++++--------
game/highscore.hh | 11 +++++++----
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/game/highscore.cc b/game/highscore.cc
index 46bdc87..ef74176 100644
--- a/game/highscore.cc
+++ b/game/highscore.cc
@@ -74,15 +74,16 @@ void HighScore::load()
std::string sscore = str.substr(8, str.length()-8);
if (sscore.empty()) throw HighScoreException("Did not find score", linenum);
+ int score = 0;
try {
- double score = boost::lexical_cast<int>(sscore) / 10000.0;
- if (score < 0.0 || score > 1.0) throw HighScoreException("Number not between 0 and 10000", linenum);
- if (playernum>0 && m_scores[playernum-1].score < score) throw HighScoreException("Lower ranked highscore is higher", linenum);
- m_scores[playernum].score = score;
+ score = boost::lexical_cast<int>(sscore);
} catch (boost::bad_lexical_cast const& blc)
{
- throw HighScoreException("Did not find valid double number", linenum);
+ throw HighScoreException("Did not find valid int number", linenum);
}
+ if (score < 0 || score > 10000) throw HighScoreException("Number not between 0 and 10000", linenum);
+ if (playernum>0 && m_scores[playernum-1].score < score) throw HighScoreException("Lower ranked highscore is higher", linenum);
+ m_scores[playernum].score = score;
playernum++;
@@ -98,11 +99,13 @@ void HighScore::save()
out.exceptions ( std::ofstream::eofbit | std::ofstream::failbit | std::ofstream::badbit );
for (size_t i=0; i<m_scores.size();i++)
{
+ if (m_scores[i].score <= 0) break; // maybe change to 500?
+
try {
out << "#PLAYER" << i << ":"
<< m_scores[i].name << std::endl;
out << "#SCORE" << i << ":"
- << m_scores[i].score*10000 << std::endl;
+ << m_scores[i].score << std::endl;
} catch (std::ofstream::failure const&) {
throw HighScoreException("Unexpected I/O error", i);
}
@@ -110,7 +113,7 @@ void HighScore::save()
out << "E" << std::endl;
}
-void HighScore::addNewHighscore(std::string name, double score)
+void HighScore::addNewHighscore(std::string name, int score)
{
HighScoreItem hsi;
hsi.name = name;
@@ -130,7 +133,7 @@ int main()
try {
HighScore hi ("", "highscore.txt");
hi.load();
- double new_score = 0.9;
+ int new_score = 9000;
if (hi.reachedNewHighscore(new_score))
{
std::cout << "Reached new highscore" << std::endl;
diff --git a/game/highscore.hh b/game/highscore.hh
index ea50b93..032eb14 100644
--- a/game/highscore.hh
+++ b/game/highscore.hh
@@ -20,7 +20,7 @@ struct HighScoreException: public std::runtime_error {
single item of a highscore.*/
struct HighScoreItem {
std::string name;
- double score;
+ int score;
// std::string song;
/**Operator for sorting by score.*/
@@ -40,15 +40,18 @@ class HighScore {
void save();
/**Check if you reached a new highscore.
+ @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 addNewHighscore does not make sense
for that score.*/
- bool reachedNewHighscore(double score)
+ bool reachedNewHighscore(int score)
{
- return score > m_scores.back().score;
+ if (score < 500) return false;
+ return score > m_scores[2].score;
}
/**Add a new entry to the highscore.*/
- void addNewHighscore(std::string name, double score);
+ void addNewHighscore(std::string name, int score);
private:
static const int m_maxEntries = 10;
std::string m_path;
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:10
|
Module: performous
Branch: master
Commit: 7ec7250d7b2d8e342927fdfc455fc8b32d615314
Author: Markus Raab <un...@ma...>
Date: Thu Jul 23 15:56:19 2009 +0200
loading and saving Highscore now works
---
game/.gitignore | 1 +
game/highscore.cc | 73 ++++++++++++++++++++++++++++++++++++++++++----------
game/highscore.hh | 34 +++++++++++++++++++++++-
3 files changed, 92 insertions(+), 16 deletions(-)
diff --git a/game/.gitignore b/game/.gitignore
index 6899cb8..179d259 100644
--- a/game/.gitignore
+++ b/game/.gitignore
@@ -1,3 +1,4 @@
.ctags
Makefile
+highscore
highscore.txt
diff --git a/game/highscore.cc b/game/highscore.cc
index 8c67110..46bdc87 100644
--- a/game/highscore.cc
+++ b/game/highscore.cc
@@ -5,10 +5,18 @@
#include <fstream>
#include <sstream>
+#include <algorithm>
HighScore::HighScore (std::string const& path_, std::string const& filename_) :
m_path(path_),
- m_filename(filename_)
+ m_filename(filename_),
+ m_scores(m_maxEntries)
+{}
+
+HighScore::~HighScore()
+{}
+
+void HighScore::load()
{
std::ifstream in((m_path + m_filename).c_str());
@@ -26,7 +34,7 @@ HighScore::HighScore (std::string const& path_, std::string const& filename_) :
std::stringstream ss;
ss.write(&data[0], size);
- convertToUTF8(ss, m_path + m_filename);
+ // XXX convertToUTF8(ss, m_path + m_filename);
// now parse line by line and build up highscore
std::string str;
@@ -49,8 +57,7 @@ HighScore::HighScore (std::string const& path_, std::string const& filename_) :
std::string name = str.substr(9, str.length()-9);
if (name.empty()) throw HighScoreException("Did not find name", linenum);
- std::cout << "name: " << name << std::endl;
- m_names.push_back(name);
+ m_scores[playernum].name = name;
std::getline(ss, str);
linenum++;
@@ -64,34 +71,72 @@ HighScore::HighScore (std::string const& path_, std::string const& filename_) :
if (nr != playernum + '0') throw HighScoreException("Did not find correct playernum", linenum);
if (str[7] != ':') throw HighScoreException("Did not find :", linenum);
- std::string score = str.substr(8, str.length()-8);
- if (score.empty()) throw HighScoreException("Did not find score", linenum);
- std::cout << "score: " << score << std::endl;
+ std::string sscore = str.substr(8, str.length()-8);
+ if (sscore.empty()) throw HighScoreException("Did not find score", linenum);
try {
- double dscore = boost::lexical_cast<int>(score) / 10000.0;
- if (dscore < 0.0 || dscore > 1.0) throw HighScoreException("Number not between 0 and 10000", linenum);
- if (playernum>0 && m_scores.back() < dscore) throw HighScoreException("Lower ranked highscore is higher", linenum);
- m_scores.push_back(dscore);
+ double score = boost::lexical_cast<int>(sscore) / 10000.0;
+ if (score < 0.0 || score > 1.0) throw HighScoreException("Number not between 0 and 10000", linenum);
+ if (playernum>0 && m_scores[playernum-1].score < score) throw HighScoreException("Lower ranked highscore is higher", linenum);
+ m_scores[playernum].score = score;
} catch (boost::bad_lexical_cast const& blc)
{
throw HighScoreException("Did not find valid double number", linenum);
}
+
playernum++;
}
}
-HighScore::~HighScore()
-{}
+void HighScore::save()
+{
+ std::ofstream out ((m_path + m_filename).c_str());
+
+ if (!out.is_open()) throw HighScoreException("Could not open file for writing", 0);
+
+ out.exceptions ( std::ofstream::eofbit | std::ofstream::failbit | std::ofstream::badbit );
+ for (size_t i=0; i<m_scores.size();i++)
+ {
+ try {
+ out << "#PLAYER" << i << ":"
+ << m_scores[i].name << std::endl;
+ out << "#SCORE" << i << ":"
+ << m_scores[i].score*10000 << std::endl;
+ } catch (std::ofstream::failure const&) {
+ throw HighScoreException("Unexpected I/O error", i);
+ }
+ }
+ out << "E" << std::endl;
+}
+
+void HighScore::addNewHighscore(std::string name, double score)
+{
+ HighScoreItem hsi;
+ hsi.name = name;
+ hsi.score = score;
+
+ m_scores.push_back(hsi);
+ std::sort(m_scores.begin(), m_scores.end());
+
+ m_scores.resize(m_maxEntries); // throw away worst score
+}
/*
-#include <iostream> // TODO debug
+#include <iostream>
int main()
{
try {
HighScore hi ("", "highscore.txt");
+ hi.load();
+ double new_score = 0.9;
+ if (hi.reachedNewHighscore(new_score))
+ {
+ std::cout << "Reached new highscore" << std::endl;
+ hi.addNewHighscore("new player", new_score);
+ }
+ hi.save();
} catch (HighScoreException const& hie)
{
std::cerr << "Exception: " << hie.what()
diff --git a/game/highscore.hh b/game/highscore.hh
index 5f4d766..ea50b93 100644
--- a/game/highscore.hh
+++ b/game/highscore.hh
@@ -4,24 +4,54 @@
#include <vector>
#include <stdexcept>
+/**Exception which will be thrown when loading or
+ saving a HighScore fails.*/
struct HighScoreException: public std::runtime_error {
HighScoreException (std::string const& msg, unsigned int linenum) :
runtime_error(msg), m_linenum(linenum)
{}
+ /**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
+ single item of a highscore.*/
+struct HighScoreItem {
+ std::string name;
+ double score;
+ // std::string song;
+
+ /**Operator for sorting by score.*/
+ bool operator < (HighScoreItem const& other) const
+ {
+ return other.score < score;
+ }
+};
+
+/**HighScore loads and saves a list of HighScoreItems.*/
class HighScore {
public:
HighScore (std::string const& path_, std::string const& filename_);
~HighScore ();
+ void load();
void save();
+
+ /**Check if you reached a new highscore.
+ @return true if the score make it into the top.
+ @return false if addNewHighscore does not make sense
+ for that score.*/
+ bool reachedNewHighscore(double score)
+ {
+ return score > m_scores.back().score;
+ }
+ /**Add a new entry to the highscore.*/
+ void addNewHighscore(std::string name, double score);
private:
+ static const int m_maxEntries = 10;
std::string m_path;
std::string m_filename;
- std::vector <std::string> m_names;
- std::vector <double> m_scores;
+ std::vector <HighScoreItem> m_scores;
};
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:04
|
Module: performous Branch: master Commit: ba813b3730474c05f3431d32c181b9c26e78316b Author: Markus Raab <un...@ma...> Date: Thu Jul 23 10:26:03 2009 +0200 small fixes in Compiling.txt --- docs/Compiling.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Compiling.txt b/docs/Compiling.txt index 8156f6c..8f1128d 100644 --- a/docs/Compiling.txt +++ b/docs/Compiling.txt @@ -14,7 +14,7 @@ To install from git: performous # Should you need to change building settings (e.g. installation prefix) - ccmake . + ccmake .. Dependencies: @@ -55,7 +55,7 @@ After that make sure that all the characters display correctly. If they don't, you need to guess which charset the original used (instead of CP1252) and retry. If you want to improve the game, join our IRC channel #Performous (Freenode) and -you'll get SVN write access. +you'll get git write access. For more (up to date) information, see http://performous.org/ |
|
From: Markus R. <god...@us...> - 2009-07-29 15:35:00
|
Module: performous
Branch: master
Commit: 47770d645728a085eecb435cfcaf228b36f7bf09
Author: Markus Raab <un...@ma...>
Date: Thu Jul 23 08:35:26 2009 +0200
missing include file
performous builds now on debian etch
---
game/joystick.cc | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index a787e68..d105b7f 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -1,6 +1,8 @@
#include "joystick.hh"
#include <iostream>
+#include <boost/lexical_cast.hpp>
+
Joysticks joysticks;
Joystick::Joystick(unsigned int _id): m_id(_id) {
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:34:58
|
Module: performous Branch: hiscore Commit: 4e72409fcb6b2412df88692cef7988448ba1fd86 Author: Markus Raab <un...@ma...> Date: Wed Jul 29 13:52:48 2009 +0200 Merge branch 'highscore' Conflicts: game/layout_singer.cc game/layout_singer.hh game/notegraph.cc game/notegraph.hh game/screen_sing.cc game/screen_songs.cc --- |
|
From: Markus R. <god...@us...> - 2009-07-29 15:34:57
|
Module: performous
Branch: hiscore
Commit: 82595126294551b772ac38d3842f9733163c5ca1
Author: Markus Raab <un...@ma...>
Date: Wed Jul 29 12:24:41 2009 +0200
optimize deactivation
---
game/screen_sing.cc | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 09161f8..5ec8717 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -63,6 +63,13 @@ void ScreenSing::activatePlayerScreen()
{
ScreenManager* sm = ScreenManager::getSingletonPtr();
+ if (!config["game/song_hiscore"].b())
+ {
+ // user does not want a per song highscore
+ sm->activateScreen("Songs");
+ return;
+ }
+
// TODO: multiple loading...
// TODO: make it possible to switch of highscore through configuration
SongHiscore hi(m_song->path, "High.sco");
@@ -74,8 +81,7 @@ void ScreenSing::activatePlayerScreen()
if (m_players.scores.empty()
|| !hi.reachedNewHiscore(m_players.scores.front())
- || !hi.isWritable()
- || !config["game/song_hiscore"].b())
+ || !hi.isWritable())
{
// if no highscore reached..
sm->activateScreen("Songs");
|
|
From: Markus R. <god...@us...> - 2009-07-29 15:34:55
|
Module: performous
Branch: hiscore
Commit: 75c176eb6cf015d46d220777115e43f73743b51e
Author: Markus Raab <un...@ma...>
Date: Wed Jul 29 11:34:15 2009 +0200
bug fix
check path, because there might be a picture given in
xml but not as file
---
game/screen_players.cc | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/game/screen_players.cc b/game/screen_players.cc
index f2b6542..81e819c 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -162,7 +162,7 @@ void ScreenPlayers::draw() {
PlayerItem player_display = m_players[baseidx + i];
if (baseidx + i < 0 || baseidx + i >= int(ss)) continue;
Surface* cover = 0;
- if (player_display.picture != "")
+ if (player_display.path != "")
{
try { cover = &m_covers[player_display.path + "/" + player_display.picture]; }
catch (std::exception const&) {}
|