Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 2, 2015, 11:20:45 PM (10 years ago)
Author:
landauf
Message:

use the generic UpdateListener interface to receive calls to preUpdate() and postUpdate() instead of limiting this functionality to singletons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h

    r10407 r10413  
    6868namespace orxonox
    6969{
    70     class Destroyable;
    71 
    7270    /**
    73         @brief Base class of ClassScopedSingletonManager, implements some static functions
    74         used to dispatch calls to preUpdate and postUpdate to all instances of this class.
    75         It also keeps track of all existing ScopedSingletonManagers and stores them in a
    76         map, sorted by the scope they belong to.
     71        @brief Base class of ClassScopedSingletonManager. Keeps track of all existing ScopedSingletonManagers
     72        and stores them in a map, sorted by the scope they belong to.
    7773    */
    7874    class _CoreExport ScopedSingletonManager
     
    8985            static void addManager(ScopedSingletonManager* manager);
    9086
    91             /// Calls preUpdate in all instances of ScopedSingletonManager that are registered in the map.
    92             template<ScopeID::Value scope>
    93             static void preUpdate(const Clock& time)
    94             {
    95                 assert(Scope<scope>::isActive());
    96                 for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)
    97                     it->second->preUpdate(time);
    98             }
    99             virtual void preUpdate(const Clock& time) = 0;
    100 
    101             /// Calls postUpdate in all instances of ScopedSingletonManager that are registered in the map.
    102             template<ScopeID::Value scope>
    103             static void postUpdate(const Clock& time)
    104             {
    105                 assert(Scope<scope>::isActive());
    106                 for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)
    107                     it->second->postUpdate(time);
    108             }
    109             virtual void postUpdate(const Clock& time) = 0;
    110 
    11187            static std::map<std::string, ScopedSingletonManager*>& getManagers();
    11288            typedef std::multimap<ScopeID::Value, ScopedSingletonManager*> ManagerMultiMap;
    113             static ManagerMultiMap& getManagersByScope();
    11489
    11590        protected:
     
    177152        }
    178153
    179         //! Called every frame by the ScopedSingletonManager
    180         void preUpdate(const Clock& time)
    181         {
    182             assert(Scope<scope>::isActive());
    183             // assuming T inherits Singleton<T>
    184             singletonPtr_->preUpdateSingleton(time);
    185         }
    186 
    187         //! Called every frame by the ScopedSingletonManager
    188         void postUpdate(const Clock& time)
    189         {
    190             assert(Scope<scope>::isActive());
    191             // assuming T inherits Singleton<T>
    192             singletonPtr_->postUpdateSingleton(time);
    193         }
    194 
    195154    private:
    196155        T* singletonPtr_;   ///< Unique instance of the singleton class @a T
     
    257216        }
    258217
    259         //! Called every frame by the ScopedSingletonManager
    260         void preUpdate(const Clock& time)
    261         {
    262             assert(Scope<scope>::isActive());
    263             // assuming T inherits Singleton<T>
    264             if (singletonPtr_ != NULL)
    265                 singletonPtr_->preUpdateSingleton(time);
    266         }
    267 
    268         //! Called every frame by the ScopedSingletonManager
    269         void postUpdate(const Clock& time)
    270         {
    271             assert(Scope<scope>::isActive());
    272             // assuming T inherits Singleton<T>
    273             if (singletonPtr_ != NULL)
    274                 singletonPtr_->postUpdateSingleton(time);
    275         }
    276 
    277218    private:
    278219        T* singletonPtr_;   ///< Unique instance of the singleton class @a T
Note: See TracChangeset for help on using the changeset viewer.