Changeset 3522 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Mar 13, 2005, 12:05:07 PM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/Makefile.am
r3521 r3522 33 33 camera.cc \ 34 34 track_manager.cc \ 35 track_node.cc \ 35 36 light.cc \ 36 37 story_entities/story_entity.cc \ … … 72 73 message_structures.h \ 73 74 light.h \ 75 track_manager.h \ 76 track_node.h \ 74 77 story_entities/story_entity.h \ 75 78 story_entities/story_def.h \ -
orxonox/trunk/src/story_entities/world.cc
r3521 r3522 116 116 trackManager->addPoint(Vector(30,0,5)); 117 117 trackManager->addPoint(Vector(40,0,5)); 118 trackManager->setDuration(2); 119 trackManager->setSavePoint(); 120 trackManager->addPoint(Vector(50,10,10)); 121 trackManager->addPoint(Vector(60,0, 10)); 122 trackManager->addPoint(Vector(70,0, 10)); 123 trackManager->addPoint(Vector(80,0,-10)); 124 trackManager->addPoint(Vector(90,0,-10)); 118 trackManager->setDuration(4); 119 int fork11, fork12, fork13; 120 trackManager->fork(3, &fork11, &fork12, &fork13); 121 trackManager->workOn(fork11); 122 trackManager->addPoint(Vector(70, 0, -10)); 123 trackManager->addPoint(Vector(100, 0, -15)); 124 trackManager->addPoint(Vector(300, 0, -15)); 125 trackManager->setDuration(10); 126 trackManager->workOn(fork12); 127 trackManager->addPoint(Vector(70, 0, 0)); 128 trackManager->addPoint(Vector(100, 0, 0)); 129 trackManager->addPoint(Vector(120,10, 0)); 130 trackManager->addPoint(Vector(150,10, 0)); 131 trackManager->addPoint(Vector(180,15, 0)); 132 trackManager->addPoint(Vector(200,10, 0)); 133 trackManager->setDuration(7); 134 trackManager->workOn(fork13); 135 trackManager->addPoint(Vector(70, 0, 10)); 136 trackManager->addPoint(Vector(100, 0, 30)); 137 trackManager->addPoint(Vector(120,-10, 30)); 138 trackManager->addPoint(Vector(150,-10, 30)); 139 trackManager->setDuration(10); 140 trackManager->join(2, fork12, fork13); 141 142 trackManager->workOn(5); 143 trackManager->addPoint(Vector(250, 20, 10)); 144 trackManager->addPoint(Vector(290, 20, 10)); 125 145 trackManager->setDuration(5); 126 146 trackManager->setSavePoint(); 127 trackManager->addPoint(Vector(110,0,5)); 128 trackManager->addPoint(Vector(120,0, 10)); 129 trackManager->addPoint(Vector(130,0, 10)); 130 trackManager->addPoint(Vector(140,0,-10)); 131 trackManager->addPoint(Vector(150,0,-10)); 132 trackManager->setDuration(3); 133 int fork11, fork12, fork13, fork14; 134 trackManager->fork(4, &fork11, &fork12, &fork13, &fork14); 135 trackManager->workOn(fork11); 136 trackManager->addPoint(Vector(170, 0, -15)); 137 trackManager->addPoint(Vector(180, 0, -15)); 138 trackManager->setDuration(3); 139 trackManager->workOn(fork12); 140 trackManager->addPoint(Vector(170, 0, 10)); 141 trackManager->addPoint(Vector(180, 0, 10)); 142 trackManager->addPoint(Vector(190,2,5)); 143 trackManager->addPoint(Vector(200,2,5)); 144 trackManager->setDuration(7); 145 int fork21, fork22; 146 trackManager->fork(2, &fork21, &fork22); 147 trackManager->workOn(fork21); 148 trackManager->addPoint(Vector(220, 10,-10)); 149 trackManager->addPoint(Vector(230, 0,-10)); 150 trackManager->addPoint(Vector(240, 0, 2)); 151 trackManager->addPoint(Vector(250, 0, 0)); 152 trackManager->addPoint(Vector(260, 0, 5)); 153 trackManager->setDuration(3); 154 trackManager->join(2, fork12, fork11); 155 trackManager->workOn(fork22); 156 trackManager->addPoint(Vector(220, -10,10)); 157 trackManager->addPoint(Vector(230, 0, 10)); 158 trackManager->addPoint(Vector(240, 0, 10)); 159 trackManager->addPoint(Vector(250, 0, 5)); 160 trackManager->setDuration(6); 161 trackManager->workOn(fork13); 162 trackManager->addPoint(Vector(200,-10,5)); 163 trackManager->addPoint(Vector(250,-10,5)); 164 trackManager->setDuration(3); 165 trackManager->workOn(fork14); 166 trackManager->addPoint(Vector(200,15,0)); 167 trackManager->addPoint(Vector(210,0,10)); 168 trackManager->setDuration(1); 169 trackManager->join(4, fork21, fork22, fork13, fork14); 170 trackManager->workOn(10); 171 trackManager->addPoint(Vector(250,-10,5)); 172 trackManager->addPoint(Vector(260,-10,5)); 147 trackManager->addPoint(Vector(350, 20, 10)); 148 trackManager->addPoint(Vector(360, 20, 10)); 149 trackManager->addPoint(Vector(370, 20, 10)); 150 trackManager->setDuration(5); 151 152 trackManager->join(2, 6, fork11); 153 173 154 trackManager->finalize(); 155 174 156 175 157 /*monitor progress*/ … … 249 231 this->glmis->step(); 250 232 233 trackManager->setBindSlave(env); 234 trackManager->condition(1, NEAREST, myPlayer); 235 251 236 break; 252 237 } -
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 } -
orxonox/trunk/src/track_manager.h
r3495 r3522 17 17 class PNode; 18 18 19 //! condition for choosing a certain Path. \todo implement a useful way.20 struct PathCondition21 {22 23 };24 25 26 19 //! A Graph-Element, that holds the curve-structure of a Level. 27 20 /** … … 36 29 37 30 TrackElement* findByID(unsigned int trackID); 31 bool backLoopCheck(TrackElement* trackElem); 38 32 39 33 bool isFresh; //!< If no Points where added until now … … 43 37 bool isJoined; //!< If the End of the Curve is joined. 44 38 bool mainJoin; //!< If the End of the Curve is joined, and this is the one Curve the others join to. 45 PathCondition cond; //!< The Split Condition;46 39 int ID; //!< The ID of this TrackElement 47 40 float startingTime; //!< The time at which this Track begins. … … 55 48 int childCount; //!< The number of Children This TrackElement has. 56 49 TrackElement** children; //!< A TrackElement can have a Tree of following TrackElements. 50 51 // CONDITION FUNCTIONS and STUFF 52 void* subject; //!< The Subject the Condition should act upon. 53 int (TrackElement::*condFunc)(void*); //!< Pointer to the condition function 54 55 int lowest(void* nothing); 56 int highest(void* nothing); 57 int random(void* nothing); 58 59 int leftRight(void* node); 60 int nearest(void* node); 61 // todo int enemyKilled(void* entity); 57 62 }; 58 63 59 64 //! the Condition to choose between the different ways of the game. 65 enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED}; 60 66 61 67 //! The TrackManager handles the flow of the Players through the game. … … 105 111 float maxTime; //!< The maximal time the track has. 106 112 int trackElemCount; //!< The count of TrackElements that exist. 107 PNode* bindSlave; 113 PNode* bindSlave; //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself. 108 114 109 115 void initChildren(unsigned int childCount); … … 117 123 // Methods to change the Path (initialisation) 118 124 void workOn(unsigned int trackID); 119 inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);} 125 /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */ 126 inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}; 120 127 void setCurveType(CurveType curveType, TrackElement* trackElem); 121 128 void setDuration(float time); … … 126 133 void fork(unsigned int count, ...); 127 134 void forkV(unsigned int count, int* trackIDs); 128 void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!! 135 void condition(CONDITION cond, void* subject); 136 void condition(unsigned int groupID, CONDITION cond, void* subject); 129 137 void join(unsigned int count, ...); 130 138 void joinV(unsigned int count, int* trackIDs); … … 132 140 133 141 // Methods to calculate the position on the Path (runtime) 134 Vector calcPos(void) const;135 Vector calcDir(void) const;142 inline Vector calcPos(void) const; 143 inline Vector calcDir(void) const; 136 144 void tick(float dt); 137 145 void jumpTo(float time); 138 void choosePath(int graphID);146 inline int choosePath(TrackElement* trackElem); 139 147 140 148 void setBindSlave(PNode* bindSlave);
Note: See TracChangeset
for help on using the changeset viewer.