Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7375 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Apr 26, 2006, 3:41:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: new Font for the Shell… this one is really readeable, and from StarTrek

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

Legend:

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

    r7374 r7375  
    1515#include "shell_input.h"
    1616
    17 #define         SHELL_DEFAULT_FONT              "fonts/dpquake_.ttf"
     17#define         SHELL_DEFAULT_FONT              "fonts/final_frontier.ttf"
    1818#define         SHELL_DEFAULT_TEXT_COLOR        1.0f, 0.0f, 0.0f, 1.0f
    1919#define         SHELL_DEFAULT_BACKGROUND_COLOR  0.0f, 0.0f, 0.0f, 1.0f
  • trunk/src/lib/shell/shell_buffer.cc

    r7374 r7375  
    2020#include "shell.h"
    2121
    22 #include "stdlibincl.h"
    23 
    2422namespace OrxShell
    2523{
     24  /**
     25   * @brief standard constructor
     26   */
     27  ShellBuffer::ShellBuffer ()
     28  {
     29    ShellBuffer::singletonRef = this;
     30    this->shell = NULL;
    2631
     32    this->lineCount = 0;
     33    this->keepBufferArray[0] = '\0';
     34    this->bufferArray[0] = '\0';
     35    this->keepBuffer = false;
    2736
    28 /**
    29  * @brief standard constructor
    30  */
    31 ShellBuffer::ShellBuffer ()
    32 {
    33   ShellBuffer::singletonRef = this;
    34   this->shell = NULL;
    35 
    36   this->lineCount = 0;
    37   this->keepBufferArray[0] = '\0';
    38   this->bufferArray[0] = '\0';
    39   this->keepBuffer = false;
    40 
    41   this->setBufferSize(100);
    42 }
    43 
    44 ShellBuffer* ShellBuffer::singletonRef = NULL;
    45 SDL_mutex* ShellBuffer::bufferMutex = NULL;
    46 
    47 /**
    48  * @brief standard deconstructor
    49  */
    50 ShellBuffer::~ShellBuffer ()
    51 {
    52   if (this->shell != NULL)
    53     delete this->shell;
    54 
    55   this->flush();
    56 
    57   if (ShellBuffer::bufferMutex != NULL)
    58     SDL_DestroyMutex(ShellBuffer::bufferMutex);
    59   ShellBuffer::bufferMutex = NULL;
    60 
    61   ShellBuffer::singletonRef = NULL;
    62 }
    63 
    64 /**
    65  * @brief registers the Shell to the Buffer
    66  * @param shell the Shell to register.
    67  */
    68 void ShellBuffer::registerShell(Shell* shell)
    69 {
    70   if (this->shell == NULL)
    71     this->shell = shell;
    72   else
    73     PRINTF(1)("already registered a Shell to the ShellBuffer\n");
    74 }
    75 
    76 /**
    77  * @brief unregisters the Shell from the Buffer
    78  * @param shell the Shell to unregister.
    79  */
    80 void ShellBuffer::unregisterShell(Shell* shell)
    81 {
    82   if (this->shell == shell)
    83     this->shell = NULL;
    84   else
    85     PRINTF(1)("cannot unregister shell, because it is not registered to the ShellBuffer\n");
    86 }
    87 
    88 /**
    89  * @brief deletes all the Buffers
    90  */
    91 void ShellBuffer::flush()
    92 {
    93   this->buffer.clear();
    94 }
    95 
    96 /**
    97  * @brief adds a new Line to the List of Buffers
    98  * @param line the Line as in the first argument in printf
    99  */
    100 bool ShellBuffer::addBufferLineStatic(const char* line, ...)
    101 {
    102   va_list arguments;
    103   va_start(arguments, line);
    104 
    105   if (ShellBuffer::bufferMutex == NULL)
    106     ShellBuffer::bufferMutex = SDL_CreateMutex();
    107 
    108   SDL_mutexP(ShellBuffer::bufferMutex);
    109 #if DEBUG < 3
    110   if (ShellBuffer::singletonRef == NULL)
    111 #endif
    112     vprintf(line, arguments);
    113 #if DEBUG < 3
    114   else
    115 #else
    116   if (ShellBuffer::singletonRef != NULL)
    117 #endif
    118     ShellBuffer::singletonRef->addBufferLine(line, arguments);
    119   SDL_mutexV(ShellBuffer::bufferMutex);
    120   return true;
    121 }
    122 
    123 /**
    124  * @brief add a Line to the List of Buffers
    125  * @param line
    126  * @param arguments
    127  *
    128  * This function Adds one line to the buffer.
    129  * and displays the line as the First Line of the display-buffer
    130  */
    131 void ShellBuffer::addBufferLine(const char* line, va_list arguments)
    132 {
    133   char* inputEnd;
    134   char* newLineBegin;
    135   char* newLineEnd;
    136 
    137   // copy the output to the bufferArray
    138   vsprintf(this->bufferArray, line, arguments);
    139 
    140   // check if we have something left in the buffers
    141   // if so, append the new String to this one.
    142   if (unlikely(this->keepBuffer))
    143   {
    144     strcat(this->keepBufferArray, this->bufferArray);
    145     inputEnd = this->keepBufferArray + strlen(this->bufferArray);
    146     newLineBegin = this->keepBufferArray;
    147     this->keepBuffer = false;
    148   }
    149   else
    150   {
    151     inputEnd = this->bufferArray + strlen(this->bufferArray);
    152     newLineBegin = this->bufferArray;
     37    this->setBufferSize(100);
    15338  }
    15439
    155   // adding all the new Lines
    156   while (newLineBegin < inputEnd)
     40  ShellBuffer* ShellBuffer::singletonRef = NULL;
     41  SDL_mutex* ShellBuffer::bufferMutex = NULL;
     42
     43  /**
     44   * @brief standard deconstructor
     45   */
     46  ShellBuffer::~ShellBuffer ()
    15747  {
    158     newLineEnd = strchr(newLineBegin, '\n');
    159     if (likely(newLineEnd != NULL && *newLineEnd == '\n'))
    160       *newLineEnd = '\0';
     48    if (this->shell != NULL)
     49      delete this->shell;
     50
     51    this->flush();
     52
     53    if (ShellBuffer::bufferMutex != NULL)
     54      SDL_DestroyMutex(ShellBuffer::bufferMutex);
     55    ShellBuffer::bufferMutex = NULL;
     56
     57    ShellBuffer::singletonRef = NULL;
     58  }
     59
     60  /**
     61   * @brief registers the Shell to the Buffer
     62   * @param shell the Shell to register.
     63   */
     64  void ShellBuffer::registerShell(Shell* shell)
     65  {
     66    if (this->shell == NULL)
     67      this->shell = shell;
     68    else
     69      PRINTF(1)("already registered a Shell to the ShellBuffer\n");
     70  }
     71
     72  /**
     73   * @brief unregisters the Shell from the Buffer
     74   * @param shell the Shell to unregister.
     75   */
     76  void ShellBuffer::unregisterShell(Shell* shell)
     77  {
     78    if (this->shell == shell)
     79      this->shell = NULL;
     80    else
     81      PRINTF(1)("cannot unregister shell, because it is not registered to the ShellBuffer\n");
     82  }
     83
     84  /**
     85   * @brief deletes all the Buffers
     86   */
     87  void ShellBuffer::flush()
     88  {
     89    this->buffer.clear();
     90  }
     91
     92  /**
     93   * @brief adds a new Line to the List of Buffers
     94   * @param line the Line as in the first argument in printf
     95   */
     96  bool ShellBuffer::addBufferLineStatic(const char* line, ...)
     97  {
     98    va_list arguments;
     99    va_start(arguments, line);
     100
     101    if (ShellBuffer::bufferMutex == NULL)
     102      ShellBuffer::bufferMutex = SDL_CreateMutex();
     103
     104    SDL_mutexP(ShellBuffer::bufferMutex);
     105#if DEBUG < 3
     106    if (ShellBuffer::singletonRef == NULL)
     107#endif
     108      vprintf(line, arguments);
     109#if DEBUG < 3
     110    else
     111#else
     112    if (ShellBuffer::singletonRef != NULL)
     113#endif
     114      ShellBuffer::singletonRef->addBufferLine(line, arguments);
     115    SDL_mutexV(ShellBuffer::bufferMutex);
     116    return true;
     117  }
     118
     119  /**
     120   * @brief add a Line to the List of Buffers
     121   * @param line
     122   * @param arguments
     123   *
     124   * This function Adds one line to the buffer.
     125   * and displays the line as the First Line of the display-buffer
     126   */
     127  void ShellBuffer::addBufferLine(const char* line, va_list arguments)
     128  {
     129    char* inputEnd;
     130    char* newLineBegin;
     131    char* newLineEnd;
     132
     133    // copy the output to the bufferArray
     134    vsprintf(this->bufferArray, line, arguments);
     135
     136    // check if we have something left in the buffers
     137    // if so, append the new String to this one.
     138    if (unlikely(this->keepBuffer))
     139    {
     140      strcat(this->keepBufferArray, this->bufferArray);
     141      inputEnd = this->keepBufferArray + strlen(this->bufferArray);
     142      newLineBegin = this->keepBufferArray;
     143      this->keepBuffer = false;
     144    }
    161145    else
    162146    {
    163       unsigned int len = strlen(newLineBegin);
    164       char* copyBuffer = new char[len+1];
    165       strcpy(copyBuffer, newLineBegin);
    166       strncpy(this->keepBufferArray, copyBuffer, len);
    167       delete[] copyBuffer;
    168       this->keepBufferArray[len] = '\0';
    169       this->keepBuffer = true;
    170       break;
     147      inputEnd = this->bufferArray + strlen(this->bufferArray);
     148      newLineBegin = this->bufferArray;
    171149    }
    172150
    173     this->lineCount++;
    174     this->buffer.push_back(newLineBegin);
    175     if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
    176       this->shell->printToDisplayBuffer(newLineBegin);
     151    // adding all the new Lines
     152    while (newLineBegin < inputEnd)
     153    {
     154      newLineEnd = strchr(newLineBegin, '\n');
     155      if (likely(newLineEnd != NULL && *newLineEnd == '\n'))
     156        *newLineEnd = '\0';
     157      else
     158      {
     159        unsigned int len = strlen(newLineBegin);
     160        char* copyBuffer = new char[len+1];
     161        strcpy(copyBuffer, newLineBegin);
     162        strncpy(this->keepBufferArray, copyBuffer, len);
     163        delete[] copyBuffer;
     164        this->keepBufferArray[len] = '\0';
     165        this->keepBuffer = true;
     166        break;
     167      }
    177168
    178     if (this->buffer.size() > this->bufferSize)
    179       this->buffer.pop_front();
     169      this->lineCount++;
     170      this->buffer.push_back(newLineBegin);
     171      if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
     172        this->shell->printToDisplayBuffer(newLineBegin);
    180173
    181     newLineBegin = newLineEnd+1;
     174      if (this->buffer.size() > this->bufferSize)
     175        this->buffer.pop_front();
     176
     177      newLineBegin = newLineEnd+1;
     178    }
    182179  }
    183 }
    184180
    185 /**
    186  * displays some nice output from the Shell
    187  */
    188 void ShellBuffer::debug() const
    189 {
    190   PRINT(3)("Debugging output to console (not this shell)\n");
     181  /**
     182   * displays some nice output from the Shell
     183   */
     184  void ShellBuffer::debug() const
     185  {
     186    PRINT(3)("Debugging output to console (not this shell)\n");
    191187
    192   std::list<std::string>::const_iterator bufferLine;
    193   for (bufferLine = this->buffer.begin(); bufferLine != this->buffer.end(); bufferLine++)
    194     printf((*bufferLine).c_str());
    195 }
     188    std::list<std::string>::const_iterator bufferLine;
     189    for (bufferLine = this->buffer.begin(); bufferLine != this->buffer.end(); bufferLine++)
     190      printf((*bufferLine).c_str());
     191  }
    196192
    197193}
Note: See TracChangeset for help on using the changeset viewer.