Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Location:
code/branches/core7/src/libraries/core
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/CMakeLists.txt

    r10407 r10413  
    3434  NamespaceNode.cc
    3535  Template.cc
     36  UpdateListener.cc
    3637  ViewportEventListener.cc
    3738  WindowEventListener.cc
  • code/branches/core7/src/libraries/core/Core.cc

    r10407 r10413  
    7979#include "object/ObjectList.h"
    8080#include "module/ModuleInstance.h"
     81#include "UpdateListener.h"
    8182
    8283namespace orxonox
     
    481482    void Core::preUpdate(const Clock& time)
    482483    {
    483         // Update singletons before general ticking
    484         ScopedSingletonManager::preUpdate<ScopeID::Root>(time);
     484        // Update UpdateListeners before general ticking
     485        for (ObjectList<UpdateListener>::iterator it = ObjectList<UpdateListener>::begin(); it != ObjectList<UpdateListener>::end(); ++it)
     486            it->preUpdate(time);
    485487        if (this->bGraphicsLoaded_)
    486488        {
     
    489491            // Update GUI
    490492            this->guiManager_->preUpdate(time);
    491             // Update singletons before general ticking
    492             ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time);
    493493        }
    494494        // Process console events and status line
     
    501501    void Core::postUpdate(const Clock& time)
    502502    {
    503         // Update singletons just before rendering
    504         ScopedSingletonManager::postUpdate<ScopeID::Root>(time);
     503        // Update UpdateListeners just before rendering
     504        for (ObjectList<UpdateListener>::iterator it = ObjectList<UpdateListener>::begin(); it != ObjectList<UpdateListener>::end(); ++it)
     505            it->postUpdate(time);
    505506        if (this->bGraphicsLoaded_)
    506507        {
    507             // Update singletons just before rendering
    508             ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time);
    509508            // Render (doesn't throw)
    510509            this->graphicsManager_->postUpdate(time);
  • code/branches/core7/src/libraries/core/CorePrereqs.h

    r10407 r10413  
    209209    class Thread;
    210210    class ThreadPool;
     211    class UpdateListener;
    211212    class ViewportEventListener;
    212213    template <class T>
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc

    r10407 r10413  
    4141        return managers;
    4242    }
    43     /*static*/ ScopedSingletonManager::ManagerMultiMap& ScopedSingletonManager::getManagersByScope()
    44     {
    45         static ManagerMultiMap managers;
    46         return managers;
    47     }
    4843
    4944    /*static*/ void ScopedSingletonManager::addManager(ScopedSingletonManager* manager)
    5045    {
    5146        getManagers()[manager->className_] = manager;
    52         getManagersByScope().insert(std::make_pair(manager->scope_, manager));
    5347    }
    5448}
  • 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.