/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: ... */ #include "track_manager.h" #include using namespace std; /** \brief initializes a TrackElement (sets the default values) */ TrackElement::TrackElement(void) { this->isFresh = true; this->isSavePoint = false; this->isFork = false; this->isJoined = false; this->cond; //!< todo think!! this->ID = -1; this->length =0; this->curveType = BEZIERCURVE; this->nodeCount = 0; childCount = 0; this->name = NULL; this->curve = NULL; this->children = NULL; } /** \brief destroys all alocated memory) \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements */ TrackElement::~TrackElement(void) { if (this->name) delete []name; if (this->curve) delete this->curve; if (this->childCount > 0) { for (int i=0; i < this->childCount; i++) delete this->children[i]; } } /** \brief Searches through all the TrackElements for trackID. \param trackID The ID to search for. \returns The TrackElement if Found, NULL otherwise. \todo make this more modular, to search for different things */ TrackElement* TrackElement::findByID(unsigned int trackID) { // return if Found. if (this->ID == trackID) return this; // search on. if (this->childCount > 0) for (int i=0; i < this->childCount; i++) { TrackElement* tmpElem; if ((tmpElem = this->children[i]->findByID(trackID))) return tmpElem; } else return NULL; } ///////////////////////////////////// ///// TRACKMANAGER ////////////////// ///////////////////////////////////// /** \brief standard constructor \todo this constructor is not jet implemented - do it */ TrackManager::TrackManager () { this->setClassName ("TrackManager"); PRINTF(3)("Initializing the TrackManager\n"); this->firstTrackElem = NULL; this->currentTrackElem = firstTrackElem; this->localTime = 0; this->maxTime = 0; this->trackElemCount = 0; } /** \brief standard destructor \todo this deconstructor is not jet implemented - do it */ TrackManager::~TrackManager () { PRINTF(3)("Destruct TrackManager\n"); PRINTF(3)("Deleting all the TrackElements\n"); delete this->firstTrackElem; // we do not have a TrackManager anymore singletonRef = NULL; } TrackManager* TrackManager::singletonRef = NULL; /** \returns The reference on the TrackManager. If the TrackManager does not exist, it will be created. */ TrackManager* TrackManager::getInstance(void) { if (singletonRef) return singletonRef; else return singletonRef = new TrackManager(); } /** \brief Searches for a given trackID. \param trackID the trackID to search for. \returns The TrackElement #trackID if found, NULL otherwise. */ TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const { return firstTrackElem->findByID(trackID); } // INITIALIZE // /** \brief Sets the trackID we are working on. \param trackID the trackID we are working on */ void TrackManager::workOn(unsigned int trackID) { this->currentTrackElem = findTrackElementByID(trackID); } /** \brief Sets the Type of the Curve \brief curveType The Type to set */ void TrackManager::setCurveType(CurveType curveType) { if (!this->currentTrackElem->isFresh) { PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n"); return; } this->currentTrackElem->curveType = curveType; switch (curveType) { case BEZIERCURVE: this->currentTrackElem->curve = new BezierCurve(); break; case UPOINTCURVE: this->currentTrackElem->curve = new UPointCurve(); break; } } /** \brief Sets the length of the current path in seconds. \param time The length in seconds. */ void TrackManager::setLength(float time) { this->currentTrackElem->length = time; } /** \brief adds a point to the current TrackElement \param newPoint The point to add. */ void TrackManager::addPoint(Vector newPoint) { if (this->currentTrackElem->isFresh) { this->setCurveType(BEZIERCURVE); this->currentTrackElem->isFresh = false; } this->currentTrackElem->curve->addNode(newPoint); } /** \brief adds save/splitpoint. \param newPoint The point to add. */ void TrackManager::addHotPoint(Vector newPoint) { if (this->currentTrackElem->isFresh) { this->setCurveType(BEZIERCURVE); this->currentTrackElem->isFresh = false; } // \todo HotPoint Handling. this->currentTrackElem->curve->addNode(newPoint); } /** \brief Sets the last HotPoint into a savePoint. If no HotPoint was defined the last added Point will be rendered into a savePoint. \n If the HotPoint was defined as a fork the Point will \b not be set into a savePoint. */ void TrackManager::setSavePoint(void) { if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint) return; this->currentTrackElem->isSavePoint = true; this->currentTrackElem->children = new TrackElement*[1]; } /** \brief adds some interessting non-linear movments through the level. \param count The Count of childrens the current HotPoint will have. If no HotPoint was defined the last added Point will be rendered into a fork. \n If the HotPoint was defined as a savePoint the Point will \b not be set into a fork. */ void TrackManager::fork(unsigned int count, ...) { int* trackIDs = new int [count]; va_list ID; va_start (ID, count); for(int i = 0; i < count; i++) { trackIDs[i] = va_arg (ID, int); } va_end(ID); this->forkV(count, trackIDs); delete []trackIDs; } /** \brief adds some interessting non-linear movments through the level. \param count The Count of childrens the current HotPoint will have. \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this). \see void TrackManager::fork(int count, ...) \todo initialisation is wrong!! also in setSavePoint. */ void TrackManager::forkV(unsigned int count, int* trackIDs) { if (this->currentTrackElem->isSavePoint) return; this->currentTrackElem->isFork = true; this->currentTrackElem->children = new TrackElement*[count]; } /** \brief decides under what condition a certain Path will be chosen. \param groupID the ID on which to choose the preceding move \param cond \todo think about this */ void TrackManager::condition(unsigned int groupID, PathCondition cond) { } /** \brief joins some tracks together again. \param count The count of Paths to join. Join will set the localTime to the longest time a Path has to get to this Point. \n Join will join all curves to the first curve. */ void TrackManager::join(unsigned int count, ...) { int* trackIDs = new int [count]; va_list ID; va_start (ID, count); for(int i = 0; i < count; i++) { trackIDs[i] = va_arg (ID, int); } va_end(ID); this->joinV(count, trackIDs); delete []trackIDs; } /** \brief joins some tracks together again. \param count The count of Paths to join. \param trackIDs an Array with the trackID's to join \see void TrackManager::join(int count, ...) */ void TrackManager::joinV(unsigned int count, int* trackIDs) { //! \todo this } // RUNTIME // /** \brief calculates the Position for the localTime of the Track. \returns the calculated Position */ Vector TrackManager::calcPos() const { } /** \brief calculates the Rotation for the localTime of the Track. \returns the calculated Rotation */ Vector TrackManager::calcDir() const { } /** \brief Advances the local-time of the Track around dt \param dt The time about which to advance. */ void TrackManager::tick(float dt) { this->localTime += dt; } /** \brief Jumps to a certain point on the Track. \param time The time on the Track to jump to. 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.) Max is trackLengthMax. */ void TrackManager::jumpTo(float time) { localTime = time; } /** \brief a Function that decides which Path we should follow. \param graphID The Path to choose. */ void TrackManager::choosePath(int graphID) { }