Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5791


Ignore:
Timestamp:
Sep 26, 2009, 2:05:30 AM (15 years ago)
Author:
landauf
Message:

Added destroy() function to OrxonoxClass.
Removed destroy() functions from some subclasses.
Expanded Timer to accept Functors of other classes too.

Location:
code/branches/core5/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/OrxonoxClass.cc

    r5772 r5791  
    4545        this->parents_ = 0;
    4646        this->metaList_ = new MetaObjectList();
     47        this->referenceCount_ = 0;
     48        this->requestedDestruction_ = false;
    4749    }
    4850
     
    5557        if (this->parents_)
    5658            delete this->parents_;
     59    }
     60
     61    /** @brief Deletes the object if no smart pointers point to this object. Otherwise schedules the object to be deleted as soon as possible. */
     62    void OrxonoxClass::destroy()
     63    {
     64        if (this->referenceCount_ > 0)
     65            this->requestedDestruction_ = true;
     66        else
     67            delete this;
    5768    }
    5869
  • code/branches/core5/src/libraries/core/OrxonoxClass.h

    r5772 r5791  
    5959            virtual ~OrxonoxClass();
    6060
     61            void destroy();
     62
    6163            /** @brief Function to collect the SetConfigValue-macro calls. */
    6264            void setConfigValues() {};
     
    9294            bool isDirectParentOf(const OrxonoxClass* object);
    9395
     96            inline unsigned int getReferenceCount() const
     97                { return this->referenceCount_; }
     98
    9499            /**
    95100            @brief
     
    117122
    118123        private:
     124            /** @brief Increments the reference counter (for smart pointers). */
     125            inline void incrementReferenceCount()
     126                { ++this->referenceCount_; }
     127            /** @brief Decrements the reference counter (for smart pointers). */
     128            inline void decrementReferenceCount()
     129                { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } }
     130
    119131            Identifier* identifier_;                   //!< The Identifier of the object
    120132            std::set<const Identifier*>* parents_;     //!< List of all parents of the object
    121133            MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
     134            unsigned int referenceCount_;              //!< Counts the references from smart pointers to this object
     135            bool requestedDestruction_;                //!< Becomes true after someone called delete on this object
     136
    122137            //! 'Fast map' that holds this-pointers of all derived types
    123138            std::vector<std::pair<unsigned int, void*> > objectPointers_;
  • code/branches/core5/src/libraries/tools/Timer.h

    r5738 r5791  
    143143                @param exeuctor A executor of the function to call
    144144            */
    145             Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false)
     145            template <class O>
     146            Timer(float interval, bool bLoop, T* object, ExecutorMember<O>* exeuctor, bool bKillAfterCall = false)
    146147            {
    147148                this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);
     
    155156                @param exeuctor A executor of the function to call
    156157            */
    157             void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false)
     158            template <class O>
     159            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<O>* executor, bool bKillAfterCall = false)
    158160            {
    159161                this->deleteExecutor();
  • code/branches/core5/src/modules/weapons/MuzzleFlash.cc

    r5738 r5791  
    4141        RegisterObject(MuzzleFlash);
    4242        this->setScale(0.1f);
    43        
     43
    4444        this->delayTimer_.setTimer(0.1f, false, this, createExecutor(createFunctor(&MuzzleFlash::destroy)));
    45 
    4645    }
    47 
    48     void MuzzleFlash::destroy()
    49     {
    50         delete this;
    51     }
    52  
    5346}
  • code/branches/core5/src/modules/weapons/MuzzleFlash.h

    r5738 r5791  
    4343            virtual ~MuzzleFlash() {}
    4444
    45 
    46 
    4745        private:
    48             void destroy();
    4946            Timer<MuzzleFlash> delayTimer_;
    50 
    5147    };
    5248}
  • code/branches/core5/src/orxonox/graphics/ParticleSpawner.h

    r5738 r5791  
    4646            virtual void processEvent(Event& event);
    4747
    48             inline void destroy()
    49                 { this->bForceDestroy_ = true; this->stopParticleSpawner(); }
     48            inline void stop(bool bDestroy)
     49                { this->bForceDestroy_ = bDestroy; this->stopParticleSpawner(); }
    5050            inline void spawn()
    5151                { this->bSuppressStart_ = false; this->startParticleSpawner(); }
  • code/branches/core5/src/orxonox/overlays/InGameConsole.h

    r5738 r5791  
    5050
    5151        void initialise();
    52         void destroy();
    5352        void setConfigValues();
    5453
  • code/branches/core5/src/orxonox/worldentities/BigExplosion.cc

    r5747 r5791  
    333333    }
    334334
    335     void BigExplosion::destroy()
    336     {
    337         delete this;
    338     }
    339 
    340335/* TODO
    341336
  • code/branches/core5/src/orxonox/worldentities/BigExplosion.h

    r5738 r5791  
    5757            void checkStop();
    5858            void stop();
    59             void destroy();
    6059            void init();
    6160            void initZero();
     
    9897            ParticleInterface*    explosionFire_;
    9998
    100             LODParticle::Value      LOD_;
    101             Timer<BigExplosion> destroyTimer_;
     99            LODParticle::Value    LOD_;
     100            Timer<BigExplosion>   destroyTimer_;
    102101    };
    103102}
  • code/branches/core5/src/orxonox/worldentities/ExplosionChunk.cc

    r5747 r5791  
    136136    }
    137137
    138     void ExplosionChunk::destroy()
    139     {
    140         delete this;
    141     }
    142 
    143138    void ExplosionChunk::tick(float dt)
    144139    {
  • code/branches/core5/src/orxonox/worldentities/ExplosionChunk.h

    r5738 r5791  
    5555            void checkStop();
    5656            void stop();
    57             void destroy();
    5857
    5958            bool                  bStop_;
    6059            ParticleInterface*    fire_;
    6160            ParticleInterface*    smoke_;
    62             LODParticle::Value      LOD_;
     61            LODParticle::Value    LOD_;
    6362            Timer<ExplosionChunk> destroyTimer_;
    6463    };
Note: See TracChangeset for help on using the changeset viewer.