Changeset 1662 for code/branches/gui/src/orxonox/gamestates
- Timestamp:
- Aug 19, 2008, 8:12:15 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox/gamestates
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r1661 r1662 33 33 #include "core/input/InputManager.h" 34 34 #include "core/input/SimpleInputState.h" 35 #include "core/input/KeyBinder.h"36 #include "overlays/console/InGameConsole.h"37 35 #include "gui/GUIManager.h" 38 36 -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r1661 r1662 35 35 #include <OgreWindowEventUtilities.h> 36 36 37 #include "core/ConsoleCommand.h" 38 #include "core/ConfigValueIncludes.h" 37 39 #include "core/input/InputManager.h" 38 #include "core/input/SimpleInputState.h"39 #include "core/input/KeyBinder.h"40 40 #include "core/Core.h" 41 42 #include "GraphicsEngine.h"43 41 #include "overlays/console/InGameConsole.h" 44 42 #include "gui/GUIManager.h" 43 #include "GraphicsEngine.h" 45 44 46 45 namespace orxonox … … 88 87 guiManager_ = new GUIManager(); 89 88 guiManager_->initialise(); 89 90 // use the ogre timer class to measure time. 91 timer_ = new Ogre::Timer(); 92 93 // add console commands 94 FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::exitGame); 95 functor->setObject(this); 96 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit")); 90 97 } 91 98 92 99 void GSGraphics::leave() 93 100 { 94 if (this->guiManager_) 95 delete guiManager_; 96 97 if (this->console_) 98 delete this->console_; 99 100 if (inputManager_) 101 delete inputManager_; 102 103 // TODO: deintialise graphics 104 } 105 101 delete this->timer_; 102 103 delete this->guiManager_; 104 105 delete this->console_; 106 107 delete this->inputManager_; 108 109 // TODO: destroy render window 110 } 111 112 /** 113 Main loop of the orxonox game. 114 We use the Ogre::Timer to measure time since it uses the most precise 115 method an a platform (however the windows timer lacks time when under 116 heavy kernel load!). 117 There is a simple mechanism to measure the average time spent in our 118 ticks as it may indicate performance issues. 119 A note about the Ogre::FrameListener: Even though we don't use them, 120 they still get called. However, the delta times are not correct (except 121 for timeSinceLastFrame, which is the most important). A little research 122 as shown that there is probably only one FrameListener that doesn't even 123 need the time. So we shouldn't run into problems. 124 */ 106 125 bool GSGraphics::tick(float dt) 107 126 { 127 // note: paramter 'dt' is of no meaning 128 108 129 Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); 109 110 // use the ogre timer class to measure time.111 if (!timer_)112 timer_ = new Ogre::Timer();113 130 114 131 unsigned long frameCount = 0; … … 146 163 this->getActiveChild()->tick(dt); 147 164 165 // tick console 166 this->console_->tick(dt); 167 148 168 // get current time once again 149 169 timeAfterTick = timer_->getMicroseconds(); -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r1661 r1662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include <OgrePrerequisites.h> 33 34 #include "core/GameState.h" 35 #include "core/OrxonoxClass.h" 34 36 35 37 namespace orxonox … … 43 45 bool tick(float dt); 44 46 void setConfigValues(); 47 48 void exitGame() { this->bAbort_ = true; } 45 49 46 50 private: -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r1661 r1662 23 23 * Reto Grieder 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 30 30 #include "GSLevel.h" 31 31 32 #include "GraphicsEngine.h"33 32 #include "core/ConsoleCommand.h" 34 33 #include "core/input/InputManager.h" 35 34 #include "core/input/SimpleInputState.h" 36 35 #include "core/input/KeyBinder.h" 36 #include "core/Loader.h" 37 37 #include "overlays/console/InGameConsole.h" 38 38 #include "gui/GUIManager.h" 39 #include "objects/Backlight.h" 40 #include "tools/ParticleInterface.h" 41 #include "Radar.h" 42 #include "Settings.h" 43 #include "GraphicsEngine.h" 39 44 40 45 namespace orxonox … … 43 48 : GameState("level") 44 49 , timefactor_(1.0f) 50 , keyBinder_(0) 51 , radar_(0) 52 , startLevel_(0) 53 , hud_(0) 45 54 { 46 55 } … … 52 61 void GSLevel::enter() 53 62 { 54 KeyBinder* keyBinder = new KeyBinder(); 55 keyBinder->loadBindings(); 56 InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder); 63 keyBinder_ = new KeyBinder(); 64 keyBinder_->loadBindings(); 65 InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder_); 66 67 // create Ogre SceneManager for the level 68 GraphicsEngine::getInstance().createNewScene(); 69 70 // Start the Radar 71 this->radar_ = new Radar(); 72 73 // Load the HUD 74 COUT(3) << "Orxonox: Loading HUD" << std::endl; 75 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 76 Loader::load(hud_); 77 78 // call the loader 79 COUT(0) << "Loading level..." << std::endl; 80 startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw"); 81 Loader::open(startLevel_); 57 82 58 83 // add console commands 59 //ConsoleCommand* command = createConsoleCommand(createFunctor(&classname::function), ) 60 //CommandExecutor::addConsoleCommandShortcut(command); 84 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor); 85 functor->setObject(this); 86 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")); 87 88 // level is loaded: we can start capturing the input 89 InputManager::getInstance().requestEnterState("game"); 61 90 } 62 91 63 92 void GSLevel::leave() 64 93 { 94 InputManager::getInstance().requestLeaveState("game"); 95 96 // TODO: Remove and destroy console command 97 98 Loader::unload(startLevel_); 99 delete this->startLevel_; 100 101 Loader::unload(hud_); 102 delete this->hud_; 103 104 // this call will delete every BaseObject! 105 // But currently this will call methods of objects that exist no more 106 // The only 'memory leak' is the ParticleSpawer. They would be deleted here 107 // and call a sceneNode method that has already been destroy by the corresponding space ship. 108 //Loader::close(); 109 110 delete this->radar_; 111 112 // TODO: delete SceneManager 113 114 InputManager::getInstance().destroyState("game"); 115 delete this->keyBinder_; 65 116 } 66 117 … … 74 125 it->tick(dt * this->timefactor_); 75 126 127 // TODO: split file into server/client/standalone 76 128 // call server/client with normal dt 77 129 //if (client_g) … … 87 139 Changes the speed of Orxonox 88 140 */ 89 //void GSLevel::setTimeFactor(float factor)90 //{91 // float change = factor / Orxonox::getInstance().getTimeFactor();92 // Orxonox::getInstance().timefactor_ = factor;93 //for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)94 //it->setSpeedFactor(it->getSpeedFactor() * change);141 void GSLevel::setTimeFactor(float factor) 142 { 143 float change = factor / this->timefactor_; 144 this->timefactor_ = factor; 145 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 146 it->setSpeedFactor(it->getSpeedFactor() * change); 95 147 96 //for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)97 // it->setTimeFactor(Orxonox::getInstance().getTimeFactor());98 //}148 for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it) 149 it->setTimeFactor(timefactor_); 150 } 99 151 } -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r1661 r1662 49 49 void setTimeFactor(float factor); 50 50 51 float timefactor_; //!< A factor to change the gamespeed 51 float timefactor_; //!< A factor to change the gamespeed 52 53 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings 54 Radar* radar_; //!< represents the Radar (not the HUD part) 55 Level* startLevel_; //!< current hard coded default level 56 Level* hud_; //!< 'level' object fo the HUD 52 57 }; 53 58 } -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r1661 r1662 30 30 #include "GSRoot.h" 31 31 32 #include <cassert>33 32 #include "core/Factory.h" 34 33 #include "core/ConfigFileManager.h" … … 36 35 #include "core/ConsoleCommand.h" 37 36 #include "core/Debug.h" 38 //#include "core/Exception.h"37 #include "core/Exception.h" 39 38 #include "core/TclBind.h" 40 39 #include "core/Core.h" … … 65 64 Factory::createClassHierarchy(); 66 65 67 // TODO: config values68 //setConfigValues();69 70 66 const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath"); 71 67 assert(dataPath); … … 81 77 TclBind::getInstance().setDataPath(Settings::getDataPath()); 82 78 79 // initialise graphics engine. Doesn't load the render window yet! 83 80 graphicsEngine_ = new GraphicsEngine(); 84 81 graphicsEngine_->setup(); // creates ogre root and other essentials 85 82 83 // console commands 84 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame); 85 functor->setObject(this); 86 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame")); 86 87 } 87 88 … … 98 99 return true; 99 100 } 101 102 /** 103 @brief 104 Requests a state. 105 */ 106 void GSRoot::loadGame(const std::string& name) 107 { 108 this->requestState(name); 109 } 100 110 } -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r1661 r1662 42 42 43 43 bool tick(float dt); 44 void loadGame(const std::string& name); 44 45 45 46 private:
Note: See TracChangeset
for help on using the changeset viewer.