- Timestamp:
- Oct 18, 2005, 11:57:44 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/render2D/element_2d.cc
r5398 r5401 35 35 { 36 36 this->init(); 37 Render2D::getInstance()->registerElement2D(this);38 37 this->setParent2D(NullElement2D::getInstance()); 39 38 } … … 49 48 { 50 49 this->init(); 51 Render2D::getInstance()->registerElement2D(this);52 50 53 51 // check Parenting, and if ok parent the stuff … … 69 67 * 2. instance->remove2D(); delete instance; 70 68 * -> result: 71 * moves its children to the Null Parent69 * moves its children to the NullElement2D 72 70 * then deletes the Element. 73 71 */ 74 72 Element2D::~Element2D () 75 73 { 76 // delete what has to be deleted here77 Render2D::getInstance()->unregisterElement2D(this);78 79 74 // remove the Node, delete it's children. 80 75 tIterator<Element2D>* iterator = this->children->getIterator(); … … 203 198 void Element2D::setLayer(E2D_LAYER layer) 204 199 { 205 Render2D::getInstance()->moveToLayer(this, layer); 200 201 202 203 206 204 this->layer = layer; 207 205 } … … 209 207 /** 210 208 * sets the layer onto which this 2D-element is projected to. 211 * @param layer the layer @see loadParams 209 * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const char* layer) 212 210 */ 213 211 void Element2D::setLayer(const char* layer) 214 212 { 215 if (!strcmp(layer, "top")) 216 this->setLayer(E2D_LAYER_TOP); 217 else if (!strcmp(layer, "medium")) 218 this->setLayer(E2D_LAYER_MEDIUM); 219 else if (!strcmp(layer, "bottom")) 220 this->setLayer(E2D_LAYER_BOTTOM); 221 else if (!strcmp(layer, "below-all")) 222 this->setLayer(E2D_LAYER_BELOW_ALL); 213 this->setLayer(Element2D::charToLayer2D(layer)); 223 214 } 224 215 … … 771 762 else 772 763 PRINT(0)(" -"); 773 PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n", 774 this->getClassName(), 775 this->getName(), 776 this->absCoordinate.x, 777 this->absCoordinate.y, 778 this->relCoordinate.x, 779 this->relCoordinate.y, 780 this->getAbsDir2D(), 781 Element2D::parentingModeToChar2D(parentMode)); 764 PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s, layer:%s\n", 765 this->getClassName(), 766 this->getName(), 767 this->absCoordinate.x, 768 this->absCoordinate.y, 769 this->relCoordinate.x, 770 this->relCoordinate.y, 771 this->getAbsDir2D(), 772 Element2D::parentingModeToChar2D(parentMode), 773 Element2D::layer2DToChar(this->layer)); 782 774 if (depth >= 2 || depth == 0) 783 775 { … … 799 791 * ticks the 2d-Element 800 792 * @param dt the time elapsed since the last tick 801 */ 802 void Element2D::tick(float dt) 803 { 804 793 * 794 * the element only gets tickt, if it is active. 795 * Be aware, that this walks through the entire Element2D-tree, 796 * searching for Elements to be ticked. 797 */ 798 void Element2D::tick2D(float dt) 799 { 800 if (this->active) 801 this->tick(dt); 802 if (this->children->getSize() > 0) 803 { 804 tIterator<Element2D>* tickIT = children->getIterator(); 805 Element2D* tickElem = tickIT->firstElement(); 806 while (tickElem != NULL) 807 { 808 tickElem->tick2D(dt); 809 tickElem = tickIT->nextElement(); 810 } 811 delete tickIT; 812 } 813 } 814 815 /** 816 * draws all the Elements from this element2D downwards 817 * @param layer the maximal Layer to draw. 818 */ 819 void Element2D::draw2D(E2D_LAYER layer) const 820 { 821 if (this->visible) 822 this->draw(); 823 if (this->children->getSize() >0) 824 { 825 tIterator<Element2D>* drawIT = children->getIterator(); 826 Element2D* drawElem = drawIT->firstElement(); 827 while (drawElem != NULL) 828 { 829 if (likely(layer >= this->layer)) 830 drawElem->draw2D(layer); 831 drawElem = drawIT->nextElement(); 832 } 833 delete drawIT; 834 } 805 835 } 806 836 … … 853 883 } 854 884 885 /** 886 * converts a layer into its corresponding string 887 * @param layer the layer to get the name-String of. 888 * @returns the Name of the Layer (on error the default-layer-string is returned) 889 */ 890 const char* Element2D::layer2DToChar(E2D_LAYER layer) 891 { 892 switch(layer) 893 { 894 case E2D_LAYER_TOP: 895 return "top"; 896 break; 897 case E2D_LAYER_MEDIUM: 898 return "medium"; 899 break; 900 case E2D_LAYER_BOTTOM: 901 return "bottom"; 902 break; 903 case E2D_LAYER_BELOW_ALL: 904 return "below-all"; 905 break; 906 default: 907 return layer2DToChar(E2D_DEFAULT_LAYER); 908 break; 909 } 910 } 911 912 /** 913 * converts a String holding a actual Layer 914 * @param layer the String to convert into a Layer2D 915 * @returns the E2D_LAYER on success, E2D_DEFAULT_LAYER on error. 916 */ 917 E2D_LAYER Element2D::charToLayer2D(const char* layer) 918 { 919 if (!strcmp(layer, "top")) 920 return (E2D_LAYER_TOP); 921 else if (!strcmp(layer, "medium")) 922 return (E2D_LAYER_MEDIUM); 923 else if (!strcmp(layer, "bottom")) 924 return (E2D_LAYER_BOTTOM); 925 else if (!strcmp(layer, "below-all")) 926 return (E2D_LAYER_BELOW_ALL); 927 else 928 return (E2D_DEFAULT_LAYER); 929 } 930 855 931 856 932 -
trunk/src/lib/graphics/render2D/element_2d.h
r5399 r5401 2 2 * @file element_2d.h 3 3 * Definition of the 2D elements rendered on top through the GraphicsEngine 4 * 5 * @todo reimplement it, so it looks just like PNode. 6 */ 4 */ 7 5 8 6 #ifndef _ELEMENT_2D_H … … 107 105 inline float getSizeX2D() const { return this->sizeX; }; 108 106 inline float getSizeY2D() const { return this->sizeY; }; 107 108 public: 109 virtual void tick(float dt) {}; 110 virtual void draw() const = 0; 111 void tick2D(float dt); 112 void draw2D(E2D_LAYER layer) const; 109 113 110 114 // LIKE PNODE … … 178 182 static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode); 179 183 184 static const char* layer2DToChar(E2D_LAYER layer); 185 static E2D_LAYER charToLayer2D(const char* layer); 186 180 187 private: 181 188 /** tells the child that the parent's Coordinate has changed */ … … 186 193 inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; } 187 194 188 public: 189 virtual void tick(float dt); 190 virtual void draw() const = 0; 195 191 196 192 197 private: -
trunk/src/lib/graphics/render2D/render_2d.cc
r5400 r5401 34 34 this->setClassID(CL_RENDER_2D, "Render2D"); 35 35 this->setName("Render2D"); 36 37 for (int i = 0; i < E2D_LAYER_COUNT; i++)38 this->element2DList[i] = new tList<Element2D>;39 36 } 40 37 … … 51 48 delete NullElement2D::getInstance(); 52 49 53 for (int i = 0; i < E2D_LAYER_COUNT; i++)54 delete this->element2DList[i];55 56 50 Render2D::singletonRef = NULL; 57 51 } 58 59 60 /**61 * registers a 2D-element to the 2D-Renderer62 * @param element2D the element to registers63 *64 * do not use this function by yourself, because this is used by Element2D's constructor65 */66 void Render2D::registerElement2D(Element2D* element2D)67 {68 if (likely(element2D != NULL) && element2D->getLayer() < E2D_LAYER_COUNT && element2D->getLayer() != E2D_LAYER_EXTERN)69 this->element2DList[element2D->getLayer()]->add(element2D);70 // DEBUG printf("::::%p, %d %d \n", element2D, element2D->getLayer(), this->element2DList[element2D->getLayer()]->getSize());71 }72 73 74 /**75 * unregisters a 2D-element from the 2D-Renderer76 * @param element2D The element to unregister77 *78 * do not use this function by yourself, because this is used by Element2D's destructor79 */80 void Render2D::unregisterElement2D(Element2D* element2D)81 {82 if (likely(element2D != NULL) && element2D->getLayer() < E2D_LAYER_COUNT && element2D->getLayer() != E2D_LAYER_EXTERN)83 this->element2DList[element2D->getLayer()]->remove(element2D);84 // DEBUG printf(":::%s layer: %d, %d\n", element2D->getClassName(), element2D->getLayer(), this->element2DList[element2D->getLayer()]->getSize());85 }86 87 88 /**89 * moves an 2D-Element to another Layer90 * @param element2D the Element to move91 * @param to which layer to move it to.92 */93 void Render2D::moveToLayer(Element2D* element2D, E2D_LAYER to)94 {95 if (element2D == NULL)96 return;97 98 if (E2D_LAYER_COUNT < to)99 to = E2D_DEFAULT_LAYER;100 if (likely(element2D->getLayer() != to))101 {102 if (element2D->getLayer() != E2D_LAYER_EXTERN)103 this->element2DList[element2D->getLayer()]->removeFromLast(element2D);104 if (to != E2D_LAYER_EXTERN)105 this->element2DList[to]->add(element2D);106 }107 }108 109 52 110 53 /** … … 114 57 void Render2D::tick(float dt) 115 58 { 116 for (int i = 0; i < E2D_LAYER_COUNT; i++) 117 { 118 tIterator<Element2D>* iterator = this->element2DList[i]->getIterator(); 119 Element2D* elem = iterator->firstElement(); 120 while (elem != NULL) 121 { 122 if (elem->isActive()) 123 elem->tick(dt); 124 elem = iterator->nextElement(); 125 } 126 delete iterator; 127 } 59 NullElement2D::getInstance()->tick2D(dt); 128 60 } 129 61 … … 135 67 { 136 68 GraphicsEngine::enter2DMode(); 137 138 if (layer != E2D_LAYER_ALL) 139 { 140 if (likely(layer != E2D_LAYER_EXTERN && this->element2DList[layer]->getSize() > 0)) 141 { 142 tIterator<Element2D>* iterator = this->element2DList[layer]->getIterator(); 143 Element2D* elem = iterator->firstElement(); 144 while (elem != NULL) 145 { 146 if (elem->isVisible()) 147 elem->draw(); 148 elem = iterator->nextElement(); 149 } 150 delete iterator; 151 } 152 } 153 else // if (layer != E2D_LAYER_ALL) 154 { 155 for (int i = 0; i < E2D_LAYER_COUNT; i++) 156 { 157 if (this->element2DList[i]->getSize() > 0) 158 { 159 tIterator<Element2D>* iterator = this->element2DList[i]->getIterator(); 160 Element2D* elem = iterator->firstElement(); 161 while (elem != NULL) 162 { 163 if (elem->isVisible()) 164 elem->draw(); 165 elem = iterator->nextElement(); 166 } 167 delete iterator; 168 } 169 } 170 } 69 NullElement2D::getInstance()->draw2D(E2D_LAYER_ALL); 171 70 GraphicsEngine::leave2DMode(); 172 71 } -
trunk/src/lib/graphics/render2D/render_2d.h
r5398 r5401 25 25 void draw(E2D_LAYER layer) const; 26 26 27 28 27 private: 29 void registerElement2D(Element2D* element2D);30 void unregisterElement2D(Element2D* element2D);31 void moveToLayer(Element2D* element2D, E2D_LAYER to);32 33 34 28 Render2D(); 35 29 static Render2D* singletonRef; //!< Reference to this class. 36 30 37 // tList<Element2D>* element2DList; //!< List of all valid 2D-elements. 38 tList<Element2D>* element2DList[E2D_LAYER_COUNT]; //!< List of all valid 2D-elements in the different Layers. 39 }; 31 }; 40 32 41 33 #endif /* _RENDER_2D_H */ -
trunk/src/lib/gui/gl_gui/glgui_handler.cc
r5391 r5401 14 14 */ 15 15 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI 17 17 18 18 #include "glgui_handler.h" -
trunk/src/story_entities/world.cc
r5397 r5401 99 99 this->path = NULL; 100 100 this->constuctorInit(name, -1); 101 //NullParent* np = NullParent::getInstance();102 101 } 103 102 … … 1027 1026 Vector* relCoor, Quaternion* relDir) 1028 1027 { 1029 NullParent::getInstance();1030 1028 if( parentNode != NULL) 1031 1029 {
Note: See TracChangeset
for help on using the changeset viewer.