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.cc

    r1574 r1591  
    4141#include "ObjectListBase.h"
    4242#include "Identifier.h"
    43 #include "IteratorBase.h"
     43#include "Iterator.h"
    4444
    4545namespace orxonox
     
    7373        @param element The element that gets removed
    7474    */
    75     void ObjectListBase::notifyIterators(ObjectListBaseElement* element)
     75    void ObjectListBase::notifyIterators(OrxonoxClass* object) const
    7676    {
    77         for (std::set<IteratorBase*>::iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
    78             if ((*(*(*it))) == element->object_)
    79                 ++(*(*it));
     77        for (std::list<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
     78            ((Iterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
     79        for (std::list<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it)
     80            ((ObjectListIterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
    8081    }
    8182
     
    8586        @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object
    8687    */
    87     ObjectListBaseElement* ObjectListBase::add(OrxonoxClass* object)
     88    ObjectListBaseElement* ObjectListBase::add(ObjectListBaseElement* element)
    8889    {
    8990        if (!this->last_)
    9091        {
    9192            // If the list is empty
    92             this->last_ = new ObjectListBaseElement(object);
     93            this->last_ = element;
    9394            this->first_ = this->last_; // There's only one object in the list now
    9495        }
     
    9798            // If the list isn't empty
    9899            ObjectListBaseElement* temp = this->last_;
    99             this->last_ = new ObjectListBaseElement(object);
     100            this->last_ = element;
    100101            this->last_->prev_ = temp;
    101102            temp->next_ = this->last_;
Note: See TracChangeset for help on using the changeset viewer.