Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5403 in orxonox.OLD


Ignore:
Timestamp:
Oct 19, 2005, 1:00:43 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk:
implemented List-addAtIteratorPosition, to add any entity in the Sorted list at a designated position (for include-sorting)
include-sort the list of added Element2D's after their layer-depth

Location:
trunk/src/lib
Files:
3 edited

Legend:

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

    r5402 r5403  
    201201  if (this->parent != NULL && this->parent->getLayer() > layer)
    202202  {
    203     PRINTF(2)("Unable to set this Element2D to layer %s, because it's parent is of higher layer %s\n",
    204     Element2D::layer2DToChar(layer), Element2D::layer2DToChar(this->parent->getLayer()));
     203    PRINTF(2)("Unable to set %s to layer %s, because it's parent(%s) is of higher layer %s\n",
     204              this->getName(),
     205              Element2D::layer2DToChar(layer),
     206              this->parent->getName(),
     207              Element2D::layer2DToChar(this->parent->getLayer()));
    205208    layer = this->parent->getLayer();
    206209  }
     
    455458 * use this to add a child to this node.
    456459 */
    457 void Element2D::addChild2D (Element2D* child, int parentingMode)
     460void Element2D::addChild2D (Element2D* child)
    458461{
    459462  if( likely(child->parent != NULL))
     
    462465    child->parent->children->remove(child);
    463466  }
    464   if (parentingMode != E2D_PARENT_NONE)
    465     child->parentMode = parentingMode;
    466467  child->parent = this;
    467468  if (likely(this != NULL))
    468469  {
    469     this->children->add(child);
     470    // ELEMENT SORTING TO LAYERS  //
     471    unsigned int childCount = this->children->getSize();
     472    tIterator<Element2D>* iterator = this->children->getIterator();
     473    Element2D* elem = iterator->firstElement();
     474    while (elem != NULL)
     475    {
     476      if (elem->layer < child->layer)
     477      {
     478        this->children->addAtIteratorPosition(child, iterator);
     479        break;
     480      }
     481      elem = iterator->nextElement();
     482    }
     483    delete iterator;
     484    if (childCount == this->children->getSize())
     485      this->children->add(child);
     486    ////////////////////////////////
    470487    if (unlikely(this->layer > child->getLayer()))
    471488    {
    472       PRINTF(2)("Layer '%s' of Child %s lower than parents layer '%s'. updating\n",
    473       Element2D::layer2DToChar(child->getLayer()), Element2D::layer2DToChar(this->layer));
     489      PRINTF(2)("Layer '%s' of Child(%s) lower than parents(%s) layer '%s'. updating...\n",
     490      Element2D::layer2DToChar(child->getLayer()),child->getName(), this->getName(), Element2D::layer2DToChar(this->layer));
    474491      child->setLayer(this->layer);
    475492    }
     
    498515{
    499516  if (child != NULL)
    500   {
    501517    child->remove2D();
    502 //    this->children->remove(child);
    503 //    child->parent = NULL;
    504   }
    505518}
    506519
     
    517530  while( pn != NULL)
    518531  {
    519     NullElement2D::getInstance()->addChild2D(pn, pn->getParentMode2D());
     532    NullElement2D::getInstance()->addChild2D(pn);
    520533    pn = iterator->nextElement();
    521534  }
     
    953966 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0))
    954967 */
    955 NullElement2D::NullElement2D () : Element2D(NULL, E2D_LAYER_TOP)
     968NullElement2D::NullElement2D () : Element2D(NULL, E2D_LAYER_BELOW_ALL)
    956969{
    957970  this->setClassID(CL_NULL_ELEMENT_2D, "NullElement2D");
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5402 r5403  
    152152
    153153
    154     void addChild2D (Element2D* child, int parentingMode = E2D_PARENT_NONE);
     154    void addChild2D (Element2D* child);
    155155    void addChild2D (const char* childName);
    156156    void removeChild2D (Element2D* child);
  • trunk/src/lib/util/list.h

    r5400 r5403  
    3737    void add(T* entity);
    3838    void addAtBeginning(T* entity); //!< @todo This should be made with an ENUM
     39    void addAtIteratorPosition(T* entity, tIterator<T>* itereator);
    3940    void remove(const T* entity);
    4041    void removeFromLast(const T* entity);
     
    122123{
    123124  if( unlikely(entity == NULL)) return;
     125
    124126  listElement<T>* el = new listElement<T>;
    125127  el->next = this->first;
     
    134136}
    135137
     138/**
     139 * add an entity at an iterators position
     140 * @param entity the entity to add
     141 * @param iterator the iterator get the Positional from
     142 *
     143 * this works best with an iterator walking with
     144 * firstElement() ; nextStep();
     145 * or
     146 * lastElement(); prevStep();
     147 */
     148template<class T>
     149    inline void tList<T>::addAtIteratorPosition(T* entity, tIterator<T>* iterator)
     150{
     151  // rule out unusable
     152  if (unlikely(entity == NULL))
     153    return;
     154  // on any error (or next == NULL) add using default add-function
     155  if (unlikely(iterator == NULL || iterator->getList() == NULL) ||
     156      iterator->tmpEl == NULL || iterator->tmpEl->next == NULL)
     157    return this->add(entity);
     158  // on prev == NULL add with addAtBeginning-function
     159  if (unlikely(iterator->tmpEl->prev == NULL))
     160    return addAtBeginning(entity);
     161  else
     162  {
     163    listElement<T>* el = new listElement<T>;
     164    el->next = iterator->tmpEl->next;
     165    el->curr = entity;
     166    el->prev = iterator->tmpEl->prev;
     167
     168    el->next->prev = el;
     169    el->prev->next = el;
     170  }
     171}
    136172
    137173/**
     
    370406template<class T> class tIterator
    371407{
     408  friend class tList<T>;
    372409  public:
    373410    tIterator(const tList<T>* list);
     
    380417    T* seekElement(const T* element);
    381418    T* iteratorElement(const tIterator<T>* iterator);
    382     bool compareListPointer(const tList<T>* list);
    383 
     419    bool compareListPointer(const tList<T>* list) const;
     420    inline const tList<T>* getList() const { return this->list; };
    384421    /** another way to iterate through the list
    385422     * !! THIS IS NOT MEANT FOR DELETION
     
    554591
    555592template<class T>
    556     bool tIterator<T>::compareListPointer(const tList<T>* list)
     593    bool tIterator<T>::compareListPointer(const tList<T>* list) const
    557594{
    558595  return (this->list == list)?true:false;
Note: See TracChangeset for help on using the changeset viewer.