Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4862 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jul 14, 2005, 2:49:33 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: introducing Layers

Location:
orxonox/trunk/src/lib/graphics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/graphics_engine.cc

    r4856 r4862  
    432432void GraphicsEngine::draw() const
    433433{
    434   Render2D::getInstance()->draw();
     434  Render2D::getInstance()->draw(E2D_ALL_LAYERS);
    435435  LightManager::getInstance()->draw();
    436436}
  • orxonox/trunk/src/lib/graphics/render2D/element_2d.cc

    r4861 r4862  
    5757  this->setPosition2D(0,0);
    5858  this->setAlignment(E2D_ALIGN_NONE);
    59   this->setLayer(E2D_TOP);
     59  this->layer = E2D_TOP;
    6060
    6161  Render2D::getInstance()->registerElement2D(this);
     
    9898  else if (!strcmp(alignment, "screen-center"))
    9999    this->setAlignment(E2D_ALIGN_SCREEN_CENTER);
     100}
     101
     102
     103/**
     104 * moves a Element to another layer
     105 * @param layer the Layer this is drawn on
     106 */
     107void Element2D::setLayer(E2D_LAYER layer)
     108{
     109  Render2D::getInstance()->moveToLayer(this, layer);
     110  this->layer = layer;
    100111}
    101112
  • orxonox/trunk/src/lib/graphics/render2D/element_2d.h

    r4861 r4862  
    1616typedef enum
    1717{
    18   E2D_TOP,                             //!< Will be rendered on top of everything else
    19   E2D_MEDIUM,                          //!< Will be rendered on the medium Layer.
    20   E2D_BOTTOM,                          //!< Will be rendered on the bottom Layer
    21   E2D_BELOW_ALL,                       //!< Will be rendered below the 3D-scene. @todo make this work.
     18  E2D_BELOW_ALL                 =     1,        //!< Will be rendered below the 3D-scene. @todo make this work.
     19  E2D_BOTTOM                    =     2,        //!< Will be rendered on the bottom Layer
     20  E2D_MEDIUM                    =     4,        //!< Will be rendered on the medium Layer.
     21  E2D_TOP                       =     8,        //!< Will be rendered on top of everything else
    2222
    23   E2D_LAYER_COUNT                      //!< The count of Layers.
    24 } E2DLayer;
    25 
     23  E2D_LAYER_COUNT               =     4         //!< The count of Layers.
     24} E2D_LAYER;
     25#define E2D_DEFAULT_LAYER       E2D_TOP
     26#define E2D_ALL_LAYERS          E2D_TOP | E2D_MEDIUM | E2D_BOTTOM | E2D_BELOW_ALL
    2627
    2728typedef enum
     
    5657    /** this returns the Absolute Position on the screen set by positioning in the tick-phase */
    5758    inline const Position2D& getPosition2D() { return this->absPos2D; };
     59
    5860    /** @param alignment the new Alignment of the 2D-Element */
    5961    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
    6062    void setAlignment(const char* alignment);
    61     /** @param layer the Layer this is drawn on */
    62     inline void setLayer(E2DLayer layer) { this->layer = layer; };
     63
     64    void setLayer(E2D_LAYER layer);
    6365    void setLayer(const char* layer);
     66    /** @returns the Layer this Element is drawn to */
     67    inline E2D_LAYER getLayer() { return this->layer; };
     68
    6469    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
    6570    inline void setVisibility(bool visible) { this->visible = visible; };
     71
    6672    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
    6773    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
     
    8692  private:
    8793    bool                    visible;
    88     E2DLayer                layer;
     94    E2D_LAYER               layer;
    8995};
    9096
  • orxonox/trunk/src/lib/graphics/render2D/render_2d.cc

    r4849 r4862  
    2323#include "element_2d.h"
    2424
     25#include <math.h>
     26
    2527using namespace std;
    2628
     
    3537   this->setName("Render2D");
    3638
    37    this->element2DList = new tList<Element2D>;
     39   for (int i = 0; i < E2D_LAYER_COUNT; i++)
     40     this->element2DList[i] = new tList<Element2D>;
    3841}
    3942
     
    4851Render2D::~Render2D ()
    4952{
    50   delete this->element2DList;
     53  for (int i = 0; i < E2D_LAYER_COUNT; i++)
     54    delete this->element2DList[i];
    5155
    5256  Render2D::singletonRef = NULL;
     
    6266void Render2D::registerElement2D(Element2D* element2D)
    6367{
    64   this->element2DList->add(element2D);
     68  this->element2DList[(int)log2(E2D_DEFAULT_LAYER)]->add(element2D);
    6569}
    6670
     
    7377void Render2D::unregisterElement2D(Element2D* element2D)
    7478{
    75   this->element2DList->remove(element2D);
     79  this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D);
    7680}
    7781
    7882
     83/**
     84 * moves an 2D-Element to another Layer
     85 * @param element2D the Element to move
     86 * @param to which layer to move it to.
     87 */
     88void Render2D::moveToLayer(Element2D* element2D, E2D_LAYER to)
     89{
     90  this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D);
     91  this->element2DList[(int)log2(to)]->add(element2D);
     92}
     93
     94
     95/**
     96 * ticks all the 2d-elements
     97 * @param dt the timestep since last dt
     98 */
    7999void Render2D::tick(float dt)
    80100{
    81   tIterator<Element2D>* iterator = this->element2DList->getIterator();
    82   Element2D* elem = iterator->nextElement();
    83   while (elem != NULL)
     101  for (int i = 0; i < E2D_LAYER_COUNT; i++)
    84102  {
    85     elem->tick(dt);
    86     elem = iterator->nextElement();
     103    tIterator<Element2D>* iterator = this->element2DList[i]->getIterator();
     104    Element2D* elem = iterator->nextElement();
     105    while (elem != NULL)
     106    {
     107      elem->tick(dt);
     108      elem = iterator->nextElement();
     109    }
     110    delete iterator;
    87111  }
    88   delete iterator;
    89 
    90112}
    91113
     
    93115 * renders all the Elements of the Render2D-engine
    94116 */
    95 void Render2D::draw() const
     117void Render2D::draw(unsigned int layer) const
    96118{
    97119  GraphicsEngine::enter2DMode();
    98120
    99   tIterator<Element2D>* iterator = this->element2DList->getIterator();
    100   Element2D* elem = iterator->nextElement();
    101   while (elem != NULL)
     121  int drawLayer = 1;
     122
     123  for (int i = 0; i < E2D_LAYER_COUNT; i++)
    102124  {
    103     if (elem->isVisible())
    104       elem->draw();
    105     elem = iterator->nextElement();
     125    if (layer & drawLayer && this->element2DList[i]->getSize() > 0)
     126    {
     127      tIterator<Element2D>* iterator = this->element2DList[i]->getIterator();
     128      Element2D* elem = iterator->nextElement();
     129      while (elem != NULL)
     130      {
     131        if (elem->isVisible())
     132          elem->draw();
     133        elem = iterator->nextElement();
     134      }
     135      delete iterator;
     136    }
     137    drawLayer << 1;
    106138  }
    107   delete iterator;
    108139
    109140  GraphicsEngine::leave2DMode();
     141
    110142}
  • orxonox/trunk/src/lib/graphics/render2D/render_2d.h

    r4849 r4862  
    2222
    2323  void tick(float dt);
    24   void draw() const;
     24  void draw(unsigned int layer) const;
    2525
    2626  void registerElement2D(Element2D* element2D);
    2727  void unregisterElement2D(Element2D* element2D);
     28  void moveToLayer(Element2D* element2D, E2D_LAYER to);
    2829
    2930 private:
    3031  Render2D();
    31   static Render2D*              singletonRef;           //!< Reference to this class.
     32  static Render2D*              singletonRef;                    //!< Reference to this class.
    3233
    33   tList<Element2D>*             element2DList;          //!< List of all valid 2D-elements.
     34//  tList<Element2D>*             element2DList;                   //!< List of all valid 2D-elements.
     35  tList<Element2D>*             element2DList[E2D_LAYER_COUNT];  //!< List of all valid 2D-elements in the different Layers.
    3436};
    3537
Note: See TracChangeset for help on using the changeset viewer.