Changeset 4584 in orxonox.OLD for orxonox/trunk/src/util/track
- Timestamp:
- Jun 10, 2005, 3:50:11 AM (19 years ago)
- Location:
- orxonox/trunk/src/util/track
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/track/track_manager.cc
r4509 r4584 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 56 56 this->childCount = 0; 57 57 this->children = NULL; 58 this->name = NULL;59 58 60 59 this->history = NULL; … … 64 63 } 65 64 66 /** 65 /** 67 66 \brief destroys all alocated memory) 68 67 \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements … … 70 69 TrackElement::~TrackElement(void) 71 70 { 72 // deleting the Name73 delete []name;74 71 // deleting the Curve 75 72 delete this->curve; 76 73 77 74 // deleting all the Children of this TrackNode. 78 if ((!this->isJoined &&this->childCount > 0) 75 if ((!this->isJoined &&this->childCount > 0) 79 76 || (this->isJoined && this->mainJoin)) // only if this is the MainJoin. 80 77 { … … 82 79 TrackElement* enumElem = iterator->nextElement(); 83 80 while (enumElem) 84 85 86 87 81 { 82 delete enumElem; 83 enumElem = iterator->nextElement(); 84 } 88 85 delete iterator; 89 86 delete this->children; … … 108 105 TrackElement* tmpElem; 109 106 while (enumElem) 110 111 112 113 114 107 { 108 if ((tmpElem = enumElem->findByID(trackID))) 109 return tmpElem; 110 enumElem = iterator->nextElement(); 111 } 115 112 delete iterator; 116 113 } … … 128 125 { 129 126 // return if Found. 130 if (this-> name && !strcmp(this->name, trackName))127 if (this->getName() && !strcmp(this->getName(), trackName)) 131 128 return this; 132 129 // search all children … … 137 134 TrackElement* tmpElem; 138 135 while (enumElem) 139 140 141 142 143 136 { 137 if ((tmpElem = enumElem->findByName(trackName))) 138 return tmpElem; 139 enumElem = iterator->nextElement(); 140 } 144 141 delete iterator; 145 142 } … … 156 153 { 157 154 tList<const TrackElement>* trackList = new tList<const TrackElement>; 158 155 159 156 this->backLoopCheckAtomic(trackList); 160 157 161 158 delete trackList; 162 159 // only returns if everything worked out … … 182 179 TrackElement* enumElem = iterator->nextElement(); 183 180 while (enumElem) 184 185 186 187 181 { 182 if (!enumElem->backLoopCheckAtomic(trackList)) 183 return false; 184 } 188 185 delete iterator; 189 186 } … … 194 191 /** 195 192 \param childCount which child to return 196 \returns the n-the children (starting at 0). 193 \returns the n-the children (starting at 0). 197 194 Be aware, that when the trackElement has no Children, NULL will be returned 198 195 */ … … 205 202 if (childCount > this->childCount) 206 203 childCount = this->childCount; 207 204 208 205 tIterator<TrackElement>* iterator = this->children->getIterator(); 209 206 TrackElement* enumElem = iterator->nextElement(); … … 212 209 delete iterator; 213 210 return enumElem; 214 }215 216 /**217 \param name the Name to set.218 */219 void TrackElement::setName(const char* name)220 {221 // delete the old name222 if (this->name)223 delete []this->name;224 // if a name was given.225 if (name)226 {227 this->name = new char[strlen(name)+1];228 strcpy(this->name, name);229 }230 else231 this->name = NULL;232 211 } 233 212 … … 255 234 TrackElement* enumElem = iterator->nextElement(); 256 235 while (enumElem) 257 258 259 260 236 { 237 PRINT(0)("=%d= ", enumElem->ID); 238 enumElem = iterator->nextElement(); 239 } 261 240 delete iterator; 262 241 PRINT(0)("\n"); 263 242 } 264 243 265 244 if(this->isHotPoint) 266 245 PRINT(0)(" is a special Point:\n"); … … 273 252 if(this->isJoined) 274 253 PRINT(0)(" is Joined at the End\n"); 275 254 276 255 if(!this->backLoopCheck()) /* this should not happen */ 277 256 PRINT(2)(" THERE IS A BACKLOOP TO THIS ELEMENT\n"); … … 294 273 */ 295 274 int TrackElement::highest(const void* nothing) const 296 { 275 { 297 276 return this->childCount-1; 298 277 } … … 308 287 if (i >= this->childCount) 309 288 return this->childCount-1; 310 else 289 else 311 290 return i; 312 291 } … … 324 303 if (tmpNode->getRelCoor().z < 0) 325 304 return 0; 326 else 305 else 327 306 return 1; 328 307 } … … 355 334 float dist = (nodeRelCoord - enumElem->curve->getNode(4)).len(); 356 335 if (dist < minDist) 357 358 359 360 336 { 337 minDist = dist; 338 childNumber = i; 339 } 361 340 i++; 362 341 enumElem = iterator->nextElement(); … … 379 358 { 380 359 this->setClassID(CL_TRACK_MANAGER, "TrackManager"); 381 360 382 361 TrackManager::singletonRef = this; // do this because otherwise the TrackNode cannot get The instance of the TrackManager 383 362 … … 417 396 TiXmlNode* container; 418 397 double x, y, z, d; 419 398 420 399 element = root->FirstChildElement(); 421 400 while( element != NULL) 422 401 { 423 402 LoadParam<TrackManager>(element, "WorkOn", this, &TrackManager::workOnS, true) 424 403 .describe("Selects a TrackElement (by name) to work on"); 425 404 426 405 LoadParam<TrackManager>(element, "Point", this, &TrackManager::addPoint, true) 427 406 .describe("Adds a new Point to the currently selected TrackElement"); 428 407 429 408 LoadParam<TrackManager>(element, "Duration", this, &TrackManager::setDuration, true) 430 409 .describe("Sets the Duration of the currently selected TrackElement"); 431 410 432 411 LoadParam<TrackManager>(element, "HotPoint", this, &TrackManager::addHotPoint, true) 433 434 412 .describe("Sets a new Point that acts as a hot point. meaning, the curve will flow through this Point"); 413 435 414 LoadParam<TrackManager>(element, "SavePoint", this, &TrackManager::setSavePointS, true) 436 415 .describe("Sets the current selected Point to a Savepoint, meaning that the curve will be ended and a new one starts, and that one starts again from this point on"); 437 416 438 417 LoadParam<TrackManager>(element, "Fork", this, &TrackManager::forkS, true) 439 418 .describe("Forks the Path into multiple forked Path names seperated by ','"); 440 419 441 420 LoadParam<TrackManager>(element, "Join", this, &TrackManager::joinS, true) 442 421 .describe("Joins multiple joining Path names seperated by ','"); 443 422 444 423 /* 445 446 447 448 449 450 451 452 453 454 424 if( !strcmp( element->Value(), "Fork")) 425 { 426 container = element->FirstChild(); 427 if( container->ToText()) 428 { 429 assert( container->Value() != NULL); 430 PRINTF(4)("Loaded Fork: %s\n", container->Value()); 431 forkS(container->Value()); 432 } 433 } 455 434 */ 456 435 /* 457 458 459 460 461 462 463 464 465 466 467 */ 436 if( !strcmp( element->Value(), "Join")) 437 { 438 container = element->FirstChild(); 439 if( container->ToText()) 440 { 441 assert( container->Value() != NULL); 442 PRINTF0("Loaded Join: %s\n", container->Value()); 443 joinS(container->Value()); 444 } 445 } 446 */ 468 447 element = element->NextSiblingElement(); 469 448 } … … 514 493 // adds the conection Point 515 494 this->addPointV(trackElem->curve->getNode(trackElem->curve->getNodeCount()), 516 495 newElem); 517 496 // add the new child to the childList. 518 497 trackElem->children->add(newElem); … … 525 504 for (int i = 0; i < trackElem->childCount; i++) 526 505 { 527 528 529 506 char* childName = new char[strlen(trackElem->getName())+10]; 507 sprintf(childName, "%s_child%d", trackElem->getName(), i); 508 trackElem->getChild(i)->setName(childName); 530 509 } 531 510 } … … 727 706 *va_arg (ID, int*) = trackIDs[i]; 728 707 } 729 va_end(ID); 708 va_end(ID); 730 709 delete []trackIDs; 731 710 } … … 748 727 this->firstTrackElem->findByID(trackIDs[i])->setName(va_arg(name, const char*)); 749 728 } 750 va_end(name); 729 va_end(name); 751 730 delete []trackIDs; 752 731 } … … 765 744 { 766 745 this->firstTrackElem->findByID(trackIDs[i])->setName(strings.getString(i)); 767 } 746 } 768 747 delete []trackIDs; 769 748 } … … 773 752 \param count The Count of childrens the current HotPoint will have. 774 753 \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this). 775 \param trackNames the names for the tracks as a char-arrey-array 754 \param trackNames the names for the tracks as a char-arrey-array 776 755 \param trackElem The TrackElement to appy this to. (if NULL choose this->currentTrackElement) 777 756 \see TrackManager::fork(unsigned int count, ...) … … 822 801 { 823 802 switch (cond) 824 825 826 827 828 829 830 831 case RANDOM: 832 833 834 835 836 837 838 839 840 841 842 803 { 804 case LOWEST: 805 trackElem->condFunc = &TrackElement::lowest; 806 break; 807 case HIGHEST: 808 trackElem->condFunc = &TrackElement::highest; 809 break; 810 case RANDOM: 811 trackElem->condFunc = &TrackElement::random; 812 break; 813 case LEFTRIGHT: 814 trackElem->condFunc = &TrackElement::leftRight; 815 break; 816 case NEAREST: 817 trackElem->condFunc = &TrackElement::nearest; 818 break; 819 case ENEMYKILLED: 820 break; 821 } 843 822 trackElem->subject=subject; 844 823 } … … 846 825 847 826 /** 848 \brief joins some tracks together again. 827 \brief joins some tracks together again. 849 828 \param count The count of Paths to join. 850 829 … … 884 863 TrackElement* tmpElem = this->firstTrackElem->findByName(name); 885 864 if (tmpElem) 886 865 trackIDs[i] = tmpElem->ID; 887 866 else 888 867 PRINTF(1)("Trying to join a Track, of which the name does not exist: %s\n", name); 889 868 } 890 869 va_end(NAME); … … 907 886 TrackElement* tmpElem = this->firstTrackElem->findByName(strings.getString(i)); 908 887 if (tmpElem) 909 888 trackIDs[i] = tmpElem->ID; 910 889 else 911 890 PRINTF(1)("Trying to join a Track, of which the name does not exist: %s\n", strings.getString(i)); 912 891 } 913 892 … … 917 896 918 897 /** 919 \brief joins some tracks together again. 898 \brief joins some tracks together again. 920 899 \param count The count of Paths to join. 921 900 \param trackIDs an Array with the trackID's to join … … 930 909 if (!this->firstTrackElem->findByID(trackIDs[i])) 931 910 { 932 933 911 PRINTF(1)("Trying to Connect Paths that do not exist yet: %d\n Not Joining Anything\n", trackIDs[i]); 912 return; 934 913 } 935 914 936 915 937 916 PRINTF(3)("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]); … … 959 938 { 960 939 if(tmpJoinElem = this->firstTrackElem->findByID(trackIDs[i])) 961 962 963 964 965 940 { 941 if (tmpJoinElem->childCount == 0 942 && tmpJoinElem->endTime > tmpLatestTime) 943 tmpLatestTime = tmpJoinElem->endTime; 944 } 966 945 } 967 946 // time the main Join. 968 947 firstJoint->jumpTime = tmpLatestTime - firstJoint->endTime; 969 948 970 949 // Joining: 971 950 for (int i = 1; i < count; i++) 972 951 { 973 952 if( tmpJoinElem = this->firstTrackElem->findByID(trackIDs[i])) 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 953 { 954 if (tmpJoinElem->childCount > 0) 955 printf("!!This Curve has children, and as such will not be joined!!\n You can try joining other childless TrackElements to this one!"); 956 else 957 { 958 this->addPointV(tmpc2Point, tmpJoinElem); 959 this->addPointV(tmpTangentPoint, tmpJoinElem); 960 this->addPointV(tmpEndPoint, tmpJoinElem); 961 // time all other Joins 962 tmpJoinElem->jumpTime = tmpLatestTime - tmpJoinElem->endTime; 963 964 //Copying Joint-Info 965 tmpJoinElem->children = firstJoint->children; 966 tmpJoinElem->childCount = firstJoint->childCount; 967 tmpJoinElem->isSavePoint = firstJoint->isSavePoint; 968 tmpJoinElem->isFork = firstJoint->isFork; 969 970 tmpJoinElem->isJoined = true; 971 } 972 } 994 973 } 995 974 if(firstJoint->children) … … 999 978 TrackElement* enumElem = iterator->nextElement(); 1000 979 while (enumElem) 1001 1002 1003 1004 1005 1006 1007 980 { 981 PRINTF(5)("Setting startingTime of %d to %f.\n", enumElem->ID, tmpLatestTime); 982 enumElem->startingTime = tmpLatestTime; 983 enumElem->endTime = tmpLatestTime + enumElem->duration; 984 985 enumElem = iterator->nextElement(); 986 } 1008 987 delete iterator; 1009 988 } … … 1021 1000 TrackElement* tmpElem = this->firstTrackElem->findByID(i); 1022 1001 if( tmpElem->childCount > 0 && tmpElem->mainJoin) 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 ((enumElem->curve->getNode(0) - 1033 1034 1035 1036 1037 1038 1039 1040 enumElem->nodeCount++; 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1002 { 1003 tIterator<TrackElement>* iterator = tmpElem->children->getIterator(); 1004 TrackElement* enumElem = iterator->nextElement(); 1005 //TrackElement* enumElem = tmpElem->children->enumerate(); 1006 while (enumElem) 1007 { 1008 1009 // c1-continuity 1010 enumElem->curve->addNode(enumElem->curve->getNode(0) + 1011 ((enumElem->curve->getNode(0) - 1012 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) 1013 ),2); 1014 enumElem->nodeCount++; 1015 // c2-continuity 1016 enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())- 1017 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 + 1018 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3); 1019 enumElem->nodeCount++; 1020 PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n %d-out: count: %d %f, %f, %f\n", 1021 tmpElem->ID, tmpElem->nodeCount, 1022 tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z, 1023 enumElem->ID, enumElem->nodeCount, 1024 enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z); 1025 1026 enumElem = iterator->nextElement(); 1027 } 1028 delete iterator; 1029 } 1051 1030 } 1052 1031 for (int i = 1; i <= trackElemCount;i++) … … 1102 1081 { 1103 1082 if (this->currentTrackElem->jumpTime != 0.0) 1104 1083 this->jumpTo(this->localTime + this->currentTrackElem->jumpTime); 1105 1084 // jump to the next TrackElement and also set the history of the new Element to the old one. 1106 1085 TrackElement* tmpHistoryElem = this->currentTrackElem; … … 1108 1087 this->currentTrackElem->history = tmpHistoryElem; 1109 1088 if (this->currentTrackElem->getName()) 1110 1111 1112 1113 1089 { 1090 this->trackText->setText(this->currentTrackElem->getName()); 1091 this->textAnimation->replay(); 1092 } 1114 1093 } 1115 1094 if (this->bindSlave) 1116 1095 { 1117 1096 Vector tmp = this->calcPos(); 1118 Quaternion quat = Quaternion(this->calcDir(), Vector(this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).x,1,this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).z)); 1097 Quaternion quat = Quaternion(this->calcDir(), Vector(this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).x,1,this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).z)); 1119 1098 1120 1099 Vector v(0.0, 1.0, 0.0); … … 1140 1119 this->currentTrackElem = this->firstTrackElem; 1141 1120 if (this->currentTrackElem->getName()) 1142 1143 1144 1145 1121 { 1122 this->trackText->setText(this->currentTrackElem->getName()); 1123 this->textAnimation->play(); 1124 } 1146 1125 } 1147 1126 this->localTime = time; … … 1151 1130 \brief a Function that decides which Path we should follow. 1152 1131 \param trackElem The Path to choose. 1153 1132 1154 1133 */ 1155 1134 int TrackManager::choosePath(TrackElement* trackElem) … … 1191 1170 TrackElement* tmpElem = this->firstTrackElem->findByID(i); 1192 1171 if (tmpElem->curve) 1193 1194 1195 1196 1197 1198 1172 for(float f = 0.0; f < 1.0; f+=dt) 1173 { 1174 // printf("%f, %f, %f\n",trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z); 1175 Vector tmpVector = tmpElem->curve->calcPos(f); 1176 glVertex3f(tmpVector.x, tmpVector.y, tmpVector.z); 1177 } 1199 1178 glEnd(); 1200 1179 } … … 1216 1195 { 1217 1196 for (int i = 1; i <= trackElemCount; i++) 1218 1219 1220 1221 1197 { 1198 TrackElement* tmpElem = this->firstTrackElem->findByID(i); 1199 tmpElem->debug(); 1200 } 1222 1201 } 1223 1202 PRINT(0)("-----------------------------------------\n"); -
orxonox/trunk/src/util/track/track_manager.h
r4509 r4584 1 /*! 1 /*! 2 2 \file track_manager.h 3 3 \brief manages all tracks defined in the world and the path the player takes … … 40 40 It is a graph and not a tree, because paths can fork and join again. 41 41 */ 42 class TrackElement 42 class TrackElement : public BaseObject 43 43 { 44 44 public: … … 51 51 52 52 TrackElement* getChild(int childNumber) const; 53 void setName(const char* name);54 /** \returns the Name of this TrackElement */55 inline const char* getName(void) const { return this->name; };56 53 57 54 private: … … 95 92 // todo int enemyKilled(void* entity); 96 93 97 private:98 char* name; //!< A name for the Trac.99 100 94 }; 101 95 … … 128 122 \li tick(): makes a Step on the Path. increases localTime by dt. 129 123 \li choosePath(): a Function that decides which Path we should follow. 130 124 131 125 TrackManager can be handled as a StateMachine. 132 126 \n\n 133 Names: 127 Names: 134 128 \li TrackManager: handles Tracks 135 129 \li Track: The Track that the ship can follow
Note: See TracChangeset
for help on using the changeset viewer.