Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 12, 2008, 2:00:15 AM (16 years ago)
Author:
landauf
Message:

Again some heavy changes in ObjectList and Iterator:
there are now two types of iterators:

Iterator<ClassName> can iterate through any objectlist, either given by ObjectList<AnyClassName>::begin() or anyidentifier→getObjects()→begin(). Important note Iterator<ClassName> uses dynamic_cast.
And yes, it's possible to do this: Iterator<WorldEntity> it = ObjectList<SpaceShip>::begin()

ObjectList<ClassName>::iterator is the second iterator - it uses the ObjectList in a templated manner and therefore doesn't need dynamic_cast. But the only thing you can do is iterating through exactly the right ObjectList: ObjectList<ClassName>::iterator it = ObjectList<ClassName>::begin(). Anything else fails.

Those changes bring, at my system, something around +12% FPS compared with trunk and +25% FPS compared with the last revision of core3. Although I have to admit the FPS gain is only that high because iterating through objects is the main thing we're doing ingame right now. It would look totally different with physics, sound, AI, scripts, triggers and so on.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/ObjectListBase.h

    r1574 r1591  
    3838#define _ObjectListBase_H__
    3939
    40 #include <set>
     40#include <list>
    4141
    4242#include "CorePrereqs.h"
     
    5555                @param object The object to store
    5656            */
    57             ObjectListBaseElement(OrxonoxClass* object) : object_(object), next_(0), prev_(0) {}
     57            ObjectListBaseElement(OrxonoxClass* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {}
    5858
    59             OrxonoxClass* object_;              //!< The object
    6059            ObjectListBaseElement* next_;       //!< The next element in the list
    6160            ObjectListBaseElement* prev_;       //!< The previous element in the list
     61            OrxonoxClass* objectBase_;
     62    };
     63
     64
     65    // ###############################
     66    // ###    ObjectListElement    ###
     67    // ###############################
     68    //! The list-element that actually contains the object
     69    template <class T>
     70    class ObjectListElement : public ObjectListBaseElement
     71    {
     72        public:
     73            ObjectListElement(T* object) : ObjectListBaseElement(object), object_(object) {}
     74            T* object_;              //!< The object
    6275    };
    6376
     
    7992            ~ObjectListBase();
    8093
    81             ObjectListBaseElement* add(OrxonoxClass* object);
     94            ObjectListBaseElement* add(ObjectListBaseElement* element);
     95
     96            struct Export
     97            {
     98                Export(ObjectListBase* list, ObjectListBaseElement* element) : list_(list), element_(element) {}
     99                ObjectListBase* list_;
     100                ObjectListBaseElement* element_;
     101            };
    82102
    83103            /** @brief Returns a pointer to the first element in the list. @return The element */
    84             inline ObjectListBaseElement* begin() const { return this->first_; }
     104            inline Export begin() { return ObjectListBase::Export(this, this->first_); }
    85105            /** @brief Returns a pointer to the element after the last element in the list. @return The element */
    86             inline ObjectListBaseElement* end() const { return 0; }
     106            inline Export end() { return ObjectListBase::Export(this, 0); }
    87107            /** @brief Returns a pointer to the last element in the list. @return The element */
    88             inline ObjectListBaseElement* rbegin() const { return this->last_; }
     108            inline Export rbegin() { return ObjectListBase::Export(this, this->last_); }
    89109            /** @brief Returns a pointer to the element in front of the first element in the list. @return The element */
    90             inline ObjectListBaseElement* rend() const { return 0; }
     110            inline Export rend() { return ObjectListBase::Export(this, 0); }
    91111
    92             inline void registerIterator(IteratorBase* iterator)
    93                 { this->iterators_.insert(this->iterators_.end(), iterator); }
    94             inline void unregisterIterator(IteratorBase* iterator)
    95                 { this->iterators_.erase(iterator); }
    96             void notifyIterators(ObjectListBaseElement* element);
     112            inline std::list<void*>::iterator registerIterator(void* iterator) { return this->iterators_.insert(this->iterators_.begin(), iterator); }
     113            inline void unregisterIterator(const std::list<void*>::iterator& iterator) { this->iterators_.erase(iterator); }
     114            inline std::list<void*>::iterator registerObjectListIterator(void* iterator) { return this->objectListIterators_.insert(this->iterators_.begin(), iterator); }
     115            inline void unregisterObjectListIterator(const std::list<void*>::iterator& iterator) { this->objectListIterators_.erase(iterator); }
     116            void notifyIterators(OrxonoxClass* object) const;
    97117
    98118            inline Identifier* getIdentifier() const { return this->identifier_; }
    99119
    100120        private:
    101             Identifier* identifier_;             //!< The Iterator owning this list
    102             ObjectListBaseElement* first_;       //!< The first element in the list
    103             ObjectListBaseElement* last_;        //!< The last element in the list
    104             std::set<IteratorBase*> iterators_;  //!< A list of iterators pointing on an element in this list
     121            Identifier* identifier_;               //!< The Iterator owning this list
     122            ObjectListBaseElement* first_;         //!< The first element in the list
     123            ObjectListBaseElement* last_;          //!< The last element in the list
     124            std::list<void*> iterators_;           //!< A list of Iterators pointing on an element in this list
     125            std::list<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
    105126    };
    106127}
Note: See TracChangeset for help on using the changeset viewer.