Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5285 in orxonox.OLD for trunk/src/lib/graphics/render2D


Ignore:
Timestamp:
Oct 6, 2005, 8:31:23 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: nicer quit-modi
TextEngine is now deleted by GraphicsEngine
trying to fix errors in the Element2D deletion

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

Legend:

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

    r5254 r5285  
    2525#include "class_list.h"
    2626#include "list.h"
     27#include "color.h"
    2728
    2829using namespace std;
    2930
     31/**
     32 * standard constructor
     33 */
    3034Element2D::Element2D()
    3135{
    3236  this->init();
     37
    3338  this->setParent2D(NullElement2D::getInstance());
     39  NullElement2D::getInstance()->debug(0);
    3440}
    3541
    3642/**
    3743 * standard constructor
    38  * @todo this constructor is not jet implemented - do it
    39 */
     44 * @param parent the parent to set for this Element2D
     45 *
     46 * NullElement2D needs this constructor with parameter NULL to initialize
     47 * itself. Otherwise it would result in an endless Loop.
     48 */
    4049Element2D::Element2D (Element2D* parent)
    4150{
     
    4453  if (this->parent != NULL)
    4554    this->setParent2D(parent);
     55  else if (NullElement2D::isInstanciated())
     56    this->setParent2D(NullElement2D::getInstance());
    4657}
    4758
    4859/**
    4960 * standard deconstructor
    50 */
     61 *
     62 * There are two general ways to delete an Element2D
     63 * 1. delete instance;
     64 *   -> result
     65 *    delete this Node and all its children and children's children...
     66 *    (danger if you still want the instance!!)
     67 *
     68 * 2. instance->remove2D(); delete instance;
     69 *   -> result:
     70 *    moves its children to the NullParent
     71 *    then deletes the Element.
     72 */
    5173Element2D::~Element2D ()
    5274{
     
    5476  Render2D::getInstance()->unregisterElement2D(this);
    5577
    56   if (this->parent)
    57     this->parent->removeChild2D(this);
    58   else
    59   {
    60     tIterator<Element2D>* iterator = this->children->getIterator();
    61     Element2D* pn = iterator->firstElement();
    62     while( pn != NULL)
    63     {
    64       delete pn;
    65       pn = iterator->nextElement();
    66     }
    67     delete iterator;
    68     /* this deletes all children in the list */
     78  // remove the Node, delete it's children.
     79  tIterator<Element2D>* iterator = this->children->getIterator();
     80  Element2D* child = iterator->firstElement();
     81
     82  while( child != NULL)
     83  {
     84    delete child;
     85    child = iterator->nextElement();
     86  }
     87  delete iterator;
     88
     89  if (this->parent != NULL)
     90  {
     91    this->parent->children->remove(this);
     92    this->parent = NULL;
    6993  }
    7094  delete this->children;
    7195
     96  // remove all other allocated memory.
    7297  if (this->toCoordinate != NULL)
    7398    delete this->toCoordinate;
     
    99124  this->toCoordinate = NULL;
    100125  this->toDirection = NULL;
    101 //  else
    102   //  this->setParent2D(parent);
    103126
    104127  Render2D::getInstance()->registerElement2D(this);
     
    480503
    481504/**
    482  * remove this pnode from the tree and adds all following to NullParent
     505 * remove this Element from the tree and adds all children to NullElement2D
    483506 *
    484  * this can be the case, if an entity in the world is being destroyed.
     507 * afterwards this Node is free, and can be reattached, or deleted freely.
    485508 */
    486509void Element2D::remove2D()
     
    495518  }
    496519  delete iterator;
     520
     521  delete this->children;
     522  this->children = new tList<Element2D>;
     523
    497524  if (this->parent != NULL)
     525  {
    498526    this->parent->children->remove(this);
     527    this->parent = NULL;
     528  }
    499529}
    500530
     
    762792}
    763793
    764 #include "color.h"
     794/**
     795 * ticks the 2d-Element
     796 * @param dt the time elapsed since the last tick
     797 */
     798void Element2D::tick(float dt)
     799{
     800
     801}
    765802
    766803/**
     
    816853
    817854
    818 
    819 /**
    820  * ticks the 2d-Element
    821  * @param dt the time elapsed since the last tick
    822  */
    823 void Element2D::tick(float dt)
    824 {
    825 
    826 }
    827 
    828 
    829 
    830 
    831 
    832 
    833 
     855///////////////////
     856// NullElement2D //
     857///////////////////
    834858NullElement2D* NullElement2D::singletonRef = 0;
    835859
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5279 r5285  
    218218  public:
    219219    /** @returns a Pointer to the only object of this Class */
    220     inline static NullElement2D* getInstance() { if (!singletonRef) singletonRef = new NullElement2D();  return singletonRef; };
     220    inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
     221    inline static bool isInstanciated() { return (NullElement2D::singletonRef != NULL)?true:false; };
    221222    virtual ~NullElement2D ();
    222223
Note: See TracChangeset for help on using the changeset viewer.