[Orxonox-commit 5753] r10413 - in code/branches/core7/src: libraries/core libraries/core/singleton libraries/util orxonox orxonox/overlays orxonox/sound

landauf at orxonox.net landauf at orxonox.net
Sat May 2 23:20:45 CEST 2015


Author: landauf
Date: 2015-05-02 23:20:45 +0200 (Sat, 02 May 2015)
New Revision: 10413

Added:
   code/branches/core7/src/libraries/core/UpdateListener.cc
   code/branches/core7/src/libraries/core/UpdateListener.h
Modified:
   code/branches/core7/src/libraries/core/CMakeLists.txt
   code/branches/core7/src/libraries/core/Core.cc
   code/branches/core7/src/libraries/core/CorePrereqs.h
   code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc
   code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h
   code/branches/core7/src/libraries/util/Singleton.h
   code/branches/core7/src/orxonox/PawnManager.cc
   code/branches/core7/src/orxonox/PawnManager.h
   code/branches/core7/src/orxonox/ShipPartManager.cc
   code/branches/core7/src/orxonox/ShipPartManager.h
   code/branches/core7/src/orxonox/overlays/InGameConsole.cc
   code/branches/core7/src/orxonox/overlays/InGameConsole.h
   code/branches/core7/src/orxonox/sound/SoundManager.cc
   code/branches/core7/src/orxonox/sound/SoundManager.h
Log:
use the generic UpdateListener interface to receive calls to preUpdate() and postUpdate() instead of limiting this functionality to singletons.

Modified: code/branches/core7/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/CMakeLists.txt	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/libraries/core/CMakeLists.txt	2015-05-02 21:20:45 UTC (rev 10413)
@@ -33,6 +33,7 @@
   Namespace.cc
   NamespaceNode.cc
   Template.cc
+  UpdateListener.cc
   ViewportEventListener.cc
   WindowEventListener.cc
   XMLNameListener.cc

Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/libraries/core/Core.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -78,6 +78,7 @@
 #include "input/InputManager.h"
 #include "object/ObjectList.h"
 #include "module/ModuleInstance.h"
+#include "UpdateListener.h"
 
 namespace orxonox
 {
@@ -480,16 +481,15 @@
 
     void Core::preUpdate(const Clock& time)
     {
-        // Update singletons before general ticking
-        ScopedSingletonManager::preUpdate<ScopeID::Root>(time);
+        // Update UpdateListeners before general ticking
+        for (ObjectList<UpdateListener>::iterator it = ObjectList<UpdateListener>::begin(); it != ObjectList<UpdateListener>::end(); ++it)
+            it->preUpdate(time);
         if (this->bGraphicsLoaded_)
         {
             // Process input events
             this->inputManager_->preUpdate(time);
             // Update GUI
             this->guiManager_->preUpdate(time);
-            // Update singletons before general ticking
-            ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time);
         }
         // Process console events and status line
         if (this->ioConsole_ != NULL)
@@ -500,12 +500,11 @@
 
     void Core::postUpdate(const Clock& time)
     {
-        // Update singletons just before rendering
-        ScopedSingletonManager::postUpdate<ScopeID::Root>(time);
+        // Update UpdateListeners just before rendering
+        for (ObjectList<UpdateListener>::iterator it = ObjectList<UpdateListener>::begin(); it != ObjectList<UpdateListener>::end(); ++it)
+            it->postUpdate(time);
         if (this->bGraphicsLoaded_)
         {
-            // Update singletons just before rendering
-            ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time);
             // Render (doesn't throw)
             this->graphicsManager_->postUpdate(time);
         }

Modified: code/branches/core7/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core7/src/libraries/core/CorePrereqs.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/libraries/core/CorePrereqs.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -208,6 +208,7 @@
     class Template;
     class Thread;
     class ThreadPool;
+    class UpdateListener;
     class ViewportEventListener;
     template <class T>
     class WeakPtr;

Added: code/branches/core7/src/libraries/core/UpdateListener.cc
===================================================================
--- code/branches/core7/src/libraries/core/UpdateListener.cc	                        (rev 0)
+++ code/branches/core7/src/libraries/core/UpdateListener.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -0,0 +1,40 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "UpdateListener.h"
+#include "core/CoreIncludes.h"
+
+namespace orxonox
+{
+    RegisterAbstractClass(UpdateListener).inheritsFrom<Listable>();
+
+    UpdateListener::UpdateListener()
+    {
+        RegisterObject(UpdateListener);
+    }
+}


Property changes on: code/branches/core7/src/libraries/core/UpdateListener.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/core7/src/libraries/core/UpdateListener.h
===================================================================
--- code/branches/core7/src/libraries/core/UpdateListener.h	                        (rev 0)
+++ code/branches/core7/src/libraries/core/UpdateListener.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -0,0 +1,50 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _UpdateListener_H__
+#define _UpdateListener_H__
+
+#include "core/CorePrereqs.h"
+
+#include "core/object/Listable.h"
+
+namespace orxonox
+{
+    class _CoreExport UpdateListener : virtual public Listable
+    {
+        public:
+            UpdateListener();
+
+            /// Gets called by Core before the framework is ticked.
+            virtual void preUpdate(const Clock& time) = 0;
+            /// Gets called by Core after the framework was ticked (but before graphics are drawn).
+            virtual void postUpdate(const Clock& time) = 0;
+    };
+}
+
+#endif /* _UpdateListener_H__ */


Property changes on: code/branches/core7/src/libraries/core/UpdateListener.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -40,15 +40,9 @@
         static std::map<std::string, ScopedSingletonManager*> managers;
         return managers;
     }
