|
From: knittl <kn...@us...> - 2009-08-03 08:40:09
|
Module: performous
Branch: master
Commit: a6e4540d55d7509db31e5959e530f8f13bd15930
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Aug 1 14:09:51 2009 +0200
Merged toward a good InputDev implementation
---
game/joystick.cc | 29 +++++++++++++++++++++++++----
game/joystick.hh | 2 +-
game/main.cc | 1 +
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 804c48e..7ab17e6 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -130,9 +130,7 @@ void input::init() {
}
void input::clear() {
// new stuffs
- for (input::Private::InputDevs::iterator it = input::Private::devices.begin() ; it != input::Private::devices.end() ; ++it) {
- it->second.clearEvents();
- }
+ // nothing to do here
// compatibility with old joystick stuffs
for(Joysticks::iterator it = joysticks.begin() ; it != joysticks.end() ; ++it ) {
it->second.clearEvents();
@@ -140,7 +138,30 @@ void input::clear() {
}
bool input::pushEvent(SDL_Event _e) {
// new stuffs
- // TODO
+ int joy_id;
+ using namespace input::Private;
+ switch(_e.type) {
+ case SDL_JOYAXISMOTION:
+ joy_id = _e.jaxis.which;
+ if( !devices[joy_id].assigned() ) break;
+ // do stuffs to devices[joy_id] events (PICK)
+ break;
+ case SDL_JOYHATMOTION:
+ joy_id = _e.jhat.which;
+ if( !devices[joy_id].assigned() ) break;
+ // do stuffs to devices[joy_id] events (PICK)
+ break;
+ case SDL_JOYBUTTONDOWN:
+ case SDL_JOYBUTTONUP:
+ joy_id = _e.jbutton.which;
+ // do stuffs to devices[joy_id] states (BUTTONS)
+ if( !devices[joy_id].assigned() ) break;
+ // do stuffs to devices[joy_id] events (BUTTONS)
+ break;
+ case SDL_JOYBALLMOTION:
+ default:
+ return false;
+ }
// compatibility with old joystick stuffs
switch(_e.type) {
case SDL_JOYAXISMOTION:
diff --git a/game/joystick.hh b/game/joystick.hh
index b62bc55..bc42d6a 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -91,7 +91,7 @@ namespace input {
void addEvent(InputDevEvent) {};
void clearEvents() {m_events.clear();};
void assign() {m_assigned = true;};
- void unassign() {m_assigned = false;};
+ 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;};
diff --git a/game/main.cc b/game/main.cc
index df9cc97..815142e 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -40,6 +40,7 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
static bool esc = false;
SDL_Event event;
// Clear input event first
+ // FIXME: onlyrequired for old Joystick compatibility
input::clear();
while(SDL_PollEvent(&event) == 1) {
// catch input event first
|