Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5850 for code/branches/core5


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
Files:
19 edited

Legend:

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

    r5838 r5850  
    264264        // create a shell
    265265        this->shell_.reset(new Shell());
     266
     267        // Create singletons that always exist (in other libraries)
     268        this->rootScope_.reset(new Scope<ScopeID::Root>());
    266269    }
    267270
     
    289292            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
    290293
     294        // Create singletons associated with graphics (in other libraries)
     295        graphicsScope_.reset(new Scope<ScopeID::Graphics>());
     296
    291297        unloader.Dismiss();
    292298
     
    296302    void Core::unloadGraphics()
    297303    {
    298         this->guiManager_.reset();;
    299         this->inputManager_.reset();;
     304        this->graphicsScope_.reset();
     305        this->guiManager_.reset();
     306        this->inputManager_.reset();
    300307        this->graphicsManager_.reset();
    301308
     
    420427    void Core::preUpdate(const Clock& time)
    421428    {
     429        // singletons from other libraries
     430        Scope<ScopeID::Root>::update(time);
    422431        if (this->bGraphicsLoaded_)
    423432        {
     
    426435            // process gui events
    427436            this->guiManager_->update(time);
     437            // graphics singletons from other libraries
     438            Scope<ScopeID::Graphics>::update(time);
    428439        }
    429440        // process thread commands
  • code/branches/core5/src/libraries/core/Core.h

    r5836 r5850  
    3636#include <boost/scoped_ptr.hpp>
    3737#include "util/OutputHandler.h"
     38#include "util/Scope.h"
    3839#include "util/ScopeGuard.h"
    3940#include "util/Singleton.h"
     
    100101            scoped_ptr<InputManager>      inputManager_;        //!< Interface to OIS
    101102            scoped_ptr<GUIManager>        guiManager_;          //!< Interface to GUI
     103            scoped_ptr<Scope<ScopeID::Root> >     rootScope_;
     104            scoped_ptr<Scope<ScopeID::Graphics> > graphicsScope_;
    102105
    103106            bool                          bGraphicsLoaded_;
  • code/branches/core5/src/libraries/util/Scope.h

    r5738 r5850  
    3131
    3232#include "UtilPrereqs.h"
     33
    3334#include <cassert>
     35#include <map>
    3436#include <set>
    35 #include <map>
    3637#include "Debug.h"
    3738
     
    4546        enum Value
    4647        {
    47             GSRoot,
    48             GSGraphics,
    49             GSLevel
     48            Root,
     49            Graphics
    5050        };
    5151    }
    5252
    53     class ScopeListener; // Forward declaration
     53    // Forward declarations
     54    class ScopeListener;
     55    class Clock;
    5456
    5557    /**
     
    8789            //! Gets called if the scope is deactivated
    8890            virtual void deactivated() = 0;
     91            //! Gets called if the scope is updated
     92            virtual void updated(const Clock& time) = 0;
    8993
    9094        private:
     
    136140                return (ScopeManager::instanceCounts_s[scope] > 0);
    137141            }
     142
     143            //! Update method for the ScopeListeners (to implement singleton updates)
     144            static void update(const Clock& time)
     145            {
     146                if (isActive())
     147                {
     148                    for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
     149                        (*(it++))->updated(time);
     150                }
     151            }
    138152    };
    139153}
  • code/branches/core5/src/libraries/util/ScopedSingleton.h

    r5802 r5850  
    3737namespace orxonox
    3838{
     39    class Clock;
    3940    /**
    4041    @brief
     
    5960                assert(Scope<scope>::isActive());
    6061
    61                 if (!T::singletonPtr_s && Scope<scope>::isActive())
     62                if (!T::singletonPtr_s)
    6263                    T::singletonPtr_s = new T();
    6364
    6465                return *T::singletonPtr_s;
    6566            }
     67
     68            //! Update method for singletons like the ingame console
     69            virtual void updated(const Clock& time) { static_cast<T*>(this)->update(time); }
     70            //! Empty update method for the static polymorphism
     71            void update(const Clock& time) { }
    6672
    6773        protected:
     
    8591            {
    8692                // The ScopedSingleton shouldn't be active bevor the scope is activated -> always assertion failed
    87                 assert(T::singletonPtr_s == 0 && false);
     93                assert(false);
    8894            }
    8995
  • code/branches/core5/src/modules/questsystem/QuestManager.h

    r5760 r5850  
    5050namespace orxonox
    5151{
    52 
    53     typedef ScopedSingleton<QuestManager, ScopeID::GSLevel> ScopedSingletonQuestManagerGSLevel; // workaround for tolua
    54 
    5552    /**
    5653    @brief
     
    6057        Damian 'Mozork' Frick
    6158    */
    62     class _QuestsystemExport QuestManager : public ScopedSingletonQuestManagerGSLevel, public orxonox::OrxonoxClass
    63     {
     59    class _QuestsystemExport QuestManager
    6460// tolua_end
     61        : public ScopedSingleton<QuestManager, ScopeID::Root>, public orxonox::OrxonoxClass
     62    { // tolua_export
    6563
    66             friend class ScopedSingleton<QuestManager, ScopeID::GSLevel>;
     64            friend class ScopedSingleton<QuestManager, ScopeID::Root>;
    6765            friend class QuestGUI;
    6866
     
    7270
    7371            //! Returns a reference to the single instance of the Quest Manager.
    74             static QuestManager& getInstance() { return ScopedSingleton<QuestManager, ScopeID::GSLevel>::getInstance(); } // tolua_export
     72            static QuestManager& getInstance() { return ScopedSingleton<QuestManager, ScopeID::Root>::getInstance(); } // tolua_export
    7573
    7674            //! Retreive the main window for the GUI.
  • code/branches/core5/src/modules/questsystem/notifications/NotificationManager.h

    r5738 r5850  
    4646namespace orxonox
    4747{
    48 
    4948    /**
    5049    @brief
     
    5453        Damian 'Mozork' Frick
    5554    */
    56     class _QuestsystemExport NotificationManager : public ScopedSingleton<NotificationManager, ScopeID::GSLevel>, public OrxonoxClass
     55    class _QuestsystemExport NotificationManager : public ScopedSingleton<NotificationManager, ScopeID::Root>, public OrxonoxClass
    5756    {
    58             friend class ScopedSingleton<NotificationManager, ScopeID::GSLevel>;
     57            friend class ScopedSingleton<NotificationManager, ScopeID::Root>;
    5958        public:
    6059            NotificationManager();
  • 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.