| 1 | /*! | 
|---|
| 2 | \file track_manager.h | 
|---|
| 3 | \brief manages all tracks defined in the world and the path the player takes | 
|---|
| 4 |  | 
|---|
| 5 | it is a container for all tracks and all track-nodes. it manages the movement of | 
|---|
| 6 | the track helper-parent (that drives the player). it is responsable for calculating | 
|---|
| 7 | smooth curves etc. | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 |  | 
|---|
| 11 | #ifndef _TRACK_MANAGER_H | 
|---|
| 12 | #define _TRACK_MANAGER_H | 
|---|
| 13 |  | 
|---|
| 14 | #include "stdincl.h" | 
|---|
| 15 | #include "curve.h" | 
|---|
| 16 |  | 
|---|
| 17 | class PNode; | 
|---|
| 18 |  | 
|---|
| 19 | //! A Graph-Element, that holds the curve-structure of a Level. | 
|---|
| 20 | /** | 
|---|
| 21 | A TrackElement is used, to define the structure of the Track itself. | 
|---|
| 22 | It is a graph and not a tree, because paths can fork and join again. | 
|---|
| 23 | */ | 
|---|
| 24 | class TrackElement | 
|---|
| 25 | { | 
|---|
| 26 | public: | 
|---|
| 27 | TrackElement(void); | 
|---|
| 28 | ~TrackElement(void); | 
|---|
| 29 |  | 
|---|
| 30 | TrackElement* findByID(unsigned int trackID); | 
|---|
| 31 | bool backLoopCheck(TrackElement* trackElem); | 
|---|
| 32 |  | 
|---|
| 33 | bool isFresh;              //!< If no Points where added until now | 
|---|
| 34 | bool isHotPoint;           //!< If the first node is a specialPoint; | 
|---|
| 35 | bool isSavePoint;          //!< If the first node is a savePoint | 
|---|
| 36 | bool isFork;               //!< If the first node is a Fork | 
|---|
| 37 | bool isJoined;             //!< If the End of the Curve is joined. | 
|---|
| 38 | bool mainJoin;             //!< If the End of the Curve is joined, and this is the one Curve the others join to. | 
|---|
| 39 | int ID;                    //!< The ID of this TrackElement | 
|---|
| 40 | float startingTime;        //!< The time at which this Track begins. | 
|---|
| 41 | float duration;            //!< The time used to cross this TrackElement (curve). | 
|---|
| 42 | float endTime;             //!< The time at which this Track ends. | 
|---|
| 43 | float jumpTime;            //!< The Time this Track has to jump to its preceding Track (only >0 if Track isJoined==true) | 
|---|
| 44 | CurveType curveType;       //!< The CurveType this will have. | 
|---|
| 45 | int nodeCount;             //!< The count of points this TrackElement has. | 
|---|
| 46 | char* name;                //!< A name for the Trac. | 
|---|
| 47 | Curve* curve;              //!< The Curve of this TrackElement | 
|---|
| 48 | int childCount;            //!< The number of Children This TrackElement has. | 
|---|
| 49 | TrackElement** children;   //!< A TrackElement can have a Tree of following TrackElements. | 
|---|
| 50 |  | 
|---|
| 51 | // runtime | 
|---|
| 52 | TrackElement* history;     //!< a pointer to the last TrackElement we were on. This is if you want to walk the path backwards again. | 
|---|
| 53 |  | 
|---|
| 54 | // CONDITION FUNCTIONS and STUFF | 
|---|
| 55 | void* subject;             //!< The Subject the Condition should act upon. | 
|---|
| 56 | int (TrackElement::*condFunc)(void*); //!< Pointer to the condition function | 
|---|
| 57 |  | 
|---|
| 58 | int lowest(void* nothing); | 
|---|
| 59 | int highest(void* nothing); | 
|---|
| 60 | int random(void* nothing); | 
|---|
| 61 |  | 
|---|
| 62 | int leftRight(void* node); | 
|---|
| 63 | int nearest(void* node); | 
|---|
| 64 | // todo  int enemyKilled(void* entity); | 
|---|
| 65 | }; | 
|---|
| 66 |  | 
|---|
| 67 | //! the Condition to choose between the different ways of the game. | 
|---|
| 68 | enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED}; | 
|---|
| 69 |  | 
|---|
| 70 | //! The TrackManager handles the flow of the Players through the game. | 
|---|
| 71 | /** | 
|---|
| 72 |  | 
|---|
| 73 | <b>The TrackManager works as followed:</b> \n | 
|---|
| 74 | \n | 
|---|
| 75 | <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b> | 
|---|
| 76 | \li workOn(): changes the ID that will be altered through the changes. | 
|---|
| 77 | \li setCurveType(): lets you set the CurveType of the Curve we are Working on. (default is BezierCurve, set this as early as possible, for this uses resources). | 
|---|
| 78 | \li setDuration(): sets the length of the current path in seconds. | 
|---|
| 79 | \li addPoint(): adds a point to the Curve. | 
|---|
| 80 | \li addHotPoint(): adds save/splitpoint.\n | 
|---|
| 81 | \li fork(): adds some interessting non-linear movments through the level (fork will force addHotPoint if not done then). | 
|---|
| 82 | \li condition(): decides under what condition a certain Path will be chosen. | 
|---|
| 83 | \li join(): joins some tracks together again. Join will set the localTime to the longest time a Path has to get to this Point) | 
|---|
| 84 | \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot. | 
|---|
| 85 |  | 
|---|
| 86 | HotPoints and Joins are at the beginning of a TrackElement. \n | 
|---|
| 87 | SavePoints and Forks are at the end of a TrackElement \n | 
|---|
| 88 | look out: <b>SAVEPOINTS CAN NOT BE FORKS</b> (but joins), because the condition is really hard to guess if you do not give some impuls. \n | 
|---|
| 89 | \n | 
|---|
| 90 | <b> 2. Runtime knows the following: </b> | 
|---|
| 91 | \li calcPos(): returns the current position on the track | 
|---|
| 92 | \li calcDir(): returns the current Direction the track is flying on. | 
|---|
| 93 | \li tick(): makes a Step on the Path. increases localTime by dt. | 
|---|
| 94 | \li choosePath(): a Function that decides which Path we should follow. | 
|---|
| 95 |  | 
|---|
| 96 | TrackManager can be handled as a StateMachine. | 
|---|
| 97 | \n\n | 
|---|
| 98 | Names: | 
|---|
| 99 | \li TrackManager: handles Tracks | 
|---|
| 100 | \li Track:        The Track that the ship can follow | 
|---|
| 101 | \li Path:         one way through the Level, that is dependent on conditionals. | 
|---|
| 102 | \li Conditional:  A decition making device, that chooses betwen different TrackElements for the Path. | 
|---|
| 103 | \li TrackElement: A Part of A whole Track | 
|---|
| 104 | */ | 
|---|
| 105 | class TrackManager : public BaseObject | 
|---|
| 106 | { | 
|---|
| 107 | private: | 
|---|
| 108 | TrackManager(void); | 
|---|
| 109 |  | 
|---|
| 110 | static TrackManager* singletonRef;  //!< There may only be one TrackManager existing. | 
|---|
| 111 | TrackElement* firstTrackElem;       //!< The first TrackElement that exists. | 
|---|
| 112 | TrackElement* currentTrackElem;     //!< The TrackElement we are working on. | 
|---|
| 113 | float localTime;                    //!< The time that has been passed since the traveling the Track. | 
|---|
| 114 | float maxTime;                      //!< The maximal time the track has. | 
|---|
| 115 | int trackElemCount;                 //!< The count of TrackElements that exist. | 
|---|
| 116 | PNode* bindSlave;                   //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself. | 
|---|
| 117 | PNode* trackNode;                   //!< The main TrackNode of this Track. | 
|---|
| 118 |  | 
|---|
| 119 | void initChildren(unsigned int childCount); | 
|---|
| 120 |  | 
|---|
| 121 | TrackElement* findTrackElementByID(unsigned int trackID) const; | 
|---|
| 122 |  | 
|---|
| 123 | public: | 
|---|
| 124 | virtual ~TrackManager(void); | 
|---|
| 125 |  | 
|---|
| 126 | static TrackManager* getInstance(void); | 
|---|
| 127 |  | 
|---|
| 128 | // Methods to change the Path (initialisation) | 
|---|
| 129 | void workOn(unsigned int trackID); | 
|---|
| 130 | /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */ | 
|---|
| 131 | inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}; | 
|---|
| 132 | void setCurveType(CurveType curveType, TrackElement* trackElem); | 
|---|
| 133 | void setDuration(float time); | 
|---|
| 134 | bool addPoint(Vector newPoint); | 
|---|
| 135 | bool addPoint(Vector newPoint, TrackElement* trackElem); | 
|---|
| 136 | int addHotPoint(Vector newPoint); | 
|---|
| 137 | int setSavePoint(void); | 
|---|
| 138 | void fork(unsigned int count, ...); | 
|---|
| 139 | void forkV(unsigned int count, int* trackIDs); | 
|---|
| 140 | void condition(CONDITION cond, void* subject); | 
|---|
| 141 | void condition(unsigned int groupID, CONDITION cond, void* subject); | 
|---|
| 142 | void join(unsigned int count, ...); | 
|---|
| 143 | void joinV(unsigned int count, int* trackIDs); | 
|---|
| 144 | void finalize(void); | 
|---|
| 145 |  | 
|---|
| 146 | // Methods to calculate the position on the Path (runtime) | 
|---|
| 147 | inline Vector calcPos(void) const; | 
|---|
| 148 | inline Vector calcDir(void) const; | 
|---|
| 149 | void tick(float dt); | 
|---|
| 150 | void jumpTo(float time); | 
|---|
| 151 | inline int choosePath(TrackElement* trackElem); | 
|---|
| 152 |  | 
|---|
| 153 | void setBindSlave(PNode* bindSlave); | 
|---|
| 154 | PNode* getTrackNode(void); | 
|---|
| 155 |  | 
|---|
| 156 | // DEBUG // | 
|---|
| 157 | void drawGraph(float dt) const; | 
|---|
| 158 | void debug(unsigned int level) const; | 
|---|
| 159 | }; | 
|---|
| 160 |  | 
|---|
| 161 | #endif /* _TRACK_MANAGER_H */ | 
|---|