Changeset 1642 for code/branches/gui/src/core/input
- Timestamp:
- Jul 23, 2008, 3:37:29 PM (16 years ago)
- Location:
- code/branches/gui/src/core/input
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/input/ExtendedInputState.cc
r1641 r1642 37 37 #include <assert.h> 38 38 #include "core/Debug.h" 39 #include "core/CoreIncludes.h" 39 40 40 41 namespace orxonox 41 42 { 43 CreateFactory(ExtendedInputState); 44 42 45 using namespace InputDevice; 46 47 ExtendedInputState::ExtendedInputState() 48 { 49 RegisterObject(ExtendedInputState); 50 } 43 51 44 52 void ExtendedInputState::numberOfJoySticksChanged(unsigned int n) -
code/branches/gui/src/core/input/ExtendedInputState.h
r1641 r1642 48 48 { 49 49 public: 50 ExtendedInputState() { }50 ExtendedInputState(); 51 51 ~ExtendedInputState() { } 52 52 -
code/branches/gui/src/core/input/InputManager.cc
r1641 r1642 62 62 SetConsoleCommandShortcut(InputManager, calibrate); 63 63 64 std::string InputManager::bindingCommmandString_s = ""; 65 InputManager* InputManager::singletonRef_s = 0; 66 64 67 using namespace InputDevice; 65 68 66 // ############################### 67 // ### Internal Methods###68 // ########## #####################69 // ############################### 69 // ############################################################ 70 // ##### Initialisation ##### 71 // ########## ########## 72 // ############################################################ 70 73 71 74 /** … … 87 90 { 88 91 RegisterRootObject(InputManager); 89 } 90 91 /** 92 @brief 93 Destructor itself only called at the end of the program, after main. 94 Instance gets registered for destruction with atexit(.). 95 */ 96 InputManager::~InputManager() 97 { 98 _destroy(); 99 } 100 101 /** 102 @brief 103 The one instance of the InputManager is stored in this function. 104 Only for internal use. Public Interface ist static. 105 @return 106 A reference to the only instance of the InputManager 107 */ 108 InputManager& InputManager::_getInstance() 109 { 110 static InputManager theOnlyInstance; 111 return theOnlyInstance; 112 } 113 114 115 // ############################################################ 116 // ##### Initialisation ##### 117 // ########## ########## 118 // ############################################################ 92 93 assert(singletonRef_s == 0); 94 singletonRef_s = this; 95 } 119 96 120 97 /** … … 129 106 The height of the render window 130 107 */ 131 bool InputManager:: _initialise(const size_t windowHnd, int windowWidth, int windowHeight,108 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, 132 109 bool createKeyboard, bool createMouse, bool createJoySticks) 133 110 { … … 431 408 /** 432 409 @brief 433 Destroys all the created input devices. InputManager will be ready for a 434 new initialisation. 435 */ 436 void InputManager::_destroy() 410 Destroys all the created input devices and states. 411 */ 412 InputManager::~InputManager() 437 413 { 438 414 if (inputSystem_) … … 550 526 Delta time 551 527 */ 552 void InputManager:: _tick(float dt)528 void InputManager::tick(float dt) 553 529 { 554 530 if (inputSystem_ == 0) … … 983 959 984 960 // ############################################################ 985 // ##### Static Interface Methods#####961 // ##### Other Public Interface Methods ##### 986 962 // ########## ########## 987 963 // ############################################################ 988 989 std::string InputManager::bindingCommmandString_s = "";990 991 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,992 bool createKeyboard, bool createMouse, bool createJoySticks)993 {994 return _getInstance()._initialise(windowHnd, windowWidth, windowHeight,995 createKeyboard, createMouse, createJoySticks);996 }997 998 int InputManager::numberOfKeyboards()999 {1000 if (_getInstance().keyboard_ != 0)1001 return 1;1002 else1003 return 0;1004 }1005 1006 int InputManager::numberOfMice()1007 {1008 if (_getInstance().mouse_ != 0)1009 return 1;1010 else1011 return 0;1012 }1013 1014 int InputManager::numberOfJoySticks()1015 {1016 return _getInstance().joySticksSize_;1017 }1018 1019 /*bool InputManager::isKeyDown(KeyCode::Enum key)1020 {1021 if (_getInstance().keyboard_)1022 return _getInstance().keyboard_->isKeyDown((OIS::KeyCode)key);1023 else1024 return false;1025 }*/1026 1027 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)1028 {1029 if (_getInstance().keyboard_)1030 return isModifierDown(modifier);1031 else1032 return false;1033 }*/1034 1035 /*const MouseState InputManager::getMouseState()1036 {1037 if (_getInstance().mouse_)1038 return _getInstance().mouse_->getMouseState();1039 else1040 return MouseState();1041 }*/1042 1043 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)1044 {1045 if (ID < _getInstance().joySticksSize_)1046 return JoyStickState(_getInstance().joySticks_[ID]->getJoyStickState(), ID);1047 else1048 return JoyStickState();1049 }*/1050 1051 void InputManager::destroy()1052 {1053 _getInstance()._destroy();1054 }1055 1056 964 1057 965 /** … … 1066 974 void InputManager::setWindowExtents(const int width, const int height) 1067 975 { 1068 if ( _getInstance().mouse_)976 if (mouse_) 1069 977 { 1070 978 // Set mouse region (if window resizes, we should alter this to reflect as well) 1071 const OIS::MouseState &mouseState = _getInstance().mouse_->getMouseState(); 1072 mouseState.width = width; 1073 mouseState.height = height; 1074 } 1075 } 1076 1077 /** 1078 @brief 1079 Method for easily storing a string with the command executor. It is used by the 1080 KeyDetector to get assign commands. The KeyDetector simply executes 1081 the command 'storeKeyStroke myName' for each button/axis. 1082 @remarks 1083 This is only a temporary hack until we thourouhgly support multiple KeyBinders. 1084 @param name 1085 The name of the button/axis. 1086 */ 1087 void InputManager::storeKeyStroke(const std::string& name) 1088 { 1089 requestLeaveState("detector"); 1090 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1091 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); 1092 } 1093 1094 /** 1095 @brief 1096 Assigns a command string to a key/button/axis. The name is determined via KeyDetector 1097 and InputManager::storeKeyStroke(.). 1098 @param command 1099 Command string that can be executed by the CommandExecutor 1100 */ 1101 void InputManager::keyBind(const std::string& command) 1102 { 1103 bindingCommmandString_s = command; 1104 requestEnterState("detector"); 1105 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1106 } 1107 1108 /** 1109 @brief 1110 Starts joy stick calibration. 1111 */ 1112 void InputManager::calibrate() 1113 { 1114 _getInstance().bCalibrating_ = true; 1115 requestEnterState("calibrator"); 1116 } 1117 1118 void InputManager::tick(float dt) 1119 { 1120 _getInstance()._tick(dt); 1121 } 979 mouse_->getMouseState().width = width; 980 mouse_->getMouseState().height = height; 981 } 982 } 983 1122 984 1123 985 // ###### InputStates ###### … … 1139 1001 if (name == "") 1140 1002 return false; 1141 if (_getInstance().inputStatesByName_.find(name) == _getInstance().inputStatesByName_.end()) 1142 { 1143 if (_getInstance().inputStatesByPriority_.find(priority) 1144 == _getInstance().inputStatesByPriority_.end()) 1145 { 1146 _getInstance().inputStatesByName_[name] = state; 1147 _getInstance().inputStatesByPriority_[priority] = state; 1003 if (!state) 1004 return false; 1005 if (inputStatesByName_.find(name) == inputStatesByName_.end()) 1006 { 1007 if (inputStatesByPriority_.find(priority) 1008 == inputStatesByPriority_.end()) 1009 { 1010 inputStatesByName_[name] = state; 1011 inputStatesByPriority_[priority] = state; 1148 1012 state->setNumOfJoySticks(numberOfJoySticks()); 1149 1013 state->setName(name); … … 1172 1036 { 1173 1037 SimpleInputState* state = new SimpleInputState(); 1174 if (_ getInstance()._configureInputState(state, name, priority))1038 if (_configureInputState(state, name, priority)) 1175 1039 return state; 1176 1040 else … … 1188 1052 { 1189 1053 ExtendedInputState* state = new ExtendedInputState(); 1190 if (_getInstance()._configureInputState(state, name, priority)) 1054 if (_configureInputState(state, name, priority)) 1055 return state; 1056 else 1057 { 1058 delete state; 1059 return 0; 1060 } 1061 } 1062 1063 /** 1064 @brief 1065 Returns a new InputState of type 'type' and configures it first. 1066 @param type 1067 String name of the class (used by the factory) 1068 */ 1069 InputState* InputManager::createInputState(const std::string& type, const std::string &name, int priority) 1070 { 1071 InputState* state = dynamic_cast<InputState*>(Factory::getIdentifier(type)->fabricate()); 1072 if (_configureInputState(state, name, priority)) 1191 1073 return state; 1192 1074 else … … 1214 1096 return false; 1215 1097 } 1216 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name);1217 if (it != _getInstance().inputStatesByName_.end())1218 { 1219 _ getInstance()._destroyState((*it).second);1098 std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name); 1099 if (it != inputStatesByName_.end()) 1100 { 1101 _destroyState((*it).second); 1220 1102 return true; 1221 1103 } … … 1233 1115 InputState* InputManager::getState(const std::string& name) 1234 1116 { 1235 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name);1236 if (it != _getInstance().inputStatesByName_.end())1117 std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name); 1118 if (it != inputStatesByName_.end()) 1237 1119 return (*it).second; 1238 1120 else … … 1248 1130 InputState* InputManager::getCurrentState() 1249 1131 { 1250 return (* _getInstance().activeStates_.rbegin()).second;1132 return (*activeStates_.rbegin()).second; 1251 1133 } 1252 1134 … … 1263 1145 { 1264 1146 // get pointer from the map with all stored handlers 1265 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name);1266 if (it != _getInstance().inputStatesByName_.end())1267 { 1268 _getInstance().stateEnterRequests_.push_back((*it).second);1147 std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name); 1148 if (it != inputStatesByName_.end()) 1149 { 1150 stateEnterRequests_.push_back((*it).second); 1269 1151 return true; 1270 1152 } … … 1283 1165 { 1284 1166 // get pointer from the map with all stored handlers 1285 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name);1286 if (it != _getInstance().inputStatesByName_.end())1287 { 1288 _getInstance().stateLeaveRequests_.push_back((*it).second);1167 std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name); 1168 if (it != inputStatesByName_.end()) 1169 { 1170 stateLeaveRequests_.push_back((*it).second); 1289 1171 return true; 1290 1172 } 1291 1173 return false; 1292 1174 } 1175 1176 1177 // ############################################################ 1178 // ##### Console Commands ##### 1179 // ########## ########## 1180 // ############################################################ 1181 1182 /** 1183 @brief 1184 Method for easily storing a string with the command executor. It is used by the 1185 KeyDetector to get assign commands. The KeyDetector simply executes 1186 the command 'storeKeyStroke myName' for each button/axis. 1187 @remarks 1188 This is only a temporary hack until we thourouhgly support multiple KeyBinders. 1189 @param name 1190 The name of the button/axis. 1191 */ 1192 void InputManager::storeKeyStroke(const std::string& name) 1193 { 1194 getInstance().requestLeaveState("detector"); 1195 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1196 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); 1197 } 1198 1199 /** 1200 @brief 1201 Assigns a command string to a key/button/axis. The name is determined via KeyDetector 1202 and InputManager::storeKeyStroke(.). 1203 @param command 1204 Command string that can be executed by the CommandExecutor 1205 */ 1206 void InputManager::keyBind(const std::string& command) 1207 { 1208 bindingCommmandString_s = command; 1209 getInstance().requestEnterState("detector"); 1210 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1211 } 1212 1213 /** 1214 @brief 1215 Starts joy stick calibration. 1216 */ 1217 void InputManager::calibrate() 1218 { 1219 getInstance().bCalibrating_ = true; 1220 getInstance().requestEnterState("calibrator"); 1221 } 1293 1222 } -
code/branches/gui/src/core/input/InputManager.h
r1641 r1642 86 86 // --> setConfigValues is private 87 87 friend ClassIdentifier<InputManager>; 88 89 public: // static functions 90 static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight, 88 // let Core class use tick(.) 89 friend Core; 90 91 public: 92 InputManager (); 93 ~InputManager(); 94 95 bool initialise(const size_t windowHnd, int windowWidth, int windowHeight, 91 96 bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false); 92 static int numberOfKeyboards(); 93 static int numberOfMice(); 94 static int numberOfJoySticks(); 95 96 static void destroy(); 97 98 //static bool isModifierDown(KeyboardModifier::Enum modifier); 99 //static bool isKeyDown(KeyCode::Enum key); 100 //static const MouseState getMouseState(); 101 //static const JoyStickState getJoyStickState(unsigned int ID); 102 103 static void setWindowExtents(const int width, const int height); 104 97 98 int numberOfKeyboards() { return keyboard_ ? 1 : 0; } 99 int numberOfMice() { return mouse_ ? 1 : 0; } 100 int numberOfJoySticks() { return joySticksSize_; } 101 102 void setWindowExtents(const int width, const int height); 103 104 SimpleInputState* createSimpleInputState (const std::string& name, int priority); 105 ExtendedInputState* createExtendedInputState(const std::string& name, int priority); 106 InputState* createInputState(const std::string& type, const std::string &name, int priority); 107 bool destroyState (const std::string& name); 108 InputState* getState (const std::string& name); 109 InputState* getCurrentState(); 110 bool requestEnterState (const std::string& name); 111 bool requestLeaveState (const std::string& name); 112 113 static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 114 static InputManager* getInstancePtr() { return singletonRef_s; } 115 116 public: // console commands 105 117 static void storeKeyStroke(const std::string& name); 106 118 static void keyBind(const std::string& command); 107 108 119 static void calibrate(); 109 110 static void tick(float dt);111 112 static SimpleInputState* createSimpleInputState (const std::string& name, int priority);113 static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);114 static bool destroyState (const std::string& name);115 static InputState* getState (const std::string& name);116 static InputState* getCurrentState();117 static bool requestEnterState (const std::string& name);118 static bool requestLeaveState (const std::string& name);119 120 120 121 private: // functions 121 122 // don't mess with a Singleton 122 InputManager ();123 123 InputManager (const InputManager&); 124 ~InputManager();125 124 126 125 // Intenal methods 127 bool _initialise(const size_t, int, int, bool, bool, bool);128 126 bool _initialiseKeyboard(); 129 127 bool _initialiseMouse(); … … 131 129 void _redimensionLists(); 132 130 133 void _destroy();134 131 void _destroyKeyboard(); 135 132 void _destroyMouse(); … … 142 139 unsigned int _getJoystick(const OIS::JoyStickEvent& arg); 143 140 144 void _tick(float dt);145 146 141 void _updateActiveStates(); 147 142 bool _configureInputState(InputState* state, const std::string& name, int priority); 143 144 void tick(float dt); 148 145 149 146 // input events … … 158 155 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 159 156 bool povMoved (const OIS::JoyStickEvent &arg, int id); 157 // don't remove that! Or else add OIS as dependency library to orxonox. 158 bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } 160 159 161 160 void setConfigValues(); 162 163 static InputManager& _getInstance();164 161 165 162 private: // variables … … 204 201 205 202 static std::string bindingCommmandString_s; 206 };207 203 static InputManager* singletonRef_s; 204 }; 208 205 } 209 206 -
code/branches/gui/src/core/input/InputState.h
r1641 r1642 40 40 #include <vector> 41 41 #include "core/Executor.h" 42 #include "core/BaseObject.h" 43 #include "core/CoreIncludes.h" 42 44 #include "InputInterfaces.h" 43 45 44 46 namespace orxonox 45 47 { 46 class _CoreExport InputState 48 class _CoreExport InputState : public BaseObject 47 49 { 48 50 friend class InputManager; 49 51 50 52 public: 51 InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) { } 53 InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) 54 { RegisterObject(InputState); } 52 55 virtual ~InputState() { } 53 56 -
code/branches/gui/src/core/input/SimpleInputState.cc
r1641 r1642 38 38 #include "core/Debug.h" 39 39 #include "core/Executor.h" 40 #include "core/CoreIncludes.h" 40 41 41 42 namespace orxonox 42 43 { 44 CreateFactory(SimpleInputState); 45 43 46 using namespace InputDevice; 44 47 … … 48 51 , joyStickHandlerAll_(0) 49 52 { 53 RegisterObject(SimpleInputState); 50 54 } 51 55 -
code/branches/gui/src/core/input/SimpleInputState.h
r1641 r1642 43 43 namespace orxonox 44 44 { 45 46 45 class _CoreExport SimpleInputState : public InputState 47 46 { 48 49 47 public: 50 48 SimpleInputState();
Note: See TracChangeset
for help on using the changeset viewer.