Changeset 1878 for code/trunk/src
- Timestamp:
- Oct 3, 2008, 1:26:48 PM (16 years ago)
- Location:
- code/trunk/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/input/ExtendedInputState.cc
r1755 r1878 366 366 void ExtendedInputState::removeAndDestroyAllHandlers() 367 367 { 368 for (std::vector<Input Tickable*>::iterator it = allHandlers_.begin();368 for (std::vector<InputHandler*>::iterator it = allHandlers_.begin(); 369 369 it != allHandlers_.end(); ++it) 370 370 delete *it; … … 387 387 True if added, false if handler already existed. 388 388 */ 389 bool ExtendedInputState::addHandler(Input Tickable* handler)389 bool ExtendedInputState::addHandler(InputHandler* handler) 390 390 { 391 391 bool success = false; … … 406 406 True if removal was successful, false if handler was not found. 407 407 */ 408 bool ExtendedInputState::removeHandler(Input Tickable* handler)408 bool ExtendedInputState::removeHandler(InputHandler* handler) 409 409 { 410 410 bool success = false; … … 449 449 { 450 450 // we can use a set to have a list of unique pointers (an object can implement all 3 handlers) 451 std::set<Input Tickable*> tempSet;451 std::set<InputHandler*> tempSet; 452 452 for (unsigned int iHandler = 0; iHandler < keyHandlers_.size(); iHandler++) 453 453 tempSet.insert(keyHandlers_[iHandler]); … … 460 460 // copy the content of the map back to the actual vector 461 461 allHandlers_.clear(); 462 for (std::set<Input Tickable*>::const_iterator itHandler = tempSet.begin();462 for (std::set<InputHandler*>::const_iterator itHandler = tempSet.begin(); 463 463 itHandler != tempSet.end(); itHandler++) 464 464 allHandlers_.push_back(*itHandler); … … 469 469 for (unsigned int i = 0; i < joyStickHandlers_.size(); ++i) 470 470 setInputDeviceEnabled(2 + i, (joyStickHandlers_[i].size() != 0)); 471 472 this->bHandlersChanged_ = true; 471 473 } 472 474 } -
code/trunk/src/core/input/ExtendedInputState.h
r1755 r1878 61 61 bool removeJoyStickHandler(JoyStickHandler* handler); 62 62 63 bool addHandler(Input Tickable* handler);64 bool removeHandler(Input Tickable* handler);63 bool addHandler(InputHandler* handler); 64 bool removeHandler(InputHandler* handler); 65 65 66 66 void removeAndDestroyAllHandlers(); … … 96 96 std::vector<JoyStickHandler*> joyStickHandlersAll_; 97 97 98 std::vector<Input Tickable*> allHandlers_;98 std::vector<InputHandler*> allHandlers_; 99 99 }; 100 100 } -
code/trunk/src/core/input/InputInterfaces.h
r1755 r1878 287 287 288 288 289 class _CoreExport Input Tickable290 { 291 public: 292 virtual ~Input Tickable() { }289 class _CoreExport InputHandler 290 { 291 public: 292 virtual ~InputHandler() { } 293 293 virtual void tickInput(float dt) = 0; 294 294 }; … … 298 298 Interface class used for key input listeners. 299 299 */ 300 class _CoreExport KeyHandler : virtual public Input Tickable300 class _CoreExport KeyHandler : virtual public InputHandler 301 301 { 302 302 public: … … 312 312 Interface class used for mouse input listeners. 313 313 */ 314 class _CoreExport MouseHandler : virtual public Input Tickable314 class _CoreExport MouseHandler : virtual public InputHandler 315 315 { 316 316 public: … … 329 329 Interface class used for joy stick input listeners. 330 330 */ 331 class _CoreExport JoyStickHandler : virtual public Input Tickable331 class _CoreExport JoyStickHandler : virtual public InputHandler 332 332 { 333 333 public: … … 342 342 class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler 343 343 { 344 friend class InputManager; 344 345 private: 346 EmptyHandler() { } 347 EmptyHandler(EmptyHandler&); 348 virtual ~EmptyHandler() { } 349 345 350 void tickInput(float dt) { } 346 351 void tickJoyStick(float dt, unsigned int joyStick) { } -
code/trunk/src/core/input/InputManager.cc
r1788 r1878 65 65 66 66 std::string InputManager::bindingCommmandString_s = ""; 67 EmptyHandler InputManager::EMPTY_HANDLER; 67 68 InputManager* InputManager::singletonRef_s = 0; 68 69 … … 189 190 190 191 stateEmpty_ = createInputState<SimpleInputState>("empty", -1); 191 stateEmpty_->setHandler( new EmptyHandler());192 stateEmpty_->setHandler(&EMPTY_HANDLER); 192 193 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 193 194 … … 198 199 199 200 stateCalibrator_ = createInputState<SimpleInputState>("calibrator", 100); 200 stateCalibrator_->setHandler( new EmptyHandler());201 stateCalibrator_->setHandler(&EMPTY_HANDLER); 201 202 InputBuffer* buffer = new InputBuffer(); 202 203 buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true); … … 430 431 431 432 // clear our own states 432 stateEmpty_->removeAndDestroyAllHandlers(); 433 stateCalibrator_->removeAndDestroyAllHandlers(); 434 stateDetector_->removeAndDestroyAllHandlers(); 433 //stateEmpty_->removeAndDestroyAllHandlers(); 434 //stateCalibrator_->removeAndDestroyAllHandlers(); 435 //stateDetector_->removeAndDestroyAllHandlers(); 436 // TODO: Memory Leak when not deleting the handlers!!! 435 437 436 438 // kick all active states 'nicely' … … 680 682 } 681 683 stateDestroyRequests_.clear(); 684 685 // check whether a state has changed its EMPTY_HANDLER situation 686 bool bUpdateRequired = false; 687 for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 688 { 689 if (it->second->handlersChanged()) 690 { 691 it->second->resetHandlersChanged(); 692 bUpdateRequired = true; 693 } 694 } 695 if (bUpdateRequired) 696 _updateActiveStates(); 682 697 683 698 // mark that we capture and distribute input … … 826 841 requestLeaveState("calibrator"); 827 842 bCalibrating_ = false; 843 } 844 845 void InputManager::clearBuffers() 846 { 847 this->keysDown_.clear(); 848 this->mouseButtonsDown_.clear(); 849 for (unsigned int i = 0; i < this->joySticksSize_; ++i) 850 this->joyStickButtonsDown_[i].clear(); 828 851 } 829 852 -
code/trunk/src/core/input/InputManager.h
r1788 r1878 108 108 void reloadInputSystem(bool joyStickSupport = true); 109 109 110 void clearBuffers(); 111 110 112 int numberOfKeyboards() { return keyboard_ ? 1 : 0; } 111 113 int numberOfMice() { return mouse_ ? 1 : 0; } … … 115 117 116 118 template <class T> 117 T* createInputState(const std::string& name, int priority) 118 { 119 T* state = new T; 120 if (_configureInputState(state, name, priority)) 121 return state; 122 else 123 { 124 delete state; 125 return 0; 126 } 127 } 119 T* createInputState(const std::string& name, int priority); 128 120 129 121 InputState* getState (const std::string& name); … … 139 131 static InputManager* getInstancePtr() { return singletonRef_s; } 140 132 141 public:// console commands133 // console commands 142 134 static void storeKeyStroke(const std::string& name); 143 135 static void keyBind(const std::string& command); 144 136 static void calibrate(); 145 137 static void reload(bool joyStickSupport = true); 138 139 public: // variables 140 static EmptyHandler EMPTY_HANDLER; 146 141 147 142 private: // functions … … 197 192 InputManagerState internalState_; //!< Current internal state 198 193 199 // some internally handled states 194 // some internally handled states and handlers 200 195 SimpleInputState* stateDetector_; //!< KeyDetector instance 201 196 SimpleInputState* stateCalibrator_; … … 234 229 static InputManager* singletonRef_s; 235 230 }; 231 232 /** 233 @brief 234 Creates a new InputState by type, name and priority. 235 236 You will have to use this method because the 237 c'tors and d'tors are private. 238 @remarks 239 The InputManager will take care of the state completely. That also 240 means it gets deleted when the InputManager is destroyed! 241 @param name 242 Name of the InputState when referenced as string 243 @param priority 244 Priority matters when multiple states are active. You can specify any 245 number, but 1 - 99 is preferred (99 means high). 246 */ 247 template <class T> 248 T* InputManager::createInputState(const std::string& name, int priority) 249 { 250 T* state = new T; 251 if (_configureInputState(state, name, priority)) 252 return state; 253 else 254 { 255 delete state; 256 return 0; 257 } 258 } 236 259 } 237 260 -
code/trunk/src/core/input/InputState.h
r1755 r1878 60 60 } 61 61 62 bool handlersChanged() { return this->bHandlersChanged_; } 63 void resetHandlersChanged() { bHandlersChanged_ = false; } 64 62 65 virtual void onEnter() { if (executorOnEnter_) (*executorOnEnter_)(); } 63 66 virtual void onLeave() { if (executorOnLeave_) (*executorOnLeave_)(); } … … 87 90 88 91 protected: 89 InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) { }92 InputState() : priority_(0), bHandlersChanged_(false), executorOnEnter_(0), executorOnLeave_(0) { } 90 93 virtual ~InputState() { } 91 94 … … 96 99 bInputDeviceEnabled_[device] = bEnabled; 97 100 } 101 102 bool bHandlersChanged_; 98 103 99 104 private: -
code/trunk/src/core/input/SimpleInputState.cc
r1755 r1878 184 184 } 185 185 186 void SimpleInputState::removeAndDestroyAllHandlers()187 {188 for (std::vector<InputTickable*>::iterator it = allHandlers_.begin();189 it != allHandlers_.end(); ++it)190 delete *it;191 192 allHandlers_.clear();193 keyHandler_ = 0;194 mouseHandler_ = 0;195 joyStickHandlerAll_ = 0;196 for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick)197 joyStickHandler_[iJoyStick] = 0;198 199 update();200 }186 //void SimpleInputState::removeAndDestroyAllHandlers() 187 //{ 188 // for (std::vector<InputHandler*>::iterator it = allHandlers_.begin(); 189 // it != allHandlers_.end(); ++it) 190 // delete *it; 191 192 // allHandlers_.clear(); 193 // keyHandler_ = 0; 194 // mouseHandler_ = 0; 195 // joyStickHandlerAll_ = 0; 196 // for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick) 197 // joyStickHandler_[iJoyStick] = 0; 198 199 // update(); 200 //} 201 201 202 202 /** … … 208 208 True if added, false if handler already existed. 209 209 */ 210 bool SimpleInputState::setHandler(Input Tickable* handler)210 bool SimpleInputState::setHandler(InputHandler* handler) 211 211 { 212 212 setKeyHandler(dynamic_cast<KeyHandler*>(handler)); … … 247 247 { 248 248 // we can use a set to have a list of unique pointers (an object can implement all 3 handlers) 249 std::set<Input Tickable*> tempSet;249 std::set<InputHandler*> tempSet; 250 250 if (keyHandler_) 251 251 tempSet.insert(keyHandler_); … … 258 258 // copy the content of the map back to the actual vector 259 259 allHandlers_.clear(); 260 for (std::set<Input Tickable*>::const_iterator itHandler = tempSet.begin();260 for (std::set<InputHandler*>::const_iterator itHandler = tempSet.begin(); 261 261 itHandler != tempSet.end(); itHandler++) 262 262 allHandlers_.push_back(*itHandler); … … 267 267 for (unsigned int i = 0; i < joyStickHandler_.size(); ++i) 268 268 setInputDeviceEnabled(2 + i, (joyStickHandler_[i] != 0)); 269 270 // inform InputManager that there might be changes in EMPTY_HANDLER situation 271 bHandlersChanged_ = true; 269 272 } 270 273 } -
code/trunk/src/core/input/SimpleInputState.h
r1755 r1878 52 52 bool setJoyStickHandler (JoyStickHandler* handler, unsigned int joyStickID); 53 53 bool setJoyStickHandler (JoyStickHandler* handler); 54 bool setHandler(Input Tickable* handler);55 void removeAndDestroyAllHandlers();54 bool setHandler(InputHandler* handler); 55 //void removeAndDestroyAllHandlers(); 56 56 57 57 private: … … 84 84 std::vector<JoyStickHandler*> joyStickHandler_; 85 85 JoyStickHandler* joyStickHandlerAll_; 86 std::vector<Input Tickable*> allHandlers_;86 std::vector<InputHandler*> allHandlers_; 87 87 }; 88 88 } -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r1828 r1878 140 140 using namespace Ogre; 141 141 142 // remove our WindowEventListener first to avoid bad calls in the procedures 143 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this); 144 142 145 delete this->guiManager_; 143 146 … … 149 152 150 153 // destroy render window 151 this->renderWindow_->removeAllViewports();152 this->renderWindow_->removeAllListeners();153 154 RenderSystem* renderer = this->ogreRoot_->getRenderSystem(); 154 155 renderer->destroyRenderWindow("Orxonox"); … … 360 361 The render window it occured in 361 362 */ 362 void GSGraphics::windowFocusChange d(Ogre::RenderWindow *rw)363 void GSGraphics::windowFocusChange(Ogre::RenderWindow *rw) 363 364 { 364 365 for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it) 365 366 it->windowFocusChanged(); 367 368 // instruct InputManager to clear the buffers (core library so we cannot use the interface) 369 InputManager::getInstance().clearBuffers(); 366 370 } 367 371 -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r1788 r1878 65 65 void windowMoved (Ogre::RenderWindow* rw); 66 66 void windowResized (Ogre::RenderWindow* rw); 67 void windowFocusChange d(Ogre::RenderWindow* rw);67 void windowFocusChange (Ogre::RenderWindow* rw); 68 68 void windowClosed (Ogre::RenderWindow* rw); 69 69 -
code/trunk/src/orxonox/gui/GUIManager.cc
r1810 r1878 156 156 SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui", 30); 157 157 state->setHandler(this); 158 state->setJoyStickHandler( new EmptyHandler());158 state->setJoyStickHandler(&InputManager::EMPTY_HANDLER); 159 159 160 160 // load the background scene -
code/trunk/src/orxonox/overlays/console/InGameConsole.cc
r1819 r1878 70 70 , consoleOverlayBorder_(0) 71 71 , consoleOverlayTextAreas_(0) 72 , inputState_(0) 72 73 { 73 74 RegisterObject(InGameConsole); … … 143 144 SetConfigValue(noiseSize_, 1.0f); 144 145 SetConfigValue(cursorSymbol_, '|'); 146 SetConfigValue(bHidesAllInput_, false).callback(this, &InGameConsole::bHidesAllInputChanged); 147 } 148 149 /** 150 @brief Called whenever bHidesAllInput_ changes. 151 */ 152 void InGameConsole::bHidesAllInputChanged() 153 { 154 if (inputState_) 155 { 156 if (bHidesAllInput_) 157 { 158 inputState_->setMouseHandler(&InputManager::EMPTY_HANDLER); 159 inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER); 160 } 161 else 162 { 163 inputState_->setMouseHandler(0); 164 inputState_->setJoyStickHandler(0); 165 } 166 } 145 167 } 146 168 … … 151 173 { 152 174 // create the corresponding input state 153 InputManager::getInstance().createInputState<SimpleInputState>("console", 40) 154 ->setKeyHandler(Shell::getInstance().getInputBuffer()); 175 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", 40); 176 inputState_->setKeyHandler(Shell::getInstance().getInputBuffer()); 177 bHidesAllInputChanged(); 155 178 156 179 // create overlay and elements -
code/trunk/src/orxonox/overlays/console/InGameConsole.h
r1755 r1878 81 81 void windowResized(int newWidth, int newHeight); 82 82 83 // config value related 84 void bHidesAllInputChanged(); 85 83 86 static Ogre::UTFString convert2UTF(std::string s); 84 87 … … 102 105 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 103 106 107 // input related 108 SimpleInputState* inputState_; 109 104 110 // config values 105 111 float relativeWidth; … … 109 115 float noiseSize_; 110 116 char cursorSymbol_; 117 bool bHidesAllInput_; 111 118 112 119 static InGameConsole* singletonRef_s;
Note: See TracChangeset
for help on using the changeset viewer.