[3311] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: ... |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | #include "track_manager.h" |
---|
[3332] | 20 | #include <stdarg.h> |
---|
[3311] | 21 | |
---|
| 22 | |
---|
| 23 | using namespace std; |
---|
| 24 | |
---|
[3331] | 25 | /** |
---|
| 26 | \brief initializes a TrackElement (sets the default values) |
---|
| 27 | */ |
---|
| 28 | TrackElement::TrackElement(void) |
---|
| 29 | { |
---|
[3332] | 30 | this->isFresh = true; |
---|
[3331] | 31 | this->isSavePoint = false; |
---|
| 32 | this->isFork = false; |
---|
| 33 | this->isJoined = false; |
---|
| 34 | this->cond; //!< todo think!! |
---|
| 35 | this->ID = -1; |
---|
| 36 | this->length =0; |
---|
| 37 | this->curveType = BEZIERCURVE; |
---|
| 38 | this->nodeCount = 0; |
---|
| 39 | childCount = 0; |
---|
[3332] | 40 | this->name = NULL; |
---|
[3331] | 41 | this->curve = NULL; |
---|
| 42 | this->children = NULL; |
---|
| 43 | } |
---|
[3311] | 44 | |
---|
[3331] | 45 | /** |
---|
[3332] | 46 | \brief destroys all alocated memory) |
---|
[3331] | 47 | \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements |
---|
| 48 | */ |
---|
| 49 | TrackElement::~TrackElement(void) |
---|
| 50 | { |
---|
[3332] | 51 | if (this->name) |
---|
| 52 | delete []name; |
---|
[3331] | 53 | if (this->curve) |
---|
| 54 | delete this->curve; |
---|
| 55 | if (this->childCount > 0) |
---|
| 56 | { |
---|
| 57 | for (int i=0; i < this->childCount; i++) |
---|
| 58 | delete this->children[i]; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
[3332] | 62 | /** |
---|
| 63 | \brief Searches through all the TrackElements for trackID. |
---|
| 64 | \param trackID The ID to search for. |
---|
| 65 | \returns The TrackElement if Found, NULL otherwise. |
---|
| 66 | |
---|
| 67 | \todo make this more modular, to search for different things |
---|
| 68 | */ |
---|
| 69 | TrackElement* TrackElement::findByID(unsigned int trackID) |
---|
| 70 | { |
---|
| 71 | // return if Found. |
---|
| 72 | if (this->ID == trackID) |
---|
| 73 | return this; |
---|
| 74 | // search on. |
---|
| 75 | if (this->childCount > 0) |
---|
| 76 | for (int i=0; i < this->childCount; i++) |
---|
| 77 | { |
---|
| 78 | TrackElement* tmpElem; |
---|
| 79 | if ((tmpElem = this->children[i]->findByID(trackID))) |
---|
| 80 | return tmpElem; |
---|
| 81 | } |
---|
| 82 | else return NULL; |
---|
| 83 | } |
---|
[3331] | 84 | |
---|
| 85 | |
---|
| 86 | |
---|
[3332] | 87 | |
---|
| 88 | |
---|
| 89 | ///////////////////////////////////// |
---|
| 90 | ///// TRACKMANAGER ////////////////// |
---|
| 91 | ///////////////////////////////////// |
---|
[3311] | 92 | /** |
---|
| 93 | \brief standard constructor |
---|
| 94 | |
---|
| 95 | \todo this constructor is not jet implemented - do it |
---|
| 96 | */ |
---|
| 97 | TrackManager::TrackManager () |
---|
| 98 | { |
---|
[3331] | 99 | this->setClassName ("TrackManager"); |
---|
| 100 | |
---|
| 101 | PRINTF(3)("Initializing the TrackManager\n"); |
---|
| 102 | this->firstTrackElem = NULL; |
---|
| 103 | this->currentTrackElem = firstTrackElem; |
---|
| 104 | this->localTime = 0; |
---|
| 105 | this->maxTime = 0; |
---|
| 106 | this->trackElemCount = 0; |
---|
[3311] | 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | /** |
---|
[3331] | 111 | \brief standard destructor |
---|
[3311] | 112 | |
---|
| 113 | \todo this deconstructor is not jet implemented - do it |
---|
| 114 | */ |
---|
[3330] | 115 | TrackManager::~TrackManager () |
---|
| 116 | { |
---|
[3331] | 117 | PRINTF(3)("Destruct TrackManager\n"); |
---|
[3311] | 118 | |
---|
[3331] | 119 | PRINTF(3)("Deleting all the TrackElements\n"); |
---|
| 120 | delete this->firstTrackElem; |
---|
| 121 | // we do not have a TrackManager anymore |
---|
| 122 | singletonRef = NULL; |
---|
[3330] | 123 | } |
---|
| 124 | |
---|
[3331] | 125 | TrackManager* TrackManager::singletonRef = NULL; |
---|
| 126 | |
---|
[3330] | 127 | /** |
---|
[3331] | 128 | \returns The reference on the TrackManager. |
---|
| 129 | |
---|
| 130 | If the TrackManager does not exist, it will be created. |
---|
| 131 | */ |
---|
| 132 | TrackManager* TrackManager::getInstance(void) |
---|
| 133 | { |
---|
| 134 | if (singletonRef) |
---|
| 135 | return singletonRef; |
---|
| 136 | else |
---|
| 137 | return singletonRef = new TrackManager(); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /** |
---|
[3330] | 141 | \brief Searches for a given trackID. |
---|
| 142 | \param trackID the trackID to search for. |
---|
[3332] | 143 | \returns The TrackElement #trackID if found, NULL otherwise. |
---|
[3330] | 144 | */ |
---|
[3332] | 145 | TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const |
---|
[3330] | 146 | { |
---|
[3332] | 147 | return firstTrackElem->findByID(trackID); |
---|
[3330] | 148 | } |
---|
| 149 | |
---|
| 150 | // INITIALIZE // |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | \brief Sets the trackID we are working on. |
---|
| 154 | \param trackID the trackID we are working on |
---|
| 155 | */ |
---|
[3332] | 156 | void TrackManager::workOn(unsigned int trackID) |
---|
[3330] | 157 | { |
---|
[3332] | 158 | this->currentTrackElem = findTrackElementByID(trackID); |
---|
[3330] | 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | \brief Sets the Type of the Curve |
---|
| 163 | \brief curveType The Type to set |
---|
| 164 | */ |
---|
[3332] | 165 | void TrackManager::setCurveType(CurveType curveType) |
---|
[3330] | 166 | { |
---|
[3332] | 167 | if (!this->currentTrackElem->isFresh) |
---|
| 168 | { |
---|
| 169 | PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n"); |
---|
| 170 | return; |
---|
| 171 | } |
---|
| 172 | this->currentTrackElem->curveType = curveType; |
---|
| 173 | switch (curveType) |
---|
| 174 | { |
---|
| 175 | case BEZIERCURVE: |
---|
| 176 | this->currentTrackElem->curve = new BezierCurve(); |
---|
| 177 | break; |
---|
| 178 | case UPOINTCURVE: |
---|
| 179 | this->currentTrackElem->curve = new UPointCurve(); |
---|
| 180 | break; |
---|
| 181 | } |
---|
[3330] | 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
| 185 | \brief Sets the length of the current path in seconds. |
---|
| 186 | \param time The length in seconds. |
---|
| 187 | */ |
---|
| 188 | |
---|
| 189 | void TrackManager::setLength(float time) |
---|
| 190 | { |
---|
[3332] | 191 | this->currentTrackElem->length = time; |
---|
[3330] | 192 | } |
---|
| 193 | |
---|
| 194 | /** |
---|
| 195 | \brief adds a point to the current TrackElement |
---|
| 196 | \param newPoint The point to add. |
---|
| 197 | */ |
---|
| 198 | void TrackManager::addPoint(Vector newPoint) |
---|
| 199 | { |
---|
[3332] | 200 | if (this->currentTrackElem->isFresh) |
---|
| 201 | { |
---|
| 202 | this->setCurveType(BEZIERCURVE); |
---|
| 203 | this->currentTrackElem->isFresh = false; |
---|
| 204 | } |
---|
| 205 | this->currentTrackElem->curve->addNode(newPoint); |
---|
[3330] | 206 | } |
---|
| 207 | |
---|
| 208 | /** |
---|
| 209 | \brief adds save/splitpoint. |
---|
| 210 | \param newPoint The point to add. |
---|
| 211 | */ |
---|
| 212 | void TrackManager::addHotPoint(Vector newPoint) |
---|
| 213 | { |
---|
[3332] | 214 | if (this->currentTrackElem->isFresh) |
---|
| 215 | { |
---|
| 216 | this->setCurveType(BEZIERCURVE); |
---|
| 217 | this->currentTrackElem->isFresh = false; |
---|
| 218 | } |
---|
[3330] | 219 | |
---|
[3332] | 220 | // \todo HotPoint Handling. |
---|
| 221 | this->currentTrackElem->curve->addNode(newPoint); |
---|
[3330] | 222 | } |
---|
| 223 | |
---|
| 224 | /** |
---|
| 225 | \brief Sets the last HotPoint into a savePoint. |
---|
| 226 | |
---|
| 227 | If no HotPoint was defined the last added Point will be rendered into a savePoint. \n |
---|
| 228 | If the HotPoint was defined as a fork the Point will \b not be set into a savePoint. |
---|
| 229 | */ |
---|
| 230 | void TrackManager::setSavePoint(void) |
---|
| 231 | { |
---|
[3332] | 232 | if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint) |
---|
| 233 | return; |
---|
| 234 | this->currentTrackElem->isSavePoint = true; |
---|
| 235 | |
---|
| 236 | this->currentTrackElem->children = new TrackElement*[1]; |
---|
[3330] | 237 | } |
---|
| 238 | |
---|
| 239 | /** |
---|
| 240 | \brief adds some interessting non-linear movments through the level. |
---|
| 241 | \param count The Count of childrens the current HotPoint will have. |
---|
| 242 | |
---|
| 243 | If no HotPoint was defined the last added Point will be rendered into a fork. \n |
---|
| 244 | If the HotPoint was defined as a savePoint the Point will \b not be set into a fork. |
---|
| 245 | */ |
---|
[3332] | 246 | void TrackManager::fork(unsigned int count, ...) |
---|
[3330] | 247 | { |
---|
[3332] | 248 | int* trackIDs = new int [count]; |
---|
| 249 | va_list ID; |
---|
| 250 | va_start (ID, count); |
---|
| 251 | for(int i = 0; i < count; i++) |
---|
| 252 | { |
---|
| 253 | trackIDs[i] = va_arg (ID, int); |
---|
| 254 | } |
---|
| 255 | va_end(ID); |
---|
| 256 | this->forkV(count, trackIDs); |
---|
| 257 | delete []trackIDs; |
---|
[3330] | 258 | } |
---|
| 259 | |
---|
| 260 | /** |
---|
| 261 | \brief adds some interessting non-linear movments through the level. |
---|
| 262 | \param count The Count of childrens the current HotPoint will have. |
---|
| 263 | \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this). |
---|
| 264 | |
---|
| 265 | \see void TrackManager::fork(int count, ...) |
---|
[3332] | 266 | |
---|
| 267 | \todo initialisation is wrong!! also in setSavePoint. |
---|
[3330] | 268 | */ |
---|
[3332] | 269 | void TrackManager::forkV(unsigned int count, int* trackIDs) |
---|
[3330] | 270 | { |
---|
[3332] | 271 | if (this->currentTrackElem->isSavePoint) |
---|
| 272 | return; |
---|
| 273 | this->currentTrackElem->isFork = true; |
---|
[3330] | 274 | |
---|
[3332] | 275 | this->currentTrackElem->children = new TrackElement*[count]; |
---|
[3330] | 276 | } |
---|
| 277 | |
---|
| 278 | /** |
---|
| 279 | \brief decides under what condition a certain Path will be chosen. |
---|
| 280 | \param groupID the ID on which to choose the preceding move |
---|
| 281 | \param cond \todo think about this |
---|
| 282 | */ |
---|
[3332] | 283 | void TrackManager::condition(unsigned int groupID, PathCondition cond) |
---|
[3330] | 284 | { |
---|
[3332] | 285 | |
---|
[3330] | 286 | } |
---|
| 287 | |
---|
| 288 | /** |
---|
| 289 | \brief joins some tracks together again. |
---|
| 290 | \param count The count of Paths to join. |
---|
| 291 | |
---|
| 292 | Join will set the localTime to the longest time a Path has to get to this Point. \n |
---|
| 293 | Join will join all curves to the first curve. |
---|
| 294 | */ |
---|
[3332] | 295 | void TrackManager::join(unsigned int count, ...) |
---|
[3330] | 296 | { |
---|
[3332] | 297 | int* trackIDs = new int [count]; |
---|
| 298 | va_list ID; |
---|
| 299 | va_start (ID, count); |
---|
| 300 | for(int i = 0; i < count; i++) |
---|
| 301 | { |
---|
| 302 | trackIDs[i] = va_arg (ID, int); |
---|
| 303 | } |
---|
| 304 | va_end(ID); |
---|
| 305 | this->joinV(count, trackIDs); |
---|
| 306 | delete []trackIDs; |
---|
[3330] | 307 | } |
---|
| 308 | |
---|
| 309 | /** |
---|
| 310 | \brief joins some tracks together again. |
---|
| 311 | \param count The count of Paths to join. |
---|
| 312 | \param trackIDs an Array with the trackID's to join |
---|
| 313 | |
---|
| 314 | \see void TrackManager::join(int count, ...) |
---|
| 315 | */ |
---|
[3332] | 316 | void TrackManager::joinV(unsigned int count, int* trackIDs) |
---|
[3330] | 317 | { |
---|
[3332] | 318 | //! \todo this |
---|
[3330] | 319 | } |
---|
| 320 | |
---|
| 321 | // RUNTIME // |
---|
| 322 | |
---|
| 323 | /** |
---|
| 324 | \brief calculates the Position for the localTime of the Track. |
---|
| 325 | \returns the calculated Position |
---|
| 326 | */ |
---|
[3332] | 327 | Vector TrackManager::calcPos() const |
---|
[3330] | 328 | { |
---|
[3332] | 329 | |
---|
[3330] | 330 | } |
---|
| 331 | |
---|
| 332 | /** |
---|
| 333 | \brief calculates the Rotation for the localTime of the Track. |
---|
| 334 | \returns the calculated Rotation |
---|
| 335 | */ |
---|
[3332] | 336 | Vector TrackManager::calcDir() const |
---|
[3330] | 337 | { |
---|
| 338 | |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | /** |
---|
| 342 | \brief Advances the local-time of the Track around dt |
---|
| 343 | \param dt The time about which to advance. |
---|
| 344 | */ |
---|
| 345 | void TrackManager::tick(float dt) |
---|
| 346 | { |
---|
[3332] | 347 | this->localTime += dt; |
---|
[3330] | 348 | } |
---|
| 349 | |
---|
| 350 | /** |
---|
[3331] | 351 | \brief Jumps to a certain point on the Track. |
---|
| 352 | \param time The time on the Track to jump to. |
---|
| 353 | |
---|
| 354 | This should be used to Jump backwards on a Track, because moving forward means to change between the Path. (it then tries to choose the default.) |
---|
| 355 | Max is trackLengthMax. |
---|
| 356 | */ |
---|
| 357 | void TrackManager::jumpTo(float time) |
---|
| 358 | { |
---|
[3332] | 359 | localTime = time; |
---|
[3331] | 360 | } |
---|
| 361 | |
---|
| 362 | /** |
---|
[3330] | 363 | \brief a Function that decides which Path we should follow. |
---|
| 364 | \param graphID The Path to choose. |
---|
| 365 | |
---|
| 366 | */ |
---|
| 367 | void TrackManager::choosePath(int graphID) |
---|
| 368 | { |
---|
| 369 | |
---|
| 370 | } |
---|
| 371 | |
---|