[Orxonox-commit 1155] r5876 - in code/branches/core5/src: libraries/core orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Oct 4 23:08:14 CEST 2009


Author: rgrieder
Date: 2009-10-04 23:08:14 +0200 (Sun, 04 Oct 2009)
New Revision: 5876

Modified:
   code/branches/core5/src/libraries/core/Core.cc
   code/branches/core5/src/libraries/core/GraphicsManager.cc
   code/branches/core5/src/libraries/core/GraphicsManager.h
   code/branches/core5/src/orxonox/gamestates/GSGraphics.cc
   code/branches/core5/src/orxonox/gamestates/GSGraphics.h
   code/branches/core5/src/orxonox/gamestates/GSIOConsole.cc
   code/branches/core5/src/orxonox/gamestates/GSIOConsole.h
   code/branches/core5/src/orxonox/gamestates/GSLevel.cc
   code/branches/core5/src/orxonox/gamestates/GSLevel.h
   code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc
   code/branches/core5/src/orxonox/gamestates/GSMainMenu.h
   code/branches/core5/src/orxonox/gamestates/GSRoot.cc
   code/branches/core5/src/orxonox/gamestates/GSRoot.h
Log:
Cleanup in the GameStates (also moved debug overlay to the GraphicsManager).

Modified: code/branches/core5/src/libraries/core/Core.cc
===================================================================
--- code/branches/core5/src/libraries/core/Core.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/libraries/core/Core.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -288,13 +288,16 @@
         // Calls the InputManager which sets up the input devices.
         inputManager_.reset(new InputManager());
 
-        // load the CEGUI interface
+        // Load the CEGUI interface
         guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
             inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
 
         bGraphicsLoaded_ = true;
         GameMode::bShowsGraphics_s = true;
 
+        // Load some sort of a debug overlay (only denoted by its name, "debug.oxo")
+        graphicsManager_->loadDebugOverlay();
+
         // Create singletons associated with graphics (in other libraries)
         graphicsScope_.reset(new Scope<ScopeID::Graphics>());
 

Modified: code/branches/core5/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/branches/core5/src/libraries/core/GraphicsManager.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/libraries/core/GraphicsManager.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -129,6 +129,8 @@
     */
     GraphicsManager::~GraphicsManager()
     {
+        Loader::unload(debugOverlay_.get());
+
         Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
         // TODO: Destroy the console command
 
@@ -321,6 +323,22 @@
         CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     }
 
+    void GraphicsManager::loadDebugOverlay()
+    {
+        // Load debug overlay to show info about fps and tick time
+        COUT(4) << "Loading Debug Overlay..." << std::endl;
+        debugOverlay_.reset(new XMLFile("debug.oxo"));
+        Loader::open(debugOverlay_.get());
+    }
+
+    /**
+    @note
+        A note about the Ogre::FrameListener: Even though we don't use them,
+        they still get called. However, the delta times are not correct (except
+        for timeSinceLastFrame, which is the most important). A little research
+        as shown that there is probably only one FrameListener that doesn't even
+        need the time. So we shouldn't run into problems.
+    */
     void GraphicsManager::update(const Clock& time)
     {
         Ogre::FrameEvent evt;

Modified: code/branches/core5/src/libraries/core/GraphicsManager.h
===================================================================
--- code/branches/core5/src/libraries/core/GraphicsManager.h	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/libraries/core/GraphicsManager.h	2009-10-04 21:08:14 UTC (rev 5876)
@@ -70,6 +70,7 @@
         bool isFullScreen() const;
 
         void upgradeToGraphics();
+        void loadDebugOverlay();
         bool rendererLoaded() const { return renderWindow_ != NULL; }
 
         void setCamera(Ogre::Camera* camera);
@@ -98,9 +99,10 @@
         Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
         Ogre::Viewport*     viewport_;                 //!< default full size viewport
 
-        // XML files for the resources
+        // XML files for the resources and the debug overlay
         shared_ptr<XMLFile> resources_;                //!< XML with resource locations
         shared_ptr<XMLFile> extResources_;             //!< XML with resource locations in the external path (only for dev runs)
+        shared_ptr<XMLFile> debugOverlay_;             //!< XML with various debug overlays
 
         // config values
         std::string         ogreConfigFile_;           //!< ogre config file name

Modified: code/branches/core5/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSGraphics.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSGraphics.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -34,15 +34,10 @@
 
 #include "GSGraphics.h"
 
-#include "util/Clock.h"
-#include "util/Convert.h"
 #include "core/CommandExecutor.h"
 #include "core/ConsoleCommand.h"
 #include "core/Game.h"
 #include "core/GUIManager.h"
-#include "core/Loader.h"
-#include "core/XMLFile.h"
-
 // HACK:
 #include "overlays/Map.h"
 
@@ -52,7 +47,6 @@
 
     GSGraphics::GSGraphics(const GameStateInfo& info)
         : GameState(info)
-        , debugOverlay_(0)
     {
     }
 
@@ -64,48 +58,21 @@
     @brief
         This function is called when we enter this game state.
 
-        Since graphics is very important for our game this function does quite a lot:
-        \li starts graphics manager
-        \li loads debug overlay
-        \li manages render window
-        \li creates input manager
-        \li loads master key bindings
-        \li loads the SoundManager
-        \li loads ingame console
-        \li loads GUI interface (GUIManager)
-        \li creates console command to toggle GUI
+        There is only one thing to do here:
+        \li create console command to toggle GUI
     */
     void GSGraphics::activate()
     {
-        // load debug overlay
-        COUT(3) << "Loading Debug Overlay..." << std::endl;
-        this->debugOverlay_ = new XMLFile("debug.oxo");
-        Loader::open(debugOverlay_);
-
         // add console command to toggle GUI
-        this->ccToggleGUI_ = createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI");
-        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
     }
 
     /**
     @brief
         This function is called when the game state is left
-
-        Created references, input states and console commands are deleted.
     */
     void GSGraphics::deactivate()
     {
-/*
-        if (this->ccToggleGUI_)
-        {
-            delete this->ccToggleGUI_;
-            this->ccToggleGUI_ = 0;
-        }
-*/
-
-        Loader::unload(this->debugOverlay_);
-        delete this->debugOverlay_;
-
         // HACK: (destroys a resource smart pointer)
         Map::hackDestroyMap();
     }
@@ -122,14 +89,6 @@
         GUIManager::getInstance().executeCode("toggleGUI()");
     }
 
