|
From: knittl <kn...@us...> - 2009-08-03 08:40:48
|
Module: performous
Branch: master
Commit: 4e9c499c37363cfe6bdb726768e231d94ebd1bb3
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Aug 1 20:04:41 2009 +0300
Proper instrument selection by controller type.
Automatic instrument selection (instead of everybody being guitar).
Drums go in the middle.
---
game/guitargraph.cc | 34 ++++++++++++++++++----------------
game/guitargraph.hh | 5 +++--
game/screen_sing.cc | 12 +++++-------
3 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 5237b90..5705dca 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -30,7 +30,7 @@ namespace {
}
-GuitarGraph::GuitarGraph(Song const& song, bool drums):
+GuitarGraph::GuitarGraph(Song const& song, bool drums, unsigned track):
m_input(drums ? input::DRUMS : input::GUITAR),
m_song(song),
m_button("button.svg"),
@@ -39,17 +39,20 @@ GuitarGraph::GuitarGraph(Song const& song, bool drums):
m_drums(drums),
m_cx(),
m_width(0.5),
- m_instrument(),
+ m_track(track),
m_level(),
m_text(getThemePath("sing_timetxt.svg"), config["graphic/text_lod"].f()),
m_hammerReady(0.0, 2.0),
m_score()
{
- std::size_t tracks = m_song.tracks.size();
- if (tracks == 0) throw std::runtime_error("No tracks");
- m_necks.push_back(new Texture("guitarneck.svg"));
- if (tracks > 1) m_necks.push_back(new Texture("bassneck.svg"));
- if (tracks > 2) m_necks.push_back(new Texture("drumneck.svg"));
+ 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("guitarneck.svg"));
+ else m_necks.push_back(new Texture("bassneck.svg"));
+ }
+ if (m_tracks.empty()) throw std::runtime_error("No tracks");
difficultyAuto();
}
@@ -61,7 +64,7 @@ void GuitarGraph::engine(double time) {
if (time < -0.5) {
if (ev.type == input::Event::PICK) {
if (ev.pressed[4]) {
- ++m_instrument;
+ ++m_track;
if (!difficulty(m_level)) difficultyAuto();
}
if (ev.pressed[0]) difficulty(DIFFICULTY_SUPAEASY);
@@ -79,7 +82,7 @@ void GuitarGraph::engine(double time) {
void GuitarGraph::drumHit(double time, int fret) {
if (fret == 0) m_pickValue.setValue(1.0);
int basepitch = diffv[m_level].basepitch;
- NoteMap const& nm = m_song.tracks[m_instrument].nm;
+ NoteMap const& nm = m_tracks[m_track]->nm;
NoteMap::const_iterator it = nm.find(basepitch + fret);
if (it == nm.end()) return;
Durations const& dur = it->second;
@@ -159,9 +162,8 @@ void GuitarGraph::difficultyAuto() {
}
bool GuitarGraph::difficulty(Difficulty level) {
- m_instrument %= m_song.tracks.size();
- Track const& track = m_song.tracks[m_instrument];
- m_drums = (m_song.tracks[m_instrument].name == "DRUMS");
+ m_track %= m_tracks.size();
+ Track const& track = *m_tracks[m_track];
uint8_t basepitch = diffv[level].basepitch;
NoteMap const& nm = track.nm;
int fail = 0;
@@ -191,7 +193,7 @@ glutil::Color const& GuitarGraph::color(int fret) const {
void GuitarGraph::draw(double time) {
if (time < -0.5) {
std::string txt = (m_drums ? "Hit a pad to change:\n" : "Play a fret to change:\n");
- txt += m_song.tracks[m_instrument].name + "/" + diffv[m_level].name;
+ txt += m_tracks[m_track]->name + "/" + diffv[m_level].name;
m_text.dimensions.screenBottom(-0.05).middle(0.0);
m_text.draw(txt);
} else {
@@ -207,9 +209,9 @@ void GuitarGraph::draw(double time) {
{ float s = dimensions.w() / 5.0f; glScalef(s, s, s); }
// Draw the neck
{
- UseTexture tex(m_necks[m_instrument]);
+ UseTexture tex(m_necks[m_track]);
glutil::Begin block(GL_TRIANGLE_STRIP);
- float w = m_instrument == 2 ? 2.0f : 2.5f;
+ float w = (m_drums ? 2.0f : 2.5f);
float texCoord = 0.0f;
float tBeg = 0.0f, tEnd;
for (Song::Beats::const_iterator it = m_song.beats.begin(); it != m_song.beats.end() && tBeg < future; ++it, texCoord += texCoordStep, tBeg = tEnd) {
@@ -301,7 +303,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_song.tracks[m_instrument].nm;
+ NoteMap const& nm = m_tracks[m_track]->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 eac6681..4fae928 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -47,7 +47,7 @@ static inline bool operator==(Chord const& a, Chord const& b) {
class GuitarGraph {
public:
/// constructor
- GuitarGraph(Song const& song, bool drums = false);
+ GuitarGraph(Song const& song, bool drums, unsigned num);
/** draws GuitarGraph
* @param time at which time to draw
*/
@@ -63,7 +63,8 @@ class GuitarGraph {
boost::ptr_vector<Texture> m_necks;
bool m_drums;
double m_cx, m_width;
- std::size_t m_instrument;
+ unsigned m_track;
+ std::vector<Track const*> m_tracks;
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 f359d95..11e714a 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -33,15 +33,13 @@ 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
+ bool drums = false;
for (int num = 0; true; ++num) {
try {
- m_instruments.push_back(new GuitarGraph(*m_song));
- } catch (std::runtime_error&) { break; }
- }
- for (int num = 0; true; ++num) {
- try {
- m_instruments.push_back(new GuitarGraph(*m_song, true));
- } catch (std::runtime_error&) { break; }
+ Instruments::iterator it = m_instruments.end();
+ if (drums && m_instruments.size() > 1) it = m_instruments.begin() + 1; // Drums go after the first guitar
+ m_instruments.insert(it, new GuitarGraph(*m_song, drums, num));
+ } catch (std::runtime_error&) { if (drums) break; drums = true; }
}
double iw = std::min(0.5, 1.0 / m_instruments.size());
for (Instruments::size_type i = 0, s = m_instruments.size(); i < s; ++i) {
|