Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 1, 2009, 11:44:53 AM (15 years ago)
Author:
rgrieder
Message:

Moved the singleton creation/destruction mess to the Core class by using just two possible Scopes:

  • ScopeID::Root for singletons that may always persists
  • ScopeID::Graphics for singletons that only work when graphics was loaded
Location:
code/branches/core5/src/orxonox
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/orxonox/CameraManager.cc

    r5805 r5850  
    3434#include "util/StringUtils.h"
    3535#include "core/GameMode.h"
     36#include "core/GraphicsManager.h"
    3637#include "core/GUIManager.h"
    3738#include "core/ObjectList.h"
     
    4445    CameraManager* CameraManager::singletonPtr_s = 0;
    4546
    46     CameraManager::CameraManager(Ogre::Viewport* viewport)
    47         : viewport_(viewport)
     47    CameraManager::CameraManager()
     48        : viewport_(GraphicsManager::getInstance().getViewport())
    4849    {
    4950        this->fallbackCamera_ = 0;
  • code/branches/core5/src/orxonox/CameraManager.h

    r5805 r5850  
    4141#include <list>
    4242#include "util/OgreForwardRefs.h"
    43 #include "util/Singleton.h"
     43#include "util/ScopedSingleton.h"
     44#include "core/OrxonoxClass.h"
    4445#include "core/SmartPtr.h"
    4546
    4647namespace orxonox
    4748{
    48     class _OrxonoxExport CameraManager : public Singleton<CameraManager>
     49    class _OrxonoxExport CameraManager : public ScopedSingleton<CameraManager, ScopeID::Graphics>, public OrxonoxClass
    4950    {
    50             friend class Singleton<CameraManager>;
     51            friend class ScopedSingleton<CameraManager, ScopeID::Graphics>;
    5152        public:
    52             CameraManager(Ogre::Viewport* viewport);
     53            CameraManager();
    5354            ~CameraManager();
    5455
  • code/branches/core5/src/orxonox/LevelManager.h

    r3370 r5850  
    3636#include <string>
    3737
    38 #include "util/Singleton.h"
     38#include "util/ScopedSingleton.h"
    3939#include "core/OrxonoxClass.h"
    4040
     
    4444    class _OrxonoxExport LevelManager
    4545    // tolua_end
    46         : public Singleton<LevelManager>, public OrxonoxClass
     46        : public ScopedSingleton<LevelManager, ScopeID::Root>, public OrxonoxClass
    4747    { // tolua_export
    48             friend class Singleton<LevelManager>;
     48            friend class ScopedSingleton<LevelManager, ScopeID::Root>;
    4949        public:
    5050            LevelManager();
     
    6363
    6464            static LevelManager* getInstancePtr() { return singletonPtr_s; }
    65             static LevelManager& getInstance()    { return Singleton<LevelManager>::getInstance(); } // tolua_export
     65            static LevelManager& getInstance()    { return ScopedSingleton<LevelManager, ScopeID::Root>::getInstance(); } // tolua_export
    6666
    6767        private:
  • code/branches/core5/src/orxonox/PlayerManager.h

    r5820 r5850  
    3434#include <cassert>
    3535#include <map>
    36 #include "util/Singleton.h"
     36#include "util/ScopedSingleton.h"
    3737#include "network/ClientConnectionListener.h"
    3838
    3939namespace orxonox
    4040{
    41     class _OrxonoxExport PlayerManager : public Singleton<PlayerManager>, public ClientConnectionListener
     41    class _OrxonoxExport PlayerManager : public ScopedSingleton<PlayerManager, ScopeID::Root>, public ClientConnectionListener
    4242    {
    43             friend class Singleton<PlayerManager>;
     43            friend class ScopedSingleton<PlayerManager, ScopeID::Root>;
    4444        public:
    4545            PlayerManager();
  • code/branches/core5/src/orxonox/gamestates/GSGraphics.cc

    r5842 r5850  
    4646#include "core/Loader.h"
    4747#include "core/XMLFile.h"
    48 #include "overlays/InGameConsole.h"
    49 #include "sound/SoundManager.h"
    5048
    5149// HACK:
     
    5856    GSGraphics::GSGraphics(const GameStateInfo& info)
    5957        : GameState(info)
    60         , console_(0)
    61         , soundManager_(0)
    6258        , masterKeyBinder_(0)
    6359        , masterInputState_(0)
     
    10096        masterKeyBinder_->loadBindings("masterKeybindings.ini");
    10197
    102         // Load the SoundManager
    103         soundManager_ = new SoundManager();
    104 
    105         // Load the InGameConsole
    106         console_ = new InGameConsole();
    107         console_->initialise();
    108 
    10998        // add console command to toggle GUI
    11099        this->ccToggleGUI_ = createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI");
     
    131120*/
    132121
    133         this->console_->destroy();
    134 
    135122        Loader::unload(this->debugOverlay_);
    136123        delete this->debugOverlay_;
    137 
    138         this->soundManager_->destroy();
    139124
    140125        // HACK: (destroys a resource smart pointer)
     
    170155            Game::getInstance().requestState("mainMenu");
    171156        }
    172 
    173         this->console_->update(time);
    174157    }
    175158}
  • code/branches/core5/src/orxonox/gamestates/GSGraphics.h

    r5842 r5850  
    6060
    6161    private:
    62         // managed singletons
    63         InGameConsole*        console_;
    64         SoundManager*         soundManager_;        //!< Keeps track of SoundBase objects
    65 
    6662        KeyBinder*            masterKeyBinder_;     //!< Key binder for master key bindings
    6763        InputState*           masterInputState_;    //!< Special input state for master input
  • code/branches/core5/src/orxonox/gamestates/GSLevel.cc

    r5842 r5850  
    4141#include "core/Game.h"
    4242#include "core/GameMode.h"
    43 #include "core/GraphicsManager.h"
    4443#include "core/GUIManager.h"
    4544#include "core/Loader.h"
    4645#include "core/XMLFile.h"
    4746
    48 #include "tools/interfaces/Tickable.h"
    49 #include "CameraManager.h"
    5047#include "LevelManager.h"
    5148#include "PlayerManager.h"
    52 #include "infos/HumanPlayer.h"
    5349
    5450namespace orxonox
     
    6561        , guiMouseOnlyInputState_(0)
    6662        , guiKeysOnlyInputState_(0)
    67         , cameraManager_(0)
    6863    {
    6964        RegisterObject(GSLevel);
     
    9893            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
    9994            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
    100 
    101             // create the global CameraManager
    102             this->cameraManager_ = new CameraManager(GraphicsManager::getInstance().getViewport());
    103         }
    104 
    105         this->playerManager_ = new PlayerManager();
    106 
    107         this->scope_GSLevel_ = new Scope<ScopeID::GSLevel>();
     95        }
    10896
    10997        if (GameMode::isMaster())
     
    126114           
    127115            // connect the HumanPlayer to the game
    128             this->playerManager_->clientConnected(0);
     116            PlayerManager::getInstance().clientConnected(0);
    129117        }
    130118    }
     
    165153        {
    166154            // disconnect the HumanPlayer
    167             this->playerManager_->clientDisconnected(0);
     155            PlayerManager::getInstance().clientDisconnected(0);
    168156           
    169157            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
     
    184172        if (GameMode::isMaster())
    185173            this->unloadLevel();
    186 
    187         if (this->cameraManager_)
    188         {
    189             delete this->cameraManager_;
    190             this->cameraManager_ = 0;
    191         }
    192 
    193         if (this->playerManager_)
    194         {
    195             this->playerManager_->destroy();
    196             this->playerManager_ = 0;
    197         }
    198 
    199         if (this->scope_GSLevel_)
    200         {
    201             delete this->scope_GSLevel_;
    202             this->scope_GSLevel_ = NULL;
    203         }
    204174
    205175        if (GameMode::showsGraphics())
  • code/branches/core5/src/orxonox/gamestates/GSLevel.h

    r5842 r5850  
    3333
    3434#include <string>
    35 #include "util/Scope.h"
    3635#include "core/OrxonoxClass.h"
    3736#include "core/GameState.h"
     
    6766        InputState*              guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
    6867        InputState*              guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
    69         CameraManager*           cameraManager_;           //!< camera manager for this level
    70         PlayerManager*           playerManager_;           //!< player manager for this level
    71         Scope<ScopeID::GSLevel>* scope_GSLevel_;
    7268
    7369        //##### ConfigValues #####
  • code/branches/core5/src/orxonox/gamestates/GSRoot.cc

    r5831 r5850  
    3737#include "tools/interfaces/TimeFactorListener.h"
    3838#include "tools/interfaces/Tickable.h"
    39 #include "LevelManager.h"
    4039
    4140namespace orxonox
     
    7069        this->ccPause_ = createConsoleCommand(createFunctor(&GSRoot::pause, this), "pause");
    7170        CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
    72 
    73         // create the LevelManager
    74         this->levelManager_ = new LevelManager();
    7571    }
    7672
     
    9086        }
    9187*/
    92 
    93         this->levelManager_->destroy();
    9488    }
    9589
  • code/branches/core5/src/orxonox/gamestates/GSRoot.h

    r5842 r5850  
    5656        float                 timeFactorPauseBackup_;
    5757
    58         LevelManager*         levelManager_;            //!< global level manager
    59 
    6058        // console commands
    6159        ConsoleCommand*       ccSetTimeFactor_;
  • code/branches/core5/src/orxonox/overlays/InGameConsole.cc

    r5738 r5850  
    8585
    8686        this->setConfigValues();
     87        this->initialise();
    8788    }
    8889
  • code/branches/core5/src/orxonox/overlays/InGameConsole.h

    r5791 r5850  
    3636
    3737#include "util/OgreForwardRefs.h"
    38 #include "util/Singleton.h"
     38#include "util/ScopedSingleton.h"
    3939#include "core/Shell.h"
    4040#include "core/WindowEventListener.h"
     
    4242namespace orxonox
    4343{
    44     class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener
     44    class _OrxonoxExport InGameConsole : public ScopedSingleton<InGameConsole, ScopeID::Graphics>, public ShellListener, public WindowEventListener
    4545    {
    46         friend class Singleton<InGameConsole>;
     46        friend class ScopedSingleton<InGameConsole, ScopeID::Graphics>;
    4747    public: // functions
    4848        InGameConsole();
  • code/branches/core5/src/orxonox/sound/SoundManager.h

    r5693 r5850  
    3232#include <cassert>
    3333#include <list>
    34 #include "util/Singleton.h"
     34#include "util/ScopedSingleton.h"
    3535#include "tools/interfaces/Tickable.h"
    3636
     
    4343     *
    4444     */
    45     class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public Tickable
     45    class _OrxonoxExport SoundManager : public ScopedSingleton<SoundManager, ScopeID::Graphics>, public Tickable
    4646    {
    47         friend class Singleton<SoundManager>;
     47        friend class ScopedSingleton<SoundManager, ScopeID::Graphics>;
    4848    public:
    4949        SoundManager();
Note: See TracChangeset for help on using the changeset viewer.