Changeset 1881 for code/trunk/src/core
- Timestamp:
- Oct 3, 2008, 3:30:15 PM (16 years ago)
- Location:
- code/trunk/src/core/input
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/input/ExtendedInputState.cc
r1878 r1881 362 362 363 363 return success; 364 }365 366 void ExtendedInputState::removeAndDestroyAllHandlers()367 {368 for (std::vector<InputHandler*>::iterator it = allHandlers_.begin();369 it != allHandlers_.end(); ++it)370 delete *it;371 372 allHandlers_.clear();373 keyHandlers_.clear();374 mouseHandlers_.clear();375 joyStickHandlersAll_.clear();376 for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandlers_.size(); ++iJoyStick)377 joyStickHandlers_[iJoyStick].clear();378 update();379 364 } 380 365 -
code/trunk/src/core/input/ExtendedInputState.h
r1878 r1881 64 64 bool removeHandler(InputHandler* handler); 65 65 66 void removeAndDestroyAllHandlers();67 68 66 private: 69 67 ExtendedInputState() { } -
code/trunk/src/core/input/InputManager.cc
r1878 r1881 107 107 , windowHnd_(0) 108 108 , internalState_(Uninitialised) 109 , stateDetector_(0)110 , stateCalibrator_(0)111 109 , stateEmpty_(0) 112 110 , stateMaster_(0) 111 , keyDetector_(0) 112 , calibratorCallbackBuffer_(0) 113 113 , bCalibrating_(false) 114 114 , keyboardModifiers_(0) … … 189 189 CCOUT(4) << "Initialising InputStates components..." << std::endl; 190 190 191 // Lowest priority empty InputState 191 192 stateEmpty_ = createInputState<SimpleInputState>("empty", -1); 192 193 stateEmpty_->setHandler(&EMPTY_HANDLER); 193 194 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 194 195 195 stateDetector_ = createInputState<SimpleInputState>("detector", 101); 196 KeyDetector* temp = new KeyDetector(); 197 temp->loadBindings("storeKeyStroke"); 198 stateDetector_->setHandler(temp); 199 200 stateCalibrator_ = createInputState<SimpleInputState>("calibrator", 100); 201 stateCalibrator_->setHandler(&EMPTY_HANDLER); 202 InputBuffer* buffer = new InputBuffer(); 203 buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true); 204 stateCalibrator_->setKeyHandler(buffer); 205 196 // Always active master InputState 206 197 stateMaster_ = new ExtendedInputState(); 207 198 stateMaster_->setName("master"); 199 200 // KeyDetector to evaluate a pressed key's name 201 SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101); 202 keyDetector_ = new KeyDetector(); 203 keyDetector_->loadBindings("storeKeyStroke"); 204 detector->setHandler(keyDetector_); 205 206 // Joy stick calibration helper callback 207 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100); 208 calibrator->setHandler(&EMPTY_HANDLER); 209 calibratorCallbackBuffer_ = new InputBuffer(); 210 calibratorCallbackBuffer_->registerListener(this, &InputManager::_completeCalibration, '\r', true); 211 calibrator->setKeyHandler(calibratorCallbackBuffer_); 208 212 209 213 internalState_ |= InternalsReady; … … 430 434 CCOUT(3) << "Destroying ..." << std::endl; 431 435 432 // clear our own states433 //stateEmpty_->removeAndDestroyAllHandlers();434 //stateCalibrator_->removeAndDestroyAllHandlers();435 //stateDetector_->removeAndDestroyAllHandlers();436 // TODO: Memory Leak when not deleting the handlers!!!437 438 436 // kick all active states 'nicely' 439 437 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); … … 443 441 } 444 442 445 // destroy all input states 446 while (inputStatesByPriority_.size() > 0) 447 _destroyState((*inputStatesByPriority_.rbegin()).second); 448 443 // Destroy calibrator helper handler and state 444 delete keyDetector_; 445 requestDestroyState("calibrator"); 446 // Destroy KeyDetector and state 447 delete calibratorCallbackBuffer_; 448 requestDestroyState("detector"); 449 // destroy the empty InputState 450 _destroyState(this->stateEmpty_); 449 451 // destroy the master input state. This might trigger a memory leak 450 452 // because the user has forgotten to destroy the KeyBinder or any Handler! 451 453 delete stateMaster_; 454 455 // destroy all user InputStates 456 while (inputStatesByPriority_.size() > 0) 457 _destroyState((*inputStatesByPriority_.rbegin()).second); 452 458 453 459 // destroy the devices … … 1231 1237 bool InputManager::requestDestroyState(const std::string& name) 1232 1238 { 1233 if (name == "empty" || name == "calibrator" || name == "detector")1234 { 1235 COUT(2) << "InputManager: Removing the '" << name << "'state is not allowed!" << std::endl;1239 if (name == "empty") 1240 { 1241 COUT(2) << "InputManager: Removing the empty state is not allowed!" << std::endl; 1236 1242 return false; 1237 1243 } -
code/trunk/src/core/input/InputManager.h
r1878 r1881 193 193 194 194 // some internally handled states and handlers 195 SimpleInputState* stateDetector_; //!< KeyDetector instance196 SimpleInputState* stateCalibrator_;197 195 SimpleInputState* stateEmpty_; 198 196 ExtendedInputState* stateMaster_; //!< Always active master input state 197 KeyDetector* keyDetector_; //!< KeyDetector instance 198 InputBuffer* calibratorCallbackBuffer_; 199 199 200 200 std::map<std::string, InputState*> inputStatesByName_; -
code/trunk/src/core/input/SimpleInputState.cc
r1878 r1881 184 184 } 185 185 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 202 186 /** 203 187 @brief -
code/trunk/src/core/input/SimpleInputState.h
r1878 r1881 53 53 bool setJoyStickHandler (JoyStickHandler* handler); 54 54 bool setHandler(InputHandler* handler); 55 //void removeAndDestroyAllHandlers();56 55 57 56 private:
Note: See TracChangeset
for help on using the changeset viewer.