|
From: Yoda-JM <yo...@us...> - 2009-09-01 19:30:22
|
Module: performous
Branch: master
Commit: ef4dae4b74d8f7029c72a9b58ecbe7c5e6452faf
Author: Vincent Le Ligeour <yo...@us...>
Date: Tue Sep 1 21:30:05 2009 +0200
Enabled back instrument audio mute
---
game/guitargraph.cc | 38 ++++++++++++++++++++++++--------------
game/guitargraph.hh | 7 ++++---
game/screen_sing.cc | 22 +++++++++-------------
3 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index eeb74b2..9f50c34 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -46,7 +46,6 @@ GuitarGraph::GuitarGraph(Audio& audio, Song const& song, bool drums, unsigned tr
m_drums(drums),
m_cx(0.0, 0.2),
m_width(0.5, 0.4),
- m_track(track),
m_stream(),
m_level(),
m_dead(1000),
@@ -69,16 +68,19 @@ GuitarGraph::GuitarGraph(Audio& audio, Song const& song, bool drums, unsigned tr
g_samplesG.push_back(Sample(getDataPath("sounds/guitar_fail5.ogg"), sr));
g_samplesG.push_back(Sample(getDataPath("sounds/guitar_fail6.ogg"), sr));
}
- for (TrackMap::const_iterator it = m_song.track_map.begin(); it != m_song.track_map.end(); ++it) {
- if (drums != (it->first == "drums")) continue;
- m_tracks.push_back(&it->second);
- if (it->first == "drums") m_necks.push_back(new Texture("drumneck.svg"));
- else if (it->first == "bass") m_necks.push_back(new Texture("bassneck.svg"));
- else m_necks.push_back(new Texture("guitarneck.svg"));
+ unsigned int i = 0;
+ for (TrackMap::const_iterator it = m_song.track_map.begin(); it != m_song.track_map.end(); ++it,++i) {
+ std::string index = it->first;
+ if (drums != (index == "drums")) continue;
+ m_track_map.insert(make_pair(index, &it->second));
+ if( i == track ) m_track_index = index;
+ if (index == "drums") m_necks.insert(index, new Texture("drumneck.svg"));
+ else if (index == "bass") m_necks.insert(index, new Texture("bassneck.svg"));
+ else m_necks.insert(index, new Texture("guitarneck.svg"));
}
for (int i = 0; i < 6; ++i) m_hit[i].setRate(5.0);
for (int i = 0; i < 5; ++i) m_holds[i] = 0;
- if (m_tracks.empty()) throw std::runtime_error("No track");
+ if (m_track_map.empty()) throw std::runtime_error("No track");
difficultyAuto();
}
@@ -102,7 +104,16 @@ void GuitarGraph::engine() {
if (time < -0.5) {
if (ev.type == input::Event::PICK || (m_drums && ev.type == input::Event::PRESS)) {
if (m_drums ? ev.pressed[0] : ev.pressed[4]) {
- ++m_track;
+ // lets find the next track
+ TrackMapConstPtr::iterator track_it = m_track_map.find(m_track_index);
+ if( track_it != m_track_map.end() ) {
+ ++track_it;
+ if(track_it != m_track_map.end()) {
+ m_track_index = track_it->first;
+ } else {
+ m_track_index = m_track_map.begin()->first;
+ }
+ }
if (!difficulty(m_level)) difficultyAuto();
}
if (ev.pressed[0 + m_drums]) difficulty(DIFFICULTY_SUPAEASY);
@@ -259,8 +270,7 @@ void GuitarGraph::difficultyAuto() {
}
bool GuitarGraph::difficulty(Difficulty level) {
- m_track %= m_tracks.size();
- Track const& track = *m_tracks[m_track];
+ Track const& track = *m_track_map.find(m_track_index)->second;
// Find the stream number
for (TrackMap::const_iterator it = m_song.track_map.begin(); it != m_song.track_map.end(); ++it) {
if (&track == &it->second) break;
@@ -299,7 +309,7 @@ void GuitarGraph::draw(double time) {
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
if (time < -0.5) {
std::string txt;
- txt += m_tracks[m_track]->name + "\n" + diffv[m_level].name;
+ txt += m_track_map.find(m_track_index)->first + "\n" + diffv[m_level].name;
m_text.dimensions.screenBottom(-0.05).middle(-0.1 + offsetX);
m_text.draw(txt);
} else {
@@ -314,7 +324,7 @@ void GuitarGraph::draw(double time) {
{ float s = dimensions.w() / 5.0f; glScalef(s, s, s); }
// Draw the neck
{
- UseTexture tex(m_necks[m_track]);
+ UseTexture tex(*m_necks.find(m_track_index)->second);
glutil::Begin block(GL_TRIANGLE_STRIP);
float w = (m_drums ? 2.0f : 2.5f);
float texCoord = 0.0f;
@@ -441,7 +451,7 @@ void GuitarGraph::updateChords() {
Durations::size_type pos[5] = {}, size[5] = {};
Durations const* durations[5] = {};
for (int fret = 0; fret < 5; ++fret) {
- NoteMap const& nm = m_tracks[m_track]->nm;
+ NoteMap const& nm = m_track_map.find(m_track_index)->second->nm;
int basepitch = diffv[m_level].basepitch;
NoteMap::const_iterator it = nm.find(basepitch + fret);
if (it == nm.end()) continue;
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index bc321e7..b965104 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -53,6 +53,7 @@ class GuitarGraph {
double dead(double time) const { return time > -0.5 && m_dead > 50; }
unsigned stream() const { return m_stream; }
double correctness() const { return m_correctness.get(); }
+ std::string getTrackIndex() const { return m_track_index;}
private:
void fail(double time, int fret);
void endHold(int fret);
@@ -63,12 +64,12 @@ class GuitarGraph {
Texture m_button_l;
Surface m_tap;
AnimValue m_hit[6];
- boost::ptr_vector<Texture> m_necks;
+ boost::ptr_map<std::string,Texture> m_necks;
bool m_drums;
AnimValue m_cx, m_width;
- unsigned m_track;
+ std::string m_track_index;
std::size_t m_stream;
- TrackVectorConstPtr m_tracks;
+ TrackMapConstPtr m_track_map;
void drumHit(double time, int pad);
void guitarPlay(double time, input::Event const& ev);
enum Difficulty {
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index f64115d..4567cc3 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -55,10 +55,10 @@ void ScreenSing::instrumentLayout(double time) {
m_instruments[i].position((0.5 + i - 0.5 * s) * iw, iw);
}
typedef std::pair<unsigned, double> CountSum;
- std::map<unsigned, CountSum> volume; // stream id to (count, sum)
+ std::map<std::string, CountSum> volume; // stream id to (count, sum)
for (Instruments::iterator it = m_instruments.begin(); it != m_instruments.end(); ++it) {
it->engine();
- CountSum& cs = volume[it->stream() + 1];
+ CountSum& cs = volume[it->getTrackIndex()];
cs.first++;
cs.second += it->correctness();
it->draw(time);
@@ -69,20 +69,16 @@ void ScreenSing::instrumentLayout(double time) {
glColor3f(1.0f, 1.0f, 1.0f);
}
// Set volume levels (averages of all instruments playing that track)
- for (std::size_t i = 0, s = m_song->music.size(); i < s; ++i) {
- double level = 1.0;
- CountSum cs = volume[i];
- if (cs.first > 0) level = cs.second / cs.first;
- //m_audio.streamFade(i, level); // +1 because 0 is bg
- }
- /*
for( std::map<std::string,std::string>::iterator it = m_song->music.begin() ; it != m_song->music.end() ; ++it ) {
double level = 1.0;
- CountSum cs = volume[it->first];
- if (cs.first > 0) level = cs.second / cs.first;
- m_audio.streamFade(it->first, level);
+ if( volume.find(it->first) == volume.end() ) {
+ m_audio.streamFade(it->first, level);
+ } else {
+ CountSum cs = volume[it->first];
+ if (cs.first > 0) level = cs.second / cs.first;
+ m_audio.streamFade(it->first, level);
+ }
}
- */
}
void ScreenSing::exit() {
|