|
From: knittl <kn...@us...> - 2009-08-03 08:40:16
|
Module: performous
Branch: master
Commit: 2fbfc307c4007f07cdef7160d3e685810fc4bd8d
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Aug 1 15:38:39 2009 +0200
Changed API .... again
---
game/joystick.cc | 8 ++++----
game/joystick.hh | 41 ++++++++++++++++++++++++++++++++---------
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 8e7edd9..a481551 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -126,9 +126,9 @@ void input::init() {
input::sdl_devices[i] = SDL_JoystickOpen(i);
std::string name = SDL_JoystickName(i);
if( name.find("Guitar Hero") != std::string::npos ) {
- input::Private::devices[i] = input::Private::InputDevPrivate(input::GUITAR_GH);
+ input::Private::devices[i] = input::Private::InputDevPrivate(input::Private::GUITAR_GH);
} else if( name.find("Harmonix") != std::string::npos ) {
- input::Private::devices[i] = input::Private::InputDevPrivate(input::GUITAR_RB);
+ input::Private::devices[i] = input::Private::InputDevPrivate(input::Private::GUITAR_RB);
} else {
input::Private::devices[i] = input::Private::InputDevPrivate();
}
@@ -139,9 +139,9 @@ void input::init() {
init_devices();
// compatibility with old joystick stuffs
for (input::Private::InputDevs::iterator it = input::Private::devices.begin() ; it != input::Private::devices.end() ; ++it) {
- if( it->second.type() == GUITAR_GH || it->second.type() == DRUM_GH ) {
+ if( it->second.type() == Private::GUITAR_GH || it->second.type() == Private::DRUM_GH ) {
joysticks[it->first] = Joystick(Joystick::GUITARHERO);
- } else if( it->second.type() == GUITAR_GH || it->second.type() == DRUM_GH ) {
+ } else if( it->second.type() == Private::GUITAR_GH || it->second.type() == Private::DRUM_GH ) {
joysticks[it->first] = Joystick(Joystick::ROCKBAND);
} else {
joysticks[it->first] = Joystick();
diff --git a/game/joystick.hh b/game/joystick.hh
index 0177861..2dbbc1e 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 Type {UNKNOWN, GUITAR ,DRUM};
static const std::size_t BUTTONS = 6;
@@ -87,9 +87,10 @@ namespace input {
};
namespace Private {
+ enum Type {UNKNOWN, GUITAR_RB, DRUM_RB, GUITAR_GH, DRUM_GH};
class InputDevPrivate {
public:
- InputDevPrivate(input::Type _type = input::UNKNOWN) : m_assigned(false), m_type(_type) {};
+ InputDevPrivate(input::Private::Type _type = input::Private::UNKNOWN) : m_assigned(false), m_type(_type) {};
bool tryPoll(InputDevEvent& _event) {
if( m_events.empty() ) return false;
_event = m_events.front();
@@ -109,13 +110,35 @@ namespace input {
void unassign() {m_assigned = false; clearEvents();};
bool assigned() {return m_assigned;};
bool pressed(int _button) {return m_pressed[_button];};
- input::Type type() {return m_type;};
- void setType(input::Type _type) {m_type=_type;init_devices();};
+ input::Private::Type type() {return m_type;};
+ bool type_match( input::Type _type) {
+ if( _type == input::UNKNOWN && m_type == input::Private::UNKNOWN ) {
+ return true;
+ } else if( _type == input::GUITAR &&
+ (m_type == input::Private::GUITAR_GH || m_type == input::Private::GUITAR_RB) ) {
+ return true;
+ } else if( _type == input::DRUM &&
+ (m_type == input::Private::DRUM_GH || m_type == input::Private::DRUM_RB) ) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ void setType(input::Type _type) {
+ if( _type == input::GUITAR ) {
+ m_type = input::Private::GUITAR_RB;
+ } else if( _type == input::DRUM ) {
+ m_type = input::Private::DRUM_RB;
+ } else {
+ m_type = input::Private::UNKNOWN;
+ }
+ init_devices();
+ };
private:
std::deque<InputDevEvent> m_events;
bool m_assigned;
bool m_pressed[BUTTONS];
- input::Type m_type;
+ input::Private::Type m_type;
};
typedef std::map<unsigned int,InputDevPrivate> InputDevs;
@@ -131,21 +154,21 @@ namespace input {
using namespace input::Private;
if( devices.size() == 0 ) throw std::runtime_error("No InputDev available");
for(InputDevs::iterator it = devices.begin() ; it != devices.end() ; ++it) {
- if( !it->second.assigned() && it->second.type() == _type ) {
+ if( !it->second.assigned() && it->second.type_match(_type) ) {
m_device_id = it->first;
it->second.assign();
return;
}
}
for(InputDevs::iterator it = devices.begin() ; it != devices.end() ; ++it) {
- if( !it->second.assigned() && it->second.type() == input::Type::UNKNOWN ) {
+ if( !it->second.assigned() && it->second.type_match(input::UNKNOWN) ) {
m_device_id = it->first;
- it->second.type(_type);
+ it->second.setType(_type);
it->second.assign();
return;
}
}
- throw std::runtime_error("No matching instrument available")
+ throw std::runtime_error("No matching instrument available");
};
~InputDev() {input::Private::devices[m_device_id].unassign();};
bool tryPoll(InputDevEvent& _e) {return input::Private::devices[m_device_id].tryPoll(_e);};
|