1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
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 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file |
---|
31 | @brief |
---|
32 | Implementation of a little Input handler that distributes everything |
---|
33 | coming from OIS. |
---|
34 | */ |
---|
35 | |
---|
36 | #ifndef _InputManager_H__ |
---|
37 | #define _InputManager_H__ |
---|
38 | |
---|
39 | #include "InputPrereqs.h" |
---|
40 | |
---|
41 | #include <map> |
---|
42 | #include <set> |
---|
43 | #include <string> |
---|
44 | #include <vector> |
---|
45 | |
---|
46 | #include "core/OrxonoxClass.h" |
---|
47 | #include "InputState.h" |
---|
48 | |
---|
49 | namespace orxonox |
---|
50 | { |
---|
51 | /** |
---|
52 | @brief |
---|
53 | Captures and distributes mouse and keyboard input. |
---|
54 | */ |
---|
55 | class _CoreExport InputManager : public OrxonoxClass |
---|
56 | { |
---|
57 | public: |
---|
58 | enum State |
---|
59 | { |
---|
60 | Nothing = 0x00, |
---|
61 | Bad = 0x02, |
---|
62 | Ticking = 0x04, |
---|
63 | Calibrating = 0x08, |
---|
64 | ReloadRequest = 0x10, |
---|
65 | }; |
---|
66 | |
---|
67 | InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); |
---|
68 | ~InputManager(); |
---|
69 | void setConfigValues(); |
---|
70 | |
---|
71 | void update(const Clock& time); |
---|
72 | void clearBuffers(); |
---|
73 | void calibrate(); |
---|
74 | void reload(); |
---|
75 | |
---|
76 | //------------------------------- |
---|
77 | // Input States |
---|
78 | //------------------------------- |
---|
79 | InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic); |
---|
80 | InputState* getState(const std::string& name); |
---|
81 | bool enterState (const std::string& name); |
---|
82 | bool leaveState (const std::string& name); |
---|
83 | bool destroyState (const std::string& name); |
---|
84 | |
---|
85 | //------------------------------- |
---|
86 | // Various getters and setters |
---|
87 | //------------------------------- |
---|
88 | void setKeyDetectorCallback(const std::string& command); |
---|
89 | bool checkJoyStickID(const std::string& idString) const; |
---|
90 | unsigned int getJoyStickQuantity() const |
---|
91 | { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; } |
---|
92 | OIS::InputManager* getOISInputManager() |
---|
93 | { return this->oisInputManager_; } |
---|
94 | |
---|
95 | static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } |
---|
96 | |
---|
97 | private: // functions |
---|
98 | // don't mess with a Singleton |
---|
99 | InputManager(const InputManager&); |
---|
100 | |
---|
101 | // Intenal methods |
---|
102 | void loadDevices(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight); |
---|
103 | void loadMouse(unsigned int windowWidth, unsigned int windowHeight); |
---|
104 | void loadJoySticks(); |
---|
105 | void destroyDevices(); |
---|
106 | |
---|
107 | void stopCalibration(); |
---|
108 | |
---|
109 | void destroyStateInternal(InputState* state); |
---|
110 | void updateActiveStates(); |
---|
111 | bool configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority); |
---|
112 | |
---|
113 | void reloadInternal(); |
---|
114 | |
---|
115 | private: // variables |
---|
116 | State internalState_; //!< Current internal state |
---|
117 | OIS::InputManager* oisInputManager_; //!< OIS input manager |
---|
118 | std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) |
---|
119 | size_t windowHnd_; //!< Render window handle |
---|
120 | |
---|
121 | // some internally handled states and handlers |
---|
122 | InputState* emptyState_; |
---|
123 | KeyDetector* keyDetector_; //!< KeyDetector instance |
---|
124 | InputBuffer* calibratorCallbackHandler_; |
---|
125 | |
---|
126 | std::map<std::string, InputState*> statesByName_; |
---|
127 | std::map<int, InputState*> activeStates_; |
---|
128 | std::vector<InputState*> activeStatesTicked_; |
---|
129 | |
---|
130 | std::set<InputState*> stateEnterRequests_; //!< Request to enter a new state |
---|
131 | std::set<InputState*> stateLeaveRequests_; //!< Request to leave a running state |
---|
132 | std::set<InputState*> stateDestroyRequests_; //!< Request to destroy a state |
---|
133 | |
---|
134 | static InputManager* singletonRef_s; |
---|
135 | }; |
---|
136 | } |
---|
137 | |
---|
138 | #endif /* _InputManager_H__ */ |
---|