[Orxonox-commit 842] r3357 - branches/resource/src/orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Jul 27 13:57:29 CEST 2009


Author: rgrieder
Date: 2009-07-27 13:57:28 +0200 (Mon, 27 Jul 2009)
New Revision: 3357

Modified:
   branches/resource/src/orxonox/gamestates/GSGraphics.cc
   branches/resource/src/orxonox/gamestates/GSMainMenu.cc
Log:
Moved some GameState code from activate/deactivate to the c'tor and d'tor. This should allow for faster GS switching.
But be careful: Only load in the c'tor what you're sure is available. For instance GSLevel doesn't require graphics, it's just an option. So loading graphical stuff in in the c'tor would be fatal because at this time it is not yet clear whether there will even be graphics (GameMode::showsGraphics() will yield false!).

Modified: branches/resource/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/resource/src/orxonox/gamestates/GSGraphics.cc	2009-07-27 09:13:25 UTC (rev 3356)
+++ branches/resource/src/orxonox/gamestates/GSGraphics.cc	2009-07-27 11:57:28 UTC (rev 3357)
@@ -64,10 +64,15 @@
         , masterInputState_(0)
         , debugOverlay_(0)
     {
+        // load master key bindings
+        masterInputState_ = InputManager::getInstance().createInputState("master", true);
+        masterKeyBinder_ = new KeyBinder();
     }
 
     GSGraphics::~GSGraphics()
     {
+        InputManager::getInstance().destroyState("master");
+        delete this->masterKeyBinder_;
     }
 
     /**
@@ -91,9 +96,7 @@
         COUT(3) << "Loading Debug Overlay..." << std::endl;
         this->debugOverlay_ = new XMLFile(Core::getMediaPathString() + "overlay/debug.oxo");
         Loader::open(debugOverlay_);
-        // load master key bindings
-        masterInputState_ = InputManager::getInstance().createInputState("master", true);
-        masterKeyBinder_ = new KeyBinder();
+
         masterKeyBinder_->loadBindings("masterKeybindings.ini");
         masterInputState_->setKeyHandler(masterKeyBinder_);
 
@@ -130,10 +133,6 @@
         }
 */
 
-        masterInputState_->setHandler(0);
-        InputManager::getInstance().destroyState("master");
-        delete this->masterKeyBinder_;
-
         delete this->console_;
 
         Loader::unload(this->debugOverlay_);

Modified: branches/resource/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- branches/resource/src/orxonox/gamestates/GSMainMenu.cc	2009-07-27 09:13:25 UTC (rev 3356)
+++ branches/resource/src/orxonox/gamestates/GSMainMenu.cc	2009-07-27 11:57:28 UTC (rev 3357)
@@ -48,14 +48,6 @@
         : GameState(info)
         , inputState_(0)
     {
-    }
-
-    GSMainMenu::~GSMainMenu()
-    {
-    }
-
-    void GSMainMenu::activate()
-    {
         inputState_ = InputManager::getInstance().createInputState("mainMenu");
         inputState_->setHandler(GUIManager::getInstancePtr());
         inputState_->setJoyStickHandler(&InputHandler::EMPTY);
@@ -64,7 +56,18 @@
         this->scene_ = new Scene(0);
         // and a Camera
         this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
+    }
 
+    GSMainMenu::~GSMainMenu()
+    {
+        InputManager::getInstance().destroyState("mainMenu");
+
+        this->scene_->getSceneManager()->destroyCamera(this->camera_);
+        delete this->scene_;
+    }
+
+    void GSMainMenu::activate()
+    {
         // show main menu
         GUIManager::getInstance().showGUI("mainmenu_4");
         GUIManager::getInstance().setCamera(this->camera_);
@@ -106,12 +109,9 @@
         delete this->ambient_;
 
         InputManager::getInstance().leaveState("mainMenu");
-        InputManager::getInstance().destroyState("mainMenu");
 
         GUIManager::getInstance().setCamera(0);
         GraphicsManager::getInstance().setCamera(0);
-        this->scene_->getSceneManager()->destroyCamera(this->camera_);
-        delete this->scene_;
 
 /*
         if (this->ccStartGame_)




More information about the Orxonox-commit mailing list