Changeset 5285 in orxonox.OLD for trunk/src/lib/graphics/render2D
- Timestamp:
- Oct 6, 2005, 8:31:23 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/render2D
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/render2D/element_2d.cc
r5254 r5285 25 25 #include "class_list.h" 26 26 #include "list.h" 27 #include "color.h" 27 28 28 29 using namespace std; 29 30 31 /** 32 * standard constructor 33 */ 30 34 Element2D::Element2D() 31 35 { 32 36 this->init(); 37 33 38 this->setParent2D(NullElement2D::getInstance()); 39 NullElement2D::getInstance()->debug(0); 34 40 } 35 41 36 42 /** 37 43 * 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 */ 40 49 Element2D::Element2D (Element2D* parent) 41 50 { … … 44 53 if (this->parent != NULL) 45 54 this->setParent2D(parent); 55 else if (NullElement2D::isInstanciated()) 56 this->setParent2D(NullElement2D::getInstance()); 46 57 } 47 58 48 59 /** 49 60 * 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 */ 51 73 Element2D::~Element2D () 52 74 { … … 54 76 Render2D::getInstance()->unregisterElement2D(this); 55 77 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; 69 93 } 70 94 delete this->children; 71 95 96 // remove all other allocated memory. 72 97 if (this->toCoordinate != NULL) 73 98 delete this->toCoordinate; … … 99 124 this->toCoordinate = NULL; 100 125 this->toDirection = NULL; 101 // else102 // this->setParent2D(parent);103 126 104 127 Render2D::getInstance()->registerElement2D(this); … … 480 503 481 504 /** 482 * remove this pnode from the tree and adds all following to NullParent505 * remove this Element from the tree and adds all children to NullElement2D 483 506 * 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. 485 508 */ 486 509 void Element2D::remove2D() … … 495 518 } 496 519 delete iterator; 520 521 delete this->children; 522 this->children = new tList<Element2D>; 523 497 524 if (this->parent != NULL) 525 { 498 526 this->parent->children->remove(this); 527 this->parent = NULL; 528 } 499 529 } 500 530 … … 762 792 } 763 793 764 #include "color.h" 794 /** 795 * ticks the 2d-Element 796 * @param dt the time elapsed since the last tick 797 */ 798 void Element2D::tick(float dt) 799 { 800 801 } 765 802 766 803 /** … … 816 853 817 854 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 /////////////////// 834 858 NullElement2D* NullElement2D::singletonRef = 0; 835 859 -
trunk/src/lib/graphics/render2D/element_2d.h
r5279 r5285 218 218 public: 219 219 /** @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; }; 221 222 virtual ~NullElement2D (); 222 223
Note: See TracChangeset
for help on using the changeset viewer.