Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5122 in orxonox.OLD


Ignore:
Timestamp:
Aug 25, 2005, 2:07:12 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: optimized TextEngine, now the chars can also be copied fast by using a const char-pointer instead of copiing the whole text-array

Location:
trunk/src
Files:
5 edited

Legend:

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

    r5121 r5122  
    464464if (this->geTextCFPS == NULL)
    465465{
    466   this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC);
     466  this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
    467467  this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
    468468  this->geTextCFPS->setAbsCoor2D(5, 5);
     
    470470if (this->geTextMaxFPS == NULL)
    471471{
    472       this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC);
     472      this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
    473473      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
    474474      this->geTextMaxFPS->setAbsCoor2D(5, 35);
     
    476476if (this->geTextMinFPS == NULL)
    477477{
    478       this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC);
     478      this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC);
    479479      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
    480480      this->geTextMinFPS->setAbsCoor2D(5, 65);
  • trunk/src/lib/graphics/text_engine.cc

    r5121 r5122  
    5050   a text with the TextEngine.
    5151*/
    52 Text::Text(Font* font, int type)
     52Text::Text(Font* font, TEXT_RENDER_TYPE type)
    5353{
    5454  this->setClassID(CL_TEXT, "Text");
     
    5757  this->font = font;
    5858  this->text = NULL;
     59  this->externText = NULL;
    5960  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
    6061  this->texture = 0;
    61   this->blending = 1.0f;
    62   this->color = Vector(1.0, 1.0, 1.0);
     62  this->blending = TEXT_DEFAULT_BLENDING;
     63  this->color = TEXT_DEFAULT_COLOR;
    6364  this->setType(type);
    6465
    65   this->setText(FONT_DEFAULT_TEXT);
     66  this->setText(NULL);
    6667}
    6768
    6869/**
    6970 *  deletes a Text out of memory
    70 
    71    This also ereases the text from the textList of the TextEngine
     71 *
     72 * This also ereases the text from the textList of the TextEngine
    7273*/
    7374Text::~Text()
    7475{
    75   ResourceManager::getInstance()->unload(this->font);
     76  if (this->font != NULL)
     77    ResourceManager::getInstance()->unload(this->font);
    7678
    7779  if (this->text)
     
    8385 * @param type the type to set.
    8486*/
    85 void Text::setType(int type)
     87void Text::setType(TEXT_RENDER_TYPE type)
    8688{
    8789  if (this->font->font)
    8890    this->type = type;
    8991  else
    90     this->type = TEXT_DYNAMIC;
     92    this->type = TEXT_RENDER_DYNAMIC;
    9193}
    9294
     
    9597 * @param text the new text to set
    9698*/
    97 void Text::setText(const char* text)
    98 {
    99   if (this->text)
    100     delete []this->text;
    101   if (text != NULL)
     99void Text::setText(const char* text, bool isExtern)
     100{
     101  if (isExtern)
    102102  {
    103     this->text = new char[strlen(text)+1];
    104     strcpy(this->text, text);
     103    this->externText = text;
     104
     105    if (unlikely(this->text != NULL))
     106    {
     107      delete[] this->text;
     108      this->text = NULL;
     109    }
    105110  }
    106111  else
    107112  {
    108     this->text = new char[1];
    109     *this->text = '\0';
     113    this->externText = NULL;
     114    if (this->text)
     115      delete[] this->text;
     116    if (text != NULL)
     117    {
     118      this->text = new char[strlen(text)+1];
     119      strcpy(this->text, text);
     120    }
     121    else
     122    {
     123      this->text = new char[1];
     124      *this->text = '\0';
     125    }
    110126  }
    111127
    112 
    113128  // setting up the Text-Width if DYNAMIC
    114   if (this->type == TEXT_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT)
     129  if (this->type & TEXT_RENDER_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT)
    115130    {
    116131      Glyph** glyphArray = this->font->getGlyphArray();
    117132
    118133      int width = 0;
    119       char* tmpText = this->text;
     134      const char* tmpText = this->externText;
     135      if (this->externText == NULL)
     136        tmpText = this->text;
    120137      while (*tmpText != '\0')
    121138        {
     
    177194  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    178195
    179   if(type == TEXT_STATIC)
    180     {
    181       glBindTexture(GL_TEXTURE_2D, this->texture);
    182       glBegin(GL_QUADS);
    183 
    184       glTexCoord2f(this->texCoord.minU, this->texCoord.minV);
    185       glVertex2f(this->getAbsCoor2D().x,   this->getAbsCoor2D().y  );
    186 
    187       glTexCoord2f(this->texCoord.maxU, this->texCoord.minV);
    188       glVertex2f(this->getAbsCoor2D().x + this->posSize.w, this->getAbsCoor2D().y  );
    189 
    190       glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV);
    191       glVertex2f(this->getAbsCoor2D().x + this->posSize.w, getAbsCoor2D().y + this->posSize.h);
    192 
    193       glTexCoord2f(this->texCoord.minU, this->texCoord.maxV);
    194       glVertex2f(getAbsCoor2D().x, getAbsCoor2D().y + this->posSize.h);
    195 
    196       glEnd();
    197     }
    198   else //(if type == TEXT_DYNAMIC)
     196  if(likely(type & TEXT_RENDER_DYNAMIC))
    199197    {
    200198      Glyph** glyphArray = this->font->getGlyphArray();
     
    204202//      glRotatef(this->getAbsDir2D(), 0,0,1);
    205203
    206       const char* tmpText = this->text;
     204      const char* tmpText = this->externText;
     205      if (this->externText == NULL)
     206        tmpText = this->text;
    207207      while (*tmpText != '\0')
     208      {
     209        if(glyphArray[*tmpText])
    208210        {
    209           if(glyphArray[*tmpText])
    210             {
    211               glCallList(glyphArray[*tmpText]->displayList);
    212               glTranslatef(glyphArray[*tmpText]->width, 0, 0);
    213             }
    214           tmpText++;
     211          glCallList(glyphArray[*tmpText]->displayList);
     212          glTranslatef(glyphArray[*tmpText]->width, 0, 0);
    215213        }
     214        tmpText++;
     215      }    }
     216  else //(if type & TEXT_RENDER_STATIC)
     217    {
     218      glBindTexture(GL_TEXTURE_2D, this->texture);
     219      glBegin(GL_QUADS);
     220
     221      glTexCoord2f(this->texCoord.minU, this->texCoord.minV);
     222      glVertex2f(this->getAbsCoor2D().x,   this->getAbsCoor2D().y  );
     223
     224      glTexCoord2f(this->texCoord.maxU, this->texCoord.minV);
     225      glVertex2f(this->getAbsCoor2D().x + this->posSize.w, this->getAbsCoor2D().y  );
     226
     227      glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV);
     228      glVertex2f(this->getAbsCoor2D().x + this->posSize.w, getAbsCoor2D().y + this->posSize.h);
     229
     230      glTexCoord2f(this->texCoord.minU, this->texCoord.maxV);
     231      glVertex2f(getAbsCoor2D().x, getAbsCoor2D().y + this->posSize.h);
     232
     233      glEnd();
     234
    216235    }
    217236  glPopMatrix();
     
    223242void Text::debug() const
    224243{
    225   PRINT(0)("=== TEXT: %s ===\n", this->text);
     244  if (this->externText == NULL)
     245    PRINT(0)("=== TEXT: %s ===\n", this->text);
     246  else
     247    PRINT(0)("=== TEXT: %s ===\n", this->externText);
     248
    226249  if (this->getBindNode())
    227250    PRINT(0)("is bind to %s; ref=%p\n", this->getBindNode()->getName(), this->getBindNode());
     
    808831      return NULL;
    809832    }
    810 
    811   return new Text(tmpFont, TEXT_DYNAMIC);
     833  else
     834    return new Text(tmpFont, TEXT_RENDER_DYNAMIC);
    812835}
    813836
  • trunk/src/lib/graphics/text_engine.h

    r5121 r5122  
    3939#define  TEXT_ALIGN_CENTER           E2D_ALIGN_CENTER
    4040#define  TEXT_ALIGN_SCREEN_CENTER    E2D_ALIGN_SCREEN_CENTER
     41#define  TEXT_DEFAULT_COLOR          Vector(1.0, 1.0, 1.0)      //!< the default Color (white)
     42#define  TEXT_DEFAULT_BLENDING       1.0f                       //!< the default blending of the text, (no blending at all)
    4143
    4244/* some default values */
    43 #define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
    44 #define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< default text to display
    45 #define FONT_DEFAULT_COLOR_R    255                  //!< default red part (color) of the text
    46 #define FONT_DEFAULT_COLOR_G    255                  //!< default red green (color) of the text
    47 #define FONT_DEFAULT_COLOR_B    255                  //!< default red blue (color) of the text
    48 #define FONT_NUM_COLORS         256                  //!< number of colors.
    49 
    50 #define FONT_HIGHEST_KNOWN_CHAR 128                  //!< The highest character known to the textEngine.
    51 
    52 #define TEXT_DEFAULT_ALIGNMENT  TEXT_ALIGN_CENTER    //!< default alignment
    53 #define TEXT_STATIC             0                    //!< Static Text
    54 #define TEXT_DYNAMIC            1                    //!< Dynamic Text
     45#define FONT_DEFAULT_SIZE            50                         //!< default size of the Text
     46#define FONT_NUM_COLORS              256                        //!< number of colors.
     47
     48#define FONT_HIGHEST_KNOWN_CHAR      128                        //!< The highest character known to the textEngine.
     49
     50#define TEXT_DEFAULT_ALIGNMENT       TEXT_ALIGN_CENTER          //!< default alignment
     51
     52typedef enum TEXT_RENDER_TYPE
     53{
     54  TEXT_RENDER_STATIC      = 1,
     55  TEXT_RENDER_DYNAMIC     = 2
     56};
    5557/**
    5658 * STATIC means: a font, that is only one GL-face.
     
    103105class Text : public Element2D
    104106{
    105   friend class TextEngine;
    106107 public:
     108   Text(Font* font, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
    107109  ~Text();
    108110
    109   void setType(int type);
    110   void setText(const char* text);
     111  void setType(TEXT_RENDER_TYPE type);
     112  void setText(const char* text, bool isExtern = false);
    111113  /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    112114  inline void setBlending(float blending) { this->blending = blending; };
     
    122124
    123125 private:
    124   Text(Font* font, int type = TEXT_DYNAMIC);
    125 
    126126  static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
    127127  static int powerOfTwo(int input);
     
    130130  Font*             font;           //!< Font of this text
    131131
    132   int               type;           //!< The type of this Font.
     132  TEXT_RENDER_TYPE  type;           //!< The type of this Font.
    133133  char*             text;           //!< The text to display
     134  const char*       externText;     //!< the text to Display from an external Source.
    134135  Vector            color;          //!< The color of the font.
    135136  float             blending;       //!< The blending intensity.
     
    207208  Text* createText(const char* fontFile,
    208209                   unsigned int fontSize = FONT_DEFAULT_SIZE,
    209                    int textType = TEXT_DYNAMIC);
     210                   int textType = TEXT_RENDER_DYNAMIC);
    210211
    211212  void debug() const;
  • trunk/src/util/shell.cc

    r5121 r5122  
    158158  if (this->inputLineText == NULL)
    159159    delete this->inputLineText;
    160   this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_DYNAMIC);
     160  this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC);
    161161  this->inputLineText->setColor(1, 0, 0);
    162162  this->inputLineText->setAlignment(TEXT_ALIGN_LEFT);
     
    184184  for (unsigned int i = 0; i < bufferDisplaySize; i++)
    185185  {
    186     this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_DYNAMIC);
     186    this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC);
    187187    this->bufferText[i]->setColor(1, 0, 0);
    188188    this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
     
    299299    this->bufferText[0] = lastText;
    300300
    301     this->bufferText[0]->setText(text);
     301    this->bufferText[0]->setText(text, true);
    302302  }
    303303}
  • trunk/src/util/track/track_manager.cc

    r5121 r5122  
    380380  this->setBindSlave(this->trackNode);
    381381  // initializing the Text
    382   this->trackText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC);
     382  this->trackText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_RENDER_DYNAMIC);
    383383  this->trackText->setAlignment(E2D_ALIGN_SCREEN_CENTER);
    384384  // initializing the Animation for the Text.
Note: See TracChangeset for help on using the changeset viewer.