|
From: Yoda-JM <yo...@us...> - 2009-07-26 12:06:26
|
Module: performous
Branch: master
Commit: 1f1d34477ab2aca4462f155ac2b28ecab475b2bc
Author: Vincent Le Ligeour <yo...@us...>
Date: Sun Jul 26 14:05:01 2009 +0200
Autodetected Guitar Hero guitars+drums)
---
game/guitargraph.cc | 12 +++++++++++-
game/joystick.cc | 10 ++++++++++
game/joystick.hh | 4 ++++
3 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 48e1acc..d21a66f 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -43,7 +43,17 @@ void GuitarGraph::inputProcess() {
if (b >= 5) continue;
static const int gh[] = { 2, 0, 1, 3, 4 };
static const int rb[] = { 3, 0, 1, 2, 4 };
- fretPressed[(true ? rb : gh)[b]] = (ev.type == JoystickEvent::BUTTON_DOWN);
+ switch( it->second.getType() ) {
+ case Joystick::ROCKBAND:
+ fretPressed[rb[b]] = (ev.type == JoystickEvent::BUTTON_DOWN);
+ break;
+ case Joystick::GUITARHERO:
+ fretPressed[gh[b]] = (ev.type == JoystickEvent::BUTTON_DOWN);
+ break;
+ default:
+ fretPressed[gh[b]] = (ev.type == JoystickEvent::BUTTON_DOWN);
+ break;
+ }
}
}
}
diff --git a/game/joystick.cc b/game/joystick.cc
index 9ff4965..4c035ec 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -5,6 +5,13 @@ Joysticks joysticks;
Joystick::Joystick(unsigned int _id): m_id(_id) {
m_joystick = SDL_JoystickOpen(m_id);
+ if( getName().find("Guitar Hero") != std::string::npos ) {
+ m_type = Joystick::GUITARHERO;
+ } else if( getName().find("Harmonix") != std::string::npos ) {
+ m_type = Joystick::ROCKBAND;
+ } else {
+ m_type = Joystick::UNKNOWN;
+ }
};
Joystick::~Joystick() {
// Do it another way :/
@@ -13,6 +20,9 @@ Joystick::~Joystick() {
std::string Joystick::getName() const {
return std::string(SDL_JoystickName(m_id));
};
+Joystick::Type Joystick::getType() const {
+ return m_type;
+}
std::string Joystick::getDescription() const {
std::string desc;
desc += "axes: ";
diff --git a/game/joystick.hh b/game/joystick.hh
index d5b4a16..1dc5201 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -42,10 +42,13 @@ class JoystickEvent {
/// joystick class used for dealing with ps3 drumsets
class Joystick {
public:
+ enum Type {UNKNOWN, GUITARHERO, ROCKBAND};
Joystick() {};
/// create joystick object with given id
Joystick(unsigned int _id);
~Joystick();
+ /// Return joystick Type
+ Joystick::Type getType() const;
/// get name of joystick
std::string getName() const;
/// get longer description of joystick
@@ -74,6 +77,7 @@ class Joystick {
SDL_Joystick * m_joystick;
std::deque<JoystickEvent> m_events;
unsigned int m_id;
+ Type m_type;
};
typedef std::map<unsigned int,Joystick> Joysticks;
|