Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 6, 2005, 8:31:23 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: nicer quit-modi
TextEngine is now deleted by GraphicsEngine
trying to fix errors in the Element2D deletion

Location:
trunk/src/lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/event_handler.cc

    r5237 r5285  
    3434EventHandler::EventHandler ()
    3535{
     36  this->setClassID(CL_EVENT_HANDLER, "EventHandler");
     37  this->setName("EventHandler");
     38
    3639  SDL_InitSubSystem(SDL_INIT_JOYSTICK);
    3740  SDL_InitSubSystem(SDL_INIT_EVENTTHREAD);
    3841//  SDL_SetEventFilter(EventHandler::eventFilter);
    3942
    40   this->setClassID(CL_EVENT_HANDLER, "EventHandler");
    4143
    4244  /* now initialize them all to zero */
     
    4951    }
    5052  this->state = ES_GAME;
     53  this->keyMapper = NULL;
    5154}
    5255
     
    7073      if( this->listeners[i][j] != NULL)
    7174      {
    72         PRINTF(2)("forgot to unsubscribe an EventListener %s!\n");//, this->listeners[i][j]->getName());
     75        PRINTF(2)("forgot to unsubscribe an EventListener!\n");// %s!\n", this->listeners[i][j]->getName());
    7376      }
    7477    }
     
    8487/**
    8588 *  initializes the event handler
    86 
    87    this has to be called before the use of the event handler
     89 *
     90 * this has to be called before the use of the event handler
    8891*/
    8992void EventHandler::init(IniParser* iniParser)
     
    142145
    143146/**
    144  *  unsubscribe all events from a specific listener
     147 * unsubscribe all events from a specific listener
    145148 * @param el: the listener that wants to unsubscribe itself
    146149 * @param state: the state in which the events shall be unsubscribed
     
    174177
    175178/**
    176  *  flush all registered events
     179 * flush all registered events
    177180 * @param state: a specific state
    178181*/
  • trunk/src/lib/graphics/graphics_engine.cc

    r5266 r5285  
    5858  this->hwVersion = NULL;
    5959  this->hwExtensions = NULL;
     60
     61  // initialize the TextEngine
     62  TextEngine::getInstance();
    6063}
    6164
     
    8184
    8285  delete Render2D::getInstance();
     86  delete TextEngine::getInstance();
    8387
    8488  SDL_QuitSubSystem(SDL_INIT_VIDEO);
     
    557561{
    558562  this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
     563  this->geTextCFPS->setName("curFPS");
    559564  this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
    560565  this->geTextCFPS->setAbsCoor2D(5, 15);
     
    563568{
    564569      this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
     570      this->geTextMaxFPS->setName("MaxFPS");
    565571      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
    566572      this->geTextMaxFPS->setAbsCoor2D(5, 40);
     
    569575{
    570576      this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
     577      this->geTextMinFPS->setName("MinFPS");
    571578      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
    572579      this->geTextMinFPS->setAbsCoor2D(5, 65);
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r5254 r5285  
    2525#include "class_list.h"
    2626#include "list.h"
     27#include "color.h"
    2728
    2829using namespace std;
    2930
     31/**
     32 * standard constructor
     33 */
    3034Element2D::Element2D()
    3135{
    3236  this->init();
     37
    3338  this->setParent2D(NullElement2D::getInstance());
     39  NullElement2D::getInstance()->debug(0);
    3440}
    3541
    3642/**
    3743 * 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 */
    4049Element2D::Element2D (Element2D* parent)
    4150{
     
    4453  if (this->parent != NULL)
    4554    this->setParent2D(parent);
     55  else if (NullElement2D::isInstanciated())
     56    this->setParent2D(NullElement2D::getInstance());
    4657}
    4758
    4859/**
    4960 * 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 */
    5173Element2D::~Element2D ()
    5274{
     
    5476  Render2D::getInstance()->unregisterElement2D(this);
    5577
    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;
    6993  }
    7094  delete this->children;
    7195
     96  // remove all other allocated memory.
    7297  if (this->toCoordinate != NULL)
    7398    delete this->toCoordinate;
     
    99124  this->toCoordinate = NULL;
    100125  this->toDirection = NULL;
    101 //  else
    102   //  this->setParent2D(parent);
    103126
    104127  Render2D::getInstance()->registerElement2D(this);
     
    480503
    481504/**
    482  * remove this pnode from the tree and adds all following to NullParent
     505 * remove this Element from the tree and adds all children to NullElement2D
    483506 *
    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.
    485508 */
    486509void Element2D::remove2D()
     
    495518  }
    496519  delete iterator;
     520
     521  delete this->children;
     522  this->children = new tList<Element2D>;
     523
    497524  if (this->parent != NULL)
     525  {
    498526    this->parent->children->remove(this);
     527    this->parent = NULL;
     528  }
    499529}
    500530
     
    762792}
    763793
    764 #include "color.h"
     794/**
     795 * ticks the 2d-Element
     796 * @param dt the time elapsed since the last tick
     797 */
     798void Element2D::tick(float dt)
     799{
     800
     801}
    765802
    766803/**
     
    816853
    817854
    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///////////////////
    834858NullElement2D* NullElement2D::singletonRef = 0;
    835859
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5279 r5285  
    218218  public:
    219219    /** @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; };
    221222    virtual ~NullElement2D ();
    222223
  • trunk/src/lib/graphics/shader.cc

    r5283 r5285  
    4949
    5050       if (vertexShaderFile != NULL)
    51         this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
     51        this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
    5252       if (fragmentShaderFile != NULL)
    53         this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
     53        this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
    5454       try  {
    55         glLinkProgramARB(this->shaderProgram); }
     55        glLinkProgramARB(this->shaderProgram); }
    5656       catch(GLenum errorCode)  {
    57         this->printError(this->shaderProgram); }
     57        this->printError(this->shaderProgram); }
    5858     }
    5959   else
     
    8484bool Shader::loadShaderProgramm(SHADER_TYPE type, const char* fileName)
    8585{
     86  GLenum shader = 0;
     87
    8688  if (type != SHADER_VERTEX && type != SHADER_FRAGMENT)
    8789    return false;
     
    9294  if (program == NULL)
    9395    return false;
    94   GLenum shader = 0;
    9596  if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
    9697  {
     
    113114      glShaderSourceARB(shader, 1, (const GLcharARB**)&program, NULL);
    114115      try {
    115         glCompileShaderARB(shader);
     116        glCompileShaderARB(shader);
    116117      }
    117118      catch (...)
    118         {
    119           this->printError(shader);
    120         }
     119        {
     120          this->printError(shader);
     121        }
    121122      glAttachObjectARB(this->shaderProgram, shader);
    122123      delete[] program;
  • trunk/src/lib/graphics/text_engine.cc

    r5215 r5285  
    848848/**
    849849 *  creates a new Text with a certain font.
    850    @see Font::Font
    851    @see Text::Text
     850 * @see Font::Font
     851 * @see Text::Text
    852852*/
    853853Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, int textType)
  • trunk/src/lib/util/list.h

    r5248 r5285  
    135135
    136136/**
    137  *  remove an entity from the list
     137 * remove an entity from the list
    138138 * @param entity: the entity to be removed
    139139 */
Note: See TracChangeset for help on using the changeset viewer.