[Orxonox-commit 1070] r5791 - in code/branches/core5/src: libraries/core libraries/tools modules/weapons orxonox/graphics orxonox/overlays orxonox/worldentities

landauf at orxonox.net landauf at orxonox.net
Sat Sep 26 02:05:30 CEST 2009


Author: landauf
Date: 2009-09-26 02:05:30 +0200 (Sat, 26 Sep 2009)
New Revision: 5791

Modified:
   code/branches/core5/src/libraries/core/OrxonoxClass.cc
   code/branches/core5/src/libraries/core/OrxonoxClass.h
   code/branches/core5/src/libraries/tools/Timer.h
   code/branches/core5/src/modules/weapons/MuzzleFlash.cc
   code/branches/core5/src/modules/weapons/MuzzleFlash.h
   code/branches/core5/src/orxonox/graphics/ParticleSpawner.h
   code/branches/core5/src/orxonox/overlays/InGameConsole.h
   code/branches/core5/src/orxonox/worldentities/BigExplosion.cc
   code/branches/core5/src/orxonox/worldentities/BigExplosion.h
   code/branches/core5/src/orxonox/worldentities/ExplosionChunk.cc
   code/branches/core5/src/orxonox/worldentities/ExplosionChunk.h
Log:
Added destroy() function to OrxonoxClass.
Removed destroy() functions from some subclasses.
Expanded Timer to accept Functors of other classes too.

Modified: code/branches/core5/src/libraries/core/OrxonoxClass.cc
===================================================================
--- code/branches/core5/src/libraries/core/OrxonoxClass.cc	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/libraries/core/OrxonoxClass.cc	2009-09-26 00:05:30 UTC (rev 5791)
@@ -44,6 +44,8 @@
         this->identifier_ = 0;
         this->parents_ = 0;
         this->metaList_ = new MetaObjectList();
+        this->referenceCount_ = 0;
+        this->requestedDestruction_ = false;
     }
 
     /** @brief Destructor: Deletes, if existing, the list of the parents. */
@@ -56,6 +58,15 @@
             delete this->parents_;
     }
 
+    /** @brief Deletes the object if no smart pointers point to this object. Otherwise schedules the object to be deleted as soon as possible. */
+    void OrxonoxClass::destroy()
+    {
+        if (this->referenceCount_ > 0)
+            this->requestedDestruction_ = true;
+        else
+            delete this;
+    }
+
     /** @brief Returns true if the objects class is of the given type or a derivative. */
     bool OrxonoxClass::isA(const Identifier* identifier)
         { return this->getIdentifier()->isA(identifier); }

Modified: code/branches/core5/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/branches/core5/src/libraries/core/OrxonoxClass.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/libraries/core/OrxonoxClass.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -58,6 +58,8 @@
             OrxonoxClass();
             virtual ~OrxonoxClass();
 
+            void destroy();
+
             /** @brief Function to collect the SetConfigValue-macro calls. */
             void setConfigValues() {};
 
@@ -91,6 +93,9 @@
             bool isParentOf(const OrxonoxClass* object);
             bool isDirectParentOf(const OrxonoxClass* object);
 
+            inline unsigned int getReferenceCount() const
+                { return this->referenceCount_; }
+
             /**
             @brief
                 Returns a valid pointer of any derived type that is
@@ -116,9 +121,19 @@
             }
 
         private:
+            /** @brief Increments the reference counter (for smart pointers). */
+            inline void incrementReferenceCount()
+                { ++this->referenceCount_; }
+            /** @brief Decrements the reference counter (for smart pointers). */
+            inline void decrementReferenceCount()
+                { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } }
+
             Identifier* identifier_;                   //!< The Identifier of the object
             std::set<const Identifier*>* parents_;     //!< List of all parents of the object
             MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
+            unsigned int referenceCount_;              //!< Counts the references from smart pointers to this object
+            bool requestedDestruction_;                //!< Becomes true after someone called delete on this object
+
             //! 'Fast map' that holds this-pointers of all derived types
             std::vector<std::pair<unsigned int, void*> > objectPointers_;
     };

Modified: code/branches/core5/src/libraries/tools/Timer.h
===================================================================
--- code/branches/core5/src/libraries/tools/Timer.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/libraries/tools/Timer.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -142,7 +142,8 @@
                 @param object The object owning the timer and the function
                 @param exeuctor A executor of the function to call
             */
-            Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false)
+            template <class O>
+            Timer(float interval, bool bLoop, T* object, ExecutorMember<O>* exeuctor, bool bKillAfterCall = false)
             {
                 this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);
             }
@@ -154,7 +155,8 @@
                 @param object The object owning the timer and the function
                 @param exeuctor A executor of the function to call
             */