-    /**
-    @note
-        A note about the Ogre::FrameListener: Even though we don't use them,
-        they still get called. However, the delta times are not correct (except
-        for timeSinceLastFrame, which is the most important). A little research
-        as shown that there is probably only one FrameListener that doesn't even
-        need the time. So we shouldn't run into problems.
-    */
     void GSGraphics::update(const Clock& time)
     {
         if (this->getActivity().topState)

Modified: code/branches/core5/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSGraphics.h	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSGraphics.h	2009-10-04 21:08:14 UTC (rev 5876)
@@ -59,8 +59,6 @@
         void toggleGUI();
 
     private:
-        XMLFile*              debugOverlay_;
-        ConsoleCommand*       ccToggleGUI_;         //!< Console command to toggle GUI
     };
 }
 

Modified: code/branches/core5/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSIOConsole.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSIOConsole.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -29,8 +29,8 @@
 #include "GSIOConsole.h"
 
 #include <iostream>
-
 #include "core/ConsoleCommand.h"
+#include "core/CommandExecutor.h"
 #include "core/Game.h"
 
 namespace orxonox
@@ -48,21 +48,11 @@
 
     void GSIOConsole::activate()
     {
-        {
-            this->ccLoadMenu_ = createConsoleCommand(createFunctor(&GSIOConsole::loadMenu, this), "loadMenu");
-            CommandExecutor::addConsoleCommandShortcut(this->ccLoadMenu_);
-        }
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSIOConsole::loadMenu, this), "loadMenu"));
     }
 
     void GSIOConsole::deactivate()
     {
-/*
-        if (this->ccLoadMenu_)
-        {
-            delete this->ccLoadMenu_;
-            this->ccLoadMenu_ = 0;
-        }
-*/
     }
 
     void GSIOConsole::update(const Clock& time)

Modified: code/branches/core5/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSIOConsole.h	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSIOConsole.h	2009-10-04 21:08:14 UTC (rev 5876)
@@ -46,9 +46,6 @@
 
     private:
         void loadMenu();
-
-        // console commands
-        ConsoleCommand* ccLoadMenu_;
     };
 }
 

Modified: code/branches/core5/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSLevel.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSLevel.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -36,8 +36,6 @@
 #include "core/input/InputState.h"
 #include "core/input/KeyBinderManager.h"
 #include "core/ConsoleCommand.h"
-#include "core/ConfigValueIncludes.h"
-#include "core/CoreIncludes.h"
 #include "core/Game.h"
 #include "core/GameMode.h"
 #include "core/GUIManager.h"
