Changeset 3835 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Apr 15, 2005, 4:59:42 PM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/track_manager.cc
r3832 r3835 48 48 this->width = TMAN_DEFAULT_WIDTH; 49 49 this->nodeCount = 0; 50 this->curve = NULL; 50 51 this->childCount = 0; 52 this->children = NULL; 51 53 this->name = NULL; 52 this->curve = NULL;53 this->children = NULL;54 54 55 55 this->history = NULL; 56 56 57 this->subject = NULL; 57 58 this->condFunc = &TrackElement::random; 58 59 } … … 64 65 TrackElement::~TrackElement(void) 65 66 { 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. 71 75 { 72 76 tIterator<TrackElement>* iterator = this->children->getIterator(); … … 86 90 \param trackID The ID to search for. 87 91 \returns The TrackElement if Found, NULL otherwise. 88 89 \todo make this more modular, to search for different things90 92 */ 91 93 TrackElement* TrackElement::findByID(unsigned int trackID) … … 94 96 if (this->ID == trackID) 95 97 return this; 96 // search on.98 // search all children 97 99 if (this->childCount > 0) 98 100 { … … 108 110 delete iterator; 109 111 } 112 // if not found 110 113 else 111 114 return NULL; … … 114 117 115 118 /** 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 */ 123 TrackElement* 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) 125 130 { 126 131 tIterator<TrackElement>* iterator = this->children->getIterator(); 127 132 TrackElement* enumElem = iterator->nextElement(); 133 TrackElement* tmpElem; 128 134 while (enumElem) 129 135 { 130 if (!enumElem->backLoopCheck(trackElem))131 return false;136 if ((tmpElem = enumElem->findByName(trackName))) 137 return tmpElem; 132 138 enumElem = iterator->nextElement(); 133 139 } 134 140 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 */ 154 bool 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; 138 176 } 139 177 140 178 /** 141 179 \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 */ 183 TrackElement* TrackElement::getChild(int childCount) const 184 { 185 // if the the trackElement has no children return NULL. 146 186 if (this->childCount == 0) 147 187 return NULL; 188 // we cannot return the childCount+m's Child, so we return the last. 148 189 if (childCount > this->childCount) 149 190 childCount = this->childCount; 150 191 151 // TrackElement* enumElem = this->children->enumerate();152 192 tIterator<TrackElement>* iterator = this->children->getIterator(); 153 193 TrackElement* enumElem = iterator->nextElement(); … … 166 206 if (this->name) 167 207 delete []this->name; 168 // if a name was given already.208 // if a name was given. 169 209 if (name) 170 210 { … … 179 219 \returns The name of this TrackElement 180 220 */ 181 c har* TrackElement::getName(void) const221 const char* TrackElement::getName(void) const 182 222 { 183 223 return this->name; … … 187 227 \brief prints out debug information about this TrackElement 188 228 */ 189 void TrackElement::debug(void) 229 void TrackElement::debug(void) const 190 230 { 191 231 PRINT(0)("--== TrackElement:%i ==--", this->ID); … … 235 275 \returns the chosen child 236 276 */ 237 int TrackElement::lowest( void* nothing)277 int TrackElement::lowest(const void* nothing) const 238 278 { 239 279 return 0; … … 245 285 \returns the chosen child 246 286 */ 247 int TrackElement::highest( void* nothing)287 int TrackElement::highest(const void* nothing) const 248 288 { 249 289 return this->childCount-1; … … 255 295 \returns the chosen child 256 296 */ 257 int TrackElement::random( void* nothing)297 int TrackElement::random(const void* nothing) const 258 298 { 259 299 int i = (int)floor ((float)rand()/(float)RAND_MAX * (float)this->childCount); … … 270 310 \returns the chosen child 271 311 */ 272 int TrackElement::leftRight( void* node)312 int TrackElement::leftRight(const void* node) const 273 313 { 274 314 PNode* tmpNode = (PNode*)node; … … 291 331 (play with this!!). 292 332 */ 293 int TrackElement::nearest( void* node)333 int TrackElement::nearest(const void* node) const 294 334 { 295 335 PNode* tmpNode = (PNode*)node; -
orxonox/trunk/src/track_manager.h
r3608 r3835 37 37 38 38 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; 40 41 41 TrackElement* getChild(int childNumber) ;42 TrackElement* getChild(int childNumber) const; 42 43 void setName(const char* name); 43 c har* getName(void) const;44 const char* getName(void) const; 44 45 45 46 // atributes … … 65 66 TrackElement* history; //!< a pointer to the last TrackElement we were on. This is if you want to walk the path backwards again. 66 67 67 void debug(void) ;68 void debug(void) const; 68 69 69 70 // CONDITION FUNCTIONS and STUFF 70 71 void* subject; //!< The Subject the Condition should act upon. 71 int (TrackElement::*condFunc)( void*); //!< Pointer to the condition function72 int (TrackElement::*condFunc)(const void*) const; //!< Pointer to the condition function 72 73 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; 76 77 77 int leftRight( void* node);78 int nearest( void* node);78 int leftRight(const void* node) const; 79 int nearest(const void* node) const; 79 80 // todo int enemyKilled(void* entity); 80 81
Note: See TracChangeset
for help on using the changeset viewer.