Changeset 3522 in orxonox.OLD for orxonox/trunk/src/track_manager.cc
- Timestamp:
- Mar 13, 2005, 12:05:07 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/track_manager.cc
r3495 r3522 20 20 21 21 #include <stdarg.h> 22 #include "p_node.h" 22 23 23 24 using namespace std; … … 34 35 this->isJoined = false; 35 36 this->mainJoin = false; 36 this->cond; //!< todo think!!37 37 this->ID = -1; 38 38 this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager. … … 46 46 this->curve = NULL; 47 47 this->children = NULL; 48 this->condFunc = &TrackElement::random; 48 49 } 49 50 … … 90 91 91 92 93 /** 94 \brief checks if there are any BackLoops in the Track 95 \param trackElem the trackElement to check about 96 it simply does this by looking if the current trackElem is found again somewhere else in the Track 97 */ 98 bool TrackElement::backLoopCheck(TrackElement* trackElem) 99 { 100 if (this->childCount == 0) 101 return true; 102 else 103 { 104 for (int i = 0; i < this->childCount; i++) 105 if(!this->children[i]->backLoopCheck(trackElem)) 106 return false; 107 108 return true; 109 } 110 } 111 112 /** 113 \brief CONDITION that chooses the first child for the decision (static) 114 \param nothing Nothing in this function 115 \returns the chosen child 116 */ 117 int TrackElement::lowest(void* nothing) 118 { 119 return 0; 120 } 121 122 /** 123 \brief CONDITION that chooses the last child for the decision (static) 124 \param nothing Nothing in this function 125 \returns the chosen child 126 */ 127 int TrackElement::highest(void* nothing) 128 { 129 return this->childCount-1; 130 } 131 132 /** 133 \brief CONDITION that chooses a random child for the decision (static) 134 \param nothing Nothing in this function 135 \returns the chosen child 136 */ 137 int TrackElement::random(void* nothing) 138 { 139 int i = (int)floor ((float)rand()/(float)RAND_MAX * (float)this->childCount); 140 if (i >= this->childCount) 141 return this->childCount-1; 142 else 143 return i; 144 } 145 146 /** 147 \brief CONDITION that chooses child 0, if the node(probably Player) 148 is left of its parent (z<0)) and 1/right otherwise. 149 \param node The node to act upon. 150 \returns the chosen child 151 */ 152 int TrackElement::leftRight(void* node) 153 { 154 PNode* tmpNode = (PNode*)node; 155 156 if (tmpNode->getRelCoor().z < 0) 157 return 0; 158 else 159 return 1; 160 } 161 162 163 /** 164 \brief CONDITION that chooses the child, that has the nearest distance to the node (probably player). 165 \param node The node to act upon. 166 \returns the chosen child 167 168 This is rather dangerous, because one must carefully set the points on the curve. 169 The best Way is to set the nodes as wide away of each other as possible, 170 but take into consideration, that if the nodes are to far from a center node, the center will be chosen. 171 (play with this!!). 172 */ 173 int TrackElement::nearest(void* node) 174 { 175 PNode* tmpNode = (PNode*)node; 176 177 Vector nodeRelCoord = tmpNode->getRelCoor(); 178 float minDist = 100000000; 179 int nodeNumber = 0; 180 for (int i = 0; i < this->childCount; i++) 181 { 182 float dist = (nodeRelCoord - this->children[i]->curve->getNode(4)).len(); 183 if (dist < minDist) 184 { 185 minDist = dist; 186 nodeNumber = i; 187 } 188 } 189 PRINTF(3)("PathDecision with nearest algorithm: %d\n", nodeNumber); 190 return nodeNumber; 191 } 92 192 93 193 … … 139 239 TrackManager* TrackManager::getInstance(void) 140 240 { 141 if ( singletonRef)142 return singletonRef;241 if (TrackManager::singletonRef) 242 return TrackManager::singletonRef; 143 243 else 144 return singletonRef = new TrackManager();244 return TrackManager::singletonRef = new TrackManager(); 145 245 } 146 246 … … 192 292 /** 193 293 \brief Sets the Type of the Curve 194 \brief curveType The Type to set 294 \param curveType The Type to set 295 \param trackElem the TrackElement that should get a new Curve. 195 296 */ 196 297 void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem) … … 333 434 /** 334 435 \brief decides under what condition a certain Path will be chosen. 436 \param cond the CONDITION of the decision 437 \param subject the Subject that will be decided upon with CONDITION cond. 438 */ 439 void TrackManager::condition(CONDITION cond, void* subject) 440 { 441 this->condition(this->currentTrackElem->ID, cond, subject); 442 } 443 /** 444 \brief decides under what condition a certain Path will be chosen. 335 445 \param groupID the ID on which to choose the preceding move 336 \param cond \todo think about this 337 */ 338 void TrackManager::condition(unsigned int groupID, PathCondition cond) 339 { 446 \param cond the CONDITION of the decision 447 \param subject the Subject that will be decided upon with CONDITION cond. 448 */ 449 void TrackManager::condition(unsigned int groupID, CONDITION cond, void* subject) 450 { 451 TrackElement* tmpElem = this->findTrackElementByID(groupID); 340 452 341 } 453 switch (cond) 454 { 455 case LOWEST: 456 tmpElem->condFunc = &TrackElement::lowest; 457 break; 458 case HIGHEST: 459 tmpElem->condFunc = &TrackElement::highest; 460 break; 461 case RANDOM: 462 tmpElem->condFunc = &TrackElement::random; 463 break; 464 case LEFTRIGHT: 465 tmpElem->condFunc = &TrackElement::leftRight; 466 break; 467 case NEAREST: 468 tmpElem->condFunc = &TrackElement::nearest; 469 break; 470 case ENEMYKILLED: 471 break; 472 } 473 tmpElem->subject=subject; 474 } 475 342 476 343 477 /** … … 372 506 { 373 507 printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]); 508 509 // checking if there is a back-loop-connection and ERROR if it is. 510 TrackElement* tmpTrackElem = this->findTrackElementByID(trackIDs[0]); 511 if (!tmpTrackElem->backLoopCheck(tmpTrackElem)) 512 PRINTF(1)("Backloop connection detected at joining trackElements\n"); 374 513 375 514 // chanching work-on to temporary value. going back at the end. … … 506 645 && this->currentTrackElem->children) 507 646 { 508 if (this->currentTrackElem->jumpTime > 0) 647 if (this->currentTrackElem->jumpTime > 0) 509 648 this->jumpTo(this->localTime + this->currentTrackElem->jumpTime); 510 this->currentTrackElem = this->currentTrackElem->children[ 0];649 this->currentTrackElem = this->currentTrackElem->children[this->choosePath(this->currentTrackElem)]; 511 650 } 512 651 if (this->bindSlave) … … 535 674 /** 536 675 \brief a Function that decides which Path we should follow. 537 \param graphIDThe Path to choose.676 \param trackElem The Path to choose. 538 677 539 678 */ 540 void TrackManager::choosePath(int graphID)541 { 542 679 int TrackManager::choosePath(TrackElement* trackElem) 680 { 681 return (trackElem->*(trackElem->condFunc))(trackElem->subject); 543 682 } 544 683 … … 587 726 void TrackManager::debug(unsigned int level) const 588 727 { 589 printf("::CLASS TRACKMANAGER::debug information::\n"); 590 // printf("Status is: % 591 printf(" Consists of %d elements\n", this->trackElemCount); 592 printf(" localTime is: %f\n", this->localTime); 728 PRINT(0)("=========================================\n"); 729 PRINT(0)("= CLASS TRACKMANAGER::debug information =\n"); 730 PRINT(0)("=========================================\n"); 731 // PRINT(0)("Status is: % 732 PRINT(0)(" Consists of %d elements\n", this->trackElemCount); 733 PRINT(0)(" localTime is: %f\n", this->localTime); 593 734 if (level >= 2) 594 735 { … … 596 737 { 597 738 TrackElement* tmpElem = this->findTrackElementByID(i); 598 printf(" ::TrackElement:%i::", tmpElem->ID);739 PRINT(0)("--== TrackElement:%i ==--", tmpElem->ID); 599 740 if(tmpElem->name) 600 printf("name:%s::", tmpElem->name);741 PRINT(0)("Name: %s::", tmpElem->name); 601 742 if(tmpElem->isFresh) 602 printf(" has not jet eddited in any way\n");603 printf("\n TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);604 printf(" consists of %d Points\n", tmpElem->nodeCount);743 PRINT(0)(" -- has not jet eddited in any way --\n"); 744 PRINT(0)("\n TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime); 745 PRINT(0)(" consists of %d Points\n", tmpElem->nodeCount); 605 746 if (tmpElem->childCount == 0) 606 printf(" has no child\n");747 PRINT(0)(" has no child\n"); 607 748 else if (tmpElem->childCount == 1) 608 printf(" has 1 child: ==%d==\n", tmpElem->children[0]->ID);749 PRINT(0)(" has 1 child: =%d=\n", tmpElem->children[0]->ID); 609 750 else if (tmpElem->childCount > 1) 610 751 { 611 printf(" has %d children: ", tmpElem->childCount);752 PRINT(0)(" has %d children: ", tmpElem->childCount); 612 753 for(int i = 0; i < tmpElem->childCount; i++) 613 printf("=%d= ", tmpElem->children[i]->ID);614 printf("\n");754 PRINT(0)("=%d= ", tmpElem->children[i]->ID); 755 PRINT(0)("\n"); 615 756 } 616 757 617 758 if(tmpElem->isHotPoint) 618 printf(" is a special Point:\n");759 PRINT(0)(" is a special Point:\n"); 619 760 if(tmpElem->isSavePoint) 620 printf(" is a SavePoint\n");761 PRINT(0)(" is a SavePoint\n"); 621 762 if(tmpElem->isFork) 622 763 { 623 printf(" is A Fork with with %d children.\n", tmpElem->childCount);764 PRINT(0)(" is A Fork with with %d children.\n", tmpElem->childCount); 624 765 } 625 766 if(tmpElem->isJoined) 626 printf(" is Joined at the End\n"); 767 PRINT(0)(" is Joined at the End\n"); 768 769 if(!tmpElem->backLoopCheck(tmpElem)) /* this should not happen */ 770 PRINT(2)(" THERE IS A BACKLOOP TO THIS ELEMENT\n"); 627 771 } 628 772 } 629 } 773 PRINT(0)("-----------------------------------------\n"); 774 }
Note: See TracChangeset
for help on using the changeset viewer.