|
From: Lasse Kärkkäi. <tr...@us...> - 2009-07-26 11:39:08
|
Module: performous
Branch: master
Commit: 1e4a04316dcb0d3f7554d2bfdc58160034a862e3
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Jul 26 14:38:17 2009 +0300
Rip out Chord stuff, make difficulty level selection better.
---
game/guitargraph.cc | 133 ++++++++++-----------------------------------------
game/guitargraph.hh | 119 +---------------------------------------------
2 files changed, 27 insertions(+), 225 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index ed37ddb..be09e32 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -2,74 +2,15 @@
#include "joystick.hh"
-Chord::Chord(int frt,double begin){
- this->fret=frt;
- this->start=begin;
- this->state=COMING;
- this->dt=0.075;
-}
-Chord::Chord(const Chord &c){
- this->fret=c.fret;
- this->event=c.event;
- this->start=c.start;
- this->end=c.end;
- this->dt=c.dt;
- this->state=c.state;
-}
-
-Chord::~Chord(){}
-Chord &Chord::operator=(const Chord &c){
- if(&c!=this){
- this->fret=c.fret;
- this->event=c.event;
- this->start=c.start;
- this->end=c.end;
- this->dt=c.dt;
- this->state=c.state;
- }
- return *this;
-}
-
-unsigned char Chord::getEvent(){
- return this->event;
-}
-
-int Chord::getFret(){
- return this->fret;
-}
-
-void Chord::setEnd(double e){
-
- this->end=e;
-}
-
-bool Chord::isBetween(double time){
-
- return (time>this->start&&time<this->end);
-}
-
-Chord::ChordState Chord::getState(){
-
- return this->state;
-}
-
-void Chord::setState(Chord::ChordState s){
-
- this->state=s;
-}
-
-bool Chord::pressNow(double t){
-
- return (t>(this->start-this->dt)&&t<(this->start+dt));
-}
-
-double Chord::getDt(){
-
- return this->dt;
-}
-
-
namespace {
+ struct Diff { std::string name; int basepitch; } diffv[] = {
+ { "Supaeasy", 0x3C },
+ { "Easy", 0x48 },
+ { "Medium", 0x54 },
+ { "Amazing", 0x60 }
+ };
+ const size_t diffsz = sizeof(diffv) / sizeof(*diffv);
+
const float past = -0.3f;
const float future = 3.0f;
const float timescale = 60.0f;
@@ -82,10 +23,12 @@ namespace {
}
GuitarGraph::GuitarGraph(Song const& song): m_song(song), m_button("button.svg"), m_pickValue(0.0, 5.0), m_instrument(), m_level(), m_text(getThemePath("sing_timetxt.svg"), config["graphic/text_lod"].f()) {
- if (m_song.tracks.empty()) throw std::runtime_error("No tracks");
+ 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"));
- m_necks.push_back(new Texture("bassneck.svg"));
- m_necks.push_back(new Texture("bassneck.svg")); // Drums
+ if (tracks > 1) m_necks.push_back(new Texture("bassneck.svg"));
+ if (tracks > 2) m_necks.push_back(new Texture("bassneck.svg")); // Drums
+ difficultyAuto();
}
void GuitarGraph::inputProcess() {
@@ -108,35 +51,26 @@ void GuitarGraph::inputProcess() {
void GuitarGraph::engine(double time) {
if (picked && time < -0.5) {
if (fretPressed[0]) difficulty(DIFFICULTY_SUPAEASY);
- if (fretPressed[1]) difficulty(DIFFICULTY_EASY);
- if (fretPressed[2]) difficulty(DIFFICULTY_MEDIUM);
- if (fretPressed[3]) difficulty(DIFFICULTY_AMAZING);
- if (fretPressed[4]) m_instrument = (m_instrument + 1) % m_song.tracks.size();
+ else if (fretPressed[1]) difficulty(DIFFICULTY_EASY);
+ else if (fretPressed[2]) difficulty(DIFFICULTY_MEDIUM);
+ else if (fretPressed[3]) difficulty(DIFFICULTY_AMAZING);
+ if (fretPressed[4]) { m_instrument = (m_instrument + 1) % m_song.tracks.size(); difficultyAuto(); }
}
if (picked) { m_pickValue.setValue(1.0); }
picked = false;
}
+void GuitarGraph::difficultyAuto() {
+ for (int level = 0; level < DIFFICULTYCOUNT; ++level) if (difficulty(Difficulty(level))) return;
+ throw std::runtime_error("No difficulty levels found");
+}
+
bool GuitarGraph::difficulty(Difficulty level) {
- Chords c;
- uint8_t basepitch;
- switch (level) {
- case DIFFICULTY_SUPAEASY: basepitch = 0x3c; break;
- case DIFFICULTY_EASY: basepitch = 0x48; break;
- case DIFFICULTY_MEDIUM: basepitch = 0x54; break;
- case DIFFICULTY_AMAZING: basepitch = 0x60; break;
- default: throw std::logic_error("Invalid difficulty level");
- }
+ uint8_t basepitch = diffv[level].basepitch;
NoteMap const& nm = m_song.tracks[m_instrument].nm;
- NoteMap::const_iterator nmIt[5];
int fail = 0;
- for (int fret = 0; fret < 5; ++fret) {
- nmIt[fret] = nm.find(basepitch + fret);
- if (nmIt[fret] == nm.end()) ++fail;
- }
+ for (int fret = 0; fret < 5; ++fret) if (nm.find(basepitch + fret) == nm.end()) ++fail;
if (fail == 5) return false;
- //std::sort(c.begin(), c.end(), chordlt);
- m_chords = c;
m_level = level;
return true;
}
@@ -145,14 +79,7 @@ void GuitarGraph::draw(double time) {
m_text.dimensions.screenBottom(-0.05).middle(0.0);
if (time < -0.5) {
std::string txt = "Play a fret to change:\n";
- txt += m_song.tracks[m_instrument].name + "/";
- switch (m_level) {
- case DIFFICULTY_SUPAEASY: txt += "Supaeasy"; break;
- case DIFFICULTY_EASY: txt += "Easy"; break;
- case DIFFICULTY_MEDIUM: txt += "Medium"; break;
- case DIFFICULTY_AMAZING: txt += "Amazing"; break;
- default: throw std::logic_error("Invalid difficulty level");
- }
+ txt += m_song.tracks[m_instrument].name + "/" + diffv[m_level].name;
m_text.draw(txt);
}
engine(time);
@@ -181,15 +108,7 @@ void GuitarGraph::draw(double time) {
glTexCoord2f(1.0f, texCoord); glVertex2f(2.5f, time2y(tEnd));
}
}
- int basepitch;
-
- switch (m_level) {
- case DIFFICULTY_SUPAEASY: basepitch = 0x3c; break;
- case DIFFICULTY_EASY: basepitch = 0x48; break;
- case DIFFICULTY_MEDIUM: basepitch = 0x54; break;
- case DIFFICULTY_AMAZING: basepitch = 0x60; break;
- default: throw std::logic_error("Invalid difficulty level");
- }
+ int basepitch = diffv[m_level].basepitch;
static glutil::Color fretColors[5] = {
glutil::Color(0.0f, 1.0f, 0.0f),
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index 7fb30a3..3af4053 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -9,122 +9,6 @@
class Song;
-class Chord{
-
-
- public:
-
- static const double CHORD_POOR = 0.075;
- static const double CHORD_GOOD = 0.050;
- static const double CHORD_GREAT = 0.020;
- static const double CHORD_PERFECT = 0.010;
-
- /**
- * Tells in which state the chord is.
- */
-
- enum ChordState{
-
- COMING,
- HELD,
- FAILED
- };
-
- /** Constructor.
- *
- * @param fret The quitar fret where the chord songs.
- * @param begin The start time of the chord.
- */
-
- Chord(int fret,double begin);
- Chord(const Chord &c);
- ~Chord();
- Chord &operator=(const Chord &c);
- unsigned char getEvent();
-
- /** Tells the quitar fret where the chord songs.
- *
- * @return quitar fret.
- */
-
- int getFret();
-
- /** Tells how long the chord last.
- *
- * @return Time between end and begin.
- */
-
- double getTime() const { return end - start; }
-
- /** Tells when the chord should be played.
- *
- * @return Chords start time in seconds.
- */
-
- double getStart() const { return start; }
-
- /** Tells when the chord ends.
- *
- * @return Chords end in seconds.
- */
-
- double getEnd() const { return end; }
-
- /** Sets the end time of chord in seconds.
- *
- * @param end End time in seconds.
- */
-
- void setEnd(double end);
-
- /** Tells if the given time is between begin and end.
- *
- * @param time Time is between begin or end or is not.
- * @return true if time is between false otherwise.
- */
-
- bool isBetween(double time);
-
- /** Tells if the player should pick this chord at given time
- *
- * @param time Time when the player tries to pick this chord.
- * @return true if chord should be picked at given time false otherwise.
- */
-
- bool pressNow(double time);
-
- /** Tells how long is the pick time.
- *
- * @return Size of picktime in seconds.
- */
-
- double getDt();
-
- /** Tells in which state the chord is.
- *
- * @return Chord-state.
- */
-
- ChordState getState();
-
- /** Set the chord state
- *
- * @param state Chord-state where the chord-changes.
- */
-
- void setState(ChordState state);
-
-private:
-
-
- int fret;
- unsigned char event;
- double start;
- double end;
- ChordState state;
- double dt;
-};
-
/// handles drawing of notes and waves
class GuitarGraph {
public:
@@ -149,9 +33,8 @@ class GuitarGraph {
DIFFICULTY_AMAZING,
DIFFICULTYCOUNT
} m_level;
+ void difficultyAuto();
bool difficulty(Difficulty level);
- typedef std::vector<Chord> Chords;
- Chords m_chords;
SvgTxtTheme m_text;
};
|