|
From: knittl <kn...@us...> - 2009-08-03 08:39:50
|
Module: performous
Branch: master
Commit: 5242395bd81f9ebd0228b03892f50caec9037de4
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Aug 1 11:16:53 2009 +0200
New API for event
---
game/joystick.cc | 2 +-
game/joystick.hh | 35 ++++++++++++++++++++++++-----------
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 5693be7..9ed995d 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -164,5 +164,5 @@ void joysticks_init() {
/**
* New input management, superseed all joysticks stuffs
*/
-void input::assign(InputDev&, input::Type) {}
+input::InputDev& input::assign(input::Type) {}
bool input::pushEvent(SDL_Event) {return false;}
diff --git a/game/joystick.hh b/game/joystick.hh
index 2f18fc6..11659a1 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -95,24 +95,37 @@ namespace input {
bool pressed; // for buttons
short value; // for axis
};
+
+ namespace Private {
+ class InputDevPrivate {
+ public:
+ InputDevPrivate() {};
+ 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,InputDevPrivate> InputDevs;
+ extern InputDevs devices;
+ }
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
+ InputDev(input::Private::InputDevPrivate& _device):m_device(_device) {};
+ bool tryPoll(InputDevEvent& _e) {return m_device.tryPoll(_e);};
+ void addEvent(InputDevEvent _e) {m_device.addEvent(_e);};
+ bool status(InputDevEvent::Type _t) {return m_device.status(_t);}; // for buttons
+ short value(InputDevEvent::Type _t) {return m_device.value(_t);}; // for axis
private:
- bool m_assigned;
- input::Type m_type;
+ input::Private::InputDevPrivate& m_device;
};
- typedef std::map<unsigned int,InputDev> InputDevs;
- extern InputDevs devices;
-
// Throw an exception if none is available
- void assign(InputDev&, input::Type);
+ InputDev& assign(input::Type);
// Returns true if event is taken, feed an InputDev by transforming SDL_Event into InputDevEvent
bool pushEvent(SDL_Event);
};
|