|
From: Yoda-JM <yo...@us...> - 2010-10-17 10:20:54
|
Module: performous
Branch: master
Commit: cb93f69bd1510831595c457e656930bb8142e2a0
Author: Vincent Le Ligeour <yo...@us...>
Date: Sun Oct 17 12:20:29 2010 +0200
Simplified joystick axis management
---
game/joystick.cc | 51 +++++++++++++++++++++++++++------------------------
1 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 59791a4..c132f99 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -736,20 +736,24 @@ bool input::SDL::pushEvent(SDL_Event _e) {
if(!devices.find(joy_id)->second.assigned()) return false;
if (_e.jaxis.axis == 5 || _e.jaxis.axis == 6 || _e.jaxis.axis == 1) {
event.type = input::Event::PICK;
+ // Direction
+ if(_e.jaxis.value > 0 ) {
+ // down
+ event.button = 0;
+ devices.find(joy_id)->second.addEvent(event);
+ } else if(_e.jaxis.value < 0 ) {
+ // up
+ event.button = 1;
+ devices.find(joy_id)->second.addEvent(event);
+ }
+ break;
} else if (_e.jaxis.axis == 2 || (devices.find(joy_id)->second.name() == "GUITAR_ROCKBAND_XBOX360" && _e.jaxis.axis == 4)) {
- // nothing to do here
- } else if (devices.find(joy_id)->second.name() == "GUITAR_ROCKBAND_XBOX360" && _e.jaxis.axis == 3) { // <= WTF HERE !!!
- // nothing to do here
- } else {
- return false;
- }
- for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
- event.pressed[i] = devices.find(joy_id)->second.pressed(i);
- }
- // XBox RB guitar's Tilt sensor
- if (devices.find(joy_id)->second.name() == "GUITAR_ROCKBAND_XBOX360" && _e.jaxis.axis == 3) {
- event.button = input::GODMODE_BUTTON;
- if (_e.jaxis.value < -2) {
+ // Whammy bar (special case for XBox RB guitar
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices.find(joy_id)->second.pressed(i);
+ }
+ event.button = input::WHAMMY_BUTTON;
+ if (_e.jaxis.value > 0) {
event.type = input::Event::PRESS;
event.pressed[event.button] = true;
} else {
@@ -758,9 +762,13 @@ bool input::SDL::pushEvent(SDL_Event _e) {
}
devices.find(joy_id)->second.addEvent(event);
break;
- } else if (_e.jaxis.axis == 2 || (devices.find(joy_id)->second.name() == "GUITAR_ROCKBAND_XBOX360" && _e.jaxis.axis == 4)) {
- event.button = input::WHAMMY_BUTTON;
- if (_e.jaxis.value > 0) {
+ } else if (devices.find(joy_id)->second.name() == "GUITAR_ROCKBAND_XBOX360" && _e.jaxis.axis == 3) {
+ // XBox RB guitar's Tilt sensor
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices.find(joy_id)->second.pressed(i);
+ }
+ event.button = input::GODMODE_BUTTON;
+ if (_e.jaxis.value < -2) {
event.type = input::Event::PRESS;
event.pressed[event.button] = true;
} else {
@@ -769,15 +777,10 @@ bool input::SDL::pushEvent(SDL_Event _e) {
}
devices.find(joy_id)->second.addEvent(event);
break;
+ } else {
+ return false;
}
- // Direction
- if(_e.jaxis.value > 0 ) { // down
- event.button = 0;
- devices.find(joy_id)->second.addEvent(event);
- } else if(_e.jaxis.value < 0 ) { // up
- event.button = 1;
- devices.find(joy_id)->second.addEvent(event);
- }
+ // we should never be there
break;
case SDL_JOYHATMOTION:
joy_id = _e.jhat.which;
|