Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5401 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Oct 18, 2005, 11:57:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: new Layering system works, now i have to do the check on reparenting, so no lower layers are children of high-layer-parents

Location:
trunk/src
Files:
6 edited

Legend:

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

    r5398 r5401  
    3535{
    3636  this->init();
    37   Render2D::getInstance()->registerElement2D(this);
    3837  this->setParent2D(NullElement2D::getInstance());
    3938}
     
    4948{
    5049  this->init();
    51   Render2D::getInstance()->registerElement2D(this);
    5250
    5351  // check Parenting, and if ok parent the stuff
     
    6967 * 2. instance->remove2D(); delete instance;
    7068 *   -> result:
    71  *    moves its children to the NullParent
     69 *    moves its children to the NullElement2D
    7270 *    then deletes the Element.
    7371 */
    7472Element2D::~Element2D ()
    7573{
    76   // delete what has to be deleted here
    77   Render2D::getInstance()->unregisterElement2D(this);
    78 
    7974  // remove the Node, delete it's children.
    8075  tIterator<Element2D>* iterator = this->children->getIterator();
     
    203198void Element2D::setLayer(E2D_LAYER layer)
    204199{
    205   Render2D::getInstance()->moveToLayer(this, layer);
     200
     201
     202
     203
    206204  this->layer = layer;
    207205}
     
    209207/**
    210208 * 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)
    212210 */
    213211void Element2D::setLayer(const char* layer)
    214212{
    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));
    223214}
    224215
     
    771762  else
    772763    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));
    782774  if (depth >= 2 || depth == 0)
    783775  {
     
    799791 * ticks the 2d-Element
    800792 * @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 */
     798void 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 */
     819void 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  }
    805835}
    806836
     
    853883}
    854884
     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 */
     890const 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 */
     917E2D_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
    855931
    856932
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5399 r5401  
    22 * @file element_2d.h
    33 * Definition of the 2D elements rendered on top through the GraphicsEngine
    4  *
    5  * @todo reimplement it, so it looks just like PNode.
    6 */
     4 */
    75
    86#ifndef _ELEMENT_2D_H
     
    107105    inline float getSizeX2D() const { return this->sizeX; };
    108106    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;
    109113
    110114    // LIKE PNODE
     
    178182    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
    179183
     184    static const char* layer2DToChar(E2D_LAYER layer);
     185    static E2D_LAYER charToLayer2D(const char* layer);
     186
    180187  private:
    181188    /** tells the child that the parent's Coordinate has changed */
     
    186193    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
    187194
    188   public:
    189     virtual void tick(float dt);
    190     virtual void draw() const = 0;
     195
    191196
    192197  private:
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r5400 r5401  
    3434   this->setClassID(CL_RENDER_2D, "Render2D");
    3535   this->setName("Render2D");
    36 
    37    for (int i = 0; i < E2D_LAYER_COUNT; i++)
    38      this->element2DList[i] = new tList<Element2D>;
    3936}
    4037
     
    5148  delete NullElement2D::getInstance();
    5249
    53   for (int i = 0; i < E2D_LAYER_COUNT; i++)
    54     delete this->element2DList[i];
    55 
    5650  Render2D::singletonRef = NULL;
    5751}
    58 
    59 
    60 /**
    61  * registers a 2D-element to the 2D-Renderer
    62  * @param element2D the element to registers
    63  *
    64  * do not use this function by yourself, because this is used by Element2D's constructor
    65  */
    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-Renderer
    76  * @param element2D The element to unregister
    77  *
    78  * do not use this function by yourself, because this is used by Element2D's destructor
    79  */
    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 Layer
    90  * @param element2D the Element to move
    91  * @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 
    10952
    11053/**
     
    11457void Render2D::tick(float dt)
    11558{
    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);
    12860}
    12961
     
    13567{
    13668  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);
    17170  GraphicsEngine::leave2DMode();
    17271}
  • trunk/src/lib/graphics/render2D/render_2d.h

    r5398 r5401  
    2525    void draw(E2D_LAYER layer) const;
    2626
    27 
    2827  private:
    29     void registerElement2D(Element2D* element2D);
    30     void unregisterElement2D(Element2D* element2D);
    31     void moveToLayer(Element2D* element2D, E2D_LAYER to);
    32 
    33 
    3428    Render2D();
    3529    static Render2D*              singletonRef;                    //!< Reference to this class.
    3630
    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 };
    4032
    4133#endif /* _RENDER_2D_H */
  • trunk/src/lib/gui/gl_gui/glgui_handler.cc

    r5391 r5401  
    1414*/
    1515
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
    1717
    1818#include "glgui_handler.h"
  • trunk/src/story_entities/world.cc

    r5397 r5401  
    9999  this->path = NULL;
    100100  this->constuctorInit(name, -1);
    101   //NullParent* np = NullParent::getInstance();
    102101}
    103102
     
    10271026                  Vector* relCoor, Quaternion* relDir)
    10281027{
    1029   NullParent::getInstance();
    10301028  if( parentNode != NULL)
    10311029    {
Note: See TracChangeset for help on using the changeset viewer.