|
From: knittl <kn...@us...> - 2009-08-03 08:41:20
|
Module: performous
Branch: master
Commit: dcb84457404ca9648ec7a0c66ae235a752621f5e
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Aug 2 15:14:34 2009 +0300
Automatically remove inactive instruments.
---
game/guitargraph.cc | 9 ++++++---
game/guitargraph.hh | 6 ++++--
game/screen_sing.cc | 9 ++++++++-
game/screen_sing.hh | 1 +
4 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 0c5d601..9c92b02 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -39,10 +39,11 @@ GuitarGraph::GuitarGraph(Song const& song, bool drums, unsigned track):
m_button("button.svg"),
m_tap("tap.svg"),
m_drums(drums),
- m_cx(),
- m_width(0.5),
+ m_cx(0.0, 0.2),
+ m_width(0.5, 0.4),
m_track(track),
m_level(),
+ m_dead(-1),
m_text(getThemePath("sing_timetxt.svg"), config["graphic/text_lod"].f()),
m_hammerReady(0.0, 2.0),
m_score()
@@ -74,6 +75,7 @@ void GuitarGraph::engine(double time) {
}
// Handle all events
for (input::Event ev; m_input.tryPoll(ev);) {
+ m_dead = false;
if (ev.type == input::Event::PRESS) m_hit[!m_drums + ev.button].setValue(1.0);
else if (ev.type == input::Event::PICK) m_hit[0].setValue(1.0);
if (time < -0.5) {
@@ -98,6 +100,7 @@ void GuitarGraph::engine(double time) {
while (m_chordIt != m_chords.end() && m_chordIt->begin + maxTolerance < time) {
if (m_chordIt->status < m_chordIt->polyphony) m_hammerReady.setTarget(0.0);
++m_chordIt;
+ ++m_dead;
}
}
@@ -223,7 +226,7 @@ glutil::Color const& GuitarGraph::color(int fret) const {
void GuitarGraph::draw(double time) {
engine(time);
Dimensions dimensions(1.0); // FIXME: bogus aspect ratio (is this fixable?)
- dimensions.screenBottom().middle(m_cx).fixedWidth(m_width);
+ dimensions.screenBottom().middle(m_cx.get()).fixedWidth(m_width.get());
glutil::PushMatrixMode pmm(GL_PROJECTION);
double offsetX = 0.5 * (dimensions.x1() + dimensions.x2());
double frac = 0.75; // Adjustable: 1.0 means fully separated, 0.0 means fully attached
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index e48c835..6a8082e 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -53,7 +53,8 @@ class GuitarGraph {
*/
void draw(double time);
void engine(double time);
- void position(double cx, double width) { m_cx = cx; m_width = width; }
+ void position(double cx, double width) { m_cx.setTarget(cx); m_width.setTarget(width); }
+ double dead(double time) const { return time > -0.5 && m_dead > 10; }
private:
input::InputDev m_input;
Song const& m_song;
@@ -62,7 +63,7 @@ class GuitarGraph {
AnimValue m_hit[6];
boost::ptr_vector<Texture> m_necks;
bool m_drums;
- double m_cx, m_width;
+ AnimValue m_cx, m_width;
unsigned m_track;
std::vector<Track const*> m_tracks;
void drumHit(double time, int pad);
@@ -74,6 +75,7 @@ class GuitarGraph {
DIFFICULTY_AMAZING,
DIFFICULTYCOUNT
} m_level;
+ int m_dead;
glutil::Color const& color(int fret) const;
void drawBar(double time, float h);
void difficultyAuto();
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 11e714a..ad4444f 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -41,10 +41,17 @@ void ScreenSing::enter() {
m_instruments.insert(it, new GuitarGraph(*m_song, drums, num));
} catch (std::runtime_error&) { if (drums) break; drums = true; }
}
+}
+
+void ScreenSing::instrumentLayout(double time) {
+ for (Instruments::iterator it = m_instruments.begin(); it != m_instruments.end();) {
+ if (it->dead(time)) it = m_instruments.erase(it); else ++it;
+ }
double iw = std::min(0.5, 1.0 / m_instruments.size());
for (Instruments::size_type i = 0, s = m_instruments.size(); i < s; ++i) {
m_instruments[i].position((0.5 + i - 0.5 * s) * iw, iw);
}
+ for (Instruments::iterator it = m_instruments.begin(); it != m_instruments.end(); ++it) it->draw(time);
}
void ScreenSing::exit() {
@@ -182,7 +189,7 @@ void ScreenSing::draw() {
theme->bg_top.draw();
}
- for (Instruments::iterator it = m_instruments.begin(); it != m_instruments.end(); ++it) it->draw(time);
+ instrumentLayout(time);
if( m_song->tracks.empty() ) {
m_layout_singer->draw(time, LayoutSinger::BOTTOM);
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index ca5ace9..fdf08ba 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -60,6 +60,7 @@ class ScreenSing: public Screen {
- is the hiscore file writable
*/
void activateNextScreen();
+ void instrumentLayout(double time);
Audio& m_audio;
Capture& m_capture;
Players& m_players;
|