-    /*static*/ ScopedSingletonManager::ManagerMultiMap& ScopedSingletonManager::getManagersByScope()
-    {
-        static ManagerMultiMap managers;
-        return managers;
-    }
 
     /*static*/ void ScopedSingletonManager::addManager(ScopedSingletonManager* manager)
     {
         getManagers()[manager->className_] = manager;
-        getManagersByScope().insert(std::make_pair(manager->scope_, manager));
     }
 }

Modified: code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -67,13 +67,9 @@
 
 namespace orxonox
 {
-    class Destroyable;
-
     /**
-        @brief Base class of ClassScopedSingletonManager, implements some static functions
-        used to dispatch calls to preUpdate and postUpdate to all instances of this class.
-        It also keeps track of all existing ScopedSingletonManagers and stores them in a
-        map, sorted by the scope they belong to.
+        @brief Base class of ClassScopedSingletonManager. Keeps track of all existing ScopedSingletonManagers
+        and stores them in a map, sorted by the scope they belong to.
     */
     class _CoreExport ScopedSingletonManager
     {
@@ -88,29 +84,8 @@
             /// Adds a new instance of ScopedSingletonManager to the map.
             static void addManager(ScopedSingletonManager* manager);
 
-            /// Calls preUpdate in all instances of ScopedSingletonManager that are registered in the map.
-            template<ScopeID::Value scope>
-            static void preUpdate(const Clock& time)
-            {
-                assert(Scope<scope>::isActive());
-                for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)
-                    it->second->preUpdate(time);
-            }
-            virtual void preUpdate(const Clock& time) = 0;
-
-            /// Calls postUpdate in all instances of ScopedSingletonManager that are registered in the map.
-            template<ScopeID::Value scope>
-            static void postUpdate(const Clock& time)
-            {
-                assert(Scope<scope>::isActive());
-                for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)
-                    it->second->postUpdate(time);
-            }
-            virtual void postUpdate(const Clock& time) = 0;
-
             static std::map<std::string, ScopedSingletonManager*>& getManagers();
             typedef std::multimap<ScopeID::Value, ScopedSingletonManager*> ManagerMultiMap;
-            static ManagerMultiMap& getManagersByScope();
 
         protected:
             const std::string className_;   ///< The name of the scoped singleton class that is managed by this object
