|
From: Yoda-JM <yo...@us...> - 2009-08-21 12:45:45
|
Module: performous
Branch: master
Commit: 5c34641afd53fae9acca8fd2e4d25f94387609d0
Author: Vincent Le Ligeour <yo...@us...>
Date: Fri Aug 21 14:44:52 2009 +0200
Removed some vector of tracks to replace it by map of tracks
---
game/guitargraph.cc | 16 ++++++++--------
game/guitargraph.hh | 2 +-
game/notes.hh | 14 +++++++++-----
game/screen_sing.cc | 8 ++++----
game/screen_songs.cc | 8 ++++----
game/song.cc | 2 +-
game/song.hh | 2 +-
game/songparser-ini.cc | 6 +++---
8 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 379f8e7..eeb74b2 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -69,16 +69,16 @@ 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 (Tracks::const_iterator it = m_song.tracks.begin(); it != m_song.tracks.end(); ++it) {
- if (drums != (it->name == "drums")) continue;
- m_tracks.push_back(&*it);
- if (it->name == "drums") m_necks.push_back(new Texture("drumneck.svg"));
- else if (it->name == "bass") m_necks.push_back(new Texture("bassneck.svg"));
+ 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"));
}
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 tracks");
+ if (m_tracks.empty()) throw std::runtime_error("No track");
difficultyAuto();
}
@@ -262,8 +262,8 @@ bool GuitarGraph::difficulty(Difficulty level) {
m_track %= m_tracks.size();
Track const& track = *m_tracks[m_track];
// Find the stream number
- for (m_stream = 0; m_stream < m_song.tracks.size(); ++m_stream) {
- if (&track == &m_song.tracks[m_stream]) break;
+ for (TrackMap::const_iterator it = m_song.track_map.begin(); it != m_song.track_map.end(); ++it) {
+ if (&track == &it->second) break;
}
// Check if the difficulty level is available
uint8_t basepitch = diffv[level].basepitch;
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index 9345dbb..bc321e7 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -68,7 +68,7 @@ class GuitarGraph {
AnimValue m_cx, m_width;
unsigned m_track;
std::size_t m_stream;
- std::vector<Track const*> m_tracks;
+ TrackVectorConstPtr m_tracks;
void drumHit(double time, int pad);
void guitarPlay(double time, input::Event const& ev);
enum Difficulty {
diff --git a/game/notes.hh b/game/notes.hh
index 29f22f5..59c3fc6 100644
--- a/game/notes.hh
+++ b/game/notes.hh
@@ -46,18 +46,22 @@ typedef std::vector<Duration> Durations;
typedef std::map<int, Durations> NoteMap;
struct Track {
+ // TODO: name should not be needed here (contained into the map)
Track(std::string n): name(n) {}
std::string name;
NoteMap nm;
};
-typedef std::vector<Track> Tracks;
+// TODO: remove the following two types
+typedef std::vector<Track> TrackVector;
+typedef std::vector<Track const*> TrackVectorConstPtr;
+// keep these ones
+typedef std::map<std::string,Track> TrackMap;
+typedef std::map<std::string,Track const*> TrackMapConstPtr; // this one really needed ? can't we save only the map key for comparison ?
namespace {
- bool isTrackInside(Tracks &_tracks, std::string _name) {
- for( Tracks::iterator it = _tracks.begin() ; it != _tracks.end() ; ++it ) {
- if(it->name == _name) return true;
- }
+ bool isTrackInside(TrackMap &track_map, std::string name) {
+ if( track_map.find(name) != track_map.end() ) return true;
return false;
}
}
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 9640093..f64115d 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -33,7 +33,7 @@ void ScreenSing::enter() {
m_engine.reset(new Engine(m_audio, *m_song, analyzers.begin(), analyzers.end(), m_players));
m_layout_singer.reset(new LayoutSinger(*m_song, m_players, theme));
// I know some purists would hang me for this loop
- if( !m_song->tracks.empty() ) {
+ if( !m_song->track_map.empty() ) {
bool drums = false;
for (int num = 0; true; ++num) {
try {
@@ -153,7 +153,7 @@ void ScreenSing::manageEvent(SDL_Event event) {
else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
if (m_score_window.get()) return;
// The rest are only available when score window is not displayed and when there are no instruments
- if (key == SDLK_RETURN && status == Song::INSTRUMENTAL_BREAK && m_song->tracks.empty()) {
+ if (key == SDLK_RETURN && status == Song::INSTRUMENTAL_BREAK && m_song->track_map.empty()) {
double diff = m_layout_singer->lyrics_begin() - 3.0 - time;
if (diff > 0.0) m_audio.seek(diff);
}
@@ -240,14 +240,14 @@ void ScreenSing::draw() {
unsigned t = clamp(time, 0.0, length);
m_progress->draw(songPercent);
std::string statustxt = (boost::format("%02u:%02u") % (t / 60) % (t % 60)).str();
- if (!m_score_window.get() && m_song->tracks.empty()) {
+ if (!m_score_window.get() && m_song->track_map.empty()) {
if (status == Song::INSTRUMENTAL_BREAK) statustxt += " ENTER to skip instrumental break";
if (status == Song::FINISHED && !config["game/karaoke_mode"].b()) statustxt += " Remember to wait for grading!";
}
theme->timer.draw(statustxt);
}
- if (config["game/karaoke_mode"].b() || !m_song->tracks.empty()) {
+ if (config["game/karaoke_mode"].b() || !m_song->track_map.empty()) {
if (!m_audio.isPlaying()) {
ScreenManager* sm = ScreenManager::getSingletonPtr();
sm->activateScreen("Songs");
diff --git a/game/screen_songs.cc b/game/screen_songs.cc
index e0bd153..a4cb4cb 100644
--- a/game/screen_songs.cc
+++ b/game/screen_songs.cc
@@ -205,7 +205,7 @@ void ScreenSongs::draw() {
// Fetch cover image from cache or try loading it
if (!song_display.cover.empty()) try { cover = &m_covers[song_display.path + song_display.cover]; } catch (std::exception const&) {}
if (!cover) {
- size_t tracks = song_display.tracks.size();
+ size_t tracks = song_display.track_map.size();
if (tracks == 0) cover = m_emptyCover.get();
else if (tracks == 1) cover = m_instrumentCover.get();
else cover = m_bandCover.get();
@@ -243,7 +243,7 @@ void ScreenSongs::draw() {
}
{
// guitar
- alpha = (isTrackInside(song_display.tracks,"guitar")) ? 1.00 : 0.25;
+ alpha = (isTrackInside(song_display.track_map,"guitar")) ? 1.00 : 0.25;
glutil::Begin block(GL_TRIANGLE_STRIP);
glColor4f(1.0, 1.0, 1.0, alpha);
x = dim.x1()+0.25*(dim.x2()-dim.x1());
@@ -255,7 +255,7 @@ void ScreenSongs::draw() {
}
{
// bass
- alpha = (isTrackInside(song_display.tracks,"bass")) ? 1.00 : 0.25;
+ alpha = (isTrackInside(song_display.track_map,"bass")) ? 1.00 : 0.25;
glutil::Begin block(GL_TRIANGLE_STRIP);
glColor4f(1.0, 1.0, 1.0, alpha);
x = dim.x1()+0.50*(dim.x2()-dim.x1());
@@ -267,7 +267,7 @@ void ScreenSongs::draw() {
}
{
// drums
- alpha = (isTrackInside(song_display.tracks,"drums")) ? 1.00 : 0.25;
+ alpha = (isTrackInside(song_display.track_map,"drums")) ? 1.00 : 0.25;
glutil::Begin block(GL_TRIANGLE_STRIP);
glColor4f(1.0, 1.0, 1.0, alpha);
x = dim.x1()+0.75*(dim.x2()-dim.x1());
diff --git a/game/song.cc b/game/song.cc
index 31de0c2..31831a6 100644
--- a/game/song.cc
+++ b/game/song.cc
@@ -5,7 +5,7 @@
void Song::reload(bool errorIgnore) {
notes.clear();
- tracks.clear();
+ track_map.clear();
beats.clear();
category.clear();
genre.clear();
diff --git a/game/song.hh b/game/song.hh
index 968c889..41b0b2e 100644
--- a/game/song.hh
+++ b/game/song.hh
@@ -37,7 +37,7 @@ class Song: boost::noncopyable {
Status status(double time) const;
int randomIdx; ///< sorting index used for random order
Notes notes; ///< notes for song (only used for singing)
- Tracks tracks; ///< guitar etc. notes for this song
+ TrackMap track_map; ///< guitar etc. notes for this song
typedef std::vector<double> Beats;
Beats beats;
int noteMin, ///< lowest note
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index 74a99b1..5899b1f 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -85,10 +85,10 @@ void SongParser::iniParse() {
// Process non-vocal tracks
if (name != "VOCALS") {
bool drums = (name == "drums");
- s.tracks.push_back(Track(name));
- NoteMap& nm = s.tracks.back().nm;
+ s.track_map.insert(make_pair(name,Track(name)));
+ NoteMap& nm2 = s.track_map.find(name)->second.nm;
for (MidiFileParser::NoteMap::const_iterator it2 = it->notes.begin(); it2 != it->notes.end(); ++it2) {
- Durations& dur = nm[it2->first];
+ Durations& dur = nm2[it2->first];
MidiFileParser::Notes const& notes = it2->second;
for (MidiFileParser::Notes::const_iterator it3 = notes.begin(); it3 != notes.end(); ++it3) {
double beg = midi.get_seconds(it3->begin);
|