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/libraries
Files:
4 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
Note: See TracChangeset for help on using the changeset viewer.