Changeset 1182 for code/branches
- Timestamp:
- Apr 24, 2008, 9:40:23 PM (17 years ago)
- Location:
- code/branches/input
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/InputBuffer.cc
r1066 r1182 40 40 //this->bActivated_ = false; 41 41 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]"; 42 this->keyboard_ = InputManager::get Singleton().getKeyboard();42 this->keyboard_ = InputManager::getKeyboard(); 43 43 this->buffer_ = ""; 44 44 -
code/branches/input/src/core/InputHandler.cc
r1066 r1182 38 38 #include "InputEvent.h" 39 39 #include "InputManager.h" 40 #include "core/CommandExecutor.h" 40 41 41 42 namespace orxonox … … 68 69 { 69 70 // simply write the key number (i) in the string 70 this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i); 71 this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i); 72 } 71 this->bindingsKeyPress_[i] = ""; 72 this->bindingsKeyRelease_[i] = ""; 73 } 74 this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD); 75 this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit"; 76 this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt"; 73 77 return true; 74 78 } … … 80 84 bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e) 81 85 { 82 if (e.key == OIS::KC_ESCAPE) 83 { 84 InputEvent e = {1, true, 0, 0, 0}; 85 InputHandlerGame::callListeners(e); 86 } 87 else if (e.key == OIS::KC_NUMPADENTER) 88 { 89 InputManager::getSingleton().setInputMode(IM_KEYBOARD); 90 } 91 else 86 this->keysDown_.push_back(e.key); 87 // find the appropriate key binding 88 std::string cmdStr = bindingsKeyPress_[int(e.key)]; 89 if (cmdStr != "") 90 { 91 CommandExecutor::execute(cmdStr); 92 COUT(3) << "Executing command: " << cmdStr << std::endl; 93 } 94 return true; 95 } 96 97 /** 98 @brief Event handler for the keyReleased Event. 99 @param e Event information 100 */ 101 bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e) 102 { 103 // remove the key from the keysDown_ list 104 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 105 { 106 if (*it == e.key) 107 { 108 keysDown_.erase(it); 109 break; 110 } 111 } 112 113 // find the appropriate key binding 114 std::string cmdStr = bindingsKeyRelease_[int(e.key)]; 115 if (cmdStr != "") 116 { 117 CommandExecutor::execute(cmdStr); 118 COUT(3) << "Executing command: " << cmdStr << std::endl; 119 } 120 return true; 121 } 122 123 /** 124 @brief Event handler for the mouseMoved Event. 125 @param e Event information 126 */ 127 bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e) 128 { 129 return true; 130 } 131 132 /** 133 @brief Event handler for the mousePressed Event. 134 @param e Event information 135 @param id The ID of the mouse button 136 */ 137 bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 138 { 139 return true; 140 } 141 142 /** 143 @brief Event handler for the mouseReleased Event. 144 @param e Event information 145 @param id The ID of the mouse button 146 */ 147 bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 148 { 149 return true; 150 } 151 152 /** 153 @brief Tick method to do additional calculations. 154 @param dt Delta time. 155 */ 156 void InputHandlerGame::tick(float dt) 157 { 158 // iterate through all the pressed keys 159 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 92 160 { 93 161 // find the appropriate key binding 94 std::string cmdStr = bindingsKeyPressed_[int(e.key)]; 95 //COUT(3) << cmdStr << " pressed" << std::endl; 96 } 97 return true; 98 } 99 100 /** 101 @brief Event handler for the keyReleased Event. 102 @param e Event information 103 */ 104 bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e) 105 { 106 // find the appropriate key binding 107 std::string cmdStr = bindingsKeyReleased_[int(e.key)]; 108 //COUT(3) << cmdStr << " released" << std::endl; 109 return true; 110 } 111 112 /** 113 @brief Event handler for the mouseMoved Event. 114 @param e Event information 115 */ 116 bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e) 117 { 118 return true; 119 } 120 121 /** 122 @brief Event handler for the mousePressed Event. 123 @param e Event information 124 @param id The ID of the mouse button 125 */ 126 bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 127 { 128 return true; 129 } 130 131 /** 132 @brief Event handler for the mouseReleased Event. 133 @param e Event information 134 @param id The ID of the mouse button 135 */ 136 bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 137 { 138 return true; 162 std::string cmdStr = bindingsKeyHold_[*it]; 163 if (cmdStr != "") 164 { 165 CommandExecutor::execute(cmdStr); 166 COUT(3) << "Executing command: " << cmdStr << std::endl; 167 } 168 } 139 169 } 140 170 … … 226 256 } 227 257 258 /** 259 @brief Tick method to do additional calculations. 260 @param dt Delta time. 261 */ 262 void InputHandlerGUI::tick(float dt) 263 { 264 265 } 266 228 267 } -
code/branches/input/src/core/InputHandler.h
r1062 r1182 38 38 39 39 #include <string> 40 #include <list> 40 41 #include <OIS/OIS.h> 41 42 … … 44 45 namespace orxonox 45 46 { 47 namespace KeybindSetting 48 { 49 enum KeybindSetting 50 { 51 None, 52 OnPress, 53 OnRelease, 54 Continuous, 55 }; 56 } 57 58 class _CoreExport BaseInputHandler 59 : public OIS::KeyListener, public OIS::MouseListener 60 { 61 virtual void tick(float dt) = 0; 62 }; 63 46 64 /** 47 65 @brief Captures mouse and keyboard input while in the actual game mode. 48 66 Manages the key bindings. 49 67 */ 50 class _CoreExport InputHandlerGame 51 : public OIS::KeyListener, public OIS::MouseListener 68 class _CoreExport InputHandlerGame : public BaseInputHandler 52 69 { 53 70 public: … … 65 82 bool keyReleased (const OIS::KeyEvent &arg); 66 83 84 void tick(float dt); 85 67 86 // temporary hack 68 87 void callListeners(InputEvent &evt); 88 89 //! Stores all the keys that are down 90 std::list<OIS::KeyCode> keysDown_; 69 91 70 92 /** denotes the maximum number of different keys there are in OIS. … … 72 94 static const int numberOfKeys_s = 256; 73 95 //! Array of input events for every pressed key 74 std::string bindingsKeyPress ed_[numberOfKeys_s];96 std::string bindingsKeyPress_[numberOfKeys_s]; 75 97 //! Array of input events for every released key 76 std::string bindingsKeyReleased_[numberOfKeys_s]; 98 std::string bindingsKeyRelease_[numberOfKeys_s]; 99 //! Array of input events for every holding key 100 std::string bindingsKeyHold_[numberOfKeys_s]; 77 101 78 102 /** denotes the maximum number of different buttons there are in OIS. … … 91 115 GUI. 92 116 */ 93 class _CoreExport InputHandlerGUI 94 : public OIS::KeyListener, public OIS::MouseListener 117 class _CoreExport InputHandlerGUI : public BaseInputHandler 95 118 { 96 119 public: 97 120 InputHandlerGUI (); 98 121 ~InputHandlerGUI(); 122 123 void tick(float dt); 99 124 100 125 private: -
code/branches/input/src/core/InputManager.cc
r1089 r1182 36 36 #include "CoreIncludes.h" 37 37 #include "Debug.h" 38 #include "InputEventListener.h"39 #include "InputHandler.h"40 38 #include "InputBuffer.h" 41 39 #include "ConsoleCommand.h" 40 #include "util/Convert.h" 42 41 43 42 namespace orxonox 44 43 { 45 ConsoleCommand(InputManager, setInputMode, AccessLevel::Admin, true).setDefaultValue(0, IM_INGAME);46 47 44 /** 48 45 @brief Constructor only resets the pointer values to 0. … … 50 47 InputManager::InputManager() : 51 48 inputSystem_(0), keyboard_(0), mouse_(0), 52 currentMode_(IM_UNINIT), setMode_(IM_UNINIT), 53 handlerGUI_(0), handlerBuffer_(0), handlerGame_(0) 49 state_(IS_UNINIT), stateRequest_(IS_UNINIT) 54 50 { 55 51 RegisterObject(InputManager); 56 }57 58 /**59 @brief Destructor only called at the end of the program60 */61 InputManager::~InputManager()62 {63 this->destroy();64 52 } 65 53 … … 68 56 @return A reference to the only instance of the InputManager 69 57 */ 70 InputManager& InputManager:: getSingleton()58 InputManager& InputManager::_getSingleton() 71 59 { 72 60 static InputManager theOnlyInstance; 73 61 return theOnlyInstance; 62 } 63 64 /** 65 @brief Destructor only called at the end of the program 66 */ 67 InputManager::~InputManager() 68 { 69 this->_destroy(); 74 70 } 75 71 … … 81 77 @param windowHeight The height of the render window 82 78 */ 83 bool InputManager:: initialise(size_t windowHnd, int windowWidth, int windowHeight)84 { 85 if (! this->inputSystem_)79 bool InputManager::_initialise(size_t windowHnd, int windowWidth, int windowHeight) 80 { 81 if (!inputSystem_) 86 82 { 87 83 // Setup basic variables … … 93 89 paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 94 90 95 #if defined OIS_LINUX_PLATFORM96 paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));97 #endif91 //#if defined OIS_LINUX_PLATFORM 92 // paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); 93 //#endif 98 94 99 95 try … … 107 103 COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl; 108 104 105 //TODO: check for already pressed keys 106 109 107 // create a mouse. If none are available the exception is caught. 110 108 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true)); … … 112 110 113 111 // Set mouse region 114 this->setWindowExtents(windowWidth, windowHeight); 112 setWindowExtents(windowWidth, windowHeight); 113 114 this->state_ = IS_NONE; 115 115 } 116 116 catch (OIS::Exception ex) … … 118 118 // something went wrong with the initialisation 119 119 COUT(ORX_ERROR) << "Error: Failed creating an input system/keyboard/mouse. Message: \"" << ex.eText << "\"" << std::endl; 120 this->inputSystem_ = 0;120 inputSystem_ = 0; 121 121 return false; 122 122 } 123 123 } 124 124 125 // create the handlers 126 this->handlerGUI_ = new InputHandlerGUI(); 127 this->handlerGame_ = new InputHandlerGame(); 128 //this->handlerBuffer_ = new InputBuffer(); 129 this->handlerGame_->loadBindings(); 130 131 /*COUT(ORX_DEBUG) << "*** InputManager: Loading key bindings..." << std::endl; 132 // load the key bindings 133 InputEvent empty = {0, false, 0, 0, 0}; 134 for (int i = 0; i < this->numberOfKeys_; i++) 135 this->bindingsKeyPressed_[i] = empty; 136 137 //assign 'abort' to the escape key 138 this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1; 139 COUT(ORX_DEBUG) << "*** InputManager: Loading done." << std::endl;*/ 140 141 return true; 125 keyboard_->setEventCallback(this); 126 mouse_->setEventCallback(this); 127 128 addKeyListener(new InputBuffer(), "buffer"); 129 130 _loadBindings(); 131 132 COUT(ORX_DEBUG) << "*** InputManager: Loading done." << std::endl; 133 134 return true; 135 } 136 137 void InputManager::_loadBindings() 138 { 139 for (int i = 0; i < numberOfKeys_s; i++) 140 { 141 // simply write the key number (i) in the string 142 this->bindingsKeyPress_[i] = ""; 143 this->bindingsKeyRelease_[i] = ""; 144 } 145 this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole"; 146 this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit"; 147 this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt"; 142 148 } 143 149 … … 145 151 @brief Destroys all the created input devices and handlers. 146 152 */ 147 void InputManager:: destroy()153 void InputManager::_destroy() 148 154 { 149 155 COUT(ORX_DEBUG) << "*** InputManager: Destroying ..." << std::endl; 150 if (this->mouse_) 151 this->inputSystem_->destroyInputObject(mouse_); 152 if (this->keyboard_) 153 this->inputSystem_->destroyInputObject(keyboard_); 154 if (this->inputSystem_) 155 OIS::InputManager::destroyInputSystem(this->inputSystem_); 156 157 this->mouse_ = 0; 158 this->keyboard_ = 0; 159 this->inputSystem_ = 0; 160 161 if (this->handlerBuffer_) 162 delete this->handlerBuffer_; 163 if (this->handlerGame_) 164 delete this->handlerGame_; 165 if (this->handlerGUI_) 166 delete this->handlerGUI_; 167 168 this->handlerBuffer_ = 0; 169 this->handlerGame_ = 0; 170 this->handlerGUI_ = 0; 156 if (mouse_) 157 inputSystem_->destroyInputObject(mouse_); 158 if (keyboard_) 159 inputSystem_->destroyInputObject(keyboard_); 160 if (inputSystem_) 161 OIS::InputManager::destroyInputSystem(inputSystem_); 162 163 mouse_ = 0; 164 keyboard_ = 0; 165 inputSystem_ = 0; 166 167 OIS::KeyListener* buffer = keyListeners_["buffer"]; 168 if (buffer) 169 { 170 this->removeKeyListener("buffer"); 171 delete buffer; 172 buffer = 0; 173 } 171 174 172 175 COUT(ORX_DEBUG) << "*** InputManager: Destroying done." << std::endl; … … 179 182 void InputManager::tick(float dt) 180 183 { 184 if (state_ == IS_UNINIT) 185 return; 186 181 187 // reset the game if it has changed 182 if (this->currentMode_ != this->setMode_) 183 { 184 switch (this->setMode_) 185 { 186 case IM_GUI: 187 this->mouse_->setEventCallback(this->handlerGUI_); 188 this->keyboard_->setEventCallback(this->handlerGUI_); 188 if (state_ != stateRequest_) 189 { 190 if (stateRequest_ != IS_CUSTOM) 191 _setDefaultState(); 192 193 switch (stateRequest_) 194 { 195 case IS_NORMAL: 189 196 break; 190 case IM_INGAME: 191 this->mouse_->setEventCallback(this->handlerGame_); 192 this->keyboard_->setEventCallback(this->handlerGame_); 197 case IS_GUI: 198 //FIXME: do stuff 193 199 break; 194 case IM_KEYBOARD: 195 this->mouse_->setEventCallback(this->handlerGame_); 196 this->keyboard_->setEventCallback(this->handlerBuffer_); 200 case IS_CONSOLE: 201 if (this->keyListeners_.find("buffer") != this->keyListeners_.end()) 202 this->activeKeyListeners_.push_back(this->keyListeners_["buffer"]); 203 this->bDefaultKeyInput = false; 197 204 break; 198 case IM_UNINIT: 199 this->mouse_->setEventCallback(0); 200 this->keyboard_->setEventCallback(0); 205 case IS_CUSTOM: 206 // don't do anything 201 207 break; 202 208 } 203 this->currentMode_ = this->setMode_;209 state_ = stateRequest_; 204 210 } 205 211 … … 207 213 if (mouse_) 208 214 mouse_->capture(); 209 210 215 if (keyboard_) 211 216 keyboard_->capture(); 212 217 } 218 219 void InputManager::_setDefaultState() 220 { 221 this->activeJoyStickListeners_.clear(); 222 this->activeKeyListeners_.clear(); 223 this->activeMouseListeners_.clear(); 224 this->bDefaultKeyInput = true; 225 this->bDefaultMouseInput = true; 226 this->bDefaultJoyStickInput = true; 227 } 228 229 230 /** 231 @brief Event handler for the keyPressed Event. 232 @param e Event information 233 */ 234 bool InputManager::keyPressed(const OIS::KeyEvent &e) 235 { 236 this->keysDown_.push_back(e.key); 237 238 if (this->bDefaultKeyInput) 239 { 240 // find the appropriate key binding 241 std::string cmdStr = bindingsKeyPress_[int(e.key)]; 242 if (cmdStr != "") 243 { 244 CommandExecutor::execute(cmdStr); 245 COUT(3) << "Executing command: " << cmdStr << std::endl; 246 } 247 } 248 else 249 { 250 for (std::list<OIS::KeyListener*>::const_iterator it = activeKeyListeners_.begin(); it != activeKeyListeners_.end(); it++) 251 (*it)->keyPressed(e); 252 } 253 return true; 254 } 255 256 /** 257 @brief Event handler for the keyReleased Event. 258 @param e Event information 259 */ 260 bool InputManager::keyReleased(const OIS::KeyEvent &e) 261 { 262 // remove the key from the keysDown_ list 263 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 264 { 265 if (*it == e.key) 266 { 267 keysDown_.erase(it); 268 break; 269 } 270 } 271 272 if (this->bDefaultKeyInput) 273 { 274 // find the appropriate key binding 275 std::string cmdStr = bindingsKeyRelease_[int(e.key)]; 276 if (cmdStr != "") 277 { 278 CommandExecutor::execute(cmdStr); 279 COUT(3) << "Executing command: " << cmdStr << std::endl; 280 } 281 } 282 else 283 { 284 for (std::list<OIS::KeyListener*>::const_iterator it = activeKeyListeners_.begin(); it != activeKeyListeners_.end(); it++) 285 (*it)->keyReleased(e); 286 } 287 return true; 288 } 289 290 /** 291 @brief Event handler for the mouseMoved Event. 292 @param e Event information 293 */ 294 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 295 { 296 return true; 297 } 298 299 /** 300 @brief Event handler for the mousePressed Event. 301 @param e Event information 302 @param id The ID of the mouse button 303 */ 304 bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 305 { 306 return true; 307 } 308 309 /** 310 @brief Event handler for the mouseReleased Event. 311 @param e Event information 312 @param id The ID of the mouse button 313 */ 314 bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 315 { 316 return true; 317 } 318 319 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 320 { 321 return true; 322 } 323 324 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 325 { 326 return true; 327 } 328 329 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 330 { 331 return true; 332 } 333 334 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 335 { 336 return true; 337 } 338 339 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 340 { 341 return true; 342 } 343 344 213 345 214 346 /** … … 221 353 { 222 354 // Set mouse region (if window resizes, we should alter this to reflect as well) 223 const OIS::MouseState &mouseState = mouse_->getMouseState();355 const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState(); 224 356 mouseState.width = width; 225 357 mouseState.height = height; … … 231 363 @remark Only has an affect if the mode actually changes 232 364 */ 233 void InputManager::setInputMode(int mode) 234 { 235 if (mode > 0 && mode < 4) 236 getSingleton().setMode_ = (InputMode)mode; 365 void InputManager::setInputState(const InputState state) 366 { 367 _getSingleton().stateRequest_ = state; 237 368 } 238 369 … … 241 372 @return The current input mode. 242 373 */ 243 InputMode InputManager::getInputMode() 244 { 245 return this->currentMode_; 246 } 247 248 void InputManager::feedInputBuffer(InputBuffer* buffer) 249 { 250 this->handlerBuffer_ = buffer; 251 } 252 374 InputManager::InputState InputManager::getInputState() 375 { 376 return _getSingleton().state_; 377 } 378 379 void InputManager::destroy() 380 { 381 _getSingleton()._destroy(); 382 } 383 384 bool InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight) 385 { 386 return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight); 387 } 388 389 bool InputManager::addKeyListener(OIS::KeyListener *listener, const std::string& name) 390 { 391 if (_getSingleton().keyListeners_.find(name) == _getSingleton().keyListeners_.end()) 392 { 393 _getSingleton().keyListeners_[name] = listener; 394 return true; 395 } 396 else 397 return false; 398 } 399 400 bool InputManager::removeKeyListener(const std::string &name) 401 { 402 std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().keyListeners_.find(name); 403 if (it != _getSingleton().keyListeners_.end()) 404 { 405 _getSingleton().keyListeners_.erase(it); 406 return true; 407 } 408 else 409 return false; 410 } 411 412 OIS::KeyListener* InputManager::getKeyListener(const std::string& name) 413 { 414 std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().keyListeners_.find(name); 415 if (it != _getSingleton().keyListeners_.end()) 416 { 417 return (*it).second; 418 } 419 else 420 return 0; 421 } 253 422 254 423 } -
code/branches/input/src/core/InputManager.h
r1084 r1182 38 38 #include "CorePrereqs.h" 39 39 40 #include <map> 41 #include <list> 40 42 #include <OIS/OIS.h> 41 43 … … 46 48 { 47 49 /** 48 @brief Designates the way input is handled currently.49 IM_GUI: All the OIS input events are passed to CEGUI50 IM_KEYBOARD: Only keyboard input is captured and passed to the InputBuffer51 IM_INGAME: Normal game mode. Key bindings and mouse are active.52 */53 enum InputMode54 {55 IM_GUI = 0,56 IM_KEYBOARD = 1,57 IM_INGAME = 2,58 IM_UNINIT = 3,59 };60 61 /**62 50 @brief Captures and distributes mouse and keyboard input. 63 51 It resolves the key bindings to InputEvents which can be heard by … … 65 53 */ 66 54 class _CoreExport InputManager 67 : public Tickable 55 : public Tickable, 56 public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener 68 57 { 69 58 public: 70 bool initialise(size_t windowHnd, int windowWidth, int windowHeight); 71 void destroy(); 59 /** 60 @brief Designates the way input is handled currently. 61 IM_GUI: All the OIS input events are passed to CEGUI 62 IM_BUFFER: Only keyboard input is captured and passed to the InputBuffer 63 IM_NORMAL: Normal game mode. Key bindings and mouse are active. 64 */ 65 enum InputState 66 { 67 IS_UNINIT, 68 IS_NONE, 69 IS_NORMAL, 70 IS_GUI, 71 IS_CONSOLE, 72 IS_CUSTOM 73 }; 74 75 public: 72 76 void tick(float dt); 73 void setWindowExtents(int width, int height);74 InputMode getInputMode();75 77 76 // temporary hack 77 void feedInputBuffer(InputBuffer* buffer); 78 static bool initialise(size_t windowHnd, int windowWidth, int windowHeight); 79 static void destroy(); 80 81 static void setWindowExtents(int width, int height); 82 static void setInputState(const InputState state); 83 static InputState getInputState(); 84 85 static bool addKeyListener(OIS::KeyListener* listener, const std::string& name); 86 //static bool removeKeyListener(OIS::KeyListener* listener); 87 static bool removeKeyListener(const std::string& name); 88 static bool enableKeyListener(const std::string& name); 89 static bool disableKeyListener(const std::string& name); 90 static OIS::KeyListener* getKeyListener(const std::string& name); 91 static bool isKeyListenerActive(const std::string& name); 92 93 static bool addMouseListener(OIS::MouseListener* listener, const std::string& name); 94 //static bool removeMouseListener(OIS::MouseListener* listener); 95 static bool removeMouseListener(const std::string& name); 96 static bool enableMouseListener(const std::string& name); 97 static bool disableMouseListener(const std::string& name); 98 static OIS::MouseListener* getMouseListener(const std::string& name); 99 static bool isMouseListenerActive(const std::string& name); 100 101 static bool addJoyStickListener(OIS::JoyStickListener* listener, const std::string& name); 102 //static bool removeJoyStickListener(OIS::JoyStickListener* listener); 103 static bool removeJoyStickListener(const std::string& name); 104 static bool enableJoyStickListener(const std::string& name); 105 static bool disableJoyStickListener(const std::string& name); 106 static OIS::JoyStickListener* getJoyStickListener(const std::string& name); 107 static bool isJoyStickListenerActive(const std::string& name); 78 108 79 109 // Temporary solutions. Will be removed soon! 80 OIS::Mouse *getMouse() { return this->mouse_ ; } 81 OIS::Keyboard *getKeyboard() { return this->keyboard_; } 82 83 static InputManager& getSingleton(); 84 static InputManager* getSingletonPtr() { return &getSingleton(); } 85 static void setInputMode(int mode); 110 static OIS::Mouse* getMouse() { return _getSingleton().mouse_ ; } 111 static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; } 86 112 87 113 private: … … 91 117 ~InputManager(); 92 118 93 OIS::InputManager *inputSystem_; //!< OIS input manager 94 OIS::Keyboard *keyboard_; //!< OIS mouse 95 OIS::Mouse *mouse_; //!< OIS keyboard 119 bool _initialise(size_t windowHnd, int windowWidth, int windowHeight); 120 void _destroy(); 121 void _setDefaultState(); 122 void _loadBindings(); 96 123 97 InputMode currentMode_; //!< Input mode currently used 98 InputMode setMode_; //!< Input mode that has been set lately 99 InputHandlerGUI *handlerGUI_; //!< Handles the input if in GUI mode 100 // FIXME: insert the InputBuffer once merged with core2 101 InputBuffer *handlerBuffer_; //!< Handles the input if in Buffer mode 102 InputHandlerGame *handlerGame_; //!< Handles the input if in Game mode 124 // input events 125 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 126 bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 127 bool mouseMoved (const OIS::MouseEvent &arg); 128 bool keyPressed (const OIS::KeyEvent &arg); 129 bool keyReleased (const OIS::KeyEvent &arg); 130 bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 131 bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 132 bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 133 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 134 bool povMoved (const OIS::JoyStickEvent &arg, int id); 103 135 104 //! Pointer to the instance of the singleton 105 //static InputManager *singletonRef_s; 136 static InputManager& _getSingleton(); 137 static InputManager* _getSingletonPtr() { return &_getSingleton(); } 138 139 private: 140 OIS::InputManager* inputSystem_; //!< OIS input manager 141 OIS::Keyboard* keyboard_; //!< OIS mouse 142 OIS::Mouse* mouse_; //!< OIS keyboard 143 144 InputState state_; 145 InputState stateRequest_; 146 147 std::list<OIS::KeyCode> keysDown_; 148 149 bool bDefaultKeyInput; 150 bool bDefaultMouseInput; 151 bool bDefaultJoyStickInput; 152 153 std::map<std::string, OIS::KeyListener*> keyListeners_; 154 std::list<OIS::KeyListener*> activeKeyListeners_; 155 std::map<std::string, OIS::MouseListener*> mouseListeners_; 156 std::list<OIS::MouseListener*> activeMouseListeners_; 157 std::map<std::string, OIS::JoyStickListener*> joystickListeners_; 158 std::list<OIS::JoyStickListener*> activeJoyStickListeners_; 159 160 161 /** denotes the maximum number of different keys there are in OIS. 162 256 should be ok since the highest number in the enum is 237. */ 163 static const int numberOfKeys_s = 256; 164 //! Array of input events for every pressed key 165 std::string bindingsKeyPress_ [numberOfKeys_s]; 166 //! Array of input events for every released key 167 std::string bindingsKeyRelease_[numberOfKeys_s]; 168 //! Array of input events for every held key 169 std::string bindingsKeyHold_ [numberOfKeys_s]; 170 171 /** denotes the maximum number of different buttons there are in OIS. 172 16 should be ok since the highest number in the enum is 7. */ 173 static const int numberOfMouseButtons_s = 16; 174 //! Array of input events for every pressed mouse button 175 std::string bindingsMouseButtonPress_ [numberOfMouseButtons_s]; 176 //! Array of input events for every released mouse button 177 std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s]; 178 //! Array of input events for every held mouse button 179 std::string bindingsMouseButtonHold_ [numberOfMouseButtons_s]; 180 181 /** denotes the maximum number of different buttons there are in OIS. 182 32 should be ok. */ 183 static const int numberOfJoyStickButtons_s = 32; 184 //! Array of input events for every pressed joystick button 185 std::string bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; 186 //! Array of input events for every released joystick button 187 std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; 188 //! Array of input events for every held joystick button 189 std::string bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; 190 106 191 }; 107 192 } -
code/branches/input/src/orxonox/Orxonox.cc
r1156 r1182 84 84 namespace orxonox 85 85 { 86 ConsoleCommand (Orxonox, exit, AccessLevel::None, true);87 ConsoleCommand (Orxonox, slomo, AccessLevel::Offline, true).setDefaultValue(0, 1.0);88 ConsoleCommand (Orxonox, setTimeFactor, AccessLevel::Offline, false).setDefaultValue(0, 1.0);89 86 ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None); 87 ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0); 88 ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0); 89 ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None); 90 90 class Testconsole : public InputBufferListener 91 91 { … … 118 118 void exit() const 119 119 { 120 CommandExecutor::execute("setInputMode 2");120 InputManager::setInputState(InputManager::IS_NORMAL); 121 121 } 122 122 … … 177 177 delete this->orxonoxHUD_; 178 178 Loader::close(); 179 InputManager:: getSingleton().destroy();179 InputManager::destroy(); 180 180 if (this->auMan_) 181 181 delete this->auMan_; … … 392 392 void Orxonox::setupInputSystem() 393 393 { 394 inputHandler_ = &InputManager::getSingleton(); 395 if (!inputHandler_->initialise(ogre_->getWindowHandle(), 394 if (!InputManager::initialise(ogre_->getWindowHandle(), 396 395 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 397 396 abortImmediateForce(); 398 inputHandler_->setInputMode(IM_INGAME);397 InputManager::setInputState(InputManager::IS_NORMAL); 399 398 } 400 399 … … 415 414 void Orxonox::startRenderLoop() 416 415 { 417 InputBuffer* ib = new InputBuffer(); 418 InputManager::getSingleton().feedInputBuffer(ib); 419 Testconsole* console = new Testconsole(ib); 420 ib->registerListener(console, &Testconsole::listen, true); 421 ib->registerListener(console, &Testconsole::execute, '\r', false); 422 ib->registerListener(console, &Testconsole::execute, '\n', false); 423 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true); 424 ib->registerListener(console, &Testconsole::clear, '§', true); 425 ib->registerListener(console, &Testconsole::removeLast, '\b', true); 426 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true); 416 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyListener("buffer")); 417 console_ = new Testconsole(ib); 418 ib->registerListener(console_, &Testconsole::listen, true); 419 ib->registerListener(console_, &Testconsole::execute, '\r', false); 420 ib->registerListener(console_, &Testconsole::execute, '\n', false); 421 ib->registerListener(console_, &Testconsole::hintandcomplete, '\t', true); 422 ib->registerListener(console_, &Testconsole::clear, '§', true); 423 ib->registerListener(console_, &Testconsole::removeLast, '\b', true); 424 ib->registerListener(console_, &Testconsole::exit, (char)0x1B, true); 427 425 428 426 // first check whether ogre root object has been created … … 442 440 eventTimes[i].clear(); 443 441 // fill the fps time list with zeros 444 for (int i = 0; i < 20; i++)442 for (int i = 0; i < 50; i++) 445 443 eventTimes[3].push_back(0); 446 444 … … 468 466 // show the current time in the HUD 469 467 orxonoxHUD_->setTime((int)now, 0); 468 orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber()); 470 469 if (eventTimes[3].back() - eventTimes[3].front() != 0) 471 orxonoxHUD_->setRocket1((int)( 20000.0f/(eventTimes[3].back() - eventTimes[3].front())));470 orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front()))); 472 471 473 472 // Iterate through all Tickables and call their tick(dt) function … … 533 532 } 534 533 535 /** 536 @brief Test method for the InputHandler. 537 But: Is actually responsible for catching an exit event.. 538 */ 539 void Orxonox::eventOccured(InputEvent &evt) 540 { 541 if (evt.id == 1) 542 this->abortRequest(); 534 void Orxonox::activateConsole() 535 { 536 InputManager::setInputState(InputManager::IS_CONSOLE); 543 537 } 544 538 } -
code/branches/input/src/orxonox/Orxonox.h
r1089 r1182 49 49 namespace orxonox { 50 50 51 class Testconsole; 52 51 53 enum gameMode{ 52 54 SERVER, … … 56 58 57 59 //! Orxonox singleton class 58 class _OrxonoxExport Orxonox : public InputEventListener60 class _OrxonoxExport Orxonox 59 61 { 60 62 public: … … 72 74 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 73 75 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 76 static inline void activateConsole(); 74 77 75 78 private: … … 95 98 float calculateEventTime(unsigned long, std::deque<unsigned long>&); 96 99 97 void eventOccured(InputEvent &evt);98 99 100 private: 100 101 GraphicsEngine* ogre_; //!< our dearest graphics engine <3 … … 102 103 audio::AudioManager* auMan_; //!< audio manager 103 104 InputManager* inputHandler_; //!< Handles input with key bindings 105 Testconsole* console_; 104 106 Ogre::Timer* timer_; //!< Main loop timer 105 107 // TODO: make this a config-value by creating a config class for orxonox -
code/branches/input/src/orxonox/objects/SpaceShip.cc
r1064 r1182 428 428 void SpaceShip::tick(float dt) 429 429 { 430 if (InputManager::get Singleton().getMouse()->getEventCallback() != this)431 { 432 if (InputManager::get Singleton().getMouse())430 if (InputManager::getMouse()->getEventCallback() != this) 431 { 432 if (InputManager::getMouse()) 433 433 { 434 InputManager::get Singleton().getMouse()->setEventCallback(this);434 InputManager::getMouse()->setEventCallback(this); 435 435 this->setMouseEventCallback_ = true; 436 436 } … … 457 457 } 458 458 459 OIS::Keyboard* mKeyboard = InputManager::get Singleton().getKeyboard();459 OIS::Keyboard* mKeyboard = InputManager::getKeyboard(); 460 460 //FIXME: variable never used 461 461 //OIS::Mouse* mMouse = InputManager::getSingleton().getMouse(); -
code/branches/input/visual_studio/vc8/core.vcproj
r1153 r1182 203 203 RelativePath="..\..\src\core\InputHandler.cc" 204 204 > 205 <FileConfiguration 206 Name="Debug|Win32" 207 ExcludedFromBuild="true" 208 > 209 <Tool 210 Name="VCCLCompilerTool" 211 /> 212 </FileConfiguration> 213 <FileConfiguration 214 Name="Release|Win32" 215 ExcludedFromBuild="true" 216 > 217 <Tool 218 Name="VCCLCompilerTool" 219 /> 220 </FileConfiguration> 205 221 </File> 206 222 <File -
code/branches/input/visual_studio/vc8/orxonox.vcproj
r1153 r1182 398 398 /> 399 399 </FileConfiguration> 400 <FileConfiguration 401 Name="Release|Win32" 402 > 403 <Tool 404 Name="VCCLCompilerTool" 405 UsePrecompiledHeader="0" 406 /> 407 </FileConfiguration> 400 408 </File> 401 409 </Filter>
Note: See TracChangeset
for help on using the changeset viewer.