Changeset 1670 for code/branches/gui/src/core/input
- Timestamp:
- Aug 26, 2008, 4:26:04 PM (16 years ago)
- Location:
- code/branches/gui/src/core/input
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/input/InputManager.cc
r1660 r1670 348 348 for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin(); 349 349 it != inputStatesByPriority_.end(); ++it) 350 (*it).second->setNumOfJoySticks(joySticksSize_);350 it->second->setNumOfJoySticks(joySticksSize_); 351 351 } 352 352 … … 506 506 } 507 507 508 /** 509 @brief 510 Removes and destroys an InputState. 511 @return 512 True if state was removed immediately, false if postponed. 513 */ 508 514 void InputManager::_destroyState(InputState* state) 509 515 { 510 assert(state );516 assert(state && !(this->internalState_ & Ticking)); 511 517 std::map<int, InputState*>::iterator it = this->activeStates_.find(state->getPriority()); 512 518 if (it != this->activeStates_.end()) … … 633 639 internalState_ |= Ticking; 634 640 635 // check for states to leave (don't use unsigned int!) 636 for (int i = stateLeaveRequests_.size() - 1; i >= 0; --i) 637 { 638 stateLeaveRequests_[i]->onLeave(); 641 // check for states to leave 642 for (std::set<InputState*>::reverse_iterator it = stateLeaveRequests_.rbegin(); 643 it != stateLeaveRequests_.rend(); ++it) 644 { 645 (*it)->onLeave(); 639 646 // just to be sure that the state actually is registered 640 assert(inputStatesByName_.find( stateLeaveRequests_[i]->getName()) != inputStatesByName_.end());641 642 activeStates_.erase( stateLeaveRequests_[i]->getPriority());647 assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end()); 648 649 activeStates_.erase((*it)->getPriority()); 643 650 _updateActiveStates(); 644 stateLeaveRequests_.pop_back();645 }646 647 648 // check for states to enter (don't use unsigned int!)649 for (int i = stateEnterRequests_.size() - 1; i >= 0; --i)651 } 652 stateLeaveRequests_.clear(); 653 654 // check for states to enter 655 for (std::set<InputState*>::reverse_iterator it = stateEnterRequests_.rbegin(); 656 it != stateEnterRequests_.rend(); ++it) 650 657 { 651 658 // just to be sure that the state actually is registered 652 assert(inputStatesByName_.find( stateEnterRequests_[i]->getName()) != inputStatesByName_.end());653 654 activeStates_[ stateEnterRequests_[i]->getPriority()] = stateEnterRequests_[i];659 assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end()); 660 661 activeStates_[(*it)->getPriority()] = (*it); 655 662 _updateActiveStates(); 656 stateEnterRequests_[i]->onEnter(); 657 stateEnterRequests_.pop_back(); 663 (*it)->onEnter(); 664 } 665 stateEnterRequests_.clear(); 666 667 // check for states to destroy 668 for (std::set<InputState*>::reverse_iterator it = stateDestroyRequests_.rbegin(); 669 it != stateDestroyRequests_.rend(); ++it) 670 { 671 _destroyState((*it)); 658 672 } 659 673 … … 703 717 for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 704 718 for (unsigned int i = 0; i < devicesNum_; ++i) 705 if ( (*it).second->isInputDeviceEnabled(i))706 activeStatesTop_[i] = (*it).second;719 if (it->second->isInputDeviceEnabled(i)) 720 activeStatesTop_[i] = it->second; 707 721 708 722 // update tickables (every state will only appear once) … … 1135 1149 /** 1136 1150 @brief 1137 Removes an input state internally.1151 Removes and destroys an input state internally. 1138 1152 @param name 1139 1153 Name of the handler. … … 1142 1156 @remarks 1143 1157 You can't remove the internal states "empty", "calibrator" and "detector". 1144 */ 1145 bool InputManager::destroyState(const std::string& name) 1158 The removal process is being postponed if InputManager::tick() is currently running. 1159 */ 1160 bool InputManager::requestDestroyState(const std::string& name) 1146 1161 { 1147 1162 if (name == "empty" || name == "calibrator" || name == "detector") … … 1153 1168 if (it != inputStatesByName_.end()) 1154 1169 { 1155 _destroyState((*it).second); 1170 if (activeStates_.find(it->second->getPriority()) != activeStates_.end()) 1171 { 1172 // The state is still active. We have to postpone 1173 stateLeaveRequests_.insert(it->second); 1174 stateDestroyRequests_.insert(it->second); 1175 } 1176 else if (this->internalState_ & Ticking) 1177 { 1178 // cannot remove state while ticking 1179 stateDestroyRequests_.insert(it->second); 1180 } 1181 else 1182 _destroyState(it->second); 1183 1156 1184 return true; 1157 1185 } … … 1171 1199 std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name); 1172 1200 if (it != inputStatesByName_.end()) 1173 return (*it).second;1201 return it->second; 1174 1202 else 1175 1203 return 0; … … 1202 1230 if (it != inputStatesByName_.end()) 1203 1231 { 1204 stateEnterRequests_.push_back((*it).second); 1205 return true; 1232 // exists 1233 if (activeStates_.find(it->second->getPriority()) == activeStates_.end()) 1234 { 1235 // not active 1236 if (stateDestroyRequests_.find(it->second) == stateDestroyRequests_.end()) 1237 { 1238 // not scheduled for destruction 1239 // set prevents a state being added multiple times 1240 stateEnterRequests_.insert(it->second); 1241 return true; 1242 } 1243 } 1206 1244 } 1207 1245 return false; … … 1222 1260 if (it != inputStatesByName_.end()) 1223 1261 { 1224 stateLeaveRequests_.push_back((*it).second); 1225 return true; 1262 // exists 1263 if (activeStates_.find(it->second->getPriority()) != activeStates_.end()) 1264 { 1265 // active 1266 stateLeaveRequests_.insert(it->second); 1267 return true; 1268 } 1226 1269 } 1227 1270 return false; -
code/branches/gui/src/core/input/InputManager.h
r1659 r1670 127 127 } 128 128 129 bool destroyState (const std::string& name);130 129 InputState* getState (const std::string& name); 131 130 InputState* getCurrentState(); 131 bool requestDestroyState (const std::string& name); 132 132 bool requestEnterState (const std::string& name); 133 133 bool requestLeaveState (const std::string& name); 134 135 void tick(float dt); 134 136 135 137 static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } … … 167 169 void _updateActiveStates(); 168 170 bool _configureInputState(InputState* state, const std::string& name, int priority); 169 170 void tick(float dt);171 171 172 172 // input events … … 204 204 std::map<int, InputState*> inputStatesByPriority_; 205 205 206 std::vector<InputState*> stateEnterRequests_; //!< Request to enter a new state 207 std::vector<InputState*> stateLeaveRequests_; //!< Request to leave the current state 206 std::set<InputState*> stateEnterRequests_; //!< Request to enter a new state 207 std::set<InputState*> stateLeaveRequests_; //!< Request to leave a running state 208 std::set<InputState*> stateDestroyRequests_; //!< Request to destroy a state 208 209 209 210 std::map<int, InputState*> activeStates_;
Note: See TracChangeset
for help on using the changeset viewer.