@@ -176,22 +151,6 @@
             delete singletonPtr_;
         }
 
-        //! Called every frame by the ScopedSingletonManager
-        void preUpdate(const Clock& time)
-        {
-            assert(Scope<scope>::isActive());
-            // assuming T inherits Singleton<T>
-            singletonPtr_->preUpdateSingleton(time);
-        }
-
-        //! Called every frame by the ScopedSingletonManager
-        void postUpdate(const Clock& time)
-        {
-            assert(Scope<scope>::isActive());
-            // assuming T inherits Singleton<T>
-            singletonPtr_->postUpdateSingleton(time);
-        }
-
     private:
         T* singletonPtr_;   ///< Unique instance of the singleton class @a T
     };
@@ -256,24 +215,6 @@
             delete singletonPtr_;
         }
 
-        //! Called every frame by the ScopedSingletonManager
-        void preUpdate(const Clock& time)
-        {
-            assert(Scope<scope>::isActive());
-            // assuming T inherits Singleton<T>
-            if (singletonPtr_ != NULL)
-                singletonPtr_->preUpdateSingleton(time);
-        }
-
-        //! Called every frame by the ScopedSingletonManager
-        void postUpdate(const Clock& time)
-        {
-            assert(Scope<scope>::isActive());
-            // assuming T inherits Singleton<T>
-            if (singletonPtr_ != NULL)
-                singletonPtr_->postUpdateSingleton(time);
-        }
-
     private:
         T* singletonPtr_;   ///< Unique instance of the singleton class @a T
     };

Modified: code/branches/core7/src/libraries/util/Singleton.h
===================================================================
--- code/branches/core7/src/libraries/util/Singleton.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/libraries/util/Singleton.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -145,15 +145,6 @@
             return (T::singletonPtr_s != NULL);
         }
 
-        //! Update method called by ClassSingletonManager (if used)
-        void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }
-        //! Empty update method for the static polymorphism
-        void preUpdate(const Clock& time) { }
-        //! Update method called by ClassSingletonManager (if used)
-        void postUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->postUpdate(time); }
-        //! Empty update method for the static polymorphism
-        void postUpdate(const Clock& time) { }
-
     protected:
         //! Constructor sets the singleton instance pointer
         Singleton()

