Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3594 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Mar 17, 2005, 5:27:36 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: TrackManager now uses tList instead of Arrays (). this is slower, but more compatible, and should have less errors

Location:
orxonox/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/defs/debug.h

    r3592 r3594  
    5252
    5353#define DEBUG_MODULE_IMPORTER           0
    54 #define DEBUG_MODULE_TRACK_MANAGER      0
     54#define DEBUG_MODULE_TRACK_MANAGER      3
    5555#define DEBUG_MODULE_LIGHT              0
    5656#define DEBUG_MODULE_PLAYER             0
  • orxonox/trunk/src/track_manager.cc

    r3593 r3594  
    6565  if ((!this->isJoined &&this->childCount > 0) || (this->isJoined && this->mainJoin))
    6666    {
    67       for (int i=0; i < this->childCount; i++)
    68         delete this->children[i];
     67      TrackElement* enumElem = children->enumerate();
     68      while (enumElem)
     69        {
     70          delete enumElem;
     71          enumElem = children->nextElement();
     72        }
    6973      delete this->children;
    7074    }
     
    8589  // search on.
    8690  if (this->childCount > 0)
    87     for (int i=0; i < this->childCount; i++)
    88       {
    89         TrackElement* tmpElem;
    90         if ((tmpElem = this->children[i]->findByID(trackID)))
    91           return tmpElem;
    92       }
    93   else return NULL;
     91    {
     92      TrackElement* enumElem = this->children->enumerate();
     93      TrackElement* tmpElem;
     94      while (enumElem)
     95        {
     96          if ((tmpElem = enumElem->findByID(trackID)))
     97            return tmpElem;
     98          enumElem = this->children->nextElement();
     99        }
     100    }
     101  else
     102    return NULL;
    94103}
    95104
     
    106115  else
    107116    {
    108       for (int i = 0; i < this->childCount; i++)
    109         if(!this->children[i]->backLoopCheck(trackElem))
    110           return false;
     117      TrackElement* enumElem = this->children->enumerate();
     118      while (enumElem)
     119        {
     120          if(!enumElem->backLoopCheck(trackElem))
     121            return false;
     122          enumElem = this->children->nextElement();
     123        }
    111124     
    112125      return true;
    113126    }
     127}
     128
     129/**
     130   \param childNumber which child to return
     131   \returns the n-the children (starting at 0)
     132*/
     133TrackElement* TrackElement::getChild(int childCount)
     134{
     135  if (this->childCount == 0)
     136    return NULL;
     137  if (childCount > this->childCount)
     138    childCount = this->childCount;
     139 
     140  TrackElement* enumElem = this->children->enumerate();
     141  for (int i = 0; i < childCount; i++)
     142    enumElem = this->children->nextElement();
     143  return enumElem;
    114144}
    115145
     
    155185    PRINT(0)("   has no child\n");
    156186  else if (this->childCount == 1)
    157     PRINT(0)("   has 1 child: =%d=\n", this->children[0]->ID);
     187    PRINT(0)("   has 1 child: =%d=\n", this->getChild(0)->ID);
    158188  else if (this->childCount > 1)
    159189    {
    160190      PRINT(0)("   has %d children: ", this->childCount);
    161       for(int i = 0; i < this->childCount; i++)
    162         PRINT(0)("=%d= ", this->children[i]->ID);
     191      TrackElement* enumElem = this->children->enumerate();
     192      while (enumElem)
     193        {
     194          PRINT(0)("=%d= ", enumElem->ID);
     195          enumElem = this->children->nextElement();
     196        }
    163197      PRINT(0)("\n");
    164198    }
     
    246280  Vector nodeRelCoord = tmpNode->getRelCoor();
    247281  float minDist = 100000000;
    248   int nodeNumber = 0;
    249   for (int i = 0; i < this->childCount; i++)
    250     {
    251       float dist = (nodeRelCoord - this->children[i]->curve->getNode(4)).len();
     282  int childNumber = 0;
     283  int i = 0;
     284
     285  TrackElement* enumElem = this->children->enumerate();
     286  while (enumElem)
     287    {
     288      float dist = (nodeRelCoord - enumElem->curve->getNode(4)).len();
    252289      if (dist < minDist)
    253290        {
    254291          minDist = dist;
    255           nodeNumber = i;
    256         }
    257     }
    258   PRINTF(4)("PathDecision with nearest algorithm: %d\n", nodeNumber);
    259   return nodeNumber;
     292          childNumber = i;
     293        }
     294      i++;
     295      enumElem = this->children->nextElement();
     296    }
     297
     298  PRINTF(4)("PathDecision with nearest algorithm: %d\n", childNumber);
     299  return childNumber;
    260300}
    261301
     
    270310TrackManager::TrackManager(void)
    271311{
    272   this->setClassName ("TrackManager");
     312  this->setClassName("TrackManager");
    273313 
    274   singletonRef = this;
     314  TrackManager::singletonRef = this;
    275315
    276316  PRINTF(3)("Initializing the TrackManager\n");
     
    281321  this->maxTime = 0;
    282322  this->trackElemCount = 1;
    283   this->bindSlave = this->trackNode = new TrackNode();
     323  this->setBindSlave(this->trackNode = new TrackNode());
    284324}
    285325
     
    292332  PRINTF(3)("Destruct TrackManager\n");
    293333
    294   PRINTF(3)("Deleting all the TrackElements\n");
     334  PRINTF(4)("Deleting all the TrackElements\n");
    295335  delete this->firstTrackElem;
    296336
    297337  // we do not have a TrackManager anymore
    298   singletonRef = NULL;
     338  TrackManager::singletonRef = NULL;
    299339}
    300340
     
    309349TrackManager* TrackManager::getInstance(void)
    310350{
    311   if (!singletonRef)
    312     singletonRef = new TrackManager();
    313   return singletonRef;
     351  if (!TrackManager::singletonRef)
     352    TrackManager::singletonRef = new TrackManager();
     353  return TrackManager::singletonRef;
    314354}
    315355
     
    322362  this->currentTrackElem->childCount = childCount;
    323363  this->currentTrackElem->mainJoin = true;
    324   this->currentTrackElem->children = new TrackElement*[childCount];
    325   for (int i=0; i<childCount; i++)
    326     {
    327       this->currentTrackElem->children[i] = new TrackElement();
    328       this->currentTrackElem->children[i]->ID = ++trackElemCount;
    329       this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
    330       this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->children[i]);
     364  this->currentTrackElem->children =  new tList<TrackElement>();
     365  for (int i = 0; i < childCount; i++)
     366    {
     367      TrackElement* newElem = new TrackElement();
     368      this->currentTrackElem->children->add(newElem);
     369      newElem->ID = ++trackElemCount;
     370      newElem->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
     371      this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->getChild(i));
    331372    }
    332373  if (childCount == 1)
    333     this->currentTrackElem->children[0]->setName(this->currentTrackElem->getName());
     374    this->currentTrackElem->getChild(0)->setName(this->currentTrackElem->getName());
    334375}
    335376
     
    356397    this->currentTrackElem = tmpElem;
    357398  else
    358     printf("TrackElement not Found, leaving unchanged\n");
    359   printf("now Working on %d\n", this->currentTrackElem->ID);
     399    PRINTF(2)("TrackElement not Found, leaving unchanged\n");
     400  PRINTF(4)("now Working on %d\n", this->currentTrackElem->ID);
    360401
    361402}
     
    428469int TrackManager::addHotPoint(Vector newPoint)
    429470{
    430   printf("setting up a HotPoint\n");
     471  PRINTF(4)("setting up a HotPoint\n");
    431472  if (this->currentTrackElem->isFresh)
    432473    {
     
    439480  this->currentTrackElem->nodeCount++;
    440481  this->initChildren(1);
    441   this->currentTrackElem = this->currentTrackElem->children[0];
     482  this->currentTrackElem = this->currentTrackElem->getChild(0);
    442483}
    443484
     
    451492int TrackManager::setSavePoint(void)
    452493{
    453   printf("setting up a SavePoint.\n");
     494  PRINTF(4)("setting up a SavePoint.\n");
    454495  if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint)
    455     return this->currentTrackElem->children[1]->ID;
     496    {
     497      PRINTF(2)("%d is already finished \n", currentTrackElem->ID);
     498      return this->currentTrackElem->getChild(0)->ID;
     499    }
    456500  this->currentTrackElem->isSavePoint = true;
    457501  this->currentTrackElem->isHotPoint = true;
    458502
    459503  this->initChildren(1);
    460   this->currentTrackElem = this->currentTrackElem->children[0];
     504  this->currentTrackElem = this->currentTrackElem->getChild(0);
    461505}
    462506
     
    493537void TrackManager::forkV(unsigned int count, int* trackIDs)
    494538{
    495   printf("Forking with %d children\n", count);
     539  PRINTF(4)("Forking with %d children\n", count);
    496540  if (this->currentTrackElem->isSavePoint)
    497541    return;
     
    521565{
    522566  TrackElement* tmpElem = this->findTrackElementByID(groupID);
    523  
    524   switch (cond)
    525     {
    526     case LOWEST:
    527       tmpElem->condFunc = &TrackElement::lowest;
    528       break;
    529     case HIGHEST:
    530       tmpElem->condFunc = &TrackElement::highest;
    531       break;
    532     case RANDOM:
    533       tmpElem->condFunc = &TrackElement::random;
    534       break;
    535     case LEFTRIGHT:
    536       tmpElem->condFunc = &TrackElement::leftRight;
    537       break;
    538     case NEAREST:
    539       tmpElem->condFunc = &TrackElement::nearest;
    540       break;
    541     case ENEMYKILLED:
    542       break;
    543     }
    544   tmpElem->subject=subject;
     567  if (!tmpElem->isFork)
     568    {
     569      PRINTF(2)("%d is not a Fork, and no condition can be set in this case\n", tmpElem->ID);
     570      return;
     571    }
     572  else
     573    {
     574      switch (cond)
     575        {
     576        case LOWEST:
     577          tmpElem->condFunc = &TrackElement::lowest;
     578          break;
     579        case HIGHEST:
     580          tmpElem->condFunc = &TrackElement::highest;
     581          break;
     582        case RANDOM:
     583          tmpElem->condFunc = &TrackElement::random;
     584          break;
     585        case LEFTRIGHT:
     586          tmpElem->condFunc = &TrackElement::leftRight;
     587          break;
     588        case NEAREST:
     589          tmpElem->condFunc = &TrackElement::nearest;
     590          break;
     591        case ENEMYKILLED:
     592          break;
     593        }
     594      tmpElem->subject=subject;
     595    }
    545596}
    546597
     
    576627void TrackManager::joinV(unsigned int count, int* trackIDs)
    577628{
    578   printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
     629  PRINTF(3)("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
    579630
    580631  // checking if there is a back-loop-connection and ERROR if it is.
    581632  TrackElement* tmpTrackElem = this->findTrackElementByID(trackIDs[0]);
    582633  if (!tmpTrackElem->backLoopCheck(tmpTrackElem))
    583     PRINTF(1)("Backloop connection detected at joining trackElements\n");
     634    PRINTF(2)("Backloop connection detected at joining trackElements\n");
    584635
    585636  // chanching work-on to temporary value. going back at the end.
     
    631682    }
    632683  if(firstJoint->childCount > 0)
    633     for(int i = 0; i < firstJoint->childCount; i++)
    634       {
    635         printf("Setting startingTime of %d to %f.\n", firstJoint->children[i]->ID, tmpLatestTime);
    636         firstJoint->children[i]->startingTime = tmpLatestTime;
    637         firstJoint->children[i]->endTime = tmpLatestTime+firstJoint->children[i]->duration;
    638       }
    639 
     684    {
     685      TrackElement* enumElem = firstJoint->children->enumerate();
     686      while (enumElem)
     687        {
     688          PRINTF(4)("Setting startingTime of %d to %f.\n", enumElem->ID, tmpLatestTime);
     689          enumElem->startingTime = tmpLatestTime;
     690          enumElem->endTime = tmpLatestTime + enumElem->duration;
     691         
     692          enumElem = firstJoint->children->nextElement();
     693        }
     694    }
    640695  // returning to the TrackElement we were working on.
    641696  this->workOn(tmpCurrentWorkingID);
     
    652707    {
    653708      TrackElement* tmpElem = findTrackElementByID(i);
    654       if (tmpElem->childCount>0 && tmpElem->mainJoin)
    655         {
    656           for (int j = 0; j < tmpElem->childCount; j++)
     709      if (tmpElem->childCount > 0 && tmpElem->mainJoin)
     710        {
     711
     712          TrackElement* enumElem = tmpElem->children->enumerate();
     713          while (enumElem)
    657714            {
    658715             
    659716              // c1-continuity
    660               tmpElem->children[j]->curve->addNode(tmpElem->children[j]->curve->getNode(0) +
    661                                                    ((tmpElem->children[j]->curve->getNode(0) -
     717              enumElem->curve->addNode(enumElem->curve->getNode(0) +
     718                                                   ((enumElem->curve->getNode(0) -
    662719                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
    663720                                                    ),2);
    664               tmpElem->children[j]->nodeCount++;
     721              enumElem->nodeCount++;
    665722              // c2-continuity
    666               tmpElem->children[j]->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
     723              enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
    667724                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
    668725                                                   tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
    669               tmpElem->children[j]->nodeCount++;                                                   
    670               printf("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
     726              enumElem->nodeCount++;                                               
     727              PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
    671728                     tmpElem->ID, tmpElem->nodeCount,
    672729                     tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
    673                      tmpElem->children[j]->ID, tmpElem->children[j]->nodeCount,
    674                      tmpElem->children[j]->curve->calcAcc(0).x, tmpElem->children[j]->curve->calcAcc(0).y, tmpElem->children[j]->curve->calcAcc(0).z);
     730                     enumElem->ID, enumElem->nodeCount,
     731                     enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z);
     732             
     733              enumElem = tmpElem->children->nextElement();
    675734            }
     735         
     736         
    676737        }
    677738    }
     
    720781      // jump to the next TrackElement and also set the history of the new Element to the old one.
    721782      TrackElement* tmpHistoryElem = this->currentTrackElem;
    722       this->currentTrackElem = this->currentTrackElem->children[this->choosePath(this->currentTrackElem)];
     783      this->currentTrackElem = this->currentTrackElem->getChild(this->choosePath(this->currentTrackElem));
    723784      this->currentTrackElem->history = tmpHistoryElem;
    724785    }
  • orxonox/trunk/src/track_manager.h

    r3593 r3594  
    3838  bool backLoopCheck(TrackElement* trackElem);
    3939
     40  TrackElement* getChild(int childNumber);
     41  void setName(const char* name);
     42  char* getName(void) const;
     43
    4044  // atributes
    4145  bool isFresh;              //!< If no Points where added until now
     
    5357  Curve* curve;              //!< The Curve of this TrackElement
    5458  int childCount;            //!< The number of Children This TrackElement has.
    55   TrackElement** children;   //!< A TrackElement can have a Tree of following TrackElements.
     59  tList<TrackElement>* children;   //!< A TrackElement can have a Tree of following TrackElements.
    5660
    57   void setName(const char* name);
    58   char* getName(void) const;
    5961
    6062  // runtime
Note: See TracChangeset for help on using the changeset viewer.