Changeset 1272
- Timestamp:
- May 14, 2008, 11:44:17 AM (17 years ago)
- Location:
- code/branches/merge
- Files:
-
- 19 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/bin/keybindings.ini
r1219 r1272 24 24 R_6= 25 25 H_6= 26 P_7= 26 P_7="exec disco.txt" 27 27 R_7= 28 28 H_7= … … 30 30 R_8= 31 31 H_8= 32 P_9= 32 P_9="disco.txt" 33 33 R_9= 34 34 H_9= -
code/branches/merge/src/core/CommandExecutor.h
r1214 r1272 89 89 inline std::string getAdditionalParameter() const 90 90 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; } 91 inline std::string getCommandString() const { return this->processedCommand_; } 91 92 92 93 void setEvaluatedParameter(unsigned int index, MultiTypeMath param); -
code/branches/merge/src/core/CorePrereqs.h
r1219 r1272 144 144 145 145 // input 146 //class GUIInputHandler; 146 147 class InputBuffer; 147 148 class InputBufferListener; 148 149 class InputManager; 150 class JoyStickHandler; 149 151 class KeyBinder; 150 class GUIInputHandler;151 152 class KeyHandler; 152 153 class MouseHandler; 153 class JoyStickHandler;154 154 155 155 } -
code/branches/merge/src/core/InputBuffer.cc
r1220 r1272 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 32 32 33 33 #include "util/Clipboard.h" 34 #include "InputManager.h" 34 #include "CoreIncludes.h" 35 #include "ConfigValueIncludes.h" 35 36 36 37 namespace orxonox 37 38 { 38 InputBuffer::InputBuffer() 39 { 40 //this->bActivated_ = false; 41 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^"; 42 this->keyboard_ = InputManager::getKeyboard(); 43 this->buffer_ = ""; 44 45 //this->keyboard_->setEventCallback(this); 46 } 47 48 InputBuffer::InputBuffer(const std::string allowedChars) 49 { 50 //this->bActivated_ = false; 51 this->allowedChars_ = allowedChars; 52 this->keyboard_ = InputManager::getKeyboard(); 53 this->buffer_ = ""; 54 } 55 /* 56 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput) 57 { 58 struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '}; 59 this->listeners_.insert(this->listeners_.end(), newListener); 60 } 61 62 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput) 63 { 64 struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_}; 65 this->listeners_.insert(this->listeners_.end(), newListener); 66 } 67 */ 68 void InputBuffer::set(const std::string& input) 69 { 70 this->buffer_ = ""; 71 this->append(input); 72 } 73 74 void InputBuffer::append(const std::string& input) 75 { 76 for (unsigned int i = 0; i < input.size(); i++) 77 { 78 if (this->charIsAllowed(input[i])) 79 this->buffer_ += input[i]; 80 81 this->updated(input[i], false); 82 } 83 this->updated(); 84 } 85 86 void InputBuffer::append(const char& input) 87 { 88 if (this->charIsAllowed(input)) 89 this->buffer_ += input; 90 91 this->updated(input, true); 92 } 93 94 void InputBuffer::clear() 95 { 96 this->buffer_ = ""; 97 this->updated(); 98 } 99 100 void InputBuffer::removeLast() 101 { 102 this->buffer_ = this->buffer_.substr(0, this->buffer_.size() - 1); 103 this->updated(); 104 } 105 106 void InputBuffer::updated() 107 { 108 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 109 { 110 if ((*it).bListenToAllChanges_) 111 (*(*it).listener_.*(*it).function_)(); 112 } 113 } 114 115 void InputBuffer::updated(const char& update, bool bSingleInput) 116 { 117 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 118 { 119 if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 120 (*(*it).listener_.*(*it).function_)(); 121 } 122 } 123 124 /*void InputBuffer::activityChanged() const 125 { 126 }*/ 127 128 bool InputBuffer::charIsAllowed(const char& input) 129 { 130 if (this->allowedChars_ == "") 131 return true; 132 else 133 return (this->allowedChars_.find(input) != std::string::npos); 134 } 135 136 bool InputBuffer::keyPressed(const OIS::KeyEvent &e) 137 { 138 /*if (e.key == OIS::KC_NUMPADENTER) 139 { 140 this->setActivated(!this->isActivated()); 141 this->clear(); 142 return true; 143 }*/ 144 145 if (this->keyboard_->isModifierDown(OIS::Keyboard::Ctrl)) 146 { 147 if (e.key == OIS::KC_V) 148 { 149 this->append(fromClipboard()); 150 return true; 151 } 152 else if (e.key == OIS::KC_C) 153 { 154 toClipboard(this->buffer_); 155 return true; 156 } 157 else if (e.key == OIS::KC_X) 158 { 159 toClipboard(this->buffer_); 160 this->clear(); 161 return true; 162 } 163 } 164 else if (this->keyboard_->isModifierDown(OIS::Keyboard::Shift)) 165 { 166 if (e.key == OIS::KC_INSERT) 167 { 168 this->append(fromClipboard()); 169 return true; 170 } 171 else if (e.key == OIS::KC_DELETE) 172 { 173 toClipboard(this->buffer_); 174 this->clear(); 175 return true; 176 } 177 } 178 179 //std::cout << this->keyboard_->getAsString(e.key) << " / " << (char)e.text << std::endl; 180 181 std::string input = this->keyboard_->getAsString(e.key); 182 /*if (input.size() >= 1) 183 this->append(input[0]);*/ 184 185 this->append((char)e.text); 186 return true; 187 } 188 189 bool InputBuffer::keyReleased(const OIS::KeyEvent &e) 190 { 191 return true; 192 } 39 InputBuffer::InputBuffer(const std::string allowedChars) : 40 buffer_(""), 41 allowedChars_(allowedChars), 42 lastKey_(KeyCode::Unassigned), 43 timeSinceKeyPressed_(0.0f), 44 timeSinceKeyRepeated_(0.0f), 45 keysToRepeat_(0) 46 { 47 RegisterObject(InputBuffer); 48 setConfigValues(); 49 } 50 51 void InputBuffer::setConfigValues() 52 { 53 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer"); 54 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 55 if (keyRepeatDeleay_ < 0.0) 56 { 57 ResetConfigValue(keyRepeatDeleay_); 58 } 59 if (keyRepeatTime_ < 0.0) 60 { 61 ResetConfigValue(keyRepeatTime_); 62 } 63 } 64 /* 65 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput) 66 { 67 struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '}; 68 listeners_.insert(listeners_.end(), newListener); 69 } 70 71 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput) 72 { 73 struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_}; 74 listeners_.insert(listeners_.end(), newListener); 75 } 76 */ 77 void InputBuffer::set(const std::string& input) 78 { 79 buffer_ = ""; 80 append(input); 81 } 82 83 void InputBuffer::append(const std::string& input) 84 { 85 for (unsigned int i = 0; i < input.size(); i++) 86 { 87 if (charIsAllowed(input[i])) 88 buffer_ += input[i]; 89 90 updated(input[i], false); 91 } 92 updated(); 93 } 94 95 void InputBuffer::append(const char& input) 96 { 97 if (charIsAllowed(input)) 98 buffer_ += input; 99 100 updated(input, true); 101 } 102 103 void InputBuffer::clear() 104 { 105 buffer_ = ""; 106 updated(); 107 } 108 109 void InputBuffer::removeLast() 110 { 111 buffer_ = buffer_.substr(0, buffer_.size() - 1); 112 updated(); 113 } 114 115 void InputBuffer::updated() 116 { 117 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 118 { 119 if ((*it).bListenToAllChanges_) 120 (*(*it).listener_.*(*it).function_)(); 121 } 122 } 123 124 void InputBuffer::updated(const char& update, bool bSingleInput) 125 { 126 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 127 { 128 if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 129 (*(*it).listener_.*(*it).function_)(); 130 } 131 } 132 133 bool InputBuffer::charIsAllowed(const char& input) 134 { 135 if (allowedChars_ == "") 136 return true; 137 else 138 return (allowedChars_.find(input) != std::string::npos); 139 } 140 141 142 void InputBuffer::processKey(const KeyEvent &evt) 143 { 144 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 145 { 146 if (evt.key == KeyCode::V) 147 append(fromClipboard()); 148 else if (evt.key == KeyCode::C) 149 toClipboard(buffer_); 150 else if (evt.key == KeyCode::X) 151 { 152 toClipboard(buffer_); 153 clear(); 154 } 155 } 156 else if (evt.isModifierDown(KeyboardModifier::Shift)) 157 { 158 if (evt.key == KeyCode::Insert) 159 { 160 append(fromClipboard()); 161 } 162 else if (evt.key == KeyCode::Delete) 163 { 164 toClipboard(buffer_); 165 clear(); 166 } 167 } 168 //std::string input = keyboard_->getAsString(e.key); 169 /*if (input.size() >= 1) 170 append(input[0]);*/ 171 172 append((char)evt.text); 173 } 174 175 void InputBuffer::tick(float dt) 176 { 177 timeSinceKeyPressed_ += dt; 178 if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_) 179 { 180 // initial time out has gone by, start repeating keys 181 while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_) 182 { 183 timeSinceKeyRepeated_ += keyRepeatTime_; 184 keysToRepeat_++; 185 } 186 } 187 } 188 189 bool InputBuffer::keyPressed(const KeyEvent &evt) 190 { 191 lastKey_ = evt.key; 192 timeSinceKeyPressed_ = 0.0; 193 timeSinceKeyRepeated_ = keyRepeatDeleay_; 194 keysToRepeat_ = 0; 195 196 processKey(evt); 197 return true; 198 } 199 200 bool InputBuffer::keyHeld(const KeyEvent& evt) 201 { 202 if (evt.key == lastKey_) 203 { 204 while (keysToRepeat_) 205 { 206 processKey(evt); 207 keysToRepeat_--; 208 } 209 } 210 return true; 211 } 212 193 213 } -
code/branches/merge/src/core/InputBuffer.h
r1219 r1272 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 35 35 #include <list> 36 36 37 #include " ois/OISKeyboard.h"38 #include " InputHandler.h"37 #include "InputInterfaces.h" 38 #include "Tickable.h" 39 39 40 40 namespace orxonox 41 41 { 42 43 42 class _CoreExport InputBufferListener 43 {}; 44 44 45 class _CoreExport InputBuffer : public KeyHandler 45 class _CoreExport InputBuffer : public KeyHandler, public TickableReal 46 { 47 struct InputBufferListenerTuple 46 48 { 47 struct InputBufferListenerTuple 48 { 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 char char_; 54 }; 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 char char_; 54 }; 55 55 56 57 InputBuffer();58 InputBuffer(const std::string allowedChars);56 public: 57 InputBuffer(const std::string allowedChars = 58 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^"); 59 59 60 template <class T> 61 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 62 { 63 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 64 this->listeners_.insert(this->listeners_.end(), newListener); 65 } 66 template <class T> 67 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 68 { 69 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 70 this->listeners_.insert(this->listeners_.end(), newListener); 71 } 60 void setConfigValues(); 72 61 73 74 void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput)75 76 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};77 78 79 80 void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput)81 82 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};83 84 62 template <class T> 63 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 64 { 65 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 66 this->listeners_.insert(this->listeners_.end(), newListener); 67 } 68 template <class T> 69 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 70 { 71 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 72 this->listeners_.insert(this->listeners_.end(), newListener); 73 } 85 74 86 void set(const std::string& input); 87 void append(const std::string& input); 88 void append(const char& input); 89 void removeLast(); 90 void clear(); 75 template <class T> 76 void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput) 77 { 78 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_}; 79 this->listeners_.insert(this->listeners_.end(), newListener); 80 } 81 template <class T> 82 void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput) 83 { 84 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_}; 85 this->listeners_.insert(this->listeners_.end(), newListener); 86 } 91 87 92 void updated(); 93 void updated(const char& update, bool bSingleInput); 88 void set(const std::string& input); 89 void append(const std::string& input); 90 void append(const char& input); 91 void removeLast(); 92 void clear(); 94 93 95 inline std::string get() const96 { return this->buffer_; }94 void updated(); 95 void updated(const char& update, bool bSingleInput); 97 96 98 /*inline void activate() 99 { this->setActivated(true); } 100 inline void deactivate() 101 { this->setActivated(false); } 102 inline void setActivated(bool bActivated) 103 { if (this->bActivated_ != bActivated) { this->bActivated_ = bActivated; this->activityChanged(); } else { this->bActivated_ = bActivated; } } 104 inline bool isActivated() const 105 { return this->bActivated_; } 97 inline std::string get() const 98 { return this->buffer_; } 106 99 107 void activityChanged() const;*/ 100 private: // functions 101 bool charIsAllowed(const char& input); 108 102 109 private: 110 bool charIsAllowed(const char& input); 103 bool keyPressed (const KeyEvent& evt); 104 bool keyReleased(const KeyEvent& evt) { return true; } 105 bool keyHeld (const KeyEvent& evt); 106 void processKey (const KeyEvent &e); 111 107 112 bool keyPressed(const OIS::KeyEvent &e); 113 bool keyReleased(const OIS::KeyEvent &e); 114 bool keyHeld(const OIS::KeyEvent &e) { return true; } 108 void tick(float dt); 115 109 116 OIS::Keyboard* keyboard_; 117 //bool bActivated_; 118 std::string buffer_; 119 std::list<InputBufferListenerTuple> listeners_; 120 std::string allowedChars_; 121 }; 110 private: // variables 111 std::string buffer_; 112 std::list<InputBufferListenerTuple> listeners_; 113 std::string allowedChars_; 114 115 KeyCode::Enum lastKey_; 116 float timeSinceKeyPressed_; 117 float timeSinceKeyRepeated_; 118 int keysToRepeat_; 119 120 // configured values 121 float keyRepeatDeleay_; 122 float keyRepeatTime_; 123 }; 122 124 } 123 125 -
code/branches/merge/src/core/InputHandler.cc
r1268 r1272 33 33 34 34 #include "InputHandler.h" 35 #include "util/Convert.h" 35 36 #include "Debug.h" 36 37 #include "ConfigValueIncludes.h" 37 38 #include "CoreIncludes.h" 38 #include "util/Convert.h" 39 #include "core/CommandExecutor.h" 39 #include "CommandExecutor.h" 40 40 41 41 namespace orxonox … … 267 267 switch (j) 268 268 { 269 // note: the first element in the struct is the string, so the following pointer270 // arithmetic works.271 269 case 0: 272 270 cont->getValue(&bindingsKeyPress_[i].commandStr); 273 271 break; 274 272 case 1: 275 cont->getValue( bindingsKeyRelease_ + i);273 cont->getValue(&bindingsKeyRelease_[i].commandStr); 276 274 break; 277 275 case 2: 278 cont->getValue( bindingsKeyHold_ + i);276 cont->getValue(&bindingsKeyHold_[i].commandStr); 279 277 } 280 278 } … … 295 293 { 296 294 case 0: 297 cont->getValue( bindingsMouseButtonPress_ + i);295 cont->getValue(&bindingsMouseButtonPress_[i].commandStr); 298 296 break; 299 297 case 1: 300 cont->getValue( bindingsMouseButtonRelease_ + i);298 cont->getValue(&bindingsMouseButtonRelease_[i].commandStr); 301 299 break; 302 300 case 2: 303 cont->getValue( bindingsMouseButtonHold_ + i);301 cont->getValue(&bindingsMouseButtonHold_[i].commandStr); 304 302 } 305 303 } … … 320 318 { 321 319 case 0: 322 cont->getValue( bindingsJoyStickButtonPress_ + i);320 cont->getValue(&bindingsJoyStickButtonPress_[i].commandStr); 323 321 break; 324 322 case 1: 325 cont->getValue( bindingsJoyStickButtonRelease_ + i);323 cont->getValue(&bindingsJoyStickButtonRelease_[i].commandStr); 326 324 break; 327 325 case 2: 328 cont->getValue( bindingsJoyStickButtonHold_ + i);326 cont->getValue(&bindingsJoyStickButtonHold_[i].commandStr); 329 327 } 330 328 } … … 345 343 for (int i = 0; i < numberOfMouseButtons_s; i++) 346 344 { 347 bindingsMouseButtonPress_ [i] = "";348 bindingsMouseButtonRelease_[i] = "";349 bindingsMouseButtonHold_ [i] = "";345 bindingsMouseButtonPress_ [i].commandStr = ""; 346 bindingsMouseButtonRelease_[i].commandStr = ""; 347 bindingsMouseButtonHold_ [i].commandStr = ""; 350 348 } 351 349 for (int i = 0; i < numberOfJoyStickButtons_s; i++) 352 350 { 353 bindingsJoyStickButtonPress_ [i] = "";354 bindingsJoyStickButtonRelease_[i] = "";355 bindingsJoyStickButtonHold_ [i] = "";351 bindingsJoyStickButtonPress_ [i].commandStr = ""; 352 bindingsJoyStickButtonRelease_[i].commandStr = ""; 353 bindingsJoyStickButtonHold_ [i].commandStr = ""; 356 354 } 357 355 } … … 370 368 // evaluate the key bindings 371 369 // TODO: what if binding is invalid? 372 //for (int i = 0; i < numberOfKeys_s; i++)373 //{374 //if (bindingsKeyPress_[i].commandStr != "")375 //{376 //bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);377 //bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();378 //}379 //}370 for (int i = 0; i < numberOfKeys_s; i++) 371 { 372 if (bindingsKeyPress_[i].commandStr != "") 373 { 374 bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr); 375 bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString(); 376 } 377 } 380 378 381 379 COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl; … … 383 381 } 384 382 385 bool KeyBinder::execute Binding(KeyBinding& binding)383 bool KeyBinder::executeSimpleBinding(KeyBinding& binding) 386 384 { 387 385 if (binding.commandStr != "") 388 386 { 389 //if (binding.commandStr != binding.evaluation.getCommandString())390 //{391 //// key binding has changed, reevaluate the command string.392 //binding.evaluation = CommandExecutor::evaluate(binding.commandStr);393 //binding.commandStr = binding.evaluation.getCommandString();394 //}387 if (binding.commandStr != binding.evaluation.getCommandString()) 388 { 389 // key binding has changed, reevaluate the command string. 390 binding.evaluation = CommandExecutor::evaluate(binding.commandStr); 391 binding.commandStr = binding.evaluation.getCommandString(); 392 } 395 393 COUT(ORX_DEBUG) << "Keybinding: Executing command: " << binding.commandStr << std::endl; 396 394 CommandExecutor::execute(binding.commandStr); … … 405 403 @param e Event information 406 404 */ 407 bool KeyBinder::keyPressed(const OIS::KeyEvent &e) 408 { 409 //COUT(ORX_DEBUG) << "Key: " << e.key << std::endl; 410 // find the appropriate key binding 411 executeBinding(bindingsKeyPress_[int(e.key)]); 412 405 bool KeyBinder::keyPressed(const KeyEvent& evt) 406 { 407 // find the appropriate key binding 408 executeSimpleBinding(bindingsKeyPress_[int(evt.key)]); 409 413 410 return true; 414 411 } … … 418 415 @param e Event information 419 416 */ 420 bool KeyBinder::keyReleased(const OIS::KeyEvent &e)421 { 422 // find the appropriate key binding 423 execute Binding(bindingsKeyRelease_[int(e.key)]);417 bool KeyBinder::keyReleased(const KeyEvent& evt) 418 { 419 // find the appropriate key binding 420 executeSimpleBinding(bindingsKeyRelease_[int(evt.key)]); 424 421 425 422 return true; … … 428 425 /** 429 426 @brief Event handler for the keyHeld Event. 430 @param e Eventinformation431 */ 432 bool KeyBinder::keyHeld(const OIS::KeyEvent &e)433 { 434 // find the appropriate key binding 435 execute Binding(bindingsKeyHold_[int(e.key)]);427 @param e Mouse state information 428 */ 429 bool KeyBinder::keyHeld(const KeyEvent& evt) 430 { 431 // find the appropriate key binding 432 executeSimpleBinding(bindingsKeyHold_[int(evt.key)]); 436 433 437 434 return true; … … 440 437 /** 441 438 @brief Event handler for the mouseMoved Event. 442 @param e Event information 443 */ 444 bool KeyBinder::mouseMoved(const OIS::MouseEvent &e) 439 @param e Mouse state information 440 */ 441 bool KeyBinder::mouseMoved(const MouseState &evt) 442 { 443 /*if (bindingMouseMoved_.commandStr != "") 444 { 445 if (bindingMouseMoved_.commandStr != bindingMouseMoved_.evaluation.getCommandString()) 446 { 447 // key binding has changed, reevaluate the command string. 448 bindingMouseMoved_.evaluation = CommandExecutor::evaluate(bindingMouseMoved_.commandStr); 449 bindingMouseMoved_.commandStr = bindingMouseMoved_.evaluation.getCommandString(); 450 } 451 COUT(3) << "Executing command: " << bindingMouseMoved_.commandStr << std::endl; 452 453 bindingMouseMoved_.evaluation.setEvaluatedParameter( 454 CommandExecutor::execute(bindingMouseMoved_.commandStr); 455 }*/ 456 457 return true; 458 } 459 460 /** 461 @brief Event handler for the mouseScrolled Event. 462 @param e Mouse state information 463 */ 464 bool KeyBinder::mouseScrolled(const MouseState &evt) 445 465 { 446 466 return true; … … 452 472 @param id The ID of the mouse button 453 473 */ 454 bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 455 { 456 // find the appropriate key binding 457 std::string cmdStr = bindingsMouseButtonPress_[int(id)]; 458 if (cmdStr != "") 459 { 460 CommandExecutor::execute(cmdStr); 461 //COUT(3) << "Executing command: " << cmdStr << std::endl; 462 } 474 bool KeyBinder::mouseButtonPressed(const MouseState& state, MouseButton::Enum id) 475 { 476 // find the appropriate key binding 477 executeSimpleBinding(bindingsMouseButtonPress_[int(id)]); 463 478 464 479 return true; … … 470 485 @param id The ID of the mouse button 471 486 */ 472 bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 473 { 474 // find the appropriate key binding 475 std::string cmdStr = bindingsMouseButtonRelease_[int(id)]; 476 if (cmdStr != "") 477 { 478 CommandExecutor::execute(cmdStr); 479 //COUT(3) << "Executing command: " << cmdStr << std::endl; 480 } 487 bool KeyBinder::mouseButtonReleased(const MouseState& state, MouseButton::Enum id) 488 { 489 // find the appropriate key binding 490 executeSimpleBinding(bindingsMouseButtonRelease_[int(id)]); 481 491 482 492 return true; … … 488 498 @param id The ID of the mouse button 489 499 */ 490 bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) 491 { 492 // find the appropriate key binding 493 std::string cmdStr = bindingsMouseButtonHold_[int(id)]; 494 if (cmdStr != "") 495 { 496 CommandExecutor::execute(cmdStr); 497 //COUT(3) << "Executing command: " << cmdStr << std::endl; 498 } 499 500 return true; 501 } 502 503 bool KeyBinder::buttonPressed(int joyStickID, const OIS::JoyStickEvent &arg, int button) 504 { 505 // find the appropriate key binding 506 std::string cmdStr = bindingsJoyStickButtonPress_[button]; 507 if (cmdStr != "") 508 { 509 CommandExecutor::execute(cmdStr); 510 //COUT(3) << "Executing command: " << cmdStr << std::endl; 511 } 512 513 return true; 514 } 515 516 bool KeyBinder::buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) 517 { 518 // find the appropriate key binding 519 std::string cmdStr = bindingsJoyStickButtonRelease_[button]; 520 if (cmdStr != "") 521 { 522 CommandExecutor::execute(cmdStr); 523 //COUT(3) << "Executing command: " << cmdStr << std::endl; 524 } 525 526 return true; 527 } 528 529 bool KeyBinder::buttonHeld(int joyStickID, const OIS::JoyStickEvent &arg, int button) 530 { 531 // find the appropriate key binding 532 std::string cmdStr = bindingsJoyStickButtonHold_[button]; 533 if (cmdStr != "") 534 { 535 CommandExecutor::execute(cmdStr); 536 //COUT(3) << "Executing command: " << cmdStr << std::endl; 537 } 538 539 return true; 540 } 541 542 bool KeyBinder::axisMoved(int joyStickID, const OIS::JoyStickEvent &arg, int axis) 543 { 544 return true; 545 } 546 547 bool KeyBinder::sliderMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 548 { 549 return true; 550 } 551 552 bool KeyBinder::povMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 553 { 554 return true; 555 } 556 557 bool KeyBinder::vector3Moved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 500 bool KeyBinder::mouseButtonHeld(const MouseState& state, MouseButton::Enum id) 501 { 502 // find the appropriate key binding 503 executeSimpleBinding(bindingsMouseButtonHold_[int(id)]); 504 505 return true; 506 } 507 508 bool KeyBinder::joyStickButtonPressed(const JoyStickState& state, int button) 509 { 510 // find the appropriate key binding 511 executeSimpleBinding(bindingsJoyStickButtonPress_[button]); 512 513 return true; 514 } 515 516 bool KeyBinder::joyStickButtonReleased(const JoyStickState& state, int button) 517 { 518 // find the appropriate key binding 519 executeSimpleBinding(bindingsJoyStickButtonRelease_[button]); 520 521 return true; 522 } 523 524 bool KeyBinder::joyStickButtonHeld(const JoyStickState& state, int button) 525 { 526 // find the appropriate key binding 527 executeSimpleBinding(bindingsJoyStickButtonHold_[button]); 528 529 return true; 530 } 531 532 bool KeyBinder::joyStickAxisMoved(const JoyStickState& state, int axis) 533 { 534 return true; 535 } 536 537 bool KeyBinder::joyStickSliderMoved(const JoyStickState& state, int index) 538 { 539 return true; 540 } 541 542 bool KeyBinder::joyStickPovMoved(const JoyStickState& state, int index) 543 { 544 return true; 545 } 546 547 bool KeyBinder::joyStickVector3Moved(const JoyStickState& state, int index) 558 548 { 559 549 return true; … … 616 606 // @param id The ID of the mouse button 617 607 //*/ 618 //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton IDid)608 //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton id) 619 609 //{ 620 610 ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); … … 627 617 // @param id The ID of the mouse button 628 618 //*/ 629 //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton IDid)619 //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton id) 630 620 //{ 631 621 ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); -
code/branches/merge/src/core/InputHandler.h
r1219 r1272 38 38 39 39 #include <string> 40 40 41 #include "ois/OIS.h" 41 42 #include "OrxonoxClass.h" 42 43 #include "CommandExecutor.h" 44 #include "InputInterfaces.h" 43 45 44 46 namespace orxonox … … 54 56 }; 55 57 } 56 57 /**58 @brief Interface class used for key input listeners.59 */60 class _CoreExport KeyHandler : public OIS::KeyListener61 {62 public:63 virtual ~KeyHandler() { }64 virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;65 };66 67 /**68 @brief Interface class used for mouse input listeners.69 */70 class _CoreExport MouseHandler : public OIS::MouseListener71 {72 public:73 virtual ~MouseHandler() { }74 virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;75 };76 77 /**78 @brief Interface class used for joy stick input listeners.79 */80 class _CoreExport JoyStickHandler81 {82 public:83 virtual ~JoyStickHandler() { }84 virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;85 virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;86 virtual bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;87 virtual bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis) = 0;88 virtual bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}89 virtual bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}90 virtual bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}91 };92 58 93 59 struct _CoreExport KeyBinding … … 113 79 void setConfigValues(); 114 80 115 std::string testtest;116 117 81 private: // functions 118 82 119 bool execute Binding(KeyBinding &binding);83 bool executeSimpleBinding(KeyBinding &binding); 120 84 121 bool keyPressed (const OIS::KeyEvent &arg);122 bool keyReleased (const OIS::KeyEvent &arg);123 bool keyHeld (const OIS::KeyEvent &arg);85 bool keyPressed (const KeyEvent& evt); 86 bool keyReleased(const KeyEvent& evt); 87 bool keyHeld (const KeyEvent& evt); 124 88 125 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 126 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); 127 bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 128 bool mouseMoved (const OIS::MouseEvent &arg); 89 bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id); 90 bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id); 91 bool mouseButtonHeld (const MouseState& state, MouseButton::Enum id); 92 bool mouseMoved (const MouseState& state); 93 bool mouseScrolled (const MouseState& state); 129 94 130 bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button);131 bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button);132 bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button);133 bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis);134 bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id);135 bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id);136 bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int id);95 bool joyStickButtonPressed (const JoyStickState& state, int button); 96 bool joyStickButtonReleased(const JoyStickState& state, int button); 97 bool joyStickButtonHeld (const JoyStickState& state, int button); 98 bool joyStickAxisMoved (const JoyStickState& state, int axis) ; 99 bool joyStickSliderMoved (const JoyStickState& state, int index) ; 100 bool joyStickPovMoved (const JoyStickState& state, int index) ; 101 bool joyStickVector3Moved (const JoyStickState& state, int index) ; 137 102 138 103 private: // variables … … 152 117 static const int numberOfMouseButtons_s = 8; 153 118 //! Array of input events for every pressed mouse button 154 std::string bindingsMouseButtonPress_ [numberOfMouseButtons_s];119 KeyBinding bindingsMouseButtonPress_ [numberOfMouseButtons_s]; 155 120 //! Array of input events for every released mouse button 156 std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];121 KeyBinding bindingsMouseButtonRelease_[numberOfMouseButtons_s]; 157 122 //! Array of input events for every held mouse button 158 std::string bindingsMouseButtonHold_ [numberOfMouseButtons_s]; 123 KeyBinding bindingsMouseButtonHold_ [numberOfMouseButtons_s]; 124 //! Key binding for mouse moved event 125 KeyBinding bindingMouseMoved_; 126 //! Key binding for mouse scrolled event 127 KeyBinding bindingMouseScrolled_; 159 128 //! Names of the mouse buttons as strings 160 129 std::string mouseButtonNames_[numberOfMouseButtons_s]; … … 163 132 static const int numberOfJoyStickButtons_s = 32; 164 133 //! Array of input events for every pressed joy stick button 165 std::string bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s];134 KeyBinding bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; 166 135 //! Array of input events for every released joy stick button 167 std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];136 KeyBinding bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; 168 137 //! Array of input events for every held joy stick button 169 std::string bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s];138 KeyBinding bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; 170 139 //! Names of the joy stick buttons as strings 171 140 std::string joyStickButtonNames_[numberOfJoyStickButtons_s]; … … 186 155 //private: 187 156 // // input events 188 189 190 157 //bool keyPressed (const OIS::KeyEvent &arg); 158 //bool keyReleased (const OIS::KeyEvent &arg); 159 //bool keyHeld (const OIS::KeyEvent &arg); 191 160 192 // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButton IDid);193 //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonIDid);194 //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonIDid);161 // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButton id); 162 //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButton id); 163 //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButton id); 195 164 // bool mouseMoved (const OIS::MouseEvent &arg); 196 165 197 198 199 200 201 202 166 //bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 167 //bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 168 //bool buttonHeld (const OIS::JoyStickEvent &arg, int button); 169 //bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 170 //bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 171 //bool povMoved (const OIS::JoyStickEvent &arg, int id); 203 172 //}; 204 173 -
code/branches/merge/src/core/InputManager.cc
r1268 r1272 30 30 @file 31 31 @brief Implementation of the InputManager that captures all the input from OIS 32 and redirects it to handlers if necessary.32 and redirects it to handlers. 33 33 */ 34 34 … … 52 52 InputManager::InputManager() : 53 53 inputSystem_(0), keyboard_(0), mouse_(0), 54 state_(IS_UNINIT), stateRequest_(IS_UNINIT) 54 joySticksSize_(0), 55 state_(IS_UNINIT), stateRequest_(IS_UNINIT), 56 keyboardModifiers_(0) 55 57 { 56 58 RegisterObject(InputManager); 57 58 this->joySticks_.reserve(5);59 //this->activeJoyStickHandlers_.reserve(10);60 this->activeKeyHandlers_.reserve(10);61 this->activeMouseHandlers_.reserve(10);62 59 } 63 60 … … 87 84 @param windowHeight The height of the render window 88 85 */ 89 bool InputManager::_initialise(const size_t windowHnd, const int windowWidth, constint windowHeight,90 const bool createKeyboard, const bool createMouse, constbool createJoySticks)86 bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight, 87 bool createKeyboard, bool createMouse, bool createJoySticks) 91 88 { 92 89 if (state_ == IS_UNINIT) … … 146 143 addKeyHandler(binder, "keybinder"); 147 144 addMouseHandler(binder, "keybinder"); 145 addJoyStickHandler(binder, "keybinder"); 148 146 149 147 // Read all the key bindings and assign them … … 235 233 bool InputManager::_initialiseJoySticks() 236 234 { 237 if (joySticks _.size()> 0)235 if (joySticksSize_ > 0) 238 236 { 239 237 CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; … … 266 264 return false; 267 265 } 266 joySticksSize_ = joySticks_.size(); 267 activeJoyStickHandlers_.resize(joySticksSize_); 268 joyStickButtonsDown_.resize(joySticksSize_); 268 269 return success; 269 270 } … … 337 338 void InputManager::_destroyJoySticks() 338 339 { 339 if (joySticks _.size()> 0)340 if (joySticksSize_ > 0) 340 341 { 341 342 // note: inputSystem_ can never be 0, or else the code is mistaken 342 for (unsigned int i = 0; i < joySticks _.size(); i++)343 for (unsigned int i = 0; i < joySticksSize_; i++) 343 344 if (joySticks_[i] != 0) 344 345 inputSystem_->destroyInputObject(joySticks_[i]); 345 346 346 347 joySticks_.clear(); 348 joySticksSize_ = 0; 347 349 activeJoyStickHandlers_.clear(); 348 350 joyStickButtonsDown_.clear(); … … 373 375 activeKeyHandlers_.clear(); 374 376 activeMouseHandlers_.clear(); 375 activeJoyStickHandlers_.clear(); 377 for (unsigned int i = 0; i < joySticksSize_; i++) 378 activeJoyStickHandlers_[i].clear(); 376 379 377 380 switch (stateRequest_) … … 383 386 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 384 387 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 385 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 386 it != joySticks_.end(); it++) 387 activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]); 388 for (unsigned int i = 0; i < joySticksSize_; i++) 389 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 388 390 break; 389 391 … … 394 396 case IS_CONSOLE: 395 397 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 396 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();397 it != joySticks_.end(); it++)398 activeJoyStickHandlers_[ *it].push_back(joyStickHandlers_["keybinder"]);398 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 399 for (unsigned int i = 0; i < joySticksSize_; i++) 400 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 399 401 400 402 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); … … 413 415 if (keyboard_) 414 416 keyboard_->capture(); 417 for (unsigned int i = 0; i < joySticksSize_; i++) 418 joySticks_[i]->capture(); 415 419 416 420 417 421 // call all the handlers for the held key events 418 for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin(); 419 itKey != keysDown_.end(); itKey++) 420 { 421 OIS::KeyEvent keyArg(keyboard_, *itKey, 0); 422 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 423 activeKeyHandlers_[i]->keyHeld(keyArg); 424 } 422 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 423 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 424 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 425 425 426 426 // call all the handlers for the held mouse button events 427 for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin(); 428 itMouseButton != mouseButtonsDown_.end(); itMouseButton++) 429 { 430 OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState()); 431 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 432 activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton); 433 } 427 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 428 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 429 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]); 434 430 435 431 // call all the handlers for the held joy stick button events 436 for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin(); 437 itJoyStick != joyStickButtonsDown_.end(); itJoyStick++) 438 { 439 OIS::JoyStick* joyStick = (*itJoyStick).first; 440 for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin(); 441 itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++) 442 { 443 OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState()); 444 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 445 activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton); 446 } 447 } 448 } 449 432 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 433 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_[iJoyStick].size(); iButton++) 434 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 435 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 436 JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]); 437 } 450 438 451 439 // ###### Key Events ###### … … 458 446 { 459 447 // check whether the key already is in the list (can happen when focus was lost) 460 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 461 { 462 if (*it == e.key) 463 { 464 keysDown_.erase(it); 465 break; 466 } 467 } 468 keysDown_.push_back(e.key); 448 unsigned int iKey = 0; 449 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key) 450 iKey++; 451 if (iKey == keysDown_.size()) 452 keysDown_.push_back(Key(e)); 453 454 // update modifiers 455 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 456 keyboardModifiers_ |= KeyboardModifier::Alt; // alt key 457 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 458 keyboardModifiers_ |= KeyboardModifier::Ctrl; // ctrl key 459 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 460 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 469 461 470 462 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 471 activeKeyHandlers_[i]->keyPressed( e);463 activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_)); 472 464 473 465 return true; … … 481 473 { 482 474 // remove the key from the keysDown_ list 483 for ( std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)484 { 485 if ( *it ==e.key)486 { 487 keysDown_.erase( it);475 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 476 { 477 if (keysDown_[iKey].key == (KeyCode::Enum)e.key) 478 { 479 keysDown_.erase(keysDown_.begin() + iKey); 488 480 break; 489 481 } 490 482 } 491 483 484 // update modifiers 485 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 486 keyboardModifiers_ &= ~KeyboardModifier::Alt; // alt key 487 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 488 keyboardModifiers_ &= ~KeyboardModifier::Ctrl; // ctrl key 489 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 490 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 491 492 492 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 493 activeKeyHandlers_[i]->keyReleased( e);493 activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_)); 494 494 495 495 return true; … … 505 505 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 506 506 { 507 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 508 activeMouseHandlers_[i]->mouseMoved(e); 507 // check for actual moved event 508 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 509 { 510 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 511 activeMouseHandlers_[i]->mouseMoved(e.state); 512 } 513 514 // check for mouse scrolled event 515 if (e.state.Z.rel != 0) 516 { 517 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 518 activeMouseHandlers_[i]->mouseScrolled(e.state); 519 } 509 520 510 521 return true; … … 519 530 { 520 531 // check whether the button already is in the list (can happen when focus was lost) 521 for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++) 522 { 523 if (*it == id) 524 { 525 mouseButtonsDown_.erase(it); 526 break; 527 } 528 } 529 mouseButtonsDown_.push_back(id); 532 unsigned int iButton = 0; 533 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id) 534 iButton++; 535 if (iButton == mouseButtonsDown_.size()) 536 mouseButtonsDown_.push_back((MouseButton::Enum)id); 530 537 531 538 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 532 activeMouseHandlers_[i]->mouse Pressed(e,id);539 activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id); 533 540 534 541 return true; … … 543 550 { 544 551 // remove the button from the keysDown_ list 545 for ( std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)546 { 547 if ( *it ==id)548 { 549 mouseButtonsDown_.erase( it);552 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 553 { 554 if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id) 555 { 556 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); 550 557 break; 551 558 } … … 553 560 554 561 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 555 activeMouseHandlers_[i]->mouse Released(e,id);562 activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id); 556 563 557 564 return true; … … 563 570 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 564 571 { 572 // use the device to identify which one called the method 565 573 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 574 unsigned int iJoyStick = 0; 575 while (joySticks_[iJoyStick] != joyStick) 576 iJoyStick++; 566 577 567 578 // check whether the button already is in the list (can happen when focus was lost) 568 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 569 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 570 { 571 if (*it == button) 572 { 573 buttonsDownList.erase(it); 579 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick]; 580 unsigned int iButton = 0; 581 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 582 iButton++; 583 if (iButton == buttonsDown.size()) 584 buttonsDown.push_back(button); 585 586 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 587 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button); 588 589 return true; 590 } 591 592 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 593 { 594 // use the device to identify which one called the method 595 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 596 unsigned int iJoyStick = 0; 597 while (joySticks_[iJoyStick] != joyStick) 598 iJoyStick++; 599 600 // remove the button from the joyStickButtonsDown_ list 601 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick]; 602 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 603 { 604 if (buttonsDown[iButton] == button) 605 { 606 buttonsDown.erase(buttonsDown.begin() + iButton); 574 607 break; 575 608 } 576 609 } 577 joyStickButtonsDown_[joyStick].push_back(button); 578 579 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)580 activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button); 581 582 return true;583 } 584 585 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)586 {610 611 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 612 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button); 613 614 return true; 615 } 616 617 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 618 { 619 // use the device to identify which one called the method 587 620 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 588 589 // remove the button from the joyStickButtonsDown_ list 590 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 591 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 592 { 593 if (*it == button) 594 { 595 buttonsDownList.erase(it); 596 break; 597 } 598 } 599 600 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 601 activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button); 602 603 return true; 604 } 605 606 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 607 { 621 unsigned int iJoyStick = 0; 622 while (joySticks_[iJoyStick] != joyStick) 623 iJoyStick++; 624 625 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 626 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis); 627 628 return true; 629 } 630 631 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 632 { 633 // use the device to identify which one called the method 608 634 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 609 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 610 activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis); 611 612 return true; 613 } 614 615 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 616 { 635 unsigned int iJoyStick = 0; 636 while (joySticks_[iJoyStick] != joyStick) 637 iJoyStick++; 638 639 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 640 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id); 641 642 return true; 643 } 644 645 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 646 { 647 // use the device to identify which one called the method 617 648 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 618 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 619 activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id); 620 621 return true; 622 } 623 624 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 625 { 649 unsigned int iJoyStick = 0; 650 while (joySticks_[iJoyStick] != joyStick) 651 iJoyStick++; 652 653 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 654 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id); 655 656 return true; 657 } 658 659 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 660 { 661 // use the device to identify which one called the method 626 662 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 627 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 628 activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id); 629 630 return true; 631 } 632 633 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 634 { 635 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 636 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 637 activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id); 663 unsigned int iJoyStick = 0; 664 while (joySticks_[iJoyStick] != joyStick) 665 iJoyStick++; 666 667 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 668 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id); 638 669 639 670 return true; … … 646 677 // ################################ 647 678 648 bool InputManager::initialise(const size_t windowHnd, const int windowWidth, constint windowHeight,649 const bool createKeyboard, const bool createMouse, constbool createJoySticks)679 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, 680 bool createKeyboard, bool createMouse, bool createJoySticks) 650 681 { 651 682 return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight, … … 686 717 int InputManager::numberOfJoySticks() 687 718 { 688 return _getSingleton().joySticks_.size(); 719 return _getSingleton().joySticksSize_; 720 } 721 722 bool InputManager::isKeyDown(KeyCode::Enum key) 723 { 724 if (_getSingleton().keyboard_) 725 return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key); 726 else 727 return false; 728 } 729 730 bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 731 { 732 if (_getSingleton().keyboard_) 733 return isModifierDown(modifier); 734 else 735 return false; 736 } 737 738 const MouseState InputManager::getMouseState() 739 { 740 if (_getSingleton().mouse_) 741 return _getSingleton().mouse_->getMouseState(); 742 else 743 return MouseState(); 744 } 745 746 const JoyStickState InputManager::getJoyStickState(unsigned int ID) 747 { 748 if (ID < _getSingleton().joySticksSize_) 749 return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID); 750 else 751 return JoyStickState(); 689 752 } 690 753 … … 1062 1125 @return False if name or id was not found, true otherwise. 1063 1126 */ 1064 bool InputManager::enableJoyStickHandler(const std::string& name, constint ID)1127 bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID) 1065 1128 { 1066 1129 // get handler pointer from the map with all stored handlers … … 1070 1133 1071 1134 // check for existence of the ID 1072 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1073 return false; 1074 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1135 if (ID >= _getSingleton().joySticksSize_) 1136 return false; 1075 1137 1076 1138 // see whether the handler already is in the list 1077 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1078 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1139 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1140 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1079 1141 { 1080 1142 if ((*it) == (*handlerIt).second) … … 1084 1146 } 1085 1147 } 1086 _getSingleton().activeJoyStickHandlers_[ joyStick].push_back((*handlerIt).second);1148 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); 1087 1149 _getSingleton().stateRequest_ = IS_CUSTOM; 1088 1150 return true; … … 1094 1156 @return False if name or id was not found, true otherwise. 1095 1157 */ 1096 bool InputManager::disableJoyStickHandler(const std::string &name, int ID)1158 bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID) 1097 1159 { 1098 1160 // get handler pointer from the map with all stored handlers … … 1102 1164 1103 1165 // check for existence of the ID 1104 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1105 return false; 1106 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1166 if (ID >= _getSingleton().joySticksSize_) 1167 return false; 1107 1168 1108 1169 // look for the handler in the list 1109 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1110 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1170 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1171 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1111 1172 { 1112 1173 if ((*it) == (*handlerIt).second) 1113 1174 { 1114 _getSingleton().activeJoyStickHandlers_[ joyStick].erase(it);1175 _getSingleton().activeJoyStickHandlers_[ID].erase(it); 1115 1176 _getSingleton().stateRequest_ = IS_CUSTOM; 1116 1177 return true; … … 1125 1186 @return False if key handler is not active or doesn't exist, true otherwise. 1126 1187 */ 1127 bool InputManager::isJoyStickHandlerActive(const std::string& name, constint ID)1188 bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID) 1128 1189 { 1129 1190 // get handler pointer from the map with all stored handlers … … 1133 1194 1134 1195 // check for existence of the ID 1135 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1136 return false; 1137 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1196 if (ID >= _getSingleton().joySticksSize_) 1197 return false; 1138 1198 1139 1199 // see whether the handler already is in the list 1140 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1141 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1200 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1201 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1142 1202 { 1143 1203 if ((*it) == (*handlerIt).second) -
code/branches/merge/src/core/InputManager.h
r1219 r1272 39 39 40 40 #include <map> 41 #include < list>41 #include <vector> 42 42 43 43 #include "ois/OIS.h" 44 44 #include "Tickable.h" 45 #include "InputInterfaces.h" 45 46 46 47 namespace orxonox 47 48 { 48 class Mouse : public OIS::Mouse49 {50 };51 52 49 /** 53 50 @brief Captures and distributes mouse and keyboard input. 54 51 */ 55 52 class _CoreExport InputManager 56 : public Tickable ,53 : public TickableReal, 57 54 public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener 58 55 { … … 72 69 73 70 public: // static functions 74 static bool initialise(const size_t windowHnd, const int windowWidth, constint windowHeight,75 const bool createKeyboard = true, const bool createMouse = true, constbool createJoySticks = false);71 static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight, 72 bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false); 76 73 static bool initialiseKeyboard(); 77 74 static bool initialiseMouse(); … … 85 82 static void destroyMouse(); 86 83 static void destroyJoySticks(); 84 85 static bool isModifierDown(KeyboardModifier::Enum modifier); 86 static bool isKeyDown(KeyCode::Enum key); 87 static const MouseState getMouseState(); 88 static const JoyStickState getJoyStickState(unsigned int ID); 87 89 88 90 static void setWindowExtents(const int width, const int height); … … 108 110 static bool removeJoyStickHandler (const std::string& name); 109 111 static JoyStickHandler* getJoyStickHandler(const std::string& name); 110 static bool enableJoyStickHandler (const std::string& name, const int id); 111 static bool disableJoyStickHandler (const std::string& name, const int id); 112 static bool isJoyStickHandlerActive (const std::string& name, const int id); 113 114 // Temporary solutions. Will be removed soon! 115 static OIS::Mouse* getMouse() { return _getSingleton().mouse_ ; } 116 static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; } 112 static bool enableJoyStickHandler (const std::string& name, unsigned int id); 113 static bool disableJoyStickHandler (const std::string& name, unsigned int id); 114 static bool isJoyStickHandlerActive (const std::string& name, unsigned int id); 117 115 118 116 private: // functions … … 123 121 124 122 // Intenal methods 125 bool _initialise(const size_t, const int, const int, const bool, const bool, constbool);123 bool _initialise(const size_t, int, int, bool, bool, bool); 126 124 bool _initialiseKeyboard(); 127 125 bool _initialiseMouse(); … … 133 131 void _destroyJoySticks(); 134 132 135 //void _setNumberOfJoysticks(int size);136 137 133 void tick(float dt); 138 134 139 135 // input events 140 141 136 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 137 bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 142 138 bool mouseMoved (const OIS::MouseEvent &arg); 143 144 145 146 147 148 149 150 139 bool keyPressed (const OIS::KeyEvent &arg); 140 bool keyReleased (const OIS::KeyEvent &arg); 141 bool buttonPressed (const OIS::JoyStickEvent &arg, int button); 142 bool buttonReleased(const OIS::JoyStickEvent &arg, int button); 143 bool axisMoved (const OIS::JoyStickEvent &arg, int axis); 144 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 145 bool povMoved (const OIS::JoyStickEvent &arg, int id); 146 bool vector3Moved (const OIS::JoyStickEvent &arg, int id); 151 147 152 148 static InputManager& _getSingleton(); … … 158 154 OIS::Mouse* mouse_; //!< OIS keyboard 159 155 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 156 unsigned int joySticksSize_; 160 157 161 158 InputState state_; 162 159 InputState stateRequest_; 160 unsigned int keyboardModifiers_; 163 161 164 162 std::map<std::string, KeyHandler*> keyHandlers_; … … 168 166 std::vector<KeyHandler*> activeKeyHandlers_; 169 167 std::vector<MouseHandler*> activeMouseHandlers_; 170 std:: map< OIS::JoyStick*,std::vector<JoyStickHandler*> > activeJoyStickHandlers_;168 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 171 169 172 std:: list<OIS::KeyCode>keysDown_;173 std:: list<OIS::MouseButtonID>mouseButtonsDown_;174 std:: map< OIS::JoyStick*, std::list<int> >joyStickButtonsDown_;170 std::vector<Key> keysDown_; 171 std::vector<MouseButton::Enum> mouseButtonsDown_; 172 std::vector<std::vector<int> > joyStickButtonsDown_; 175 173 176 174 }; 175 177 176 } 178 177 -
code/branches/merge/src/core/SignalHandler.cc
r1062 r1272 35 35 36 36 #include <assert.h> 37 #include <iostream> 37 38 38 39 #include "Debug.h" … … 43 44 44 45 #include <wait.h> 46 #include <X11/Xlib.h> 47 #include <X11/Xutil.h> 48 #include <X11/keysym.h> 49 50 bool SignalHandler::bXAutoKeyRepeatOn_ = false; 45 51 46 52 SignalHandler::SignalHandler() … … 58 64 this->fileName = fileName; 59 65 66 // prepare for restoring XAutoKeyRepeat 67 Display* display; 68 if ((display = XOpenDisplay(0))) 69 { 70 XKeyboardState oldState; 71 XGetKeyboardControl(display, &oldState); 72 if (oldState.global_auto_repeat == AutoRepeatModeOn) 73 bXAutoKeyRepeatOn_ = true; 74 else 75 bXAutoKeyRepeatOn_ = false; 76 XCloseDisplay(display); 77 } 78 else 79 { 80 std::cout << "Warning: couldn't open X display to restore XAutoKeyRepeat." << std::endl; 81 bXAutoKeyRepeatOn_ = false; 82 } 83 84 60 85 // make sure doCatch is only called once without calling dontCatch 61 86 assert( sigRecList.size() == 0 ); … … 120 145 sigName = "SIGILL"; 121 146 break; 147 } 148 149 if (bXAutoKeyRepeatOn_) 150 { 151 std::cout << "Trying to restore XAutoKeyRepeat" << std::endl; 152 Display* display; 153 if ((display = XOpenDisplay(0))) 154 { 155 XAutoRepeatOn(display); 156 XCloseDisplay(display); 157 } 122 158 } 123 159 -
code/branches/merge/src/core/SignalHandler.h
r1062 r1272 86 86 std::string appName; 87 87 std::string fileName; 88 89 // used to turn on KeyAutoRepeat if OIS crashes 90 static bool bXAutoKeyRepeatOn_; 88 91 }; 89 92 -
code/branches/merge/src/core/Tickable.cc
r1062 r1272 40 40 RegisterRootObject(Tickable); 41 41 } 42 43 /** 44 @brief Constructor: Registers the object in the TickableReal-list 45 */ 46 TickableReal::TickableReal() 47 { 48 RegisterRootObject(TickableReal); 49 } 42 50 } -
code/branches/merge/src/core/Tickable.h
r1062 r1272 62 62 }; 63 63 64 //! The Tickable interface provides a tick(dt) function, that gets called every frame. 65 class _CoreExport TickableReal : virtual public OrxonoxClass 66 { 67 public: 68 /** 69 @brief Gets called every frame. 70 @param dt The time since the last frame in seconds 71 */ 72 virtual void tick(float dt) = 0; 73 74 protected: 75 TickableReal(); 76 }; 77 64 78 } 65 79 -
code/branches/merge/src/orxonox/Orxonox.cc
r1268 r1272 290 290 // The render window width and height are used to set up the mouse movement. 291 291 if (!InputManager::initialise(ogre_->getWindowHandle(), 292 ogre_->getWindowWidth(), ogre_->getWindowHeight() ))292 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) 293 293 return false; 294 294 … … 495 495 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 496 496 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 497 orxonoxConsole_->tick((float)evt.timeSinceLastFrame * this->timefactor_); 497 // Iterate through all TickableReals and call their tick(dt) function 498 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 499 it->tick((float)evt.timeSinceLastFrame); 500 orxonoxConsole_->tick((float)evt.timeSinceLastFrame); 498 501 499 502 // don't forget to call _fireFrameStarted in ogre to make sure -
code/branches/merge/src/orxonox/objects/SpaceShip.cc
r1265 r1272 142 142 void SpaceShip::init() 143 143 { 144 145 146 147 148 149 150 151 144 if ((!network::Client::getSingleton() || network::Client::getSingleton()->getShipID()==objectID )) 145 { 146 if (!setMouseEventCallback_) 147 { 148 InputManager::addMouseHandler(this, "SpaceShip"); 149 setMouseEventCallback_ = true; 150 } 151 } 152 152 153 153 // START CREATING THRUSTER … … 233 233 234 234 COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl; 235 235 } 236 236 */ 237 237 if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp")) … … 259 259 260 260 COUT(4) << "Loader: Initialized SpaceShip" << std::endl; 261 262 263 264 265 266 261 } 262 263 if (xmlElem->Attribute("camera")) 264 { 265 this->setCamera(); 266 } 267 267 } 268 268 … … 349 349 } 350 350 351 bool SpaceShip::mouseMoved(const OIS::MouseEvent &e)351 bool SpaceShip::mouseMoved(const MouseState& state) 352 352 { 353 353 /* … … 366 366 if (this->bRMousePressed_) 367 367 { 368 this->camNode_->roll(Degree(- e.state.X.rel * 0.10));369 this->camNode_->yaw(Degree( e.state.Y.rel * 0.10));370 } 371 else 372 { 373 float minDimension = e.state.height;374 if ( e.state.width < minDimension)375 minDimension = e.state.width;376 377 this->mouseX_ += e.state.X.rel;368 this->camNode_->roll(Degree(-state.X.rel * 0.10)); 369 this->camNode_->yaw(Degree(state.Y.rel * 0.10)); 370 } 371 else 372 { 373 float minDimension = state.height; 374 if (state.width < minDimension) 375 minDimension = state.width; 376 377 this->mouseX_ += state.X.rel; 378 378 if (this->mouseX_ < -minDimension) 379 379 this->mouseX_ = -minDimension; … … 381 381 this->mouseX_ = minDimension; 382 382 383 this->mouseY_ += e.state.Y.rel;383 this->mouseY_ += state.Y.rel; 384 384 if (this->mouseY_ < -minDimension) 385 385 this->mouseY_ = -minDimension; … … 409 409 } 410 410 411 bool SpaceShip::mouse Pressed(const OIS::MouseEvent &e, OIS::MouseButtonIDid)412 { 413 if (id == OIS::MB_Left)411 bool SpaceShip::mouseButtonPressed(const MouseState& state, MouseButton::Enum id) 412 { 413 if (id == MouseButton::Left) 414 414 this->bLMousePressed_ = true; 415 else if (id == OIS::MB_Right)415 else if (id == MouseButton::Right) 416 416 this->bRMousePressed_ = true; 417 417 … … 419 419 } 420 420 421 bool SpaceShip::mouse Released(const OIS::MouseEvent &e, OIS::MouseButtonIDid)422 { 423 if (id == OIS::MB_Left)421 bool SpaceShip::mouseButtonReleased(const MouseState& state, MouseButton::Enum id) 422 { 423 if (id == MouseButton::Left) 424 424 this->bLMousePressed_ = false; 425 else if (id == OIS::MB_Right)425 else if (id == MouseButton::Right) 426 426 { 427 427 this->bRMousePressed_ = false; … … 454 454 this->timeToReload_ = this->reloadTime_; 455 455 } 456 457 OIS::Keyboard* mKeyboard = InputManager::getKeyboard();458 456 459 457 … … 523 521 } 524 522 525 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ ){ 526 COUT(4) << "steering our ship: " << objectID << " mkeyboard: " << mKeyboard << std::endl; 527 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 523 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ ) 524 { 525 COUT(4) << "steering our ship: " << objectID << std::endl; 526 if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W)) 528 527 this->acceleration_.x = this->translationAcceleration_; 529 else if( mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))528 else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S)) 530 529 this->acceleration_.x = -this->translationAcceleration_; 531 530 else 532 531 this->acceleration_.x = 0; 533 532 534 if ( mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))533 if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D)) 535 534 this->acceleration_.y = -this->translationAcceleration_; 536 else if ( mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))535 else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A)) 537 536 this->acceleration_.y = this->translationAcceleration_; 538 537 else 539 538 this->acceleration_.y = 0; 540 539 541 if ( mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))540 if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q)) 542 541 this->momentum_ = Radian(-this->rotationAccelerationRadian_); 543 else if ( mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))542 else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E)) 544 543 this->momentum_ = Radian(this->rotationAccelerationRadian_); 545 544 else -
code/branches/merge/src/orxonox/objects/SpaceShip.h
r1264 r1272 34 34 #include <OgrePrerequisites.h> 35 35 36 #include "core/Input Handler.h"36 #include "core/InputInterfaces.h" 37 37 #include "Camera.h" 38 38 #include "Model.h" … … 68 68 { SpaceShip::instance_s->setMaxSpeed(value); } 69 69 70 bool mouseMoved(const OIS::MouseEvent &e); 71 bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id); 72 bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id); 73 bool mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } 70 bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id); 71 bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id); 72 bool mouseButtonHeld (const MouseState& state, MouseButton::Enum id) { return true; } 73 bool mouseMoved (const MouseState& state); 74 bool mouseScrolled (const MouseState& state) { return true; } 74 75 75 76 -
code/branches/merge/visual_studio/base_properties_debug.vsprops
r1089 r1272 13 13 BasicRuntimeChecks="3" 14 14 RuntimeLibrary="3" 15 DebugInformationFormat=" 4"15 DebugInformationFormat="3" 16 16 /> 17 17 <Tool -
code/branches/merge/visual_studio/vc8/core.vcproj
r1223 r1272 351 351 </File> 352 352 <File 353 RelativePath="..\..\src\core\InputInterfaces.h" 354 > 355 </File> 356 <File 353 357 RelativePath="..\..\src\core\InputManager.h" 354 358 > -
code/branches/merge/visual_studio/vc8/ois.vcproj
r1219 r1272 560 560 </File> 561 561 </Filter> 562 <Filter 563 Name="linux" 564 > 565 <File 566 RelativePath="..\..\src\ois\linux\EventHelpers.cpp" 567 > 568 <FileConfiguration 569 Name="Release|Win32" 570 ExcludedFromBuild="true" 571 > 572 <Tool 573 Name="VCCLCompilerTool" 574 /> 575 </FileConfiguration> 576 <FileConfiguration 577 Name="Debug|Win32" 578 ExcludedFromBuild="true" 579 > 580 <Tool 581 Name="VCCLCompilerTool" 582 /> 583 </FileConfiguration> 584 </File> 585 <File 586 RelativePath="..\..\src\ois\linux\LinuxForceFeedback.cpp" 587 > 588 <FileConfiguration 589 Name="Release|Win32" 590 ExcludedFromBuild="true" 591 > 592 <Tool 593 Name="VCCLCompilerTool" 594 /> 595 </FileConfiguration> 596 <FileConfiguration 597 Name="Debug|Win32" 598 ExcludedFromBuild="true" 599 > 600 <Tool 601 Name="VCCLCompilerTool" 602 /> 603 </FileConfiguration> 604 </File> 605 <File 606 RelativePath="..\..\src\ois\linux\LinuxInputManager.cpp" 607 > 608 <FileConfiguration 609 Name="Release|Win32" 610 ExcludedFromBuild="true" 611 > 612 <Tool 613 Name="VCCLCompilerTool" 614 /> 615 </FileConfiguration> 616 <FileConfiguration 617 Name="Debug|Win32" 618 ExcludedFromBuild="true" 619 > 620 <Tool 621 Name="VCCLCompilerTool" 622 /> 623 </FileConfiguration> 624 </File> 625 <File 626 RelativePath="..\..\src\ois\linux\LinuxJoyStickEvents.cpp" 627 > 628 <FileConfiguration 629 Name="Release|Win32" 630 ExcludedFromBuild="true" 631 > 632 <Tool 633 Name="VCCLCompilerTool" 634 /> 635 </FileConfiguration> 636 <FileConfiguration 637 Name="Debug|Win32" 638 ExcludedFromBuild="true" 639 > 640 <Tool 641 Name="VCCLCompilerTool" 642 /> 643 </FileConfiguration> 644 </File> 645 <File 646 RelativePath="..\..\src\ois\linux\LinuxKeyboard.cpp" 647 > 648 <FileConfiguration 649 Name="Release|Win32" 650 ExcludedFromBuild="true" 651 > 652 <Tool 653 Name="VCCLCompilerTool" 654 /> 655 </FileConfiguration> 656 <FileConfiguration 657 Name="Debug|Win32" 658 ExcludedFromBuild="true" 659 > 660 <Tool 661 Name="VCCLCompilerTool" 662 /> 663 </FileConfiguration> 664 </File> 665 <File 666 RelativePath="..\..\src\ois\linux\LinuxMouse.cpp" 667 > 668 <FileConfiguration 669 Name="Release|Win32" 670 ExcludedFromBuild="true" 671 > 672 <Tool 673 Name="VCCLCompilerTool" 674 /> 675 </FileConfiguration> 676 <FileConfiguration 677 Name="Debug|Win32" 678 ExcludedFromBuild="true" 679 > 680 <Tool 681 Name="VCCLCompilerTool" 682 /> 683 </FileConfiguration> 684 </File> 685 </Filter> 562 686 </Filter> 563 687 <Filter … … 650 774 <File 651 775 RelativePath="..\..\src\ois\OISInterface.h" 776 > 777 </File> 778 </Filter> 779 <Filter 780 Name="linux" 781 > 782 <File 783 RelativePath="..\..\src\ois\linux\EventHelpers.h" 784 > 785 </File> 786 <File 787 RelativePath="..\..\src\ois\linux\LinuxForceFeedback.h" 788 > 789 </File> 790 <File 791 RelativePath="..\..\src\ois\linux\LinuxInputManager.h" 792 > 793 </File> 794 <File 795 RelativePath="..\..\src\ois\linux\LinuxJoyStickEvents.h" 796 > 797 </File> 798 <File 799 RelativePath="..\..\src\ois\linux\LinuxKeyboard.h" 800 > 801 </File> 802 <File 803 RelativePath="..\..\src\ois\linux\LinuxMouse.h" 804 > 805 </File> 806 <File 807 RelativePath="..\..\src\ois\linux\LinuxPrereqs.h" 652 808 > 653 809 </File>
Note: See TracChangeset
for help on using the changeset viewer.