|
From: knittl <kn...@us...> - 2009-08-03 08:40:17
|
Module: performous
Branch: master
Commit: 9cac693cae7d7a12628ec96e6e793a2d1c4d0729
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Aug 1 16:40:18 2009 +0300
Started GuitarGraph conversion to new input framework.
Button mapping code added to joystick.cc.
---
game/guitargraph.cc | 19 +++++++++++++------
game/guitargraph.hh | 2 ++
game/joystick.cc | 14 ++++++++++++++
game/joystick.hh | 4 ++--
4 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 4520da3..30470bb 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -1,7 +1,5 @@
#include "guitargraph.hh"
-#include "joystick.hh"
-
namespace {
struct Diff { std::string name; int basepitch; } diffv[] = {
{ "Supaeasy", 0x3C },
@@ -21,12 +19,21 @@ namespace {
float a = clamp(1.0 - t / future); // Note: we want 1.0 alpha already at zero t.
return std::pow(a, 0.8); // Nicer curve
}
- bool fretPressed[5] = {};
- bool fretHit[5] = {};
- bool picked = false;
}
-GuitarGraph::GuitarGraph(Song const& song): m_song(song), m_button("button.svg"), m_tap("tap.svg"), m_pickValue(0.0, 5.0), m_drums(), m_instrument(), m_level(), m_text(getThemePath("sing_timetxt.svg"), config["graphic/text_lod"].f()), m_hammerReady(0.0, 2.0), m_score() {
+GuitarGraph::GuitarGraph(Song const& song, bool drums = false):
+ m_input(drums ? input::DRUMS : input::GUITAR),
+ m_song(song),
+ m_button("button.svg"),
+ m_tap("tap.svg"),
+ m_pickValue(0.0, 5.0),
+ m_drums(),
+ m_instrument(),
+ 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"));
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index aa27b88..73bce81 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -4,6 +4,7 @@
#include <boost/scoped_ptr.hpp>
#include "animvalue.hh"
#include "engine.hh"
+#include "joystick.hh"
#include "surface.hh"
#include "opengl_text.hh"
@@ -54,6 +55,7 @@ class GuitarGraph {
void draw(double time);
void engine(double time);
private:
+ InputDev m_input;
Song const& m_song;
Surface m_button;
Surface m_tap;
diff --git a/game/joystick.cc b/game/joystick.cc
index 226aa75..52f94bd 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -3,6 +3,20 @@
#include <boost/lexical_cast.hpp>
+enum TypeSDL {UNKNOWN, GUITAR_RB, DRUM_RB, GUITAR_GH, DRUM_GH, TYPESDL_N};
+static const int SDL_BUTTONS = 6;
+
+int buttonFromSDL(TypeSDL type, unsigned sdlButton) {
+ static const int inputmap[TYPESDL_N][SDL_BUTTONS] = {
+ { 2, 0, 1, 3, 4, 0 }, // Guitar Hero guitar
+ { 3, 4, 1, 2, 0, 4 }, // Guitar Hero drums
+ { 3, 0, 1, 2, 4, 0 }, // Rock Band guitar
+ { 3, 4, 1, 2, 0, 0 } // Rock Band drums
+ };
+ if (sdlButton > SDL_BUTTONS) return -1;
+ return inputmap[instrument][sdlButton];
+}
+
Joysticks joysticks;
Joystick::Joystick(Joystick::Type _type): m_type(_type) { }
diff --git a/game/joystick.hh b/game/joystick.hh
index 7262d02..d9574f4 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -70,7 +70,7 @@ extern Joysticks joysticks;
* New input management, superseed all joysticks stuffs
*/
namespace input {
- enum Type {UNKNOWN, GUITAR_RB, DRUM_RB, GUITAR_GH, DRUM_GH};
+ enum DevType { GUITAR, DRUMS };
static const std::size_t BUTTONS = 6;
@@ -122,7 +122,7 @@ namespace input {
// First gives a correct instrument type
// Then gives an unknown instrument type
// Finally throw an exception if only wrong (or none) instrument are available
- InputDev(input::Type) : m_device_id() {input::Private::devices[m_device_id].assign();};
+ InputDev(input::DevType) : m_device_id() {input::Private::devices[m_device_id].assign();};
~InputDev() {input::Private::devices[m_device_id].unassign();};
bool tryPoll(InputDevEvent& _e) {return input::Private::devices[m_device_id].tryPoll(_e);};
void addEvent(InputDevEvent _e) {input::Private::devices[m_device_id].addEvent(_e);};
|