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/orxonox/objects/NPC.cc

    r1574 r1591  
    3131
    3232#include "core/CoreIncludes.h"
     33#include "core/Iterator.h"
    3334
    3435namespace orxonox {
     
    117118    int numberOfNeighbour = 0;  //number of observed neighbours
    118119    float distance = 0;  // distance to the actual element
    119     for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; ++it) {  //go through all elements
     120    for(ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it) {  //go through all elements
    120121      distance = getDistance(*it);  //get distance between this and actual
    121122      if ((distance > 0) && (distance < SEPERATIONDISTANCE)) {  //do only if actual is inside detectionradius
     
    144145    //float distance = 0;
    145146    //go through all elements
    146     for(Iterator<NPC> it = ObjectList<NPC>::begin(); it; ++it) {  //just working with 3 elements at the moment
     147    for(ObjectList<NPC>::iterator it = ObjectList<NPC>::begin(); it; ++it) {  //just working with 3 elements at the moment
    147148      float distance = getDistance(*it);  //get distance between this and actual
    148149      if ((distance > 0) && (distance < ALIGNMENTDISTANCE)) {  //check if actual element is inside detectionradius
     
    164165    //float distance = 0;
    165166    //go through all elements
    166     for(Iterator<NPC> it = ObjectList<NPC>::begin(); it; ++it) {  //just working with 3 elements at the moment
     167    for(ObjectList<NPC>::iterator it = ObjectList<NPC>::begin(); it; ++it) {  //just working with 3 elements at the moment
    167168      float distance = getDistance(*it);  //get distance between this and actual
    168169      if ((distance > 0) && (distance < COHESIONDISTANCE)) {  //check if actual element is inside detectionradius
Note: See TracChangeset for help on using the changeset viewer.