Modified: code/branches/core7/src/orxonox/PawnManager.cc
===================================================================
--- code/branches/core7/src/orxonox/PawnManager.cc	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/PawnManager.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -36,7 +36,7 @@
 {
     ManageScopedSingleton(PawnManager, ScopeID::Root, false);
 
-    RegisterAbstractClass(PawnManager).inheritsFrom<Tickable>();
+    RegisterAbstractClass(PawnManager).inheritsFrom<UpdateListener>();
 
     PawnManager::PawnManager()
     {

Modified: code/branches/core7/src/orxonox/PawnManager.h
===================================================================
--- code/branches/core7/src/orxonox/PawnManager.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/PawnManager.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -32,11 +32,11 @@
 #include "OrxonoxPrereqs.h"
 
 #include "util/Singleton.h"
-#include "tools/interfaces/Tickable.h"
+#include "core/UpdateListener.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport PawnManager : public Singleton<PawnManager>, public Tickable
+    class _OrxonoxExport PawnManager : public Singleton<PawnManager>, public UpdateListener
     {
             friend class Singleton<PawnManager>;
         public:
@@ -44,6 +44,7 @@
             virtual ~PawnManager();
 
             virtual void preUpdate(const Clock& time);
+            virtual void postUpdate(const Clock& time) { /*no action*/ }
 
         private:
 

Modified: code/branches/core7/src/orxonox/ShipPartManager.cc
===================================================================
--- code/branches/core7/src/orxonox/ShipPartManager.cc	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/ShipPartManager.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -36,7 +36,7 @@
 {
     ManageScopedSingleton(ShipPartManager, ScopeID::Root, false);
 
-    RegisterAbstractClass(ShipPartManager).inheritsFrom<Tickable>();
+    RegisterAbstractClass(ShipPartManager).inheritsFrom<UpdateListener>();
 
     ShipPartManager::ShipPartManager()
     {

Modified: code/branches/core7/src/orxonox/ShipPartManager.h
===================================================================
--- code/branches/core7/src/orxonox/ShipPartManager.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/ShipPartManager.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -32,11 +32,11 @@
 #include "OrxonoxPrereqs.h"
 
 #include "util/Singleton.h"
-#include "tools/interfaces/Tickable.h"
+#include "core/UpdateListener.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport ShipPartManager : public Singleton<ShipPartManager>, public Tickable
+    class _OrxonoxExport ShipPartManager : public Singleton<ShipPartManager>, public UpdateListener
     {
             friend class Singleton<ShipPartManager>;
         public:
@@ -44,6 +44,7 @@
             virtual ~ShipPartManager();
 
             virtual void preUpdate(const Clock& time);
+            virtual void postUpdate(const Clock& time) { /*no action*/ }
 
         private:
 

Modified: code/branches/core7/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/core7/src/orxonox/overlays/InGameConsole.cc	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/overlays/InGameConsole.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -66,7 +66,7 @@
 
     ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false);
 
-    RegisterAbstractClass(InGameConsole).inheritsFrom<WindowEventListener>();
+    RegisterAbstractClass(InGameConsole).inheritsFrom<WindowEventListener>().inheritsFrom<UpdateListener>();
 
     /**
         @brief Constructor: Creates and initializes the InGameConsole.

Modified: code/branches/core7/src/orxonox/overlays/InGameConsole.h
===================================================================
--- code/branches/core7/src/orxonox/overlays/InGameConsole.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/overlays/InGameConsole.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -38,10 +38,11 @@
 #include "util/Singleton.h"
 #include "core/WindowEventListener.h"
 #include "core/command/Shell.h"
+#include "core/UpdateListener.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener
+    class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener, public UpdateListener
     {
         friend class Singleton<InGameConsole>;
     public: // functions
@@ -52,6 +53,7 @@
         void setConfigValues();
 
         void preUpdate(const Clock& time);
+        void postUpdate(const Clock& time) { /*no action*/ }
 
         static void openConsole();
         static void closeConsole();

Modified: code/branches/core7/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/core7/src/orxonox/sound/SoundManager.cc	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/sound/SoundManager.cc	2015-05-02 21:20:45 UTC (rev 10413)
@@ -65,7 +65,7 @@
         }
     }
 
-    RegisterAbstractClass(SoundManager).inheritsFrom<Configurable>();
+    RegisterAbstractClass(SoundManager).inheritsFrom<Configurable>().inheritsFrom<UpdateListener>();
 
     SoundManager::SoundManager()
         : effectsPoolSize_(0)

Modified: code/branches/core7/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/core7/src/orxonox/sound/SoundManager.h	2015-05-02 20:41:10 UTC (rev 10412)
+++ code/branches/core7/src/orxonox/sound/SoundManager.h	2015-05-02 21:20:45 UTC (rev 10413)
@@ -40,6 +40,7 @@
 #include "util/Singleton.h"
 #include "core/config/Configurable.h"
 #include "core/object/SmartPtr.h"
+#include "core/UpdateListener.h"
 
 // tolua_begin
 namespace orxonox
@@ -58,7 +59,7 @@
     //! The SoundManager class manages the OpenAL device, context and listener position.
     class _OrxonoxExport SoundManager
     // tolua_end
-        : public Singleton<SoundManager>, public Configurable
+        : public Singleton<SoundManager>, public Configurable, public UpdateListener
     { // tolua_export
         friend class Singleton<SoundManager>;
 
@@ -67,6 +68,7 @@
         ~SoundManager();
 
         void preUpdate(const Clock& time);
+        void postUpdate(const Clock& time) { /*no action*/ }
         void setConfigValues();
 
         // tolua_begin




More information about the Orxonox-commit mailing list