Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2009, 11:08:14 PM (15 years ago)
Author:
rgrieder
Message:

Cleanup in the GameStates (also moved debug overlay to the GraphicsManager).

Location:
code/branches/core5/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/Core.cc

    r5875 r5876  
    289289        inputManager_.reset(new InputManager());
    290290
    291         // load the CEGUI interface
     291        // Load the CEGUI interface
    292292        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
    293293            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
     
    295295        bGraphicsLoaded_ = true;
    296296        GameMode::bShowsGraphics_s = true;
     297
     298        // Load some sort of a debug overlay (only denoted by its name, "debug.oxo")
     299        graphicsManager_->loadDebugOverlay();
    297300
    298301        // Create singletons associated with graphics (in other libraries)
  • code/branches/core5/src/libraries/core/GraphicsManager.cc

    r5855 r5876  
    130130    GraphicsManager::~GraphicsManager()
    131131    {
     132        Loader::unload(debugOverlay_.get());
     133
    132134        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
    133135        // TODO: Destroy the console command
     
    322324    }
    323325
     326    void GraphicsManager::loadDebugOverlay()
     327    {
     328        // Load debug overlay to show info about fps and tick time
     329        COUT(4) << "Loading Debug Overlay..." << std::endl;
     330        debugOverlay_.reset(new XMLFile("debug.oxo"));
     331        Loader::open(debugOverlay_.get());
     332    }
     333
     334    /**
     335    @note
     336        A note about the Ogre::FrameListener: Even though we don't use them,
     337        they still get called. However, the delta times are not correct (except
     338        for timeSinceLastFrame, which is the most important). A little research
     339        as shown that there is probably only one FrameListener that doesn't even
     340        need the time. So we shouldn't run into problems.
     341    */
    324342    void GraphicsManager::update(const Clock& time)
    325343    {
  • code/branches/core5/src/libraries/core/GraphicsManager.h

    r5738 r5876  
    7171
    7272        void upgradeToGraphics();
     73        void loadDebugOverlay();
    7374        bool rendererLoaded() const { return renderWindow_ != NULL; }
    7475
     
    99100        Ogre::Viewport*     viewport_;                 //!< default full size viewport
    100101
    101         // XML files for the resources
     102        // XML files for the resources and the debug overlay
    102103        shared_ptr<XMLFile> resources_;                //!< XML with resource locations
    103104        shared_ptr<XMLFile> extResources_;             //!< XML with resource locations in the external path (only for dev runs)
     105        shared_ptr<XMLFile> debugOverlay_;             //!< XML with various debug overlays
    104106
    105107        // config values
  • code/branches/core5/src/orxonox/gamestates/GSGraphics.cc

    r5863 r5876  
    3535#include "GSGraphics.h"
    3636
    37 #include "util/Clock.h"
    38 #include "util/Convert.h"
    3937#include "core/CommandExecutor.h"
    4038#include "core/ConsoleCommand.h"
    4139#include "core/Game.h"
    4240#include "core/GUIManager.h"
    43 #include "core/Loader.h"
    44 #include "core/XMLFile.h"
    45 
    4641// HACK:
    4742#include "overlays/Map.h"
     
    5348    GSGraphics::GSGraphics(const GameStateInfo& info)
    5449        : GameState(info)
    55         , debugOverlay_(0)
    5650    {
    5751    }
     
    6559        This function is called when we enter this game state.
    6660
    67         Since graphics is very important for our game this function does quite a lot:
    68         \li starts graphics manager
    69         \li loads debug overlay
    70         \li manages render window
    71         \li creates input manager
    72         \li loads master key bindings
    73         \li loads the SoundManager
    74         \li loads ingame console
    75         \li loads GUI interface (GUIManager)
    76         \li creates console command to toggle GUI
     61        There is only one thing to do here:
     62        \li create console command to toggle GUI
    7763    */
    7864    void GSGraphics::activate()
    7965    {
    80         // load debug overlay
    81         COUT(3) << "Loading Debug Overlay..." << std::endl;
    82         this->debugOverlay_ = new XMLFile("debug.oxo");
    83         Loader::open(debugOverlay_);
    84 
    8566        // add console command to toggle GUI
    86         this->ccToggleGUI_ = createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI");
    87         CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
     67        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
    8868    }
    8969
     
    9171    @brief
    9272        This function is called when the game state is left
    93 
    94         Created references, input states and console commands are deleted.
    9573    */
    9674    void GSGraphics::deactivate()
    9775    {
    98 /*
    99         if (this->ccToggleGUI_)
    100         {
    101             delete this->ccToggleGUI_;
    102             this->ccToggleGUI_ = 0;
    103         }
    104 */
    105 
    106         Loader::unload(this->debugOverlay_);
    107         delete this->debugOverlay_;
    108 
    10976        // HACK: (destroys a resource smart pointer)
    11077        Map::hackDestroyMap();
     
    12390    }
    12491
    125     /**
    126     @note
    127         A note about the Ogre::FrameListener: Even though we don't use them,
    128         they still get called. However, the delta times are not correct (except
    129         for timeSinceLastFrame, which is the most important). A little research
    130         as shown that there is probably only one FrameListener that doesn't even
    131         need the time. So we shouldn't run into problems.
    132     */
    13392    void GSGraphics::update(const Clock& time)
    13493    {
  • code/branches/core5/src/orxonox/gamestates/GSGraphics.h

    r5863 r5876  
    6060
    6161    private:
    62         XMLFile*              debugOverlay_;
    63         ConsoleCommand*       ccToggleGUI_;         //!< Console command to toggle GUI
    6462    };
    6563}
  • code/branches/core5/src/orxonox/gamestates/GSIOConsole.cc

    r5829 r5876  
    3030
    3131#include <iostream>
    32 
    3332#include "core/ConsoleCommand.h"
     33#include "core/CommandExecutor.h"
    3434#include "core/Game.h"
    3535
     
    4949    void GSIOConsole::activate()
    5050    {
    51         {
    52             this->ccLoadMenu_ = createConsoleCommand(createFunctor(&GSIOConsole::loadMenu, this), "loadMenu");
    53             CommandExecutor::addConsoleCommandShortcut(this->ccLoadMenu_);
    54         }
     51        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSIOConsole::loadMenu, this), "loadMenu"));
    5552    }
    5653
    5754    void GSIOConsole::deactivate()
    5855    {
    59 /*
    60         if (this->ccLoadMenu_)
    61         {
    62             delete this->ccLoadMenu_;
    63             this->ccLoadMenu_ = 0;
    64         }
    65 */
    6656    }
    6757
  • code/branches/core5/src/orxonox/gamestates/GSIOConsole.h

    r5842 r5876  
    4747    private:
    4848        void loadMenu();
    49 
    50         // console commands
    51         ConsoleCommand* ccLoadMenu_;
    5249    };
    5350}
  • code/branches/core5/src/orxonox/gamestates/GSLevel.cc

    r5863 r5876  
    3737#include "core/input/KeyBinderManager.h"
    3838#include "core/ConsoleCommand.h"
    39 #include "core/ConfigValueIncludes.h"
    40 #include "core/CoreIncludes.h"
    4139#include "core/Game.h"
    4240#include "core/GameMode.h"
     
    5149{
    5250    DeclareGameState(GSLevel, "level", false, false);
    53     SetConsoleCommand(GSLevel, showIngameGUI, true);
    54 
    55     XMLFile* GSLevel::startFile_s = NULL;
    5651
    5752    GSLevel::GSLevel(const GameStateInfo& info)
     
    6055        , guiMouseOnlyInputState_(0)
    6156        , guiKeysOnlyInputState_(0)
     57        , startFile_(0)
    6258    {
    63         RegisterObject(GSLevel);
    6459    }
    6560
     
    6863    }
    6964
    70     void GSLevel::setConfigValues()
    71     {
    72     }
    73 
    7465    void GSLevel::activate()
    7566    {
    76         setConfigValues();
    77 
    7867        if (GameMode::showsGraphics())
    7968        {
     
    8776            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
    8877            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
     78
     79            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
    8980        }
    9081
     
    129120            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
    130121            Ogre::CompositorManager::getSingleton().removeAll();
    131         }
    132122
    133         // this call will delete every BaseObject!
    134         // But currently this will call methods of objects that exist no more
    135         // The only 'memory leak' is the ParticleSpawer. They would be deleted here
    136         // and call a sceneNode method that has already been destroy by the corresponding space ship.
    137         //Loader::close();
    138 
    139         if (GameMode::showsGraphics())
    140         {
    141123            InputManager::getInstance().leaveState("game");
    142124        }
     
    158140    void GSLevel::update(const Clock& time)
    159141    {
    160         // Note: Temporarily moved to GSGraphics.
     142        // Note: Temporarily moved to GSRoot.
    161143        //// Call the scene objects
    162144        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
     
    168150        // call the loader
    169151        COUT(0) << "Loading level..." << std::endl;
    170         startFile_s = new XMLFile(LevelManager::getInstance().getDefaultLevel());
    171         Loader::open(startFile_s);
     152        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
     153        Loader::open(startFile_);
    172154    }
    173155
    174156    void GSLevel::unloadLevel()
    175157    {
    176         Loader::unload(startFile_s);
    177 
    178         delete startFile_s;
     158        Loader::unload(startFile_);
     159        delete startFile_;
    179160    }
    180161}
  • code/branches/core5/src/orxonox/gamestates/GSLevel.h

    r5863 r5876  
    3838namespace orxonox
    3939{
    40     class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass
     40    class _OrxonoxExport GSLevel : public GameState
    4141    {
    4242    public:
    4343        GSLevel(const GameStateInfo& info);
    4444        ~GSLevel();
    45         void setConfigValues();
    4645
    4746        void activate();
     
    4948        void update(const Clock& time);
    5049
    51         static void showIngameGUI(bool show);
    52 
    53         static XMLFile* startFile_s;
    54 
    5550    protected:
    5651        void loadLevel();
    5752        void unloadLevel();
     53        void showIngameGUI(bool show);
    5854
    5955        InputState*              gameInputState_;          //!< input state for normal ingame playing
    6056        InputState*              guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
    6157        InputState*              guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
     58
     59        XMLFile* startFile_;
    6260    };
    6361}
  • code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc

    r5863 r5876  
    3131#include <OgreSceneManager.h>
    3232
    33 #include "util/Clock.h"
    3433#include "core/input/InputManager.h"
    3534#include "core/input/InputState.h"
     
    5756
    5857        // create an empty Scene
    59         this->scene_ = new Scene(0);
     58        this->scene_ = new Scene(NULL);
    6059        // and a Camera
    6160        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
     61        // Load sound
     62        this->ambient_ = new SoundMainMenu();
    6263    }
    6364
     
    7778        GraphicsManager::getInstance().setCamera(this->camera_);
    7879
    79         this->ccStartStandalone_ = createConsoleCommand(createFunctor(&GSMainMenu::startStandalone, this), "startGame");
    80         CommandExecutor::addConsoleCommandShortcut(this->ccStartStandalone_);
    81         this->ccStartServer_ = createConsoleCommand(createFunctor(&GSMainMenu::startServer, this), "startServer");
    82         CommandExecutor::addConsoleCommandShortcut(this->ccStartServer_);
    83         this->ccStartClient_ = createConsoleCommand(createFunctor(&GSMainMenu::startClient, this), "startClient");
    84         CommandExecutor::addConsoleCommandShortcut(this->ccStartClient_);
    85         this->ccStartDedicated_ = createConsoleCommand(createFunctor(&GSMainMenu::startDedicated, this), "startDedicated");
    86         CommandExecutor::addConsoleCommandShortcut(this->ccStartDedicated_);
    87         this->ccStartMainMenu_ = createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu, this), "startMainMenu");
    88         CommandExecutor::addConsoleCommandShortcut(this->ccStartMainMenu_);
     80        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone, this), "startGame"));
     81        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startServer, this), "startServer"));
     82        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startClient, this), "startClient"));
     83        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated, this), "startDedicated"));
     84        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu, this), "startMainMenu"));
    8985
    9086        KeyBinderManager::getInstance().setToDefault();
    9187        InputManager::getInstance().enterState("mainMenu");
    9288
    93         this->ambient_ = new SoundMainMenu();
    9489        this->ambient_->play(true);
    9590    }
     
    9792    void GSMainMenu::deactivate()
    9893    {
    99         this->ambient_->destroy();
     94        this->ambient_->stop();
    10095
    10196        InputManager::getInstance().leaveState("mainMenu");
     
    10398        GUIManager::getInstance().setCamera(0);
    10499        GraphicsManager::getInstance().setCamera(0);
    105 
    106 /*
    107         if (this->ccStartGame_)
    108         {
    109             delete this->ccStartGame_;
    110             this->ccStartGame_ = 0;
    111         }
    112 */
    113100    }
    114101
  • code/branches/core5/src/orxonox/gamestates/GSMainMenu.h

    r5842 r5876  
    5858        Ogre::Camera*     camera_;
    5959
    60         // console commands
    61         ConsoleCommand* ccStartStandalone_;
    62         ConsoleCommand* ccStartServer_;
    63         ConsoleCommand* ccStartClient_;
    64         ConsoleCommand* ccStartDedicated_;
    65         ConsoleCommand* ccStartMainMenu_;
    66 
    6760        // ambient sound for the main menu
    6861        SoundMainMenu* ambient_;
  • code/branches/core5/src/orxonox/gamestates/GSRoot.cc

    r5855 r5876  
    4848        , timeFactorPauseBackup_(1.0f)
    4949    {
    50         this->ccSetTimeFactor_ = 0;
    51         this->ccPause_ = 0;
    5250    }
    5351
     
    6361
    6462        // time factor console command
    65         this->ccSetTimeFactor_ = createConsoleCommand(createFunctor(&GSRoot::setTimeFactor, this), "setTimeFactor");
    66         CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
     63        ConsoleCommand* command = createConsoleCommand(createFunctor(&GSRoot::setTimeFactor, this), "setTimeFactor");
     64        CommandExecutor::addConsoleCommandShortcut(command).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
    6765
    6866        // time factor console command
    69         this->ccPause_ = createConsoleCommand(createFunctor(&GSRoot::pause, this), "pause");
    70         CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
     67        command = createConsoleCommand(createFunctor(&GSRoot::pause, this), "pause");
     68        CommandExecutor::addConsoleCommandShortcut(command).accessLevel(AccessLevel::Offline);
    7169    }
    7270
    7371    void GSRoot::deactivate()
    7472    {
    75 /*
    76         if (this->ccSetTimeFactor_)
    77         {
    78             delete this->ccSetTimeFactor_;
    79             this->ccSetTimeFactor_ = 0;
    80         }
    81 
    82         if (this->ccPause_)
    83         {
    84             delete this->ccPause_;
    85             this->ccPause_ = 0;
    86         }
    87 */
    8873    }
    8974
  • code/branches/core5/src/orxonox/gamestates/GSRoot.h

    r5850 r5876  
    5555        bool                  bPaused_;
    5656        float                 timeFactorPauseBackup_;
    57 
    58         // console commands
    59         ConsoleCommand*       ccSetTimeFactor_;
    60         ConsoleCommand*       ccPause_;
    6157    };
    6258}
Note: See TracChangeset for help on using the changeset viewer.