Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/render2D/render_2d.cc @ 5068

Last change on this file since 5068 was 5068, checked in by bensch, 19 years ago

orxonox/trunk: added Shell Class to the utils.
This class should enable us to print all the output from orxonox directly onto the screen.
Also it should allow inputting some little Commands, so that we have more force over our little project :)

Also added a new Function to tList, removeLast, that is very quick in deleting the last element, as this is used inside of the Shell (deleting the Last Element is a major issue)

File size: 3.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: ...
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
18#include "render_2d.h"
19
20#include "graphics_engine.h"
21#include "class_list.h"
22#include "list.h"
23#include "element_2d.h"
24
25#include <math.h>
26
27using namespace std;
28
29
30
31/**
32 * standard constructor
33 */
34Render2D::Render2D ()
35{
36   this->setClassID(CL_RENDER_2D, "Render2D");
37   this->setName("Render2D");
38
39   for (int i = 0; i < E2D_LAYER_COUNT; i++)
40     this->element2DList[i] = new tList<Element2D>;
41}
42
43/**
44 *  the singleton reference to this class
45 */
46Render2D* Render2D::singletonRef = NULL;
47
48/**
49 * standard deconstructor
50 */
51Render2D::~Render2D ()
52{
53  for (int i = 0; i < E2D_LAYER_COUNT; i++)
54    delete this->element2DList[i];
55
56  Render2D::singletonRef = NULL;
57}
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 */
66void Render2D::registerElement2D(Element2D* element2D)
67{
68  this->element2DList[(int)log2(E2D_DEFAULT_LAYER)]->add(element2D);
69}
70
71/**
72 * unregisters a 2D-element from the 2D-Renderer
73 * @param element2D The element to unregister
74 *
75 * do not use this function by yourself, because this is used by Element2D's destructor
76 */
77void Render2D::unregisterElement2D(Element2D* element2D)
78{
79  this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D);
80}
81
82
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 */
99void Render2D::tick(float dt)
100{
101  for (int i = 0; i < E2D_LAYER_COUNT; i++)
102  {
103    tIterator<Element2D>* iterator = this->element2DList[i]->getIterator();
104    Element2D* elem = iterator->nextElement();
105    while (elem != NULL)
106    {
107      if (elem->isActive())
108        elem->tick(dt);
109      elem = iterator->nextElement();
110    }
111    delete iterator;
112  }
113}
114
115/**
116 * renders all the Elements of the Render2D-engine
117 * @param layer the Layer to draw
118 */
119void Render2D::draw(unsigned int layer) const
120{
121  GraphicsEngine::enter2DMode();
122
123  int drawLayer = 1;
124
125  for (int i = 0; i < E2D_LAYER_COUNT; i++)
126  {
127    if (layer & drawLayer && this->element2DList[i]->getSize() > 0)
128    {
129      tIterator<Element2D>* iterator = this->element2DList[i]->getIterator();
130      Element2D* elem = iterator->nextElement();
131      while (elem != NULL)
132      {
133        if (elem->isVisible())
134          elem->draw();
135        elem = iterator->nextElement();
136      }
137      delete iterator;
138    }
139    drawLayer << 1;
140  }
141  GraphicsEngine::leave2DMode();
142
143}
Note: See TracBrowser for help on using the repository browser.