Changeset 1670 for code/branches/gui/src/core
- Timestamp:
- Aug 26, 2008, 4:26:04 PM (16 years ago)
- Location:
- code/branches/gui/src/core
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/CommandLine.h
r1664 r1670 38 38 #define SetCommandLineArgument(name, defaultValue) \ 39 39 BaseCommandLineArgument& CmdArgumentDummyBoolVar##name \ 40 = orxonox::CommandLine::add CommandLineArgument(#name, defaultValue)40 = orxonox::CommandLine::addArgument(#name, defaultValue) 41 41 #define SetCommandLineSwitch(name) \ 42 42 BaseCommandLineArgument& CmdArgumentDummyBoolVar##name \ 43 = orxonox::CommandLine::add CommandLineArgument(#name, false)43 = orxonox::CommandLine::addArgument(#name, false) 44 44 45 45 … … 89 89 protected: 90 90 BaseCommandLineArgument(const std::string& name) 91 : name_(name)92 , bHasDefaultValue_(true)91 : bHasDefaultValue_(true) 92 , name_(name) 93 93 { } 94 94 … … 216 216 217 217 template <class T> 218 static const CommandLineArgument<T>* get CommandLineArgument(const std::string& name);218 static const CommandLineArgument<T>* getArgument(const std::string& name); 219 219 //! Writes the argument value in the given parameter. 220 220 template <class T> 221 static void get CommandLineValue(const std::string& name, T* value)222 { *value = get CommandLineArgument<T>(name)->getValue(); }223 template <class T> 224 static BaseCommandLineArgument& add CommandLineArgument(const std::string& name, T defaultValue);221 static void getValue(const std::string& name, T* value) 222 { *value = getArgument<T>(name)->getValue(); } 223 template <class T> 224 static BaseCommandLineArgument& addArgument(const std::string& name, T defaultValue); 225 225 226 226 private: … … 264 264 */ 265 265 template <class T> 266 const CommandLineArgument<T>* CommandLine::get CommandLineArgument(const std::string& name)266 const CommandLineArgument<T>* CommandLine::getArgument(const std::string& name) 267 267 { 268 268 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); … … 302 302 */ 303 303 template <class T> 304 BaseCommandLineArgument& CommandLine::add CommandLineArgument(const std::string& name, T defaultValue)304 BaseCommandLineArgument& CommandLine::addArgument(const std::string& name, T defaultValue) 305 305 { 306 306 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); -
code/branches/gui/src/core/Core.cc
r1642 r1670 36 36 #include "CoreIncludes.h" 37 37 #include "ConfigValueIncludes.h" 38 #include "input/InputManager.h"39 #include "TclThreadManager.h"38 //#include "input/InputManager.h" 39 //#include "TclThreadManager.h" 40 40 41 41 namespace orxonox … … 188 188 } 189 189 190 / **191 @brief Ticks every core class in a specified sequence. Has to be called192 every Orxonox tick!193 @param dt Delta Time194 */195 void Core::tick(float dt)196 {197 TclThreadManager::getInstance().tick(dt);198 InputManager::getInstance().tick(dt);199 }190 ///** 191 // @brief Ticks every core class in a specified sequence. Has to be called 192 // every Orxonox tick! 193 // @param dt Delta Time 194 //*/ 195 //void Core::tick(float dt) 196 //{ 197 // TclThreadManager::getInstance().tick(dt); 198 // InputManager::getInstance().tick(dt); 199 //} 200 200 } 201 201 -
code/branches/gui/src/core/Core.h
r1638 r1670 58 58 static void resetLanguage(); 59 59 60 static void tick(float dt);60 //static void tick(float dt); 61 61 62 62 private: -
code/branches/gui/src/core/Exception.h
r1664 r1670 88 88 std::string functionName_; 89 89 std::string fileName_; 90 // mutable because of"what()" is a const method90 // mutable because "what()" is a const method 91 91 mutable std::string fullDescription_; 92 92 }; … … 101 101 : Exception(description, lineNumber, fileName, functionName) 102 102 { 103 // let the catcher decide whether to display the message or not104 //COUT(1) << this->getFullDescription() << std::endl;103 // let the catcher decide whether to display the message below level 3 104 COUT(3) << this->getFullDescription() << std::endl; 105 105 } 106 106 … … 108 108 : Exception(description) 109 109 { 110 // let the catcher decide whether to display the message or not111 //COUT(1) << this->getFullDescription() << std::endl;110 // let the catcher decide whether to display the message below level 3 111 COUT(3) << this->getFullDescription() << std::endl; 112 112 } 113 113 -
code/branches/gui/src/core/GameState.cc
r1661 r1670 47 47 : name_(name) 48 48 , bPauseParent_(false) 49 , bActive_(false) 50 , bSuspended_(false) 49 //, bActive_(false) 50 //, bSuspended_(false) 51 //, bRunning_(false) 52 , scheduledTransition_(0) 51 53 , parent_(0) 52 54 , activeChild_(0) 53 55 { 56 Operations temp = {false, false, false, false, false}; 57 this->operation_ = temp; 54 58 } 55 59 … … 60 64 GameState::~GameState() 61 65 { 62 if (this-> bActive_)66 if (this->operation_.active) 63 67 { 64 68 if (this->parent_) … … 133 137 if (it != this->grandchildrenToChildren_.end()) 134 138 { 135 if (state-> isActive())139 if (state->getOperation().active) 136 140 { 137 141 ThrowException(GameState, "Cannot remove active game state child '" … … 247 251 GameState* GameState::getCurrentState() 248 252 { 249 if (this-> bActive_)253 if (this->operation_.active) 250 254 { 251 255 if (this->activeChild_) … … 284 288 void GameState::requestState(const std::string& name) 285 289 { 286 if (name == "") 287 { 288 // user would like to leave every state. 289 GameState* current = getCurrentState(); 290 if (current) 291 { 292 // Deactivate all states but root 293 GameState* root = getRootNode(); 294 current->makeTransition(root); 295 // Kick root too 296 root->deactivate(); 297 } 298 } 290 GameState* current = getCurrentState(); 291 if (current != 0 && (current->getOperation().entering || current->getOperation().leaving)) 292 { 293 ThrowException(GameState, "Making state transitions during enter()/leave() is forbidden."); 294 } 295 //if (name == "") 296 //{ 297 // // user would like to leave every state. 298 // if (current) 299 // { 300 // // Deactivate all states but root 301 // GameState* root = getRootNode(); 302 // current->makeTransition(root); 303 // //// Kick root too 304 // //assert(!(root->getOperation().entering || root->getOperation().leaving)); 305 // //if (root->operation_.running) 306 // // root->scheduledTransition_ = 0; 307 // //else 308 // // root->deactivate(); 309 // } 310 //} 299 311 else 300 312 { 301 313 GameState* request = checkState(name); 302 GameState* current = getCurrentState();303 314 if (request) 304 315 { … … 331 342 { 332 343 // we're always already active 333 assert(this-> bActive_);344 assert(this->operation_.active); 334 345 335 346 if (state == this) … … 349 360 assert(this->parent_ != 0); 350 361 351 // first, leave this state. 362 // only do the transition if we're not currently running 363 if (this->operation_.running) 364 { 365 //this->bDeactivationScheduled_ = true; 366 this->scheduledTransition_ = state; 367 } 368 else 369 { 370 this->deactivate(); 371 this->parent_->makeTransition(state); 372 } 373 374 } 375 } 376 377 /** 378 @brief 379 Activates the state. Only sets bActive_ to true and notifies the parent. 380 */ 381 void GameState::activate() 382 { 383 if (this->parent_) 384 this->parent_->activeChild_ = this; 385 this->operation_.active = true; 386 this->operation_.entering = true; 387 this->enter(); 388 this->operation_.entering = false; 389 } 390 391 /** 392 Activates the state. Only sets bActive_ to false and notifies the parent. 393 */ 394 void GameState::deactivate() 395 { 396 this->operation_.leaving = true; 397 this->leave(); 398 this->operation_.leaving = false; 399 this->operation_.active = false; 400 if (this->parent_) 401 this->parent_->activeChild_ = 0; 402 } 403 404 /** 405 @brief 406 Update method that calls ticked() with enclosed bRunning_ = true 407 If there was a state transition request within ticked() then this 408 method will transition in the end. 409 @param dt Delta time 410 @note 411 This method is not virtual! You cannot override it therefore. 412 */ 413 void GameState::tick(float dt) 414 { 415 this->operation_.running = true; 416 this->ticked(dt); 417 this->operation_.running = false; 418 419 if (this->scheduledTransition_) 420 { 421 // state was requested to be deactivated when ticked. 422 this->makeTransition(this->scheduledTransition_); 423 this->scheduledTransition_ = 0; 352 424 this->deactivate(); 353 this->parent_->makeTransition(state); 354 } 355 } 356 357 /** 358 @brief 359 Activates the state. Only sets bActive_ to true and notifies the parent. 360 */ 361 void GameState::activate() 362 { 363 this->bActive_ = true; 364 if (this->parent_) 365 this->parent_->activeChild_ = this; 366 this->enter(); 367 } 368 369 /** 370 Activates the state. Only sets bActive_ to false and notifies the parent. 371 */ 372 void GameState::deactivate() 373 { 374 this->leave(); 375 this->bActive_ = false; 376 if (this->parent_) 377 this->parent_->activeChild_ = 0; 425 } 378 426 } 379 427 -
code/branches/gui/src/core/GameState.h
r1661 r1670 61 61 { 62 62 public: 63 struct Operations 64 { 65 unsigned active : 1; 66 unsigned entering : 1; 67 unsigned leaving : 1; 68 unsigned running : 1; 69 unsigned suspended : 1; 70 }; 71 63 72 GameState(const std::string& name); 64 73 virtual ~GameState(); … … 71 80 void requestState(const std::string& name); 72 81 73 //! Determines whether the state is active. 74 bool isActive() { return this->bActive_; } 75 //! Determines whether the state is suspended. 76 bool isSuspended() { return this->bSuspended_; } 77 //! Determines whether the state is the current 78 bool isCurrentState() { return this->bActive_ && !this->activeChild_; } 82 ////! Determines whether the state is active. 83 //bool isActive() { return this->bActive_; } 84 ////! Determines whether the state is suspended. 85 //bool isSuspended() { return this->bSuspended_; } 86 ////! Determines whether the state is the current 87 //bool isCurrentState() { return this->bActive_ && !this->activeChild_; } 88 const Operations getOperation() { return this->operation_; } 79 89 80 virtual bool tick(float dt) { return true; } 90 void tick(float dt); 91 void tickChild(float dt) { if (this->activeChild_) this->activeChild_->tick(dt); } 81 92 82 93 protected: 83 //virtual void enter() = 0; 84 //virtual void leave() = 0; 85 //virtual void tick(float dt) = 0; 86 virtual void enter() { } 87 virtual void leave() { } 94 virtual void enter() = 0; 95 virtual void leave() = 0; 96 virtual void ticked(float dt) = 0; 97 //virtual void enter() { } 98 //virtual void leave() { } 99 //virtual void ticked(float dt) { } 88 100 89 101 GameState* getActiveChild() { return this->activeChild_; } 102 bool hasScheduledTransition() { return this->scheduledTransition_; } 90 103 91 104 private: … … 102 115 bool bPauseParent_; 103 116 104 bool bActive_; 105 bool bSuspended_; 117 Operations operation_; 106 118 107 119 GameState* parent_; 108 120 GameState* activeChild_; 121 GameState* scheduledTransition_; 109 122 std::map<std::string, GameState*> allChildren_; 110 123 std::map<GameState*, GameState*> grandchildrenToChildren_; -
code/branches/gui/src/core/Script.cc
r1638 r1670 198 198 for (std::map<unsigned int, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it) 199 199 { 200 if ( (*it).second == expectedValue)200 if (it->second == expectedValue) 201 201 expectedValue = !expectedValue; 202 202 else -
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.