Changeset 1878 for code/trunk/src/core/input
- Timestamp:
- Oct 3, 2008, 1:26:48 PM (16 years ago)
- Location:
- code/trunk/src/core/input
- Files:
-
- 8 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 }
Note: See TracChangeset
for help on using the changeset viewer.