Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10413 for code/branches/core7


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.

Location:
code/branches/core7/src
Files:
2 added
14 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
  • code/branches/core7/src/libraries/util/Singleton.h

    r10398 r10413  
    146146        }
    147147
    148         //! Update method called by ClassSingletonManager (if used)
    149         void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }
    150         //! Empty update method for the static polymorphism
    151         void preUpdate(const Clock& time) { }
    152         //! Update method called by ClassSingletonManager (if used)
    153         void postUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->postUpdate(time); }
    154         //! Empty update method for the static polymorphism
    155         void postUpdate(const Clock& time) { }
    156 
    157148    protected:
    158149        //! Constructor sets the singleton instance pointer
  • code/branches/core7/src/orxonox/PawnManager.cc

    r10407 r10413  
    3737    ManageScopedSingleton(PawnManager, ScopeID::Root, false);
    3838
    39     RegisterAbstractClass(PawnManager).inheritsFrom<Tickable>();
     39    RegisterAbstractClass(PawnManager).inheritsFrom<UpdateListener>();
    4040
    4141    PawnManager::PawnManager()
  • code/branches/core7/src/orxonox/PawnManager.h

    r8351 r10413  
    3333
    3434#include "util/Singleton.h"
    35 #include "tools/interfaces/Tickable.h"
     35#include "core/UpdateListener.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport PawnManager : public Singleton<PawnManager>, public Tickable
     39    class _OrxonoxExport PawnManager : public Singleton<PawnManager>, public UpdateListener
    4040    {
    4141            friend class Singleton<PawnManager>;
     
    4545
    4646            virtual void preUpdate(const Clock& time);
     47            virtual void postUpdate(const Clock& time) { /*no action*/ }
    4748
    4849        private:
  • code/branches/core7/src/orxonox/ShipPartManager.cc

    r10407 r10413  
    3737    ManageScopedSingleton(ShipPartManager, ScopeID::Root, false);
    3838
    39     RegisterAbstractClass(ShipPartManager).inheritsFrom<Tickable>();
     39    RegisterAbstractClass(ShipPartManager).inheritsFrom<UpdateListener>();
    4040
    4141    ShipPartManager::ShipPartManager()
  • code/branches/core7/src/orxonox/ShipPartManager.h

    r10262 r10413  
    3333
    3434#include "util/Singleton.h"
    35 #include "tools/interfaces/Tickable.h"
     35#include "core/UpdateListener.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport ShipPartManager : public Singleton<ShipPartManager>, public Tickable
     39    class _OrxonoxExport ShipPartManager : public Singleton<ShipPartManager>, public UpdateListener
    4040    {
    4141            friend class Singleton<ShipPartManager>;
     
    4545
    4646            virtual void preUpdate(const Clock& time);
     47            virtual void postUpdate(const Clock& time) { /*no action*/ }
    4748
    4849        private:
  • code/branches/core7/src/orxonox/overlays/InGameConsole.cc

    r10407 r10413  
    6767    ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false);
    6868
    69     RegisterAbstractClass(InGameConsole).inheritsFrom<WindowEventListener>();
     69    RegisterAbstractClass(InGameConsole).inheritsFrom<WindowEventListener>().inheritsFrom<UpdateListener>();
    7070
    7171    /**
  • code/branches/core7/src/orxonox/overlays/InGameConsole.h

    r8858 r10413  
    3939#include "core/WindowEventListener.h"
    4040#include "core/command/Shell.h"
     41#include "core/UpdateListener.h"
    4142
    4243namespace orxonox
    4344{
    44     class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener
     45    class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener, public UpdateListener
    4546    {
    4647        friend class Singleton<InGameConsole>;
     
    5354
    5455        void preUpdate(const Clock& time);
     56        void postUpdate(const Clock& time) { /*no action*/ }
    5557
    5658        static void openConsole();
  • code/branches/core7/src/orxonox/sound/SoundManager.cc

    r10407 r10413  
    6666    }
    6767
    68     RegisterAbstractClass(SoundManager).inheritsFrom<Configurable>();
     68    RegisterAbstractClass(SoundManager).inheritsFrom<Configurable>().inheritsFrom<UpdateListener>();
    6969
    7070    SoundManager::SoundManager()
  • code/branches/core7/src/orxonox/sound/SoundManager.h

    r9667 r10413  
    4141#include "core/config/Configurable.h"
    4242#include "core/object/SmartPtr.h"
     43#include "core/UpdateListener.h"
    4344
    4445// tolua_begin
     
    5960    class _OrxonoxExport SoundManager
    6061    // tolua_end
    61         : public Singleton<SoundManager>, public Configurable
     62        : public Singleton<SoundManager>, public Configurable, public UpdateListener
    6263    { // tolua_export
    6364        friend class Singleton<SoundManager>;
     
    6869
    6970        void preUpdate(const Clock& time);
     71        void postUpdate(const Clock& time) { /*no action*/ }
    7072        void setConfigValues();
    7173
Note: See TracChangeset for help on using the changeset viewer.