@@ -50,31 +48,22 @@
 namespace orxonox
 {
     DeclareGameState(GSLevel, "level", false, false);
-    SetConsoleCommand(GSLevel, showIngameGUI, true);
 
-    XMLFile* GSLevel::startFile_s = NULL;
-
     GSLevel::GSLevel(const GameStateInfo& info)
         : GameState(info)
         , gameInputState_(0)
         , guiMouseOnlyInputState_(0)
         , guiKeysOnlyInputState_(0)
+        , startFile_(0)
     {
-        RegisterObject(GSLevel);
     }
 
     GSLevel::~GSLevel()
     {
     }
 
-    void GSLevel::setConfigValues()
-    {
-    }
-
     void GSLevel::activate()
     {
-        setConfigValues();
-
         if (GameMode::showsGraphics())
         {
             gameInputState_ = InputManager::getInstance().createInputState("game");
@@ -86,6 +75,8 @@
 
             guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
             guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
+
+            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
         }
 
         if (GameMode::isMaster())
@@ -128,16 +119,7 @@
             
             // unload all compositors (this is only necessary because we don't yet destroy all resources!)
             Ogre::CompositorManager::getSingleton().removeAll();
-        }
 
-        // this call will delete every BaseObject!
-        // But currently this will call methods of objects that exist no more
-        // The only 'memory leak' is the ParticleSpawer. They would be deleted here
-        // and call a sceneNode method that has already been destroy by the corresponding space ship.
-        //Loader::close();
-
-        if (GameMode::showsGraphics())
-        {
             InputManager::getInstance().leaveState("game");
         }
 
@@ -157,7 +139,7 @@
 
     void GSLevel::update(const Clock& time)
     {
-        // Note: Temporarily moved to GSGraphics.
+        // Note: Temporarily moved to GSRoot.
         //// Call the scene objects
         //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
         //    it->tick(time.getDeltaTime() * this->timeFactor_);
@@ -167,14 +149,13 @@
     {
         // call the loader
         COUT(0) << "Loading level..." << std::endl;
-        startFile_s = new XMLFile(LevelManager::getInstance().getDefaultLevel());
-        Loader::open(startFile_s);
+        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
+        Loader::open(startFile_);
     }
 
     void GSLevel::unloadLevel()
     {
-        Loader::unload(startFile_s);
-
-        delete startFile_s;
+        Loader::unload(startFile_);
+        delete startFile_;
     }
 }

Modified: code/branches/core5/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSLevel.h	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSLevel.h	2009-10-04 21:08:14 UTC (rev 5876)
@@ -37,28 +37,26 @@
 
 namespace orxonox
 {
-    class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass
+    class _OrxonoxExport GSLevel : public GameState
     {
     public:
         GSLevel(const GameStateInfo& info);
         ~GSLevel();
-        void setConfigValues();
 
         void activate();
         void deactivate();
         void update(const Clock& time);
 
-        static void showIngameGUI(bool show);
-
-        static XMLFile* startFile_s;
-
     protected:
         void loadLevel();
         void unloadLevel();
+        void showIngameGUI(bool show);
 
         InputState*              gameInputState_;          //!< input state for normal ingame playing
         InputState*              guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
         InputState*              guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
+
+        XMLFile* startFile_;
     };
 }
 

Modified: code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -30,7 +30,6 @@
 
 #include <OgreSceneManager.h>
 
-#include "util/Clock.h"
 #include "core/input/InputManager.h"
 #include "core/input/InputState.h"
 #include "core/input/KeyBinderManager.h"
@@ -56,9 +55,11 @@
         inputState_->setIsExclusiveMouse(false);
 
         // create an empty Scene
-        this->scene_ = new Scene(0);
+        this->scene_ = new Scene(NULL);
         // and a Camera
         this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
+        // Load sound
+        this->ambient_ = new SoundMainMenu();
     }
 
     GSMainMenu::~GSMainMenu()
@@ -76,40 +77,26 @@
         GUIManager::getInstance().setCamera(this->camera_);
         GraphicsManager::getInstance().setCamera(this->camera_);
 
