Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7737 in orxonox.OLD


Ignore:
Timestamp:
May 19, 2006, 11:38:34 PM (18 years ago)
Author:
bensch
Message:

Using MultiLine-Text in the Shell. This is much faster, and Nicer :)

Location:
trunk/src/lib
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/multi_line_text.cc

    r7457 r7737  
    3232
    3333  this->lineSpacing = 1.0f;
     34  this->lineCount = 0;
    3435  this->setLineWidth(100.0f);
    3536}
     
    141142      width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
    142143  }
     144
     145  this->lineCount = lineEnds.size()+1;
    143146  this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->getFont()->getMaxHeight()));
    144147}
  • trunk/src/lib/graphics/text_engine/multi_line_text.h

    r7454 r7737  
    2626    /** @returns the LineSpacing */
    2727    inline float getLineSpacing() const { return this->lineSpacing; };
     28    inline unsigned int getLineCount() const { return this->lineCount; };
    2829
    2930    virtual void draw() const;
     
    3637    float                      lineSpacing;
    3738    std::vector<unsigned int>  lineEnds;
     39    unsigned int               lineCount;
    3840};
    3941
  • trunk/src/lib/shell/shell.cc

    r7426 r7737  
    2121#include "shell_input.h"
    2222
    23 
    24 #include "text.h"
     23#include "multi_line_text.h"
     24
    2525#include "graphics_engine.h"
    2626#include "material.h"
    2727#include "event_handler.h"
    28 #include "debug.h"
    29 #include "class_list.h"
    30 
    31 #include "key_names.h"
    32 #include <stdarg.h>
    33 #include <stdio.h>
    3428
    3529namespace OrxShell
     
    137131    std::list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
    138132    bool top = false;
    139     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     133    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    140134    {
    141135      (*text)->setVisibility(true);
     
    164158    this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5);
    165159
    166     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     160    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    167161      (*text)->setVisibility(false);
    168162    this->bufferOffset = 0;
     
    257251     * output is routed from Some other Thread or by Changing any Values.
    258252     */
    259     std::list<Text*> bufferTextCopy = this->bufferText;
    260     for (std::list<Text*>::iterator text = bufferTextCopy.begin(); text != bufferTextCopy.end(); ++text, ++i)
     253    std::list<MultiLineText*> bufferTextCopy = this->bufferText;
     254    for (std::list<MultiLineText*>::iterator text = bufferTextCopy.begin(); text != bufferTextCopy.end(); ++text, ++i)
    261255    {
    262256      this->resetText(*text, i);
     
    296290      for (unsigned int i = oldSize; i <= bufferDisplaySize; i++)
    297291      {
    298         this->bufferText.push_back(new Text);
     292        this->bufferText.push_back(new MultiLineText);
     293        this->bufferText.back()->setLineWidth(this->getSizeX2D() * GraphicsEngine::getInstance()->getResolutionX());
     294        this->bufferText.back()->setLineSpacing(0);
    299295      }
    300296    }
     
    308304  void Shell::flush()
    309305  {
    310     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     306    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    311307    {
    312308      (*text)->setText("");  // remove all chars from the BufferTexts.
     
    322318  void Shell::printToDisplayBuffer(const std::string& text)
    323319  {
     320    // Remove Last Entry and prepend it to the front.
    324321    this->bufferText.push_front(this->bufferText.back());
    325322    this->bufferText.pop_back();
    326323
    327 
    328     unsigned int i = 0;
    329     for (std::list<Text*>::iterator textIt = ++this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, i++)
    330     {
    331       (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5);
    332     }
    333 
    334     this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
    335     this->bufferText.front()->setRelCoorSoft2D(this->calculateLinePosition(0),10);
     324    // Set the new Text.
     325    this->bufferText.front()->setText(text);
     326
     327    // The LineCount will be started here.
     328    int linePos = -1;
     329
     330    // The First Line gets a special Animation
     331    this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(linePos)- Vector2D(-1000,0));
     332
     333    // Move all lines one Entry up.
     334    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     335    {
     336      linePos += (*textIt)->getLineCount();
     337      (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8);
     338    }
     339
    336340
    337341    /*  FANCY EFFECTS :)
     
    344348    */
    345349
    346     this->bufferText.front()->setText(text);
    347350  }
    348351
     
    389392    {
    390393      /// FIXME
    391       PRINTF(1)("Should not heappen\n");
     394      PRINTF(1)("Should not happen\n");
    392395      it--;
    393396    }
    394     for (std::list<Text*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     397    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
    395398    {
    396399      (*textIt)->setText((*it));
     
    398401      {
    399402        /// FIXME
    400         PRINTF(1)("Should not heappen\n");
     403        PRINTF(1)("Should not happen\n");
    401404        break;
    402405      }
     
    478481  Vector2D Shell::calculateLinePosition(unsigned int lineNumber)
    479482  {
    480     return Vector2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize - lineNumber - 2) + this->textSize);
     483    Vector2D val(5, (int)(this->textSize + this->lineSpacing)*(int)((int)this->bufferDisplaySize - (int)lineNumber - (int)2) + (int)this->textSize);
     484     val.debug();
     485     return val;
    481486  }
    482487
  • trunk/src/lib/shell/shell.h

    r7426 r7737  
    2020
    2121// FORWARD DECLARATION
    22 class Text;
     22class MultiLineText;
    2323class ShellInput;
    2424class Material;
     
    104104    // BUFFER
    105105    unsigned int                bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters).
    106     std::list<Text*>            bufferText;             //!< A list of stored bufferTexts for the display of the buffer.
     106    std::list<MultiLineText*>   bufferText;             //!< A list of stored bufferTexts for the display of the buffer.
    107107    int                         bufferOffset;           //!< how many lines from the bottom up we display the Buffer.
    108108    std::list<std::string>::const_iterator  bufferIterator;         //!< used to move through and print the Buffer
  • trunk/src/lib/shell/shell_buffer.cc

    r7729 r7737  
    1717
    1818#include "shell_buffer.h"
     19
     20#include <stdarg.h>
     21
    1922#include "debug.h"
    2023#include "shell.h"
     24#include "lib/util/threading.h"
    2125
    2226namespace OrxShell
     
    3943
    4044  ShellBuffer* ShellBuffer::singletonRef = NULL;
    41   SDL_mutex* ShellBuffer::bufferMutex = NULL;
     45  std::list<std::string> ShellBuffer::buffer;
    4246
    4347  /**
     
    4852    if (this->shell != NULL)
    4953      delete this->shell;
    50 
    51     this->flush();
    52 
    53     if (ShellBuffer::bufferMutex != NULL)
    54       SDL_DestroyMutex(ShellBuffer::bufferMutex);
    55     ShellBuffer::bufferMutex = NULL;
    5654
    5755    ShellBuffer::singletonRef = NULL;
     
    9997    va_start(arguments, line);
    10098
    101     if (ShellBuffer::bufferMutex == NULL)
    102       ShellBuffer::bufferMutex = SDL_CreateMutex();
     99    static OrxThread::Mutex ShellBuffer__bufferMutex;
    103100
    104     SDL_mutexP(ShellBuffer::bufferMutex);
     101    OrxThread::MutexLock bufferLock(&ShellBuffer__bufferMutex);
    105102#if DEBUG_LEVEL < 3
    106103    if (ShellBuffer::singletonRef == NULL)
     
    113110#endif
    114111      ShellBuffer::singletonRef->addBufferLine(line, arguments);
    115     SDL_mutexV(ShellBuffer::bufferMutex);
    116112    return true;
    117113  }
  • trunk/src/lib/shell/shell_buffer.h

    r7661 r7737  
    88#define _SHELL_BUFFER_H
    99
    10 #include <stdarg.h>
    1110#include <list>
    12 #include "lib/util/threading.h"
    1311
    1412#define      SHELL_BUFFER_SIZE       16384         //!< The Size of the input-buffers (should be large enough to carry any kind of input)
     
    5048
    5149  private:
    52     static ShellBuffer*      singletonRef;                       //!< The singleton-reference to the only memeber of this class.
    53     unsigned int             bufferSize;                         //!< The Size of the buffer
    54     std::list<std::string>   buffer;                             //!< A list of stored char-arrays(strings) to store the history
     50    static ShellBuffer*           singletonRef;                       //!< The singleton-reference to the only memeber of this class.
     51    unsigned int                  bufferSize;                         //!< The Size of the buffer
    5552
    56     Shell*                   shell;                              //!< the Registered Shell.
    57     char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
    58     char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
    59     bool                     keepBuffer;                         //!< if the keepbuffer contains unfinished lines.
     53    Shell*                        shell;                              //!< the Registered Shell.
     54    char                          bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
     55    char                          keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
     56    bool                          keepBuffer;                         //!< if the keepbuffer contains unfinished lines.
    6057
    61     unsigned long            lineCount;                          //!< how many Lines have been written out so far.
     58    unsigned long                 lineCount;                          //!< how many Lines have been written out so far.
    6259
    63     static SDL_mutex*        bufferMutex;                        //!< Only one thread may write into the ShellBuffer at a time.
     60    static std::list<std::string> buffer;                             //!< A list of stored char-arrays(strings) to store the history
    6461  };
    6562
  • trunk/src/lib/sound/ogg_player.cc

    r7729 r7737  
    4848    this->buffers[1] = 0;
    4949    this->musicThreadID = NULL;
    50     this->musicMutex = SDL_CreateMutex();
    5150
    5251    if (!fileName.empty())
     
    6463  {
    6564    this->release();
    66     SDL_DestroyMutex(this->musicMutex);
    6765  }
    6866
     
    7674  bool OggPlayer::open(const std::string& fileName)
    7775  {
    78     MutexLock(this->musicMutex);
     76    OrxThread::MutexLock musicLock(&this->musicMutex);
    7977    // release old Ogg-File (if loaded)
    8078    if (this->state & OggPlayer::FileOpened)
     
    208206    if (this->state & OggPlayer::FileOpened)
    209207    {
    210       SDL_mutexP(this->musicMutex);
     208      OrxThread::MutexLock musicLock(&this->musicMutex);
    211209      ov_time_seek(&this->oggStream, timeCode);
    212       SDL_mutexV(this->musicMutex);
    213210    }
    214211  }
     
    259256    while (ogg->state & OggPlayer::Playing)
    260257    {
    261       SDL_mutexP(ogg->musicMutex);
    262       ogg->update();
    263       SDL_mutexV(ogg->musicMutex);
     258      {
     259        OrxThread::MutexLock musicLock(&ogg->musicMutex);
     260        ogg->update();
     261      }
    264262      SDL_Delay(1);
    265263    }
     
    281279    this->state |= OggPlayer::Playing;
    282280
    283     SDL_mutexP(this->musicMutex);
     281    OrxThread::MutexLock musicLock(&this->musicMutex);
    284282    if(!this->stream(this->buffers[0]) || !this->stream(this->buffers[1]))
    285283    {
    286       SDL_mutexV(this->musicMutex);
    287284      this->state &= ~OggPlayer::Playing;
    288285      return false;
     
    296293    if (DEBUG_LEVEL >= 3)
    297294      SoundEngine::checkError("OggPlayer::playback()::alSourcePlay", __LINE__);
    298     SDL_mutexV(this->musicMutex);
    299295    return true;
    300296  }
     
    502498    switch(code)
    503499    {
    504     case OV_EREAD:
    505       return ("Read from media.");
    506     case OV_ENOTVORBIS:
    507       return ("Not Vorbis data.");
    508     case OV_EVERSION:
    509       return ("Vorbis version mismatch.");
    510     case OV_EBADHEADER:
    511       return ("Invalid Vorbis header.");
    512     case OV_EFAULT:
    513       return ("Internal logic fault (bug or heap/stack corruption.");
    514     default:
    515       return ("Unknown Ogg error.");
     500      case OV_EREAD:
     501        return ("Read from media.");
     502      case OV_ENOTVORBIS:
     503        return ("Not Vorbis data.");
     504      case OV_EVERSION:
     505        return ("Vorbis version mismatch.");
     506      case OV_EBADHEADER:
     507        return ("Invalid Vorbis header.");
     508      case OV_EFAULT:
     509        return ("Internal logic fault (bug or heap/stack corruption.");
     510      default:
     511        return ("Unknown Ogg error.");
    516512    }
    517513  }
  • trunk/src/lib/sound/ogg_player.h

    r7460 r7737  
    8787
    8888    SDL_Thread*         musicThreadID;        //!< The Thread in which music is Played back.
    89     SDL_mutex*          musicMutex;           //!< A Mutex so that the two threads do not interfere.
     89    OrxThread::Mutex    musicMutex;           //!< A Mutex so that the two threads do not interfere.
    9090  };
    9191
  • trunk/src/lib/util/threading.cc

    r7329 r7737  
    2020using namespace std;
    2121
     22namespace OrxThread
     23{
    2224
    2325/**
     
    2527 * @todo this constructor is not jet implemented - do it
    2628*/
    27 Threading::Threading ()
     29Thread::Thread()
    2830{
    2931}
     
    3335 * standard deconstructor
    3436*/
    35 Threading::~Threading ()
     37Thread::~Thread()
    3638{
    3739  // delete what has to be deleted here
    3840}
     41
     42}
  • trunk/src/lib/util/threading.h

    r7331 r7737  
    1515#endif
    1616
     17namespace OrxThread
     18{
     19  //! A class for Wrapping Threads
     20  class Thread
     21  {
    1722
    18 //! A class for Wrapping Threads
    19 class Threading
    20 {
    21 
    22 public:
    23   Threading();
    24   virtual ~Threading();
     23  public:
     24    Thread();
     25    virtual ~Thread();
    2526
    2627
    27 private:
     28  private:
    2829
    29 };
     30  };
    3031
    31 //! A Class that locks a Mutex within its scope
    32 class MutexLock
    33 {
    34 public:
    35   //! Locks the Mutex mutex in this Scope.
    36   MutexLock(SDL_mutex* mutex) { SDL_mutexP(mutex); this->mutex = mutex; };
    37   ~MutexLock() { SDL_mutexV(mutex); };
    38 private:
    39   SDL_mutex* mutex;         //!< The Mutex to lock.
    40 };
     32  class Mutex
     33  {
     34  public:
     35    Mutex() {  this->mutex = SDL_CreateMutex(); };
     36    ~Mutex() { SDL_DestroyMutex(this->mutex); }
    4137
     38    void lock() { SDL_mutexP(mutex); };
     39    void unlock() { SDL_mutexV(mutex); };
     40
     41    SDL_mutex* getMutex() const { return this->mutex; };
     42  private:
     43    SDL_mutex* mutex;
     44  };
     45
     46  //! A Class that locks a Mutex within its scope
     47  class MutexLock
     48  {
     49  public:
     50    //! Locks the Mutex mutex in this Scope.
     51    MutexLock(Mutex* mutex) { SDL_mutexP(mutex->getMutex()); this->mutex = mutex; };
     52    ~MutexLock() { SDL_mutexV(mutex->getMutex()); };
     53  private:
     54    Mutex* mutex;         //!< The Mutex to lock.
     55  };
     56}
    4257
    4358#endif /* _THREADING_H */
Note: See TracChangeset for help on using the changeset viewer.