Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5775 in orxonox.OLD


Ignore:
Timestamp:
Nov 25, 2005, 1:54:33 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: stl::list in Element2D

Location:
trunk/src/lib/graphics/render2D
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r5671 r5775  
    1919#include "render_2d.h"
    2020
     21#include "p_node.h"
     22
    2123#include "graphics_engine.h"
    22 #include "p_node.h"
    2324#include "load_param.h"
    2425#include "tinyxml.h"
    2526#include "class_list.h"
    26 #include "list.h"
     27
    2728#include "color.h"
    2829
     
    7374{
    7475  // remove the Node, delete it's children.
    75   tIterator<Element2D>* iterator = this->children->getIterator();
    76   Element2D* child = iterator->firstElement();
    77 
    78   while( child != NULL)
    79   {
    80     delete child;
    81     child = iterator->nextElement();
    82   }
    83   delete iterator;
     76  list<Element2D*>::iterator child;
     77  for (child = this->children.begin(); child != this->children.end(); child++)
     78    delete *child;
    8479
    8580  if (this->parent != NULL)
    8681  {
    87     this->parent->children->remove(this);
     82    this->parent->children.remove(this);
    8883    this->parent = NULL;
    8984  }
    90   delete this->children;
    9185
    9286  // remove all other allocated memory.
     
    113107  this->setParentMode2D(E2D_PARENT_ALL);
    114108  this->parent = NULL;
    115   this->children = new tList<Element2D>;
    116109  this->absDirection = 0.0;
    117110  this->relDirection = 0.0;
     
    517510  {
    518511    PRINTF(5)("Element2D::addChild() - reparenting node: removing it and adding it again\n");
    519     child->parent->children->remove(child);
     512    child->parent->children.remove(child);
    520513  }
    521514  child->parent = this;
     
    523516  {
    524517    // ELEMENT SORTING TO LAYERS  //
    525     unsigned int childCount = this->children->getSize();
    526     tIterator<Element2D>* iterator = this->children->getIterator();
    527     Element2D* elem = iterator->firstElement();
    528     while (elem != NULL)
    529     {
    530       if (elem->layer < child->layer)
     518    unsigned int childCount = this->children.size();
     519
     520    list<Element2D*>::iterator elem;
     521    for (elem = this->children.begin(); elem != this->children.end(); elem++)
     522    {
     523      if ((*elem)->layer < child->layer)
    531524      {
    532         this->children->addAtIteratorPosition(child, iterator);
     525        this->children.insert(elem, child);
    533526        break;
    534527      }
    535       elem = iterator->nextElement();
    536     }
    537     delete iterator;
    538     if (childCount == this->children->getSize())
    539       this->children->add(child);
     528    }
     529
     530    if (childCount == this->children.size())
     531      this->children.push_back(child);
    540532    ////////////////////////////////
    541533    if (unlikely(this->layer > child->getLayer()))
     
    579571void Element2D::remove2D()
    580572{
    581   tIterator<Element2D>* iterator = this->children->getIterator();
    582   Element2D* pn = iterator->firstElement();
    583 
    584   while( pn != NULL)
    585   {
    586     NullElement2D::getInstance()->addChild2D(pn);
    587     pn = iterator->nextElement();
    588   }
    589   delete iterator;
    590 
    591   delete this->children;
    592   this->children = new tList<Element2D>;
     573  list<Element2D*>::iterator child;
     574  for (child = this->children.begin(); child != this->children.end(); child++)
     575    NullElement2D::getInstance()->addChild2D(*child);
     576
     577  this->children.erase(this->children.begin(), this->children.end());
    593578
    594579  if (this->parent != NULL)
    595580  {
    596     this->parent->children->remove(this);
     581    this->parent->children.remove(this);
    597582    this->parent = NULL;
    598583  }
     
    802787
    803788  // UPDATE CHILDREN
    804   if(this->children->getSize() > 0)
    805   {
    806     tIterator<Element2D>* iterator = this->children->getIterator();
    807     Element2D* pn = iterator->firstElement();
    808     while( pn != NULL)
     789  if(this->children.size() > 0)
     790  {
     791    list<Element2D*>::iterator child;
     792    for (child = this->children.begin(); child != this->children.end(); child++)
    809793    {
    810794      /* if this node has changed, make sure, that all children are updated also */
    811795      if( likely(this->bRelCoorChanged))
    812         pn->parentCoorChanged ();
     796        (*child)->parentCoorChanged ();
    813797      if( likely(this->bRelDirChanged))
    814         pn->parentDirChanged ();
    815 
    816       pn->update2D(dt);
    817       pn = iterator->nextElement();
    818     }
    819     delete iterator;
     798        (*child)->parentDirChanged ();
     799
     800      (*child)->update2D(dt);
     801    }
    820802  }
    821803
     
    836818  for (unsigned int i = 0; i < level; i++)
    837819    PRINT(0)(" |");
    838   if (this->children->getSize() > 0)
     820  if (this->children.size() > 0)
    839821    PRINT(0)(" +");
    840822  else
     
    853835  if (depth >= 2 || depth == 0)
    854836  {
    855     tIterator<Element2D>* iterator = this->children->getIterator();
    856     Element2D* pn = iterator->firstElement();
    857     while( pn != NULL)
     837    list<Element2D*>::const_iterator child;
     838    for (child = this->children.begin(); child != this->children.end(); child++)
    858839    {
    859840      if (depth == 0)
    860         pn->debug(0, level + 1);
     841        (*child)->debug(0, level + 1);
    861842      else
    862         pn->debug(depth - 1, level +1);
    863       pn = iterator->nextElement();
    864     }
    865     delete iterator;
     843        (*child)->debug(depth - 1, level +1);
     844    }
    866845  }
    867846}
     
    879858  if (this->active)
    880859    this->tick(dt);
    881   if (this->children->getSize() > 0)
    882   {
    883     tIterator<Element2D>* tickIT = children->getIterator();
    884     Element2D* tickElem = tickIT->firstElement();
    885     while (tickElem != NULL)
    886     {
    887       tickElem->tick2D(dt);
    888       tickElem = tickIT->nextElement();
    889     }
    890     delete tickIT;
     860  if (this->children.size() > 0)
     861  {
     862    list<Element2D*>::iterator child;
     863    for (child = this->children.begin(); child != this->children.end(); child++)
     864      (*child)->tick2D(dt);
    891865  }
    892866}
     
    900874  if (this->visible)
    901875    this->draw();
    902   if (this->children->getSize() > 0)
    903   {
    904     tIterator<Element2D>* drawIT = children->getIterator();
    905     Element2D* drawElem = drawIT->firstElement();
    906     while (drawElem != NULL)
    907     {
     876  if (this->children.size() > 0)
     877  {
     878    list<Element2D*>::const_iterator child;
     879    for (child = this->children.begin(); child != this->children.end(); child++)
    908880      if (likely(layer >= this->layer))
    909         drawElem->draw2D(layer);
    910       drawElem = drawIT->nextElement();
    911     }
    912     delete drawIT;
     881        (*child)->draw2D(layer);
    913882  }
    914883}
     
    948917  {
    949918    Vector childColor =  Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(20,0,.0));
    950     tIterator<Element2D>* iterator = this->children->getIterator();
    951     Element2D* pn = iterator->firstElement();
    952     while( pn != NULL)
     919    list<Element2D*>::const_iterator child;
     920    for (child = this->children.begin(); child != this->children.end(); child++)
    953921    {
    954922      // drawing the Dependency graph
     
    961929                   0);
    962930        glColor3f(childColor.x, childColor.y, childColor.z);
    963         glVertex3f(pn->getAbsCoor2D ().x,
    964                    pn->getAbsCoor2D ().y,
     931        glVertex3f((*child)->getAbsCoor2D ().x,
     932                   (*child)->getAbsCoor2D ().y,
    965933                   0);
    966934        glEnd();
    967935      }
    968936      if (depth == 0)
    969         pn->debugDraw2D(0, size, childColor, level+1);
     937        (*child)->debugDraw2D(0, size, childColor, level+1);
    970938      else
    971         pn->debugDraw2D(depth - 1, size, childColor, level +1);
    972       pn = iterator->nextElement();
    973     }
    974     delete iterator;
     939        (*child)->debugDraw2D(depth - 1, size, childColor, level +1);
     940    }
    975941  }
    976942  if (level == 0)
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5417 r5775  
    1010
    1111#include "vector.h"
     12#include <list>
    1213
    1314// FORWARD DECLARATION
    1415class PNode;
    1516class TiXmlElement;
    16 template<class T> class tList;
    1717
    1818//!< An enumerator defining the Depth of a 2D-element.
     
    171171    inline Element2D* getParent2D () const { return this->parent; };
    172172    /** @returns the List of Children of this Element2D */
    173     inline const tList<Element2D>* getChildren2D() const { return this->children; };
     173    inline const std::list<Element2D*>& getChildren2D() const { return this->children; };
    174174
    175175    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
     
    234234
    235235    Element2D*              parent;             //!< a pointer to the parent node
    236     tList<Element2D>*       children;           //!< list of the children of this Element2D
     236    std::list<Element2D*>   children;           //!< list of the children of this Element2D
    237237
    238238    unsigned int            parentMode;         //!< the mode of the binding
Note: See TracChangeset for help on using the changeset viewer.