Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7744 in orxonox.OLD


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

trunk: the Buffer is moving pretty smoothly :)

Location:
trunk/src/lib/shell
Files:
4 edited

Legend:

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

    r7742 r7744  
    5353  ->completionPlugin(0, OrxShell::CompletorFileSystem(".ttf", "fonts/"));
    5454
     55
     56  void Shell::testShell()
     57  {
     58    for (unsigned int i = 0; i < 100; i++)
     59      PRINT(0)("%d\n", i);
     60  }
     61  SHELL_COMMAND(test, Shell, testShell);
     62
     63
    5564  /**
    5665   * standard constructor
     
    6877
    6978    // BUFFER
    70     this->bufferOffset = 0;
    7179    this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
    7280
     
    137145      }
    138146    }
     147    repositionText();
    139148  }
    140149
     
    155164    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    156165      (*text)->setVisibility(false);
    157     this->bufferOffset = 0;
     166    // Go to the End again.
     167    this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
    158168  }
    159169
     
    352362  void Shell::moveDisplayBuffer(int lineCount)
    353363  {
    354     if (this->bufferOffset == 0)
    355     {
    356       this->bufferIterator = ShellBuffer::getInstance()->getBuffer().end();
    357       //     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    358       //       this->bufferIterator->prevStep();
    359     }
    360 
    361     // boundraries
    362     if (this->bufferOffset + lineCount > (int)ShellBuffer::getInstance()->getBuffer().size())
    363       lineCount = (int)ShellBuffer::getInstance()->getBuffer().size()- this->bufferOffset;
    364     else if (this->bufferOffset + lineCount < 0)
    365       lineCount = -bufferOffset;
    366     this->bufferOffset += lineCount;
    367 
    368     // moving the iterator to the right position
    369     int move = 0;
    370     while (move != lineCount)
    371     {
    372       if (move < lineCount)
    373       {
    374         ++move;
    375         this->bufferIterator--;
     364    // moving the iterator to the right position (counting the steps)
     365    int moves = 0;
     366    while (moves != lineCount)
     367    {
     368      if (moves < lineCount)
     369      {
     370        if(this->bufferIterator == --ShellBuffer::getInstance()->getBuffer().end())
     371          break;
     372        ++moves;
     373        ++this->bufferIterator;
    376374      }
    377375      else
    378376      {
    379         --move;
    380         this->bufferIterator++;
    381       }
    382     }
     377        if (this->bufferIterator == ShellBuffer::getInstance()->getBuffer().begin())
     378          break;
     379        --moves;
     380        --this->bufferIterator;
     381      }
     382    }
     383
     384
    383385    // redisplay the buffers
     386    int linePos = moves;
    384387    std::list<std::string>::const_iterator it = this->bufferIterator;
    385     if (it == ShellBuffer::getInstance()->getBuffer().end())
    386     {
    387       /// FIXME
    388       PRINTF(1)("Should not happen\n");
    389       it--;
    390     }
    391     for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
    392     {
     388    std::list<MultiLineText*>::iterator textIt;
     389    for (textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, ++it)
     390    {
     391      if (it == ShellBuffer::getInstance()->getBuffer().end())
     392      {
     393        PRINTF(1)("LAST LINE REACHED\n");
     394        break;
     395      }
     396
     397
     398      (*textIt)->setRelCoor2D(calculateLinePosition( (linePos++ > 0)? linePos : 0));
    393399      (*textIt)->setText((*it));
    394       if (it == ShellBuffer::getInstance()->getBuffer().begin())
    395       {
    396         /// FIXME
    397         PRINTF(1)("Should not happen\n");
    398         break;
    399       }
    400       it--;
    401     }
     400    }
     401    while (textIt != this->bufferText.end())
     402    {
     403      (*textIt)->setText("");
     404      textIt++;
     405    }
     406
     407    this->repositionText();
    402408  }
    403409
     
    493499    ShellBuffer::getInstance()->debug();
    494500  }
    495 
    496   // void Shell::testI (int i)
    497   // {
    498   //   PRINTF(3)("This is the Test for one Int '%d'\n", i);
    499   // }
    500   //
    501   // void Shell::testS (const char* s)
    502   // {
    503   //   PRINTF(3)("This is the Test for one String '%s'\n", s);
    504   // }
    505   //
    506   // void Shell::testB (bool b)
    507   // {
    508   //   PRINTF(3)("This is the Test for one Bool: ");
    509   //   if (b)
    510   //     PRINTF(3)("true\n");
    511   //   else
    512   //     PRINTF(3)("false\n");
    513   // }
    514   //
    515   // void Shell::testF (float f)
    516   // {
    517   //   PRINTF(3)("This is the Test for one Float '%f'\n", f);
    518   // }
    519   //
    520   // void Shell::testSF (const char* s, float f)
    521   // {
    522   //   PRINTF(3)("This is the Test for one String '%s' and one Float '%f'\n",s , f);
    523   // }
    524 
    525501}
  • trunk/src/lib/shell/shell.h

    r7738 r7744  
    7979    void debug() const;
    8080
     81    void testShell();
    8182  private:
    8283    void repositionText();
     
    8586    // helpers //
    8687    Vector2D calculateLinePosition(unsigned int lineNumber);
    87 
    88     //     void testI (int i);
    89     //     void testS (const std::string& s);
    90     //     void testB (bool b);
    91     //     void testF (float f);
    92     //     void testSF (const std::string& s, float f);
    9388
    9489  private:
     
    107102    unsigned int                bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters).
    108103    std::list<MultiLineText*>   bufferText;             //!< A list of stored bufferTexts for the display of the buffer.
    109     int                         bufferOffset;           //!< how many lines from the bottom up we display the Buffer.
     104
    110105    std::list<std::string>::const_iterator  bufferIterator;         //!< used to move through and print the Buffer
    111106  };
  • trunk/src/lib/shell/shell_buffer.cc

    r7737 r7744  
    164164
    165165      this->lineCount++;
    166       this->buffer.push_back(newLineBegin);
     166      this->buffer.push_front(newLineBegin);
    167167      if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
    168168        this->shell->printToDisplayBuffer(newLineBegin);
    169169
    170170      if (this->buffer.size() > this->bufferSize)
    171         this->buffer.pop_front();
     171        this->buffer.pop_back();
    172172
    173173      newLineBegin = newLineEnd+1;
     
    183183
    184184    std::list<std::string>::const_iterator bufferLine;
    185     for (bufferLine = this->buffer.begin(); bufferLine != this->buffer.end(); bufferLine++)
     185    for (bufferLine = --this->buffer.end(); bufferLine != this->buffer.begin(); --bufferLine)
    186186      printf((*bufferLine).c_str());
    187187  }
  • trunk/src/lib/shell/shell_buffer.h

    r7737 r7744  
    1818
    1919  //! A class handling output from orxonox via debug.h
     20  /**
     21   * the ShellBuffer redirects output from PRINTF(x) to the Shell and STDOUT
     22   * the ShellBuffer is a front-filling queue of limited length, that has the
     23   * youngest added Entry at the beginning, and the oldest at the end.
     24   */
    2025  class ShellBuffer
    2126  {
     
    2631    inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; };
    2732    /** @returns true if this class is instanciated, false otherwise */
    28 inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
     33    inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?false:true; };
    2934
    3035    void registerShell(Shell* shell);
    3136    void unregisterShell(Shell* shell);
     37
     38    static bool addBufferLineStatic(const char* line, ...);
     39    void addBufferLine(const char* line, va_list arg);
    3240
    3341    // BUFFER //
     
    3543    void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
    3644    void flush();
    37     static bool addBufferLineStatic(const char* line, ...);
    38     void addBufferLine(const char* line, va_list arg);
     45
    3946    /** @returns the List of stings from the Buffer */
    4047    const std::list<std::string>& getBuffer() const { return this->buffer; };
    4148    /** @returns the Count of lines processed by the Shell. */
    42     inline long getLineCount() const { return this->lineCount; };
     49    inline unsigned long getLineCount() const { return this->lineCount; };
    4350
    4451    void debug() const;
     
    5865    unsigned long                 lineCount;                          //!< how many Lines have been written out so far.
    5966
     67    // The Beginning of buffer (buffer.front()) is the last added line.
    6068    static std::list<std::string> buffer;                             //!< A list of stored char-arrays(strings) to store the history
    6169  };
Note: See TracChangeset for help on using the changeset viewer.