-        this->ccStartStandalone_ = createConsoleCommand(createFunctor(&GSMainMenu::startStandalone, this), "startGame");
-        CommandExecutor::addConsoleCommandShortcut(this->ccStartStandalone_);
-        this->ccStartServer_ = createConsoleCommand(createFunctor(&GSMainMenu::startServer, this), "startServer");
-        CommandExecutor::addConsoleCommandShortcut(this->ccStartServer_);
-        this->ccStartClient_ = createConsoleCommand(createFunctor(&GSMainMenu::startClient, this), "startClient");
-        CommandExecutor::addConsoleCommandShortcut(this->ccStartClient_);
-        this->ccStartDedicated_ = createConsoleCommand(createFunctor(&GSMainMenu::startDedicated, this), "startDedicated");
-        CommandExecutor::addConsoleCommandShortcut(this->ccStartDedicated_);
-        this->ccStartMainMenu_ = createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu, this), "startMainMenu");
-        CommandExecutor::addConsoleCommandShortcut(this->ccStartMainMenu_);
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone, this), "startGame"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startServer, this), "startServer"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startClient, this), "startClient"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated, this), "startDedicated"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu, this), "startMainMenu"));
 
         KeyBinderManager::getInstance().setToDefault();
         InputManager::getInstance().enterState("mainMenu");
 
-        this->ambient_ = new SoundMainMenu();
         this->ambient_->play(true);
     }
 
     void GSMainMenu::deactivate()
     {
-        this->ambient_->destroy();
+        this->ambient_->stop();
 
         InputManager::getInstance().leaveState("mainMenu");
 
         GUIManager::getInstance().setCamera(0);
         GraphicsManager::getInstance().setCamera(0);
-
-/*
-        if (this->ccStartGame_)
-        {
-            delete this->ccStartGame_;
-            this->ccStartGame_ = 0;
-        }
-*/
     }
 
     void GSMainMenu::update(const Clock& time)

Modified: code/branches/core5/src/orxonox/gamestates/GSMainMenu.h
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSMainMenu.h	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSMainMenu.h	2009-10-04 21:08:14 UTC (rev 5876)
@@ -57,13 +57,6 @@
         Scene*            scene_;
         Ogre::Camera*     camera_;
 
-        // console commands
-        ConsoleCommand* ccStartStandalone_;
-        ConsoleCommand* ccStartServer_;
-        ConsoleCommand* ccStartClient_;
-        ConsoleCommand* ccStartDedicated_;
-        ConsoleCommand* ccStartMainMenu_;
-
         // ambient sound for the main menu
         SoundMainMenu* ambient_;
     };

Modified: code/branches/core5/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSRoot.cc	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSRoot.cc	2009-10-04 21:08:14 UTC (rev 5876)
@@ -47,8 +47,6 @@
         , bPaused_(false)
         , timeFactorPauseBackup_(1.0f)
     {
-        this->ccSetTimeFactor_ = 0;
-        this->ccPause_ = 0;
     }
 
     GSRoot::~GSRoot()
@@ -62,29 +60,16 @@
         this->timeFactor_ = 1.0f;
 
         // time factor console command
-        this->ccSetTimeFactor_ = createConsoleCommand(createFunctor(&GSRoot::setTimeFactor, this), "setTimeFactor");
-        CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
+        ConsoleCommand* command = createConsoleCommand(createFunctor(&GSRoot::setTimeFactor, this), "setTimeFactor");
+        CommandExecutor::addConsoleCommandShortcut(command).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
 
         // time factor console command
-        this->ccPause_ = createConsoleCommand(createFunctor(&GSRoot::pause, this), "pause");
-        CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
+        command = createConsoleCommand(createFunctor(&GSRoot::pause, this), "pause");
+        CommandExecutor::addConsoleCommandShortcut(command).accessLevel(AccessLevel::Offline);
     }
 
     void GSRoot::deactivate()
     {
-/*
-        if (this->ccSetTimeFactor_)
-        {
-            delete this->ccSetTimeFactor_;
-            this->ccSetTimeFactor_ = 0;
-        }
-
-        if (this->ccPause_)
-        {
-            delete this->ccPause_;
-            this->ccPause_ = 0;
-        }
-*/
     }
 
     void GSRoot::update(const Clock& time)

Modified: code/branches/core5/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/core5/src/orxonox/gamestates/GSRoot.h	2009-10-04 21:05:17 UTC (rev 5875)
+++ code/branches/core5/src/orxonox/gamestates/GSRoot.h	2009-10-04 21:08:14 UTC (rev 5876)
@@ -54,10 +54,6 @@
         float                 timeFactor_;              //!< A factor that sets the gamespeed. 1 is normal.
         bool                  bPaused_;
         float                 timeFactorPauseBackup_;
-
-        // console commands
-        ConsoleCommand*       ccSetTimeFactor_;
-        ConsoleCommand*       ccPause_;
     };
 }
 




More information about the Orxonox-commit mailing list