Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5113 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Aug 23, 2005, 11:18:39 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk:restoring the trunk…

Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/coord/p_node.cc

    r5111 r5113  
    165165void PNode::setRelCoor (const Vector& relCoord)
    166166{
     167  if (this->toCoordinate!= NULL)
     168  {
     169    delete this->toCoordinate;
     170    this->toCoordinate = NULL;
     171  }
     172
    167173  this->relCoordinate = relCoord;
    168174  this->bRelCoorChanged = true;
     
    213219void PNode::setAbsCoor (const Vector& absCoord)
    214220{
     221  if (this->toCoordinate!= NULL)
     222  {
     223    delete this->toCoordinate;
     224    this->toCoordinate = NULL;
     225  }
     226
    215227  if( likely(this->parentMode & PNODE_MOVEMENT))
    216228  {
     
    276288void PNode::setRelDir (const Quaternion& relDir)
    277289{
     290  if (this->toDirection!= NULL)
     291  {
     292    delete this->toDirection;
     293    this->toDirection = NULL;
     294  }
    278295  this->relDirection = relDir;
    279296  this->bRelCoorChanged = true;
     
    327344void PNode::setAbsDir (const Quaternion& absDir)
    328345{
     346  if (this->toDirection!= NULL)
     347  {
     348    delete this->toDirection;
     349    this->toDirection = NULL;
     350  }
     351
    329352  if (likely(this->parent != NULL))
    330353    this->relDirection = absDir / this->parent->getAbsDir();
  • trunk/src/lib/coord/p_node.h

    r5111 r5113  
    6666  /** @returns the relative position */
    6767  inline const Vector& getRelCoor () const { return this->prevRelCoordinate; };
     68  /** @returns the Relative Coordinate Destination */
     69  inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
    6870  void setAbsCoor (const Vector& absCoord);
    6971  void setAbsCoor (float x, float y, float z);
     
    7880  /** @returns the relative Direction */
    7981  inline const Quaternion& getRelDir () const { return this->prevRelDirection; };
     82  /** @returns the Relative Directional Destination */
     83  inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
    8084  /** @returns a Vector pointing into the relative Direction */
    8185  inline Vector getRelDirV() const { return this->prevRelDirection.apply(Vector(0,1,0)); };
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r5111 r5113  
    214214void Element2D::setRelCoor2D (const Vector& relCoord)
    215215{
     216  if (this->toCoordinate!= NULL)
     217  {
     218    delete this->toCoordinate;
     219    this->toCoordinate = NULL;
     220  }
    216221  this->relCoordinate = relCoord;
    217222  this->bRelCoorChanged = true;
     
    227232void Element2D::setRelCoor2D (float x, float y, float z)
    228233{
    229   this->setAbsCoor2D(Vector(x,y,z));
     234  this->setRelCoor2D(Vector(x,y,z));
    230235}
    231236
     
    288293void Element2D::setAbsCoor2D (const Vector& absCoord)
    289294{
     295  if (this->toCoordinate!= NULL)
     296  {
     297    delete this->toCoordinate;
     298    this->toCoordinate = NULL;
     299  }
     300
    290301  if( likely(this->parentMode & E2D_PARENT_MOVEMENT))
    291302  {
     
    362373void Element2D::setRelDir2D (float relDir)
    363374{
     375  if (this->toDirection!= NULL)
     376  {
     377    delete this->toDirection;
     378    this->toDirection = NULL;
     379  }
     380
    364381  this->relDirection = relDir;
    365382  this->bRelDirChanged = true;
     
    386403void Element2D::setAbsDir2D (float absDir)
    387404{
     405  if (this->toDirection!= NULL)
     406  {
     407    delete this->toDirection;
     408    this->toDirection = NULL;
     409  }
     410
    388411  if (likely(this->parent != NULL))
    389412    this->relDirection = absDir - this->parent->getAbsDir2D();
     
    712735  {
    713736    tIterator<Element2D>* iterator = this->children->getIterator();
    714       //PNode* pn = this->children->enumerate ();
    715737    Element2D* pn = iterator->nextElement();
    716738    while( pn != NULL)
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5111 r5113  
    108108    /** @returns the relative position */
    109109    inline const Vector& getRelCoor2D () const { return this->prevRelCoordinate; };
     110    /** @returns the Relative Coordinate Destination */
     111    inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
    110112    const Vector& getRelCoor2Dpx() const;
    111113    void setAbsCoor2D (const Vector& absCoord);
     
    123125    /** @returns the relative Direction */
    124126    inline float getRelDir2D () const { return this->prevRelDirection; };
     127    /** @returns the Relative Directional Destination */
     128    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
    125129    void setAbsDir2D (float absDir);
    126130    /** @returns the absolute Direction */
  • trunk/src/lib/graphics/text_engine.cc

    r5111 r5113  
    592592          if( glyphSurf != NULL )
    593593            {
    594 
    595594              SDL_SetAlpha(glyphSurf, 0, 0);
    596595
     
    598597              TexCoord tmpTexCoord;
    599598              tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w;
    600               tmpTexCoord.maxU = (float)(tmpRect.x +1 +tmpGlyph->width)/(float)tmpSurf->w;
     599              tmpTexCoord.maxU = (float)(tmpRect.x +1 + tmpGlyph->width)/(float)tmpSurf->w;
    601600              tmpTexCoord.minV = (float)tmpRect.y/(float)tmpSurf->w;
    602601              tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w;
     
    620619
    621620              // Outputting Glyphs to BMP-files.
    622               /*
    623                 char outname[64];
     621/*
     622                char outname[512];
    624623                if (i < 10)
    625                 sprintf( outname, "glyph-00%d.bmp", i );
     624                sprintf( outname, "%s-glyph-00%d.bmp", this->getName(), i );
    626625                else if (i <100)
    627                 sprintf( outname, "glyph-0%d.bmp", i );
     626                  sprintf( outname, "%s-glyph-0%d.bmp", this->getName(), i );
    628627                else
    629                 sprintf( outname, "glyph-%d.bmp", i );
    630                 SDL_SaveBMP(tmpSurf, outname);
    631               */
     628                  sprintf( outname, "%s-glyph-%d.bmp", this->getName(), i );
     629                SDL_SaveBMP(tmpSurf, outname);*/
     630
    632631            }
    633632        }
     
    712711                  x = 0;
    713712                  y = y + maxLineHeight;
    714                   maxLineHeight = 0;
     713                  //maxLineHeight = 0;
    715714                }
    716715              if (y + maxLineHeight + 1 > size)
  • trunk/src/lib/lang/base_object.cc

    r5111 r5113  
    5252  //  delete []this->className;
    5353  if (this->objectName)
    54     delete []this->objectName;}
     54    delete[] this->objectName;}
    5555
    5656/**
     
    8484{
    8585  if (this->objectName)
    86     delete []this->objectName;
     86    delete[] this->objectName;
    8787  if (objectName)
    8888  {
  • trunk/src/lib/lang/base_object.h

    r5111 r5113  
    2727
    2828  void setName (const char* newName);
    29   /** \brief returns the Name of this Object */
     29  /** returns the Name of this Object */
    3030  inline const char* getName ()const { return this->objectName; };
    3131
  • trunk/src/lib/lang/class_list.cc

    r5111 r5113  
    4848{
    4949  delete this->objectList;
     50  if(ClassList::classList != NULL)
     51  {
     52    delete ClassList::classList;
     53    ClassList::classList = NULL;
     54  }
    5055  --ClassList::classCount;
    5156}
     
    5661//! the Count of classes
    5762unsigned int ClassList::classCount = 0;
     63
     64//! a List of all strings of all classes, that have registered so far.
     65tList<const char>* ClassList::classList = NULL;
    5866
    5967/**
     
    109117}
    110118
     119/**
     120 * grabs the names of all Classes, and injects it into a List of const chars
     121 * @return the generated List
     122 *
     123 * This function first looks, if the List has been changed (by the ListSize)
     124 * befor it changes anything.
     125 */
     126const tList<const char>* ClassList::getClassList()
     127{
     128  if (unlikely(ClassList::classList != NULL && ClassList::classList->getSize() != ClassList::classCount))
     129  {
     130    delete ClassList::classList;
     131    ClassList::classList = NULL;
     132  }
     133  if (unlikely(ClassList::classList == NULL))
     134    ClassList::classList = new tList<const char>;
     135
     136  if(likely(ClassList::first != NULL))
     137  {
     138    ClassList* tmpCL = ClassList::first;
     139    while (likely(tmpCL != NULL))
     140    {
     141      ClassList::classList->add(tmpCL->className);
     142      tmpCL = tmpCL->next;
     143    }
     144  }
     145  return ClassList::classList;
     146}
     147
     148/**
     149 * searches for classID and returns the list of Entities
     150 * @param classID the ID of the class to get the list from
     151 * @return the List accessed by classID, or NULL if not found
     152 */
    111153tList<BaseObject>* ClassList::getList(long classID)
    112154{
     
    119161    {
    120162      if (unlikely(tmpCL->classID == classID))
     163        return tmpCL->objectList;
     164      tmpCL = tmpCL->next;
     165    }
     166  }
     167  return NULL;
     168}
     169
     170/**
     171 * searches for className and returns the list of Entities
     172 * @param className the name of the class to get the list from
     173 * @return the List accessed by classID, or NULL if not found
     174 */tList<BaseObject>* ClassList::getList(const char* className)
     175{
     176  if(unlikely(ClassList::first == NULL))
     177    return NULL;
     178  else
     179  {
     180    ClassList* tmpCL = ClassList::first;
     181    while (likely(tmpCL != NULL))
     182    {
     183      if (unlikely(!strcmp(tmpCL->className, className)))
    121184        return tmpCL->objectList;
    122185      tmpCL = tmpCL->next;
     
    205268}
    206269
    207 
    208270/**
    209271 * prints out a string of all the types this Object matches
     
    222284  }
    223285}
     286
     287/**
     288 * converts a ClassID into a string
     289 * @param classID the ClassID to search for
     290 * @return a String containing the name of the Class, NULL if the Class was not found
     291 */
     292const char* ClassList::IDToString(ClassID classID)
     293{
     294  if(likely(ClassList::first != NULL))
     295  {
     296    ClassList* tmpCL = ClassList::first;
     297    while (likely(tmpCL != NULL))
     298    {
     299      if (tmpCL->classID == classID)
     300        return tmpCL->className;
     301      tmpCL = tmpCL->next;
     302    }
     303  }
     304  return NULL;
     305}
     306
     307/**
     308 * converts a String into a ClassID
     309 * @param className the name of the class to search for
     310 * @return the ClassID. CL_NULL, if the class was not found.
     311 */
     312long ClassList::StringToID(const char* className)
     313{
     314  if(likely(ClassList::first != NULL))
     315  {
     316    ClassList* tmpCL = ClassList::first;
     317    while (likely(tmpCL != NULL))
     318    {
     319      if (!strcasecmp(tmpCL->className, className))
     320        return tmpCL->classID;
     321      tmpCL = tmpCL->next;
     322    }
     323  }
     324  return CL_NULL;
     325}
     326
     327
    224328
    225329/**
  • trunk/src/lib/lang/class_list.h

    r5111 r5113  
    3535
    3636    // STATIC FUNCTIONS
    37     static void               addToClassList(BaseObject* objectPointer, const long& classID, const char* className);
    38     static void               removeFromClassList(BaseObject* objectPointer);
     37    static void                     addToClassList(BaseObject* objectPointer, const long& classID, const char* className);
     38    static void                     removeFromClassList(BaseObject* objectPointer);
    3939
    40     static tList<BaseObject>* getList(long classID = CL_NULL);
    41     static BaseObject*        getObject(const char* name, long classID = CL_NULL);
    42     static bool               exists(const BaseObject* object, long classID = CL_NULL);
     40    static tList<BaseObject>*       getList(long classID = CL_NULL);
     41    static tList<BaseObject>*       getList(const char* className);
     42    static const tList<const char>* getClassList();
     43    static BaseObject*              getObject(const char* name, long classID = CL_NULL);
     44    static bool                     exists(const BaseObject* object, long classID = CL_NULL);
    4345
    44     static void               whatIs(const BaseObject* object);
    45     static void debug(unsigned int debugLevel = 0, long classID = CL_NULL);
     46    static void                     whatIs(const BaseObject* object);
     47
     48    static const char*              IDToString(ClassID classID = CL_NULL);
     49    static long                     StringToID(const char* className);
     50    static void                     debug(unsigned int debugLevel = 0, long classID = CL_NULL);
     51
    4652
    4753  private:
    48     tList<BaseObject>*       objectList;             //!< A list of Objects belonging to this Class
     54    tList<BaseObject>*              objectList;             //!< A list of Objects belonging to this Class
    4955
    50     long                     classID;                //!< ClassID stored in this ClassList \see ClassID
    51     const char*              className;              //!< Name of the Class Stored here
     56    long                            classID;                //!< ClassID stored in this ClassList \see ClassID
     57    const char*                     className;              //!< Name of the Class Stored here
    5258
    53     ClassList*               next;                   //!< Pointer to the next class in the List
     59    ClassList*                      next;                   //!< Pointer to the next class in the List
    5460
    5561    // STATIC MEMBERS
    56     static ClassList*        first;                  //!< The first Class in the List
    57     static unsigned int      classCount;             //!< The Count of classes that have been registered (should match the lower description)
     62    static ClassList*               first;                  //!< The first Class in the List
     63    static tList<const char>*       classList;              //!< a List of all Names of all classes, that have registered so far.
     64    static unsigned int             classCount;             //!< The Count of classes that have been registered (should match the lower description)
    5865};
    5966
  • trunk/src/lib/util/list.h

    r5111 r5113  
    135135  void removeLast();
    136136  void flush();
    137   T* firstElement();
    138   T* lastElement();
    139   bool isEmpty();
    140   unsigned int getSize();
     137  T* firstElement() const;
     138  T* lastElement() const;
     139  bool isEmpty() const;
     140  unsigned int getSize() const;
    141141  bool inList(T* entity);
    142   tIterator<T>* getIterator();
     142  tIterator<T>* getIterator() const;
    143143  T* nextElement(T* toEntity);
    144144  T* toArray();
     
    303303*/
    304304template<class T>
    305 inline T* tList<T>::firstElement()
     305inline T* tList<T>::firstElement() const
    306306{
    307307  return this->first->curr;
     
    314314*/
    315315template<class T>
    316 inline T* tList<T>::lastElement()
     316inline T* tList<T>::lastElement() const
    317317{
    318318  return this->last->curr;
     
    325325*/
    326326template<class T>
    327 inline bool tList<T>::isEmpty()
     327inline bool tList<T>::isEmpty() const
    328328{
    329329  return (this->size==0)?true:false;
     
    359359*/
    360360template<class T>
    361 inline unsigned int tList<T>::getSize()
     361inline unsigned int tList<T>::getSize() const
    362362{
    363363  return this->size;
     
    372372*/
    373373template<class T>
    374 inline tIterator<T>* tList<T>::getIterator()
     374inline tIterator<T>* tList<T>::getIterator() const
    375375{
    376376  tIterator<T>* iterator = new tIterator<T>(this->first);
  • trunk/src/util/loading/load_param.cc

    r5111 r5113  
    1717
    1818#include "list.h"
    19 #include "array.h"
    2019#include "base_object.h"
    2120
     
    386385 * searches for classes, which beginn with classNameBegin
    387386 * @param classNameBegin the beginning string of a Class
    388  * @return a NEW char-array with ClassNames. The ARRAY should be deleted afterwards,
     387 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
    389388 * !! The strings MUST NOT be deleted !!
    390389 */
    391 Array<char*>* LoadClassDescription::searchClassWithShort(const char* classNameBegin)
     390tList<const char>* LoadClassDescription::searchClassWithShort(const char* classNameBegin)
    392391{
    393392  unsigned int searchLength = strlen(classNameBegin);
    394   Array<char*>* retVal = new Array<char*>;
     393  tList<const char>* retVal = new tList<const char>;
    395394
    396395  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
     
    401400        !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))
    402401    {
    403       retVal->addEntry(enumClassDesc->className);
     402      retVal->add(enumClassDesc->className);
    404403    }
    405404    enumClassDesc = iterator->nextElement();
     
    407406  delete iterator;
    408407
    409   retVal->finalizeArray();
    410408  return retVal;
    411409}
  • trunk/src/util/loading/load_param.h

    r5111 r5113  
    3131// Forward Declaration //
    3232template<class T> class tList;
    33 template<class T> class Array;
    3433
    3534//! macro that makes it even more easy to load a Parameter
     
    312311
    313312  static void printAll(const char* fileName = NULL);
    314   static Array<char*>* searchClassWithShort(const char* classNameBegin);
     313  static tList<const char>* searchClassWithShort(const char* classNameBegin);
    315314//  static const LoadParamDescription* getClass(const char* className);
    316315
  • trunk/src/util/resource_manager.cc

    r5111 r5113  
    9999      this->dataDir = new char[strlen(realDir)+1];
    100100      strcpy(this->dataDir, realDir);
    101       delete realDir;
     101      delete[] realDir;
    102102      return true;
    103103    }
    104104  else
    105105    {
    106       PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir, this->dataDir);
    107       delete realDir;
     106      PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir, this->dataDir);
     107      delete[] realDir;
    108108      return false;
    109109    }
     
    631631
    632632  // checking for the termination of the string given. If there is a "/" at the end cut it away
    633   if (directoryName[strlen(directoryName)-1] == '/')
     633  if (directoryName[strlen(directoryName)-1] == '/' ||
     634      directoryName[strlen(directoryName)-1] == '\\')
    634635    {
    635636      tmpDirName = new char[strlen(directoryName)+1];
     
    651652                            ))
    652653        {
    653           delete tmpDirName;
     654          delete[] tmpDirName;
    654655          return true;
    655656        }
  • trunk/src/util/shell.cc

    r5111 r5113  
    2020#include "text_engine.h"
    2121#include "list.h"
    22 #include "array.h"
    2322#include "graphics_engine.h"
    2423#include "event_handler.h"
    2524
    2625#include "load_param.h"
     26#include "class_list.h"
     27
     28#include "key_names.h"
    2729#include "debug.h"
    2830#include <stdarg.h>
     
    4042  this->setName("Shell");
    4143
     44  this->shellHeight = 400;
     45  this->bActive = false;
    4246  this->buffer = new tList<char>;
    4347
    44   this->textSize = 10;
     48  this->textSize = 15;
     49  this->lineSpacing = 5;
    4550
    4651  //this->bufferSize = 0;
    4752  this->bufferText = NULL;
    4853  this->setBufferSize(100);
     54  this->bufferDisplaySize = 10;
    4955  this->setBufferDisplaySize(10);
    50   this->setAbsCoor2D(3, GraphicsEngine::getInstance()->getResolutionY());
     56  this->setAbsCoor2D(3, -400);
    5157  this->delayed = 0;
    5258  this->setRepeatDelay(.3, .05);
    5359  this->pressedKey = SDLK_FIRST;
    5460
    55   this->inputLineText = TextEngine::getInstance()->createText("fonts/earth.ttf", 10, TEXT_DYNAMIC, 255, 0, 0);
    56   this->inputLineText->setAlignment(TEXT_ALIGN_LEFT);
    57   this->inputLineText->setText(NULL);
     61  this->inputLineText = NULL;
    5862  this->inputLine = new char[1];
    5963  this->inputLine[0] = '\0';
    60   this->inputLineText->setParent2D(this);
    61 
    62 
     64
     65  this->rebuildText();
     66  this->completionList = NULL;
     67
     68  // EVENT-Handler subscription of '`' to all States, and all other keyboard commands to ES_SEHLL
    6369  EventHandler* evh = EventHandler::getInstance();
    6470  evh->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
     
    7783  for (int i = 0; i < this->bufferDisplaySize; i++)
    7884    delete this->bufferText[i];
    79   delete this->bufferText;
     85  delete[] this->bufferText;
    8086
    8187  // delete the inputLine
     
    9399  delete charIterator;
    94100
     101//  if (this->completionList != NULL)
     102    //delete this->completionList;
     103
    95104  Shell::singletonRef = NULL;
    96105}
     106
     107
     108void Shell::activate()
     109{
     110  if (this->bActive == true)
     111    PRINTF(3)("The shell is already active\n");
     112  this->bActive = true;
     113
     114  EventHandler::getInstance()->setState(ES_SHELL);
     115  this->setRelCoorSoft2D(0, 0, 1, 5);
     116}
     117
     118void Shell::deactivate()
     119{
     120  if (this->bActive == false)
     121    PRINTF(3)("The shell is already inactive\n");
     122  this->bActive = false;
     123
     124  EventHandler::getInstance()->setState(ES_GAME);
     125  this->setRelCoorSoft2D(0, -400, 1, 5);
     126}
     127
     128void Shell::setTextSize(unsigned int textSize, unsigned int lineSpacing)
     129{
     130  this->textSize = textSize;
     131  this->lineSpacing = lineSpacing;
     132
     133  this->rebuildText();
     134}
     135
     136void Shell::rebuildText()
     137{
     138  if (this->inputLineText == NULL)
     139    delete this->inputLineText;
     140  this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0);
     141  this->inputLineText->setAlignment(TEXT_ALIGN_LEFT);
     142  this->inputLineText->setText(NULL);
     143  this->inputLineText->setParent2D(this);
     144  this->inputLineText->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize);
     145
     146  this->setBufferDisplaySize(this->bufferDisplaySize);
     147}
     148
     149
    97150
    98151/**
     
    106159    for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    107160      delete this->bufferText[i];
    108     delete this->bufferText;
     161    delete[] this->bufferText;
    109162  }
    110163
     
    112165  for (unsigned int i = 0; i < bufferDisplaySize; i++)
    113166  {
    114     this->bufferText[i] = TextEngine::getInstance()->createText("fonts/earth.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0);
     167    this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0);
    115168    this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
    116     this->bufferText[i]->setRelCoor2D(5, 12+12*i);
     169    this->bufferText[i]->setRelCoor2D(5, (this->textSize + this->lineSpacing)*(bufferDisplaySize - i -1));
    117170    this->bufferText[i]->setText(NULL);
    118171    this->bufferText[i]->setParent2D(this);
    119172  }
    120 
    121 
    122173  this->bufferDisplaySize = bufferDisplaySize;
     174
     175  this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
    123176}
    124177
     
    153206 * @param line the Line as in the first argument in printf
    154207 * @param args the arguments as a va_list
    155  *
    156  * @todo optimize
    157208 */
    158209bool Shell::addBufferLineStatic(const char* line, ...)
     
    174225  return true;
    175226}
    176 int curr = 0;
    177227
    178228/**
     
    199249   }
    200250
    201    if (likely(bufferText != NULL))
     251   if (this->bActive && likely(bufferText != NULL))
    202252   {
    203      Text* moveText = this->bufferText[this->bufferDisplaySize-1];
    204      for (int i = this->bufferDisplaySize-1; i > 0; i--)
     253     Text* lastText = this->bufferText[this->bufferDisplaySize-1];
     254     Vector firstCoord = this->bufferText[0]->getRelCoorSoft2D();
     255
     256     Text* swapText;
     257     Text* moveText = this->bufferText[0];
     258     this->bufferText[0]->setRelCoorSoft2D(this->bufferText[1]->getRelCoorSoft2D(), 5);
     259     for (unsigned int i = 1; i < this->bufferDisplaySize; i++)
    205260     {
    206        this->bufferText[i] = this->bufferText[i-1];
     261       if ( i < this->bufferDisplaySize-1)
     262         this->bufferText[i]->setRelCoorSoft2D(this->bufferText[i+1]->getRelCoorSoft2D(),5);
     263       swapText = this->bufferText[i];
     264       this->bufferText[i] = moveText;
     265       moveText = swapText;
    207266     }
    208      this->bufferText[0] = moveText;
     267     lastText->setRelCoor2D(firstCoord);
     268     this->bufferText[0] = lastText;
     269
     270     this->bufferText[0]->setText(newLine);
    209271   }
    210    this->bufferText[0]->setText(newLine);
    211    // this->bufferText->
    212 //  this->inputLineText->setText(newLine);
    213272}
    214273
     
    246305}
    247306
    248 
    249307/**
    250308 * deletes the InputLine
     
    258316  this->inputLine = new char[1];
    259317  *this->inputLine = '\0';
    260 
    261318}
    262319
     
    316373bool Shell::executeCommand()
    317374{
    318 
    319375  this->addBufferLineStatic("Execute Command: %s\n", this->inputLine);
    320376  delete this->inputLine;
     
    337393}
    338394
    339 
    340 #include "key_names.h"
    341395/**
    342396 * listens for some event
     
    352406      if (EventHandler::getInstance()->getState() == ES_GAME)
    353407      {
    354         EventHandler::getInstance()->setState(ES_SHELL);
    355         this->setRelCoorSoft2D(0, GraphicsEngine::getInstance()->getResolutionY()-150, 1, 5);
     408        this->activate();
    356409      }
    357410
    358411      else
    359412      {
    360         EventHandler::getInstance()->setState(ES_GAME);
    361         this->setRelCoorSoft2D(0, GraphicsEngine::getInstance()->getResolutionY()+10, 1, 5);
     413        this->deactivate();
    362414      }
    363415    }
     
    382434  {
    383435    if (this->pressedKey == event.type)
     436    {
    384437      this->pressedKey = SDLK_FIRST;
    385     this->delayed = 0.0;
     438      this->delayed = 0.0;
     439    }
    386440  }
    387441}
     
    426480
    427481//  glTexCoord2f(this->texCoord.maxU, this->texCoord.minV);
    428   glVertex2f(this->getAbsCoor2D().x + 800, this->getAbsCoor2D().y  );
     482  glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y  );
    429483
    430484//  glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV);
    431   glVertex2f(this->getAbsCoor2D().x + 800, this->getAbsCoor2D().y + 150);
     485  glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
    432486
    433487//  glTexCoord2f(this->texCoord.minU, this->texCoord.maxV);
    434   glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + 150);
     488  glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
    435489
    436490  glEnd();
     
    451505  strcpy(completionLine, this->inputLine);
    452506
    453    char* commandBegin = strrchr(completionLine, ' ');
     507  char* commandBegin = strrchr(completionLine, ' ');
    454508  if (commandBegin == NULL)
    455509    commandBegin = completionLine;
     
    462516  }
    463517
    464   printf("%s\n",commandBegin);
    465    Array<char*>* classArray = LoadClassDescription::searchClassWithShort(commandBegin);
    466    if (classArray->getCount() == 0)
    467    {
    468      delete[] completionLine;
    469      delete classArray;
    470      //PRINTF(0)("no completion found for %s\n", commandBegin);
    471      return false;
    472    }
    473 
    474    for (unsigned int i = 0; i < classArray->getCount(); i++)
    475    {
    476      PRINTF(0)("%s\n", classArray->getEntry(i));
    477    }
    478    if (classArray->getCount() == 1)
    479    {
    480      this->removeCharacters(strlen(commandBegin));
    481      this->addCharacters(classArray->getEntry(0));
    482      this->addCharacter(' ');
    483    }
    484 
    485    delete[] completionLine;
    486    delete classArray;
     518  char* objectStart;
     519  if (objectStart = strstr(commandBegin, "::"))
     520  {
     521    char* classIdentity = new char[objectStart - commandBegin +1];
     522    strncpy(classIdentity, commandBegin, objectStart - commandBegin);
     523    classIdentity[objectStart - commandBegin] = '\0';
     524    this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity));
     525    delete[] classIdentity;
     526  }
     527  else
     528    this->classComplete(commandBegin);
     529
     530  delete[] completionLine;
     531}
     532
     533/**
     534 * autocompletes a className
     535 * @param classBegin the Beginning of a String to autoComplete
     536 * @return true on success, false otherwise
     537 */
     538bool Shell::classComplete(const char* classBegin)
     539{
     540  if (unlikely(classBegin == NULL))
     541    return false;
     542  const tList<const char>* clList = ClassList::getClassList();
     543  if (clList != NULL)
     544  {
     545    const tList<const char>* classList = this->createCompleteList(clList, classBegin);
     546    if (classList != NULL)
     547      this->generalComplete(classList, classBegin, "%s::", "::");
     548    else
     549      return false;
     550  }
     551  else
     552    return false;
     553  return true;
     554}
     555
     556/**
     557 * autocompletes an ObjectName
     558 * @param objectBegin the beginning string of a Object
     559 * @param classID the ID of the Class to search for.
     560 * @return true on success, false otherwise
     561 */
     562bool Shell::objectComplete(const char* objectBegin, long classID)
     563{
     564  printf("%s\n", objectBegin);
     565
     566  if (unlikely(objectBegin == NULL))
     567    return false;
     568  tList<BaseObject>* boList = ClassList::getList(classID);
     569  if (boList != NULL)
     570  {
     571    printf("\n", boList->firstElement()->getName());
     572    const tList<const char>* objectList = this->createCompleteList(boList, objectBegin);
     573    if (objectList != NULL)
     574      this->generalComplete(objectList, objectBegin, "%s");
     575    else
     576      return false;
     577  }
     578  else
     579    return false;
     580  return true;
     581}
     582
     583bool Shell::functionComplete(const char* functionBegin)
     584{
     585}
     586
     587/**
     588 * completes the inputline on grounds of an inputList
     589 * @param stringList the List to parse through
     590 * @param begin the String to search in the inputList, and to extend with it.
     591 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
     592 * @param addBack what should be added at the end of the completion
     593 * @param addFront what should be added to the front of one finished completion
     594 * @return true if ok, false otherwise
     595 */
     596bool Shell::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
     597{
     598  if (stringList->getSize() == 0)
     599    return false;
     600
     601  const char* addString = stringList->firstElement();
     602  unsigned int addLength = 0;
     603  unsigned int inputLenght = strlen(begin);
     604
     605  if (addString != NULL)
     606    addLength = strlen(addString);
     607  tIterator<const char>* charIterator = stringList->getIterator();
     608  const char* charElem = charIterator->nextElement();
     609  while (charElem != NULL)
     610  {
     611    PRINTF(0)(displayAs, charElem);
     612    for (unsigned int i = inputLenght; i < addLength; i++)
     613      if (addString[i] != charElem[i])
     614    {
     615      addLength = i;
     616      break;
     617    }
     618    charElem = charIterator->nextElement();
     619  }
     620  delete charIterator;
     621
     622  if (addLength >= inputLenght)
     623  {
     624    char* adder = new char[addLength+1];
     625    strncpy(adder, addString, addLength);
     626    adder[addLength] = '\0';
     627    this->removeCharacters(inputLenght);
     628    this->addCharacters(adder);
     629    if (addBack != NULL && stringList->getSize() == 1)
     630      this->addCharacters("::");
     631    delete[] adder;
     632  }
     633  return true;
     634}
     635
     636
     637
     638/**
     639 * searches for classes, which beginn with classNameBegin
     640 * @param inputList the List to parse through
     641 * @param classNameBegin the beginning string
     642 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     643 * !! The strings MUST NOT be deleted !!
     644 */
     645const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin)
     646{
     647  if (inputList == NULL || classNameBegin == NULL)
     648    return NULL;
     649  unsigned int searchLength = strlen(classNameBegin);
     650  if (this->completionList != NULL)
     651    delete this->completionList;
     652  this->completionList = new tList<const char>;
     653
     654//  tList<const char>* classList = ClassList::getClassList();
     655
     656  tIterator<const char>* iterator = inputList->getIterator();
     657  const char* enumString = iterator->nextElement();
     658  while (enumString != NULL)
     659  {
     660    if (strlen(enumString)>searchLength+1 &&
     661        !strncasecmp(enumString, classNameBegin, searchLength))
     662    {
     663      this->completionList->add(enumString);
     664    }
     665    enumString = iterator->nextElement();
     666  }
     667  delete iterator;
     668
     669  return this->completionList;
     670}
     671
     672/**
     673 * searches for classes, which beginn with classNameBegin
     674 * @param inputList the List to parse through
     675 * @param classNameBegin the beginning string
     676 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     677 * !! The strings MUST NOT be deleted !!
     678 */
     679const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin)
     680{
     681  if (inputList == NULL || classNameBegin == NULL)
     682    return NULL;
     683  unsigned int searchLength = strlen(classNameBegin);
     684  if (this->completionList != NULL)
     685    delete this->completionList;
     686  this->completionList = new tList<const char>;
     687
     688  tIterator<BaseObject>* iterator = inputList->getIterator();
     689  BaseObject* enumBO = iterator->nextElement();
     690  while (enumBO != NULL)
     691  {
     692    if (enumBO->getName() != NULL &&
     693        strlen(enumBO->getName())>searchLength+1 &&
     694        !strncasecmp(enumBO->getName(), classNameBegin, searchLength))
     695    {
     696      this->completionList->add(enumBO->getName());
     697    }
     698    enumBO = iterator->nextElement();
     699  }
     700  delete iterator;
     701
     702  return this->completionList;
    487703}
    488704
     
    494710  if (this->pressedKey != SDLK_FIRST)
    495711    printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
    496 
    497 }
     712}
  • trunk/src/util/shell.h

    r5111 r5113  
    3636
    3737
    38     void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
     38    void activate();
     39    void deactivate();
    3940
    40     void setBufferDisplaySize(unsigned int bufferDisplaySize);
     41    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
     42    void rebuildText();
    4143
    4244    // BUFFER //
     45    void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
     46    void setBufferDisplaySize(unsigned int bufferDisplaySize);
    4347    void flushBuffers();
    4448    static bool addBufferLineStatic(const char* line, ...);
     
    6771  private:
    6872    bool autoComplete();
     73    bool classComplete(const char* classBegin);
     74    bool objectComplete(const char* objectBegin, long classID);
     75    bool functionComplete(const char* functionBegin);
     76
     77    bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
     78
     79    const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
     80    const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
    6981
    7082
     
    88100    unsigned int           textSize;               //!< The size of the text.
    89101    unsigned int           lineSpacing;            //!< The Spacing between lines.
     102    unsigned int           shellHeight;            //!< The hight of the Shell in Pixels
     103    bool                   bActive;                //!< if the shell is active;
    90104
    91105    char                   bufferArray[10000];     //!< a BUFFER for fast writing
     106
     107    // completion
     108    tList<const char>*    completionList;          //!< A list of completions, that are io.
    92109};
    93110
Note: See TracChangeset for help on using the changeset viewer.