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/Identifier.h

    r1586 r1591  
    6060#include <utility>
    6161
    62 #include "Iterator.h"
     62#include "MetaObjectList.h"
     63#include "ObjectListBase.h"
    6364#include "util/Debug.h"
    6465#include "util/String.h"
     
    103104            bool isDirectParentOf(const Identifier* identifier) const;
    104105
    105             void addObject(OrxonoxClass* object);
    106 
    107106            /** @brief Returns the list of all existing objects of this class. @return The list */
    108107            inline ObjectListBase* getObjects() const
     
    113112            void setName(const std::string& name);
    114113
    115             virtual void updateConfigValues() const = 0;
     114            void updateConfigValues() const;
    116115
    117116            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
     
    231230
    232231            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     232            ObjectListBase* objects_;                                      //!< The list of all objects of this class
    233233
    234234        private:
     
    264264            bool bSetName_;                                                //!< True if the name is set
    265265            std::string name_;                                             //!< The name of the class the Identifier belongs to
    266             ObjectListBase* objects_;                                      //!< The list of all objects of this class
    267266            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
    268267            static int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
     
    301300            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    302301            static bool isFirstCall();
    303 
    304             void updateConfigValues() const;
     302            void addObject(T* object);
    305303
    306304            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
     
    411409
    412410    /**
    413         @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.
    414     */
    415     template <class T>
    416     void ClassIdentifier<T>::updateConfigValues() const
    417     {
    418         for (Iterator<T> it = this->getObjects()->begin(); it; ++it)
    419             (*it)->setConfigValues();
     411        @brief Adds an object of the given type to the ObjectList.
     412        @param object The object to add
     413    */
     414    template <class T>
     415    void ClassIdentifier<T>::addObject(T* object)
     416    {
     417        COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
     418        object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
    420419    }
    421420
Note: See TracChangeset for help on using the changeset viewer.