|
From: knittl <kn...@us...> - 2009-08-03 08:39:48
|
Module: performous
Branch: master
Commit: b13e8fd4d7f1779f6bd823a838e430c657430ddd
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Aug 1 10:56:49 2009 +0200
Added new input device API
---
game/joystick.cc | 6 ++++++
game/joystick.hh | 44 ++++++++++++++++++++++++++++++++------------
2 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 21bdcb6..5693be7 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -160,3 +160,9 @@ void joysticks_init() {
std::cout << " Description: " << joysticks[i].getDescription() << std::endl;
}
}
+
+/**
+ * New input management, superseed all joysticks stuffs
+ */
+void input::assign(InputDev&, input::Type) {}
+bool input::pushEvent(SDL_Event) {return false;}
diff --git a/game/joystick.hh b/game/joystick.hh
index 1dc5201..2f18fc6 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -83,17 +83,37 @@ class Joystick {
typedef std::map<unsigned int,Joystick> Joysticks;
extern Joysticks joysticks;
-class InputDevEvent {
- public:
- InputDevEvent() {};
-};
+/**
+ * New input management, superseed all joysticks stuffs
+ */
+namespace input {
+ enum Type {UNKNOWN, GUITAR, DRUM};
-class InputDev {
- public:
- InputDev() {};
- bool tryPoll(InputDevEvent& _event) {(void)_event;return true;};
- bool fret(unsigned int _id) {(void)_id;return false;};
- // reserved for feeding the device with event
- void addEvent(SDL_JoyButtonEvent _event) {(void)_event;};
- private:
+ struct InputDevEvent {
+ enum Type {GREEN, RED, YELLOW, BLUE, ORANGE, KICK, PICK, WHAMMY};
+ Type type;
+ bool pressed; // for buttons
+ short value; // for axis
+ };
+
+ class InputDev {
+ public:
+ InputDev() {};
+ bool tryPoll(InputDevEvent&) {return true;};
+ void addEvent(InputDevEvent) {};
+ bool status(InputDevEvent::Type) {return false;}; // for buttons
+ short value(InputDevEvent::Type) {return 0;}; // for axis
+ private:
+ bool m_assigned;
+ input::Type m_type;
+ };
+
+ typedef std::map<unsigned int,InputDev> InputDevs;
+ extern InputDevs devices;
+
+ // Throw an exception if none is available
+ void assign(InputDev&, input::Type);
+ // Returns true if event is taken, feed an InputDev by transforming SDL_Event into InputDevEvent
+ bool pushEvent(SDL_Event);
};
+
|