Changeset 1670 for code/branches/gui/src/orxonox/gamestates
- Timestamp:
- Aug 26, 2008, 4:26:04 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox/gamestates
- Files:
-
- 10 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.