Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7762 in orxonox.OLD for trunk


Ignore:
Timestamp:
May 22, 2006, 6:20:35 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellBuffer gets polled from the Shell, and does not put the other way round

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell.cc

    r7757 r7762  
    6262    this->setName("Shell");
    6363
     64    this->shellBuffer = ShellBuffer::getInstance();
     65
    6466    // EVENT-Handler subscription of '`' to all States.
    6567    EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
     
    7072
    7173    // BUFFER
    72     this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
     74    this->bufferIterator = this->shellBuffer->getBuffer().begin();
    7375
    7476    // INPUT LINE
     
    9193
    9294    this->deactivate();
    93     // register the shell at the ShellBuffer
    94     ShellBuffer::getInstance()->registerShell(this);
    9595  }
    9696
     
    100100  Shell::~Shell ()
    101101  {
    102     ShellBuffer::getInstance()->unregisterShell(this);
    103 
    104102    // delete the displayable Buffers
    105103    while (!this->bufferText.empty())
     
    120118      PRINTF(3)("The shell is already active\n");
    121119    this->bActive = true;
     120    this->activate2D();
    122121
    123122    EventHandler::getInstance()->pushState(ES_SHELL);
     
    126125    this->setRelCoorSoft2D(0, 0, 5);
    127126
    128     std::list<std::string>::const_iterator textLine = ShellBuffer::getInstance()->getBuffer().begin();
     127    this->linesProcessed = this->shellBuffer->getLineCount();
     128    std::list<std::string>::const_iterator textLine = this->bufferIterator = this->shellBuffer->getBuffer().begin();
    129129    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    130130    {
    131131      (*text)->setVisibility(true);
    132       if (textLine !=  ShellBuffer::getInstance()->getBuffer().end())
     132      if (textLine !=  this->shellBuffer->getBuffer().end())
    133133      {
    134134        (*text)->setText((*textLine));
     
    150150      PRINTF(3)("The shell is already inactive\n");
    151151    this->bActive = false;
     152    this->deactivate2D();
    152153
    153154    EventHandler::getInstance()->withUNICODE(false);
     
    159160      (*text)->setVisibility(false);
    160161    // Go to the End again.
    161     this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
     162    this->bufferIterator = this->shellBuffer->getBuffer().begin();
    162163  }
    163164
     
    337338      (*textIt)->setText("");  // remove all chars from the BufferTexts.
    338339    }
    339     ShellBuffer::getInstance()->flush();
     340    this->shellBuffer->flush();
    340341    // BUFFER FLUSHING
    341342  }
     
    353354    // Set the new Text.
    354355    this->bufferText.front()->setText(text);
     356    this->bufferIterator = this->shellBuffer->getBuffer().begin();
    355357
    356358    // The LineCount will be started here.
     
    358360    // The First Line gets a special Animation
    359361    this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
     362
    360363
    361364    // Move all lines one Entry up.
     
    378381      if (moves < lineCount)
    379382      {
    380         if(this->bufferIterator == --ShellBuffer::getInstance()->getBuffer().end())
     383        if(this->bufferIterator == --this->shellBuffer->getBuffer().end())
    381384          break;
    382385        ++moves;
     
    385388      else
    386389      {
    387         if (this->bufferIterator == ShellBuffer::getInstance()->getBuffer().begin())
     390        if (this->bufferIterator == this->shellBuffer->getBuffer().begin())
    388391          break;
    389392        --moves;
     
    414417    for (textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, ++it)
    415418    {
    416       if (it == ShellBuffer::getInstance()->getBuffer().end())
     419      if (it == this->shellBuffer->getBuffer().end())
    417420      {
    418421        PRINTF(1)("LAST LINE REACHED\n");
     
    473476  }
    474477
     478  void Shell::tick(float dt)
     479  {
     480    if (this->linesProcessed < this->shellBuffer->getLineCount())
     481    {
     482      unsigned int pollLines = this->shellBuffer->getLineCount() - this->linesProcessed;
     483      if (this->bufferText.size() < pollLines)
     484        pollLines = this->bufferText.size();
     485      if (unlikely(this->shellBuffer->getBuffer().size() < pollLines))
     486        pollLines = this->shellBuffer->getBuffer().size();
     487
     488      std::list<std::string>::const_iterator line = this->shellBuffer->getBuffer().begin();
     489      unsigned int i;
     490      for(i = 0; i < pollLines; i++)
     491        line ++;
     492      for (i = 0; i < pollLines; i++)
     493      {
     494        this->printToDisplayBuffer((*--line));
     495      }
     496    }
     497    this->linesProcessed = this->shellBuffer->getLineCount();
     498  }
     499
     500
    475501  /**
    476502   * displays the Shell
     
    527553
    528554
    529     ShellBuffer::getInstance()->debug();
     555    this->shellBuffer->debug();
    530556  }
    531557
  • trunk/src/lib/shell/shell.h

    r7757 r7762  
    1414
    1515#include "shell_input.h"
     16#include "shell_buffer.h"
    1617#include "material.h"
    1718
     
    7576    virtual void process(const Event &event);
    7677    // Element2D-functions
     78    virtual void tick(float dt);
    7779    virtual void draw() const;
     80
    7881
    7982    void debug() const;
     
    9093  private:
    9194    // GENERAL
     95    ShellBuffer*                shellBuffer;            //!< The local ShellBuffer.
     96
    9297    bool                        bActive;                //!< If the shell is active.
    9398    unsigned int                shellHeight;            //!< The hight of the Shell in Pixels.
     
    104109    std::list<MultiLineText*>   bufferText;             //!< A list of stored bufferTexts for the display of the buffer.
    105110
     111    unsigned long               linesProcessed;         //!< How many Lines have been processed.
     112
    106113    std::list<std::string>::const_iterator  bufferIterator;         //!< used to move through and print the Buffer
    107114  };
  • trunk/src/lib/shell/shell_buffer.cc

    r7761 r7762  
    3232  {
    3333    ShellBuffer::singletonRef = this;
    34     this->shell = NULL;
    3534
    3635    this->lineCount = 0;
    3736    this->bufferArray[0] = '\0';
    3837
    39     this->setBufferSize(100);
     38    this->setMaxBufferSize(100);
    4039  }
    4140
     
    4847  ShellBuffer::~ShellBuffer ()
    4948  {
    50     if (this->shell != NULL)
    51       delete this->shell;
    52 
    5349    ShellBuffer::singletonRef = NULL;
    54   }
    55 
    56   /**
    57    * @brief registers the Shell to the Buffer
    58    * @param shell the Shell to register.
    59    */
    60   void ShellBuffer::registerShell(Shell* shell)
    61   {
    62     if (this->shell == NULL)
    63       this->shell = shell;
    64     else
    65       PRINTF(1)("already registered a Shell to the ShellBuffer\n");
    66   }
    67 
    68   /**
    69    * @brief unregisters the Shell from the Buffer
    70    * @param shell the Shell to unregister.
    71    */
    72   void ShellBuffer::unregisterShell(Shell* shell)
    73   {
    74     if (this->shell == shell)
    75       this->shell = NULL;
    76     else
    77       PRINTF(1)("cannot unregister shell, because it is not registered to the ShellBuffer\n");
    7850  }
    7951
     
    136108      {
    137109        this->lineCount++;
    138 
    139         printf("Test:: %s \n", inputBuffer.substr(lineBegin, lineEnd - lineBegin).c_str());
    140110        this->buffer.push_front(inputBuffer.substr(lineBegin, lineEnd - lineBegin));
    141         if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
    142           this->shell->printToDisplayBuffer(this->buffer.front());
    143111      }
    144112      else      // No end of Line reached.
     
    148116      }
    149117
    150 
    151 
    152       if (this->buffer.size() > this->bufferSize)
     118      if (this->buffer.size() > this->maxBufferSize)
    153119        this->buffer.pop_back();
    154120    }
  • trunk/src/lib/shell/shell_buffer.h

    r7761 r7762  
    1616namespace OrxShell
    1717{
    18   // FORWARD DECLARATION
    19   class Shell;
    20 
    2118  //! A class handling output from orxonox via debug.h
    2219  /**
     
    3532    inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
    3633
    37     void registerShell(Shell* shell);
    38     void unregisterShell(Shell* shell);
    39 
    4034    static bool addBufferLineStatic(const char* line, ...);
    4135    void addBufferLine(const char* line, va_list arg);
    4236
    43     // BUFFER //
     37    /// BUFFER
    4438    /** @param bufferSize the new Buffer-Size */
    45     void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
     39    void setMaxBufferSize(unsigned int maxBufferSize) { this->maxBufferSize = maxBufferSize; };
    4640    void flush();
    4741
     
    5044    /** @returns the Count of lines processed by the Shell. */
    5145    inline unsigned long getLineCount() const { return this->lineCount; };
     46    /** @returns the Current Buffer Size. */
     47    inline unsigned int getBufferSize() const { return this->buffer.size(); };
    5248
    5349    void debug() const;
     
    5854  private:
    5955    static ShellBuffer*           singletonRef;                       //!< The singleton-reference to the only memeber of this class.
    60     unsigned int                  bufferSize;                         //!< The Size of the buffer
     56    unsigned int                  maxBufferSize;                         //!< The Size of the buffer
    6157
    62     Shell*                        shell;                              //!< the Registered Shell.
    6358    char                          bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
    6459    std::string                   keepBuffer;                         //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
  • trunk/src/story_entities/game_world.h

    r7739 r7762  
    1212#include "playable.h"
    1313
    14 class OrxShell::Shell;
     14namespace OrxShell { class Shell; };
    1515class WorldEntity;
    1616class GameRules;
Note: See TracChangeset for help on using the changeset viewer.