Changeset 1670
- Timestamp:
- Aug 26, 2008, 4:26:04 PM (16 years ago)
- Location:
- code/branches/gui
- Files:
-
- 10 added
- 24 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_; -
code/branches/gui/src/orxonox/Main.cc
r1664 r1670 44 44 #include "gamestates/GSRoot.h" 45 45 #include "gamestates/GSGraphics.h" 46 #include "gamestates/GSLevel.h" 46 #include "gamestates/GSStandalone.h" 47 #include "gamestates/GSServer.h" 48 #include "gamestates/GSClient.h" 47 49 #include "gamestates/GSGUI.h" 50 #include "gamestates/GSIO.h" 51 #include "gamestates/GSIOConsole.h" 48 52 49 53 using namespace orxonox; … … 77 81 78 82 79 #ifdef __cplusplus80 extern "C" {81 #endif83 //#ifdef __cplusplus 84 //extern "C" { 85 //#endif 82 86 83 87 int main(int argc, char** argv) … … 122 126 GSRoot root; 123 127 GSGraphics graphics; 124 GSLevel level; 128 GSStandalone standalone; 129 GSServer server; 130 GSClient client; 125 131 GSGUI gui; 132 GSIO io; 133 GSIOConsole ioConsole; 126 134 127 135 root.addChild(&graphics); 128 graphics.addChild(&level); 136 graphics.addChild(&standalone); 137 graphics.addChild(&server); 138 graphics.addChild(&client); 129 139 graphics.addChild(&gui); 130 140 141 root.addChild(&io); 142 io.addChild(&ioConsole); 143 131 144 root.feedCommandLine(argc, argv); 132 root.requestState(" root");133 root.tick(0.0f);134 root.requestState("");145 root.requestState("ioConsole"); 146 while (!root.isGameFinished()) 147 root.tick(0.0f); 135 148 136 149 return 0; 137 150 } 138 151 139 #ifdef __cplusplus140 }141 #endif152 //#ifdef __cplusplus 153 //} 154 //#endif -
code/branches/gui/src/orxonox/Orxonox.cc
r1663 r1670 424 424 425 425 // tick the core (needs real time for input and tcl thread management) 426 Core::tick(dt);426 //Core::tick(dt); 427 427 428 428 // Call those objects that need the real time -
code/branches/gui/src/orxonox/OrxonoxStableHeaders.h
r1638 r1670 49 49 #include <CEGUI.h> 50 50 #include <boost/thread/recursive_mutex.hpp> 51 #include <boost/thread/mutex.hpp> 52 #include <boost/thread/condition.hpp> 53 #include <boost/thread/thread.hpp> 51 54 52 55 //----------------------------------------------------------------------- -
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r1662 r1670 58 58 } 59 59 60 bool GSGUI::tick(float dt)60 void GSGUI::ticked(float dt) 61 61 { 62 62 // tick CEGUI 63 63 GUIManager::getInstance().tick(dt); 64 64 65 return true;65 this->tickChild(dt); 66 66 } 67 67 } -
code/branches/gui/src/orxonox/gamestates/GSGUI.h
r1661 r1670 44 44 void enter(); 45 45 void leave(); 46 bool tick(float dt);46 void ticked(float dt); 47 47 48 48 }; -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r1662 r1670 38 38 #include "core/ConfigValueIncludes.h" 39 39 #include "core/input/InputManager.h" 40 #include "core/Core.h" 40 #include "core/TclThreadManager.h" 41 //#include "core/Core.h" 41 42 #include "overlays/console/InGameConsole.h" 42 43 #include "gui/GUIManager.h" … … 48 49 : GameState("graphics") 49 50 , timer_(0) 50 , bAbort_(false)51 51 , debugRefreshTime_(0.0f) 52 52 , inputManager_(0) … … 90 90 // use the ogre timer class to measure time. 91 91 timer_ = new Ogre::Timer(); 92 93 // add console commands94 FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::exitGame);95 functor->setObject(this);96 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));97 92 } 98 93 … … 123 118 need the time. So we shouldn't run into problems. 124 119 */ 125 bool GSGraphics::tick(float dt)120 void GSGraphics::ticked(float dt) 126 121 { 127 122 // note: paramter 'dt' is of no meaning … … 147 142 { 148 143 timer_->reset(); 149 while (! bAbort_)144 while (!this->hasScheduledTransition()) 150 145 { 151 146 // get current time … … 154 149 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 155 150 156 157 // tick the core (needs real time for input and tcl thread management) 158 // TODO: ticks of InputManager and tcl thread manager have to be separated. 159 Core::tick(dt); 160 161 // tick child state 162 if (this->getActiveChild()) 163 this->getActiveChild()->tick(dt); 151 this->inputManager_->tick(dt); 152 TclThreadManager::getInstance().tick(dt); 153 154 this->tickChild(dt); 164 155 165 156 // tick console … … 210 201 COUT(1) << ex.what() << std::endl; 211 202 COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl; 212 } return true;203 } 213 204 } 214 205 } -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r1662 r1670 43 43 ~GSGraphics(); 44 44 45 bool tick(float dt);46 45 void setConfigValues(); 47 48 void exitGame() { this->bAbort_ = true; }49 46 50 47 private: 51 48 void enter(); 52 49 void leave(); 50 void ticked(float dt); 53 51 54 52 Ogre::Timer* timer_; //!< Main loop timer 55 bool bAbort_; //!< aborts the render loop if true56 53 57 54 // config values -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r1664 r1670 30 30 #include "GSLevel.h" 31 31 32 #include "core/ConsoleCommand.h"33 32 #include "core/input/InputManager.h" 34 33 #include "core/input/SimpleInputState.h" 35 34 #include "core/input/KeyBinder.h" 36 35 #include "core/Loader.h" 37 #include "core/CommandLine.h"38 #include "overlays/console/InGameConsole.h"39 #include "gui/GUIManager.h"40 36 #include "objects/Backlight.h" 41 37 #include "tools/ParticleInterface.h" 38 #include "Settings.h" 42 39 #include "Radar.h" 43 #include "Settings.h"44 40 #include "GraphicsEngine.h" 45 41 46 42 namespace orxonox 47 43 { 48 SetCommandLineArgument(port, 55556).setShortcut("p").setInformation("PORT"); 49 SetCommandLineArgument(ip, "127.0.0.0").setInformation("#.#.#.#"); 50 51 GSLevel::GSLevel() 52 : GameState("level") 44 GSLevel::GSLevel(const std::string& name) 45 : GameState(name) 53 46 , timefactor_(1.0f) 54 47 , keyBinder_(0) 48 , inputState_(0) 55 49 , radar_(0) 56 50 , startLevel_(0) … … 65 59 void GSLevel::enter() 66 60 { 61 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 67 62 keyBinder_ = new KeyBinder(); 68 63 keyBinder_->loadBindings(); 69 InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder_);64 inputState_->setHandler(keyBinder_); 70 65 71 66 // create Ogre SceneManager for the level … … 79 74 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 80 75 Loader::load(hud_); 81 82 // call the loader83 COUT(0) << "Loading level..." << std::endl;84 startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");85 Loader::open(startLevel_);86 87 // add console commands88 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);89 functor->setObject(this);90 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));91 92 // level is loaded: we can start capturing the input93 InputManager::getInstance().requestEnterState("game");94 76 } 95 77 96 78 void GSLevel::leave() 97 79 { 98 InputManager::getInstance().requestLeaveState("game");99 100 // TODO: Remove and destroy console command101 102 Loader::unload(startLevel_);103 delete this->startLevel_;104 105 80 Loader::unload(hud_); 106 81 delete this->hud_; … … 116 91 // TODO: delete SceneManager 117 92 118 InputManager::getInstance().destroyState("game"); 93 inputState_->setHandler(0); 94 InputManager::getInstance().requestDestroyState("game"); 119 95 delete this->keyBinder_; 120 96 } 121 97 122 bool GSLevel::tick(float dt)98 void GSLevel::ticked(float dt) 123 99 { 124 100 // Call those objects that need the real time … … 128 104 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 129 105 it->tick(dt * this->timefactor_); 130 131 // TODO: split file into server/client/standalone132 // call server/client with normal dt133 //if (client_g)134 // client_g->tick(dt * this->timefactor_);135 //if (server_g)136 // server_g->tick(dt * this->timefactor_);137 138 return true;139 106 } 140 107 … … 153 120 it->setTimeFactor(timefactor_); 154 121 } 122 123 void GSLevel::loadLevel() 124 { 125 // call the loader 126 COUT(0) << "Loading level..." << std::endl; 127 startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw"); 128 Loader::open(startLevel_); 129 } 130 131 void GSLevel::unloadLevel() 132 { 133 Loader::unload(startLevel_); 134 delete this->startLevel_; 135 } 155 136 } -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r1662 r1670 38 38 { 39 39 public: 40 GSLevel( );41 ~GSLevel();40 GSLevel(const std::string& name); 41 virtual ~GSLevel(); 42 42 43 bool tick(float dt); 43 // this has to be public because proteced triggers a bug in msvc 44 // when taking the function address. 45 void setTimeFactor(float factor); 46 float getTimeFactor() { return this->timefactor_; } 47 48 protected: 49 virtual void enter(); 50 virtual void leave(); 51 virtual void ticked(float dt); 52 53 void loadLevel(); 54 void unloadLevel(); 44 55 45 56 private: 46 void enter();47 void leave();48 49 void setTimeFactor(float factor);50 57 51 58 float timefactor_; //!< A factor to change the gamespeed 52 59 53 60 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings 61 SimpleInputState* inputState_; 54 62 Radar* radar_; //!< represents the Radar (not the HUD part) 55 63 Level* startLevel_; //!< current hard coded default level -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r1664 r1670 52 52 , settings_(0) 53 53 , graphicsEngine_(0) 54 , bExit_(false) 54 55 { 55 56 } … … 101 102 102 103 std::string dataPath; 103 CommandLine::get CommandLineValue("dataPath", &dataPath);104 CommandLine::getValue("dataPath", &dataPath); 104 105 if (dataPath != "") 105 106 { … … 122 123 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame")); 123 124 124 requestState("gui"); 125 // add console commands 126 functor = createFunctor(&GSRoot::exitGame); 127 functor->setObject(this); 128 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit")); 125 129 } 126 130 … … 128 132 { 129 133 delete graphicsEngine_; 134 delete settings_; 130 135 131 delete settings_;136 // TODO: remove and destroy console commands 132 137 } 133 138 134 bool GSRoot::tick(float dt)139 void GSRoot::ticked(float dt) 135 140 { 136 if (this->getActiveChild()) 137 this->getActiveChild()->tick(dt); 138 return true; 141 this->tickChild(dt); 139 142 } 140 143 -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r1664 r1670 42 42 43 43 void feedCommandLine(int argc, char** argv); 44 bool tick(float dt);45 44 void loadGame(const std::string& name); 45 46 void exitGame() 47 { requestState("root"); } 48 bool isGameFinished() { return (this->getActiveChild() == 0); } 46 49 47 50 private: 48 51 void enter(); 49 52 void leave(); 53 void ticked(float dt); 50 54 51 55 Settings* settings_; 52 56 GraphicsEngine* graphicsEngine_; //!< our dearest graphics engine <3 57 bool bExit_; 53 58 }; 54 59 } -
code/branches/gui/src/orxonox/gui/GUIManager.cc
r1662 r1670 92 92 } 93 93 94 InputManager::getInstance(). destroyState("gui");94 InputManager::getInstance().requestDestroyState("gui"); 95 95 96 96 if (guiSystem_) -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
r1653 r1670 95 95 96 96 // destroy the input state previously created (InputBuffer gets destroyed by the Shell) 97 InputManager::getInstance(). destroyState("console");97 InputManager::getInstance().requestDestroyState("console"); 98 98 99 99 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); -
code/branches/gui/visual_studio/vc8/core.vcproj
r1663 r1670 149 149 > 150 150 <File 151 RelativePath="..\..\src\core\BaseGameState.cc" 152 > 153 </File> 154 <File 151 155 RelativePath="..\..\src\core\ConfigFileManager.cc" 152 156 > … … 376 380 > 377 381 <File 382 RelativePath="..\..\src\core\BaseGameState.h" 383 > 384 </File> 385 <File 378 386 RelativePath="..\..\src\core\ConfigFileManager.h" 379 387 > -
code/branches/gui/visual_studio/vc8/orxonox.vcproj
r1661 r1670 496 496 > 497 497 <File 498 RelativePath="..\..\src\orxonox\gamestates\GSClient.cc" 499 > 500 </File> 501 <File 498 502 RelativePath="..\..\src\orxonox\gamestates\GSGraphics.cc" 499 503 > … … 504 508 </File> 505 509 <File 510 RelativePath="..\..\src\orxonox\gamestates\GSIO.cc" 511 > 512 </File> 513 <File 514 RelativePath="..\..\src\orxonox\gamestates\GSIOConsole.cc" 515 > 516 </File> 517 <File 506 518 RelativePath="..\..\src\orxonox\gamestates\GSLevel.cc" 507 519 > … … 509 521 <File 510 522 RelativePath="..\..\src\orxonox\gamestates\GSRoot.cc" 523 > 524 </File> 525 <File 526 RelativePath="..\..\src\orxonox\gamestates\GSServer.cc" 527 > 528 </File> 529 <File 530 RelativePath="..\..\src\orxonox\gamestates\GSStandalone.cc" 511 531 > 512 532 </File> … … 738 758 > 739 759 <File 760 RelativePath="..\..\src\orxonox\gamestates\GSClient.h" 761 > 762 </File> 763 <File 740 764 RelativePath="..\..\src\orxonox\gamestates\GSGraphics.h" 741 765 > … … 746 770 </File> 747 771 <File 772 RelativePath="..\..\src\orxonox\gamestates\GSIO.h" 773 > 774 </File> 775 <File 776 RelativePath="..\..\src\orxonox\gamestates\GSIOConsole.h" 777 > 778 </File> 779 <File 748 780 RelativePath="..\..\src\orxonox\gamestates\GSLevel.h" 749 781 > … … 751 783 <File 752 784 RelativePath="..\..\src\orxonox\gamestates\GSRoot.h" 785 > 786 </File> 787 <File 788 RelativePath="..\..\src\orxonox\gamestates\GSServer.h" 789 > 790 </File> 791 <File 792 RelativePath="..\..\src\orxonox\gamestates\GSStandalone.h" 753 793 > 754 794 </File>
Note: See TracChangeset
for help on using the changeset viewer.