Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/OrxonoxClass.h

    r5738 r5929  
    5555        friend class ClassIdentifier;
    5656
     57        template <class T>
     58        friend class SmartPtr;
     59
     60        template <class T>
     61        friend class WeakPtr;
     62
    5763        public:
    5864            OrxonoxClass();
    5965            virtual ~OrxonoxClass();
     66
     67            void destroy();
    6068
    6169            /** @brief Function to collect the SetConfigValue-macro calls. */
     
    7280            bool isDirectParentOf(const Identifier* identifier);
    7381
    74             template <class B> bool isA(const SubclassIdentifier<B>* identifier);
    75             template <class B> bool isExactlyA(const SubclassIdentifier<B>* identifier);
    76             template <class B> bool isChildOf(const SubclassIdentifier<B>* identifier);
    77             template <class B> bool isDirectChildOf(const SubclassIdentifier<B>* identifier);
    78             template <class B> bool isParentOf(const SubclassIdentifier<B>* identifier);
    79             template <class B> bool isDirectParentOf(const SubclassIdentifier<B>* identifier);
    80 
    81             template <class B> bool isA(const SubclassIdentifier<B> identifier);
    82             template <class B> bool isExactlyA(const SubclassIdentifier<B> identifier);
    83             template <class B> bool isChildOf(const SubclassIdentifier<B> identifier);
    84             template <class B> bool isDirectChildOf(const SubclassIdentifier<B> identifier);
    85             template <class B> bool isParentOf(const SubclassIdentifier<B> identifier);
    86             template <class B> bool isDirectParentOf(const SubclassIdentifier<B> identifier);
     82            template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
     83                { return this->isA(*identifier); }
     84            template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
     85                { return this->isExactlyA(*identifier); }
     86            template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
     87                { return this->isChildOf(*identifier); }
     88            template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
     89                { return this->isDirectChildOf(*identifier); }
     90            template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
     91                { return this->isParentOf(*identifier); }
     92            template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
     93                { return this->isDirectParentOf(*identifier); }
    8794
    8895            bool isA(const OrxonoxClass* object);
     
    93100            bool isDirectParentOf(const OrxonoxClass* object);
    94101
     102            inline unsigned int getReferenceCount() const
     103                { return this->referenceCount_; }
     104
    95105            /**
    96106            @brief
     
    100110                Returns NULL if the no pointer was found.
    101111            */
    102             template <class T>
    103             FORCEINLINE T* getDerivedPointer(unsigned int classID)
     112            FORCEINLINE void* getDerivedPointer(unsigned int classID)
    104113            {
    105114                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
    106115                {
    107116                    if (this->objectPointers_[i].first == classID)
    108                         return static_cast<T*>(this->objectPointers_[i].second);
     117                        return this->objectPointers_[i].second;
    109118                }
    110119                return NULL;
    111120            }
    112             //! Const version of getDerivedPointer
    113             template <class T>
    114             FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
    115             {
    116                 return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);
    117             }
     121
     122            //! Version of getDerivedPointer with template
     123            template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID)
     124            {   return static_cast<T*>(this->getDerivedPointer(classID));   }
     125            //! Const version of getDerivedPointer with template
     126            template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
     127            {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
    118128
    119129        private:
     130            /** @brief Increments the reference counter (for smart pointers). */
     131            inline void incrementReferenceCount()
     132                { ++this->referenceCount_; }
     133            /** @brief Decrements the reference counter (for smart pointers). */
     134            inline void decrementReferenceCount()
     135                { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } }
     136               
     137            /** @brief Register a weak pointer which points to this object. */
     138            template <class T>
     139            inline void registerWeakPtr(WeakPtr<T>* pointer)
     140                { this->weakPointers_.insert(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); }
     141            /** @brief Unegister a weak pointer which pointed to this object before. */
     142            template <class T>
     143            inline void unregisterWeakPtr(WeakPtr<T>* pointer)
     144                { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); }
     145
    120146            Identifier* identifier_;                   //!< The Identifier of the object
    121147            std::set<const Identifier*>* parents_;     //!< List of all parents of the object
    122148            MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
     149            int referenceCount_;                       //!< Counts the references from smart pointers to this object
     150            bool requestedDestruction_;                //!< Becomes true after someone called delete on this object
     151            std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies)
     152
    123153            //! 'Fast map' that holds this-pointers of all derived types
    124154            std::vector<std::pair<unsigned int, void*> > objectPointers_;
Note: See TracChangeset for help on using the changeset viewer.