Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3835 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Apr 15, 2005, 4:59:42 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: TrackManager update: TrackElement-class cleaned up

Location:
orxonox/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/track_manager.cc

    r3832 r3835  
    4848  this->width = TMAN_DEFAULT_WIDTH;
    4949  this->nodeCount = 0;
     50  this->curve = NULL;
    5051  this->childCount = 0;
     52  this->children = NULL;
    5153  this->name = NULL;
    52   this->curve = NULL;
    53   this->children = NULL;
    5454
    5555  this->history = NULL;
    5656
     57  this->subject = NULL;
    5758  this->condFunc = &TrackElement::random;
    5859}
     
    6465TrackElement::~TrackElement(void)
    6566{
    66   if (this->name)
    67     delete []name;
    68   if (this->curve)
    69     delete this->curve;
    70   if ((!this->isJoined &&this->childCount > 0) || (this->isJoined && this->mainJoin))
     67  // deleting the Name
     68  delete []name;
     69  // deleting the Curve
     70  delete this->curve;
     71
     72  // deleting all the Children of this TrackNode.
     73  if ((!this->isJoined &&this->childCount > 0)
     74      || (this->isJoined && this->mainJoin)) // only if this is the MainJoin.
    7175    {
    7276      tIterator<TrackElement>* iterator = this->children->getIterator();
     
    8690   \param trackID The ID to search for.
    8791   \returns The TrackElement if Found, NULL otherwise.
    88    
    89    \todo make this more modular, to search for different things
    9092*/
    9193TrackElement* TrackElement::findByID(unsigned int trackID)
     
    9496  if (this->ID == trackID)
    9597    return this;
    96   // search on.
     98  // search all children
    9799  if (this->childCount > 0)
    98100    {
     
    108110      delete iterator;
    109111    }
     112  // if not found
    110113  else
    111114    return NULL;
     
    114117
    115118/**
    116    \brief checks if there are any BackLoops in the Track
    117    \param trackElem the trackElement to check about
    118    it simply does this by looking if the current trackElem is found again somewhere else in the Track
    119 */
    120 bool TrackElement::backLoopCheck(TrackElement* trackElem)
    121 {
    122   if (this->childCount == 0)
    123     return true;
    124   else
     119   \brief Searches through all the TrackElements for a trackName
     120   \param trackName The name to search for.
     121   \returns The TrackElement if Found, NULL otherwise.
     122*/
     123TrackElement* TrackElement::findByName(const char* trackName)
     124{
     125  // return if Found.
     126  if (this->name && !strcmp(this->name, trackName))
     127    return this;
     128  // search all children
     129  if (this->childCount > 0)
    125130    {
    126131      tIterator<TrackElement>* iterator = this->children->getIterator();
    127132      TrackElement* enumElem = iterator->nextElement();
     133      TrackElement* tmpElem;
    128134      while (enumElem)
    129135        {
    130           if(!enumElem->backLoopCheck(trackElem))
    131             return false;
     136          if ((tmpElem = enumElem->findByName(trackName)))
     137            return tmpElem;
    132138          enumElem = iterator->nextElement();
    133139        }
    134140      delete iterator;
    135      
    136       return true;
    137     }
     141    }
     142  // if not found
     143  else
     144    return NULL;
     145}
     146
     147/**
     148   \brief checks if there are any BackLoops in the Track (Backloops only
     149   \param trackElem the trackElement to check about
     150   \returns true if NO loop was found, false Otherwise
     151   You actually have to act on false!!
     152   it simply does this by looking if the current trackElem is found again somewhere else in the Track
     153*/
     154bool TrackElement::backLoopCheck(const TrackElement* trackElem, unsigned int depth) const
     155{
     156  if(depth == 0 || this != trackElem)
     157    {
     158      if (this->children)
     159        {
     160          tIterator<TrackElement>* iterator = this->children->getIterator();
     161          TrackElement* enumElem = iterator->nextElement();
     162          while (enumElem)
     163            {
     164              if(!enumElem->backLoopCheck(trackElem, depth + 1))
     165                return false;
     166              enumElem = iterator->nextElement();
     167            }
     168          delete iterator;
     169        }
     170    }
     171  else
     172    return false;
     173
     174  // only returns if everything worked out
     175  return true;
    138176}
    139177
    140178/**
    141179   \param childNumber which child to return
    142    \returns the n-the children (starting at 0)
    143 */
    144 TrackElement* TrackElement::getChild(int childCount)
    145 {
     180   \returns the n-the children (starting at 0).
     181   Be aware, that when the trackElement has no Children, NULL will be returned
     182*/
     183TrackElement* TrackElement::getChild(int childCount) const
     184{
     185  // if the the trackElement has no children return NULL.
    146186  if (this->childCount == 0)
    147187    return NULL;
     188  // we cannot return the childCount+m's Child, so we return the last.
    148189  if (childCount > this->childCount)
    149190    childCount = this->childCount;
    150191 
    151   //  TrackElement* enumElem = this->children->enumerate();
    152192  tIterator<TrackElement>* iterator = this->children->getIterator();
    153193  TrackElement* enumElem = iterator->nextElement();
     
    166206  if (this->name)
    167207    delete []this->name;
    168   // if a name was given already.
     208  // if a name was given.
    169209  if (name)
    170210    {
     
    179219   \returns The name of this TrackElement
    180220*/
    181 char* TrackElement::getName(void) const
     221const char* TrackElement::getName(void) const
    182222{
    183223  return this->name;
     
    187227   \brief prints out debug information about this TrackElement
    188228*/
    189 void TrackElement::debug(void)
     229void TrackElement::debug(void) const
    190230{
    191231  PRINT(0)("--== TrackElement:%i ==--", this->ID);
     
    235275   \returns the chosen child
    236276*/
    237 int TrackElement::lowest(void* nothing)
     277int TrackElement::lowest(const void* nothing) const
    238278{
    239279  return 0;
     
    245285   \returns the chosen child
    246286*/
    247 int TrackElement::highest(void* nothing)
     287int TrackElement::highest(const void* nothing) const
    248288{
    249289  return this->childCount-1;
     
    255295   \returns the chosen child
    256296*/
    257 int TrackElement::random(void* nothing)
     297int TrackElement::random(const void* nothing) const
    258298{
    259299  int i = (int)floor ((float)rand()/(float)RAND_MAX * (float)this->childCount);
     
    270310   \returns the chosen child
    271311*/
    272 int TrackElement::leftRight(void* node)
     312int TrackElement::leftRight(const void* node) const
    273313{
    274314  PNode* tmpNode = (PNode*)node;
     
    291331   (play with this!!).
    292332*/
    293 int TrackElement::nearest(void* node)
     333int TrackElement::nearest(const void* node) const
    294334{
    295335  PNode* tmpNode = (PNode*)node;
  • orxonox/trunk/src/track_manager.h

    r3608 r3835  
    3737
    3838  TrackElement* findByID(unsigned int trackID);
    39   bool backLoopCheck(TrackElement* trackElem);
     39  TrackElement* findByName(const char* trackName);
     40  bool backLoopCheck(const TrackElement* trackElem, unsigned int depth = 0) const;
    4041
    41   TrackElement* getChild(int childNumber);
     42  TrackElement* getChild(int childNumber) const;
    4243  void setName(const char* name);
    43   char* getName(void) const;
     44  const char* getName(void) const;
    4445
    4546  // atributes
     
    6566  TrackElement* history;     //!< a pointer to the last TrackElement we were on. This is if you want to walk the path backwards again.
    6667
    67   void debug(void);
     68  void debug(void) const;
    6869
    6970  // CONDITION FUNCTIONS and STUFF
    7071  void* subject;             //!< The Subject the Condition should act upon.
    71   int (TrackElement::*condFunc)(void*); //!< Pointer to the condition function
     72  int (TrackElement::*condFunc)(const void*) const; //!< Pointer to the condition function
    7273
    73   int lowest(void* nothing);
    74   int highest(void* nothing);
    75   int random(void* nothing);
     74  int lowest(const void* nothing) const;
     75  int highest(const void* nothing) const;
     76  int random(const void* nothing) const;
    7677
    77   int leftRight(void* node);
    78   int nearest(void* node);
     78  int leftRight(const void* node) const;
     79  int nearest(const void* node) const;
    7980  // todo  int enemyKilled(void* entity);
    8081
Note: See TracChangeset for help on using the changeset viewer.