|
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();
+};
|