Changeset 3274 for code/branches/core4/src/core/input/InputManager.h
- Timestamp:
- Jul 12, 2009, 4:12:04 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/input/InputManager.h
r3270 r3274 37 37 #define _InputManager_H__ 38 38 39 #include " core/CorePrereqs.h"39 #include "InputPrereqs.h" 40 40 41 41 #include <map> … … 43 43 #include <string> 44 44 #include <vector> 45 #include <ois/OISKeyboard.h>46 #include <ois/OISMouse.h>47 #include <ois/OISJoyStick.h>48 45 49 46 #include "util/Math.h" 50 47 #include "util/OrxEnum.h" 51 48 #include "core/OrxonoxClass.h" 52 #include "InputInterfaces.h"53 49 54 50 namespace orxonox … … 71 67 Captures and distributes mouse and keyboard input. 72 68 */ 73 class _CoreExport InputManager 74 : public OrxonoxClass, 75 public OIS::KeyListener, public OIS::MouseListener 69 class _CoreExport InputManager : public OrxonoxClass 76 70 { 77 71 // --> setConfigValues is private 78 72 friend class ClassIdentifier<InputManager>; 79 friend class JoyStick;80 73 81 74 public: … … 99 92 void clearBuffers(); 100 93 101 unsigned int numberOfKeyboards() { return keyboard_ ? 1 : 0; }102 unsigned int numberOfMice() { return mouse_ ? 1 : 0; }103 unsigned int numberOfJoySticks() { return joySticks_.size(); }104 105 94 void setWindowExtents(const int width, const int height); 106 95 void setKeyDetectorCallback(const std::string& command); 107 96 108 template <class T> 109 T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); 97 InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); 110 98 111 99 InputState* getState (const std::string& name); … … 114 102 bool requestEnterState (const std::string& name); 115 103 bool requestLeaveState (const std::string& name); 104 105 OIS::InputManager* getInputSystem() { return this->inputSystem_; } 106 bool checkJoyStickID(const std::string& idString) const; 107 unsigned int getJoyStickQuantity() const 108 { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; } 116 109 117 110 #ifdef ORXONOX_PLATFORM_LINUX … … 130 123 static void reload(); 131 124 132 public: // variables133 static EmptyHandler EMPTY_HANDLER;134 135 private: // functions for friends136 OIS::InputManager* getInputSystem() { return this->inputSystem_; }137 bool checkJoyStickID(const std::string&);138 139 125 private: // functions 140 126 // don't mess with a Singleton 141 InputManager 127 InputManager(const InputManager&); 142 128 143 129 // Intenal methods … … 145 131 void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight); 146 132 void _initialiseJoySticks(); 147 void _configureJoySticks();148 133 149 void _loadCalibration();150 134 void _startCalibration(); 151 void _completeCalibration(); 152 void _evaluateCalibration(); 135 void _stopCalibration(); 153 136 154 void _destroyKeyboard();155 void _destroyMouse();156 void _destroyJoySticks();157 137 void _destroyState(InputState* state); 158 138 159 139 void _reload(); 160 140 161 void _fireAxis(unsigned int iJoyStick, int axis, int value);162 unsigned int _getJoystick(const OIS::JoyStickEvent& arg);163 164 141 void _updateActiveStates(); 165 142 bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority); 166 143 167 // input events168 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);169 bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id);170 bool mouseMoved (const OIS::MouseEvent &arg);171 bool keyPressed (const OIS::KeyEvent &arg);172 bool keyReleased (const OIS::KeyEvent &arg);173 174 144 void setConfigValues(); 175 void _calibrationFileCallback();176 145 177 146 private: // variables 178 147 OIS::InputManager* inputSystem_; //!< OIS input manager 179 OIS::Keyboard* keyboard_; //!< OIS mouse 180 OIS::Mouse* mouse_; //!< OIS keyboard 181 std::vector<JoyStick*> joySticks_; //!< Orxonox joy sticks 182 unsigned int devicesNum_; 148 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 183 149 size_t windowHnd_; //!< Render window handle 184 150 InputManagerState internalState_; //!< Current internal state 185 151 186 152 // some internally handled states and handlers 187 SimpleInputState*stateEmpty_;153 InputState* stateEmpty_; 188 154 KeyDetector* keyDetector_; //!< KeyDetector instance 189 155 InputBuffer* calibratorCallbackBuffer_; … … 196 162 197 163 std::map<int, InputState*> activeStates_; 198 std::vector<std::vector<InputState*> > activeStatesTriggered_;199 164 std::vector<InputState*> activeStatesTicked_; 200 201 unsigned int keyboardModifiers_; //!< Bit mask representing keyboard modifiers.202 203 std::vector<Key> keysDown_;204 std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_;205 165 206 166 static InputManager* singletonRef_s; 207 167 }; 208 209 /**210 @brief211 Creates a new InputState by type, name and priority.212 213 You will have to use this method because the214 c'tors and d'tors are private.215 @remarks216 The InputManager will take care of the state completely. That also217 means it gets deleted when the InputManager is destroyed!218 @param name219 Name of the InputState when referenced as string220 @param priority221 Priority matters when multiple states are active. You can specify any222 number, but 1 - 99 is preferred (99 means high).223 */224 template <class T>225 T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)226 {227 T* state = new T;228 if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))229 return state;230 else231 {232 delete state;233 return 0;234 }235 }236 168 } 237 169
Note: See TracChangeset
for help on using the changeset viewer.