-            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false)
+            template <class O>
+            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<O>* executor, bool bKillAfterCall = false)
             {
                 this->deleteExecutor();
 

Modified: code/branches/core5/src/modules/weapons/MuzzleFlash.cc
===================================================================
--- code/branches/core5/src/modules/weapons/MuzzleFlash.cc	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/modules/weapons/MuzzleFlash.cc	2009-09-26 00:05:30 UTC (rev 5791)
@@ -40,14 +40,7 @@
     {
         RegisterObject(MuzzleFlash);
         this->setScale(0.1f);
-        
-        this->delayTimer_.setTimer(0.1f, false, this, createExecutor(createFunctor(&MuzzleFlash::destroy)));
 
+        this->delayTimer_.setTimer(0.1f, false, this, createExecutor(createFunctor(&MuzzleFlash::destroy)));
     }
-
-    void MuzzleFlash::destroy()
-    {
-        delete this;
-    }
- 
 }

Modified: code/branches/core5/src/modules/weapons/MuzzleFlash.h
===================================================================
--- code/branches/core5/src/modules/weapons/MuzzleFlash.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/modules/weapons/MuzzleFlash.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -42,12 +42,8 @@
             MuzzleFlash(BaseObject* creator);
             virtual ~MuzzleFlash() {}
 
-
-
         private:
-            void destroy();
             Timer<MuzzleFlash> delayTimer_;
-
     };
 }
 

Modified: code/branches/core5/src/orxonox/graphics/ParticleSpawner.h
===================================================================
--- code/branches/core5/src/orxonox/graphics/ParticleSpawner.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/orxonox/graphics/ParticleSpawner.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -45,8 +45,8 @@
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void processEvent(Event& event);
 
-            inline void destroy()
-                { this->bForceDestroy_ = true; this->stopParticleSpawner(); }
+            inline void stop(bool bDestroy)
+                { this->bForceDestroy_ = bDestroy; this->stopParticleSpawner(); }
             inline void spawn()
                 { this->bSuppressStart_ = false; this->startParticleSpawner(); }
 

Modified: code/branches/core5/src/orxonox/overlays/InGameConsole.h
===================================================================
--- code/branches/core5/src/orxonox/overlays/InGameConsole.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/orxonox/overlays/InGameConsole.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -49,7 +49,6 @@
         ~InGameConsole();
 
         void initialise();
-        void destroy();
         void setConfigValues();
 
         void update(const Clock& time);

Modified: code/branches/core5/src/orxonox/worldentities/BigExplosion.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/BigExplosion.cc	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/orxonox/worldentities/BigExplosion.cc	2009-09-26 00:05:30 UTC (rev 5791)
@@ -332,11 +332,6 @@
         }
     }
 
-    void BigExplosion::destroy()
-    {
-        delete this;
-    }
-
 /* TODO
 
     void BigExplosion::setDebrisMeshes()

Modified: code/branches/core5/src/orxonox/worldentities/BigExplosion.h
===================================================================
--- code/branches/core5/src/orxonox/worldentities/BigExplosion.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/orxonox/worldentities/BigExplosion.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -56,7 +56,6 @@
             void LODchanged();
             void checkStop();
             void stop();
-            void destroy();
             void init();
             void initZero();
 
@@ -97,8 +96,8 @@
             ParticleInterface*    explosionSmoke_;
             ParticleInterface*    explosionFire_;
 
-            LODParticle::Value      LOD_;
-            Timer<BigExplosion> destroyTimer_;
+            LODParticle::Value    LOD_;
+            Timer<BigExplosion>   destroyTimer_;
     };
 }
 

Modified: code/branches/core5/src/orxonox/worldentities/ExplosionChunk.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/ExplosionChunk.cc	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/orxonox/worldentities/ExplosionChunk.cc	2009-09-26 00:05:30 UTC (rev 5791)
@@ -135,11 +135,6 @@
         }
     }
 
-    void ExplosionChunk::destroy()
-    {
-        delete this;
-    }
-
     void ExplosionChunk::tick(float dt)
     {
         static const unsigned int CHANGES_PER_SECOND = 5;

Modified: code/branches/core5/src/orxonox/worldentities/ExplosionChunk.h
===================================================================
--- code/branches/core5/src/orxonox/worldentities/ExplosionChunk.h	2009-09-25 22:51:19 UTC (rev 5790)
+++ code/branches/core5/src/orxonox/worldentities/ExplosionChunk.h	2009-09-26 00:05:30 UTC (rev 5791)
@@ -54,12 +54,11 @@
             void LODchanged();
             void checkStop();
             void stop();
-            void destroy();
 
             bool                  bStop_;
             ParticleInterface*    fire_;
             ParticleInterface*    smoke_;
-            LODParticle::Value      LOD_;
+            LODParticle::Value    LOD_;
             Timer<ExplosionChunk> destroyTimer_;
     };
 }




More information about the Orxonox-commit mailing list