[918] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1502] | 3 | * > www.orxonox.net < |
---|
[918] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[973] | 28 | |
---|
[918] | 29 | /** |
---|
[1755] | 30 | @file |
---|
| 31 | @brief |
---|
| 32 | Implementation of a little Input handler that distributes everything |
---|
| 33 | coming from OIS. |
---|
| 34 | */ |
---|
[973] | 35 | |
---|
| 36 | #ifndef _InputManager_H__ |
---|
| 37 | #define _InputManager_H__ |
---|
| 38 | |
---|
[3274] | 39 | #include "InputPrereqs.h" |
---|
[1062] | 40 | |
---|
[1219] | 41 | #include <map> |
---|
[3196] | 42 | #include <set> |
---|
| 43 | #include <string> |
---|
[1293] | 44 | #include <vector> |
---|
[3196] | 45 | |
---|
[1349] | 46 | #include "util/Math.h" |
---|
[2896] | 47 | #include "util/OrxEnum.h" |
---|
[1524] | 48 | #include "core/OrxonoxClass.h" |
---|
[973] | 49 | |
---|
| 50 | namespace orxonox |
---|
| 51 | { |
---|
[2896] | 52 | struct InputStatePriority : OrxEnum<InputStatePriority> |
---|
| 53 | { |
---|
| 54 | OrxEnumConstructors(InputStatePriority); |
---|
| 55 | |
---|
| 56 | static const int Empty = -1; |
---|
| 57 | static const int Dynamic = 0; |
---|
| 58 | |
---|
| 59 | static const int HighPriority = 1000; |
---|
| 60 | static const int Console = HighPriority + 0; |
---|
| 61 | static const int Calibrator = HighPriority + 1; |
---|
| 62 | static const int Detector = HighPriority + 2; |
---|
| 63 | }; |
---|
| 64 | |
---|
[1755] | 65 | /** |
---|
| 66 | @brief |
---|
| 67 | Captures and distributes mouse and keyboard input. |
---|
| 68 | */ |
---|
[3274] | 69 | class _CoreExport InputManager : public OrxonoxClass |
---|
[1755] | 70 | { |
---|
| 71 | // --> setConfigValues is private |
---|
| 72 | friend class ClassIdentifier<InputManager>; |
---|
[1066] | 73 | |
---|
[1755] | 74 | public: |
---|
| 75 | enum InputManagerState |
---|
| 76 | { |
---|
| 77 | Uninitialised = 0x00, |
---|
| 78 | OISReady = 0x01, |
---|
| 79 | InternalsReady = 0x02, |
---|
| 80 | Ticking = 0x04, |
---|
| 81 | Calibrating = 0x08, |
---|
| 82 | ReloadRequest = 0x10, |
---|
| 83 | }; |
---|
[1219] | 84 | |
---|
[3270] | 85 | InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); |
---|
[1755] | 86 | ~InputManager(); |
---|
[1293] | 87 | |
---|
[3270] | 88 | void initialise(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); |
---|
[1219] | 89 | |
---|
[3270] | 90 | void reloadInputSystem(); |
---|
[1219] | 91 | |
---|
[1878] | 92 | void clearBuffers(); |
---|
| 93 | |
---|
[1755] | 94 | void setWindowExtents(const int width, const int height); |
---|
[1887] | 95 | void setKeyDetectorCallback(const std::string& command); |
---|
[1502] | 96 | |
---|
[3274] | 97 | InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); |
---|
[1524] | 98 | |
---|
[1755] | 99 | InputState* getState (const std::string& name); |
---|
| 100 | InputState* getCurrentState(); |
---|
| 101 | bool requestDestroyState (const std::string& name); |
---|
| 102 | bool requestEnterState (const std::string& name); |
---|
| 103 | bool requestLeaveState (const std::string& name); |
---|
[1219] | 104 | |
---|
[3274] | 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; } |
---|
| 109 | |
---|
[2896] | 110 | void update(const Clock& time); |
---|
[1219] | 111 | |
---|
[1755] | 112 | static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } |
---|
| 113 | static InputManager* getInstancePtr() { return singletonRef_s; } |
---|
[1219] | 114 | |
---|
[1878] | 115 | // console commands |
---|
[1755] | 116 | static void calibrate(); |
---|
[3270] | 117 | static void reload(); |
---|
[973] | 118 | |
---|
[1755] | 119 | private: // functions |
---|
| 120 | // don't mess with a Singleton |
---|
[3274] | 121 | InputManager(const InputManager&); |
---|
[973] | 122 | |
---|
[1755] | 123 | // Intenal methods |
---|
| 124 | void _initialiseKeyboard(); |
---|
[3270] | 125 | void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight); |
---|
[1755] | 126 | void _initialiseJoySticks(); |
---|
[973] | 127 | |
---|
[2662] | 128 | void _startCalibration(); |
---|
[3274] | 129 | void _stopCalibration(); |
---|
[2662] | 130 | |
---|
[1755] | 131 | void _destroyState(InputState* state); |
---|
[1349] | 132 | |
---|
[3270] | 133 | void _reload(); |
---|
[1502] | 134 | |
---|
[1755] | 135 | void _updateActiveStates(); |
---|
[2896] | 136 | bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority); |
---|
[1219] | 137 | |
---|
[1755] | 138 | void setConfigValues(); |
---|
[1219] | 139 | |
---|
[1755] | 140 | private: // variables |
---|
| 141 | OIS::InputManager* inputSystem_; //!< OIS input manager |
---|
[3274] | 142 | std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) |
---|
[1755] | 143 | size_t windowHnd_; //!< Render window handle |
---|
| 144 | InputManagerState internalState_; //!< Current internal state |
---|
[1219] | 145 | |
---|
[1878] | 146 | // some internally handled states and handlers |
---|
[3274] | 147 | InputState* stateEmpty_; |
---|
[2662] | 148 | KeyDetector* keyDetector_; //!< KeyDetector instance |
---|
[1881] | 149 | InputBuffer* calibratorCallbackBuffer_; |
---|
[1502] | 150 | |
---|
[1755] | 151 | std::map<std::string, InputState*> inputStatesByName_; |
---|
[1219] | 152 | |
---|
[1755] | 153 | std::set<InputState*> stateEnterRequests_; //!< Request to enter a new state |
---|
| 154 | std::set<InputState*> stateLeaveRequests_; //!< Request to leave a running state |
---|
| 155 | std::set<InputState*> stateDestroyRequests_; //!< Request to destroy a state |
---|
[1502] | 156 | |
---|
[1755] | 157 | std::map<int, InputState*> activeStates_; |
---|
[2896] | 158 | std::vector<InputState*> activeStatesTicked_; |
---|
[1349] | 159 | |
---|
[1755] | 160 | static InputManager* singletonRef_s; |
---|
| 161 | }; |
---|
[973] | 162 | } |
---|
| 163 | |
---|
| 164 | #endif /* _InputManager_H__ */ |
---|