[3311] | 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 | |
---|
[3495] | 14 | #include "curve.h" |
---|
[3608] | 15 | #include "base_object.h" |
---|
[3311] | 16 | |
---|
[3845] | 17 | // Forward Definition |
---|
[3433] | 18 | class PNode; |
---|
[3845] | 19 | class Text; |
---|
[3847] | 20 | template<class T> class tAnimation; |
---|
[3608] | 21 | template<class T> class tList; |
---|
[3311] | 22 | |
---|
[3588] | 23 | // Static Definitions |
---|
| 24 | |
---|
| 25 | //! The Default Curve-Type to set for the whole path (if not chosen otherwise). |
---|
[3836] | 26 | #define TMAN_DEFAULT_CURVETYPE CURVE_BEZIER |
---|
[3588] | 27 | #define TMAN_DEFAULT_DURATION 10 |
---|
[3596] | 28 | #define TMAN_DEFAULT_WIDTH 10 |
---|
[3588] | 29 | |
---|
[3331] | 30 | //! A Graph-Element, that holds the curve-structure of a Level. |
---|
| 31 | /** |
---|
| 32 | A TrackElement is used, to define the structure of the Track itself. |
---|
| 33 | It is a graph and not a tree, because paths can fork and join again. |
---|
| 34 | */ |
---|
| 35 | class TrackElement |
---|
| 36 | { |
---|
| 37 | public: |
---|
| 38 | TrackElement(void); |
---|
| 39 | ~TrackElement(void); |
---|
| 40 | |
---|
[3332] | 41 | TrackElement* findByID(unsigned int trackID); |
---|
[3835] | 42 | TrackElement* findByName(const char* trackName); |
---|
| 43 | bool backLoopCheck(const TrackElement* trackElem, unsigned int depth = 0) const; |
---|
[3332] | 44 | |
---|
[3835] | 45 | TrackElement* getChild(int childNumber) const; |
---|
[3594] | 46 | void setName(const char* name); |
---|
[3835] | 47 | const char* getName(void) const; |
---|
[3594] | 48 | |
---|
[3588] | 49 | // atributes |
---|
[3332] | 50 | bool isFresh; //!< If no Points where added until now |
---|
[3354] | 51 | bool isHotPoint; //!< If the first node is a specialPoint; |
---|
[3331] | 52 | bool isSavePoint; //!< If the first node is a savePoint |
---|
| 53 | bool isFork; //!< If the first node is a Fork |
---|
| 54 | bool isJoined; //!< If the End of the Curve is joined. |
---|
[3356] | 55 | bool mainJoin; //!< If the End of the Curve is joined, and this is the one Curve the others join to. |
---|
[3331] | 56 | int ID; //!< The ID of this TrackElement |
---|
[3333] | 57 | float startingTime; //!< The time at which this Track begins. |
---|
| 58 | float duration; //!< The time used to cross this TrackElement (curve). |
---|
[3433] | 59 | float endTime; //!< The time at which this Track ends. |
---|
| 60 | float jumpTime; //!< The Time this Track has to jump to its preceding Track (only >0 if Track isJoined==true) |
---|
[3596] | 61 | float width; //!< Th width of the Path. This tells the Player(s), how far he(they) can go to the left/right. |
---|
[3331] | 62 | int nodeCount; //!< The count of points this TrackElement has. |
---|
| 63 | Curve* curve; //!< The Curve of this TrackElement |
---|
| 64 | int childCount; //!< The number of Children This TrackElement has. |
---|
[3594] | 65 | tList<TrackElement>* children; //!< A TrackElement can have a Tree of following TrackElements. |
---|
[3522] | 66 | |
---|
[3588] | 67 | |
---|
[3527] | 68 | // runtime |
---|
| 69 | TrackElement* history; //!< a pointer to the last TrackElement we were on. This is if you want to walk the path backwards again. |
---|
| 70 | |
---|
[3835] | 71 | void debug(void) const; |
---|
[3593] | 72 | |
---|
[3522] | 73 | // CONDITION FUNCTIONS and STUFF |
---|
| 74 | void* subject; //!< The Subject the Condition should act upon. |
---|
[3835] | 75 | int (TrackElement::*condFunc)(const void*) const; //!< Pointer to the condition function |
---|
[3522] | 76 | |
---|
[3835] | 77 | int lowest(const void* nothing) const; |
---|
| 78 | int highest(const void* nothing) const; |
---|
| 79 | int random(const void* nothing) const; |
---|
[3522] | 80 | |
---|
[3835] | 81 | int leftRight(const void* node) const; |
---|
| 82 | int nearest(const void* node) const; |
---|
[3522] | 83 | // todo int enemyKilled(void* entity); |
---|
[3588] | 84 | |
---|
| 85 | private: |
---|
| 86 | char* name; //!< A name for the Trac. |
---|
| 87 | |
---|
[3331] | 88 | }; |
---|
| 89 | |
---|
[3522] | 90 | //! the Condition to choose between the different ways of the game. |
---|
| 91 | enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED}; |
---|
[3331] | 92 | |
---|
[3330] | 93 | //! The TrackManager handles the flow of the Players through the game. |
---|
| 94 | /** |
---|
| 95 | |
---|
| 96 | <b>The TrackManager works as followed:</b> \n |
---|
| 97 | \n |
---|
| 98 | <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b> |
---|
| 99 | \li workOn(): changes the ID that will be altered through the changes. |
---|
[3332] | 100 | \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). |
---|
[3333] | 101 | \li setDuration(): sets the length of the current path in seconds. |
---|
[3330] | 102 | \li addPoint(): adds a point to the Curve. |
---|
| 103 | \li addHotPoint(): adds save/splitpoint.\n |
---|
| 104 | \li fork(): adds some interessting non-linear movments through the level (fork will force addHotPoint if not done then). |
---|
| 105 | \li condition(): decides under what condition a certain Path will be chosen. |
---|
| 106 | \li join(): joins some tracks together again. Join will set the localTime to the longest time a Path has to get to this Point) |
---|
| 107 | \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot. |
---|
| 108 | |
---|
[3332] | 109 | HotPoints and Joins are at the beginning of a TrackElement. \n |
---|
| 110 | SavePoints and Forks are at the end of a TrackElement \n |
---|
[3330] | 111 | 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 |
---|
| 112 | \n |
---|
| 113 | <b> 2. Runtime knows the following: </b> |
---|
| 114 | \li calcPos(): returns the current position on the track |
---|
| 115 | \li calcDir(): returns the current Direction the track is flying on. |
---|
| 116 | \li tick(): makes a Step on the Path. increases localTime by dt. |
---|
| 117 | \li choosePath(): a Function that decides which Path we should follow. |
---|
| 118 | |
---|
| 119 | TrackManager can be handled as a StateMachine. |
---|
[3331] | 120 | \n\n |
---|
| 121 | Names: |
---|
| 122 | \li TrackManager: handles Tracks |
---|
| 123 | \li Track: The Track that the ship can follow |
---|
| 124 | \li Path: one way through the Level, that is dependent on conditionals. |
---|
| 125 | \li Conditional: A decition making device, that chooses betwen different TrackElements for the Path. |
---|
| 126 | \li TrackElement: A Part of A whole Track |
---|
[3330] | 127 | */ |
---|
[3331] | 128 | class TrackManager : public BaseObject |
---|
| 129 | { |
---|
[3330] | 130 | private: |
---|
[3331] | 131 | TrackManager(void); |
---|
| 132 | |
---|
[3588] | 133 | static TrackManager* singletonRef; //!< There may only be one TrackManager. |
---|
| 134 | |
---|
[3331] | 135 | TrackElement* firstTrackElem; //!< The first TrackElement that exists. |
---|
[3332] | 136 | TrackElement* currentTrackElem; //!< The TrackElement we are working on. |
---|
[3588] | 137 | CurveType curveType; //!< The CurveType the entire TrackSystem will have. |
---|
[3331] | 138 | float localTime; //!< The time that has been passed since the traveling the Track. |
---|
| 139 | float maxTime; //!< The maximal time the track has. |
---|
| 140 | int trackElemCount; //!< The count of TrackElements that exist. |
---|
[3845] | 141 | |
---|
| 142 | // external |
---|
[3522] | 143 | PNode* bindSlave; //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself. |
---|
[3556] | 144 | PNode* trackNode; //!< The main TrackNode of this Track. |
---|
[3845] | 145 | Text* trackText; //!< The text to display when switching between Worlds. |
---|
[3847] | 146 | tAnimation<Text>* textAnimation; //!< An Animation for the Text. |
---|
[3330] | 147 | |
---|
[3836] | 148 | void initChildren(unsigned int childCount, TrackElement* trackElem = NULL); |
---|
[3311] | 149 | |
---|
| 150 | public: |
---|
[3543] | 151 | virtual ~TrackManager(void); |
---|
[3544] | 152 | |
---|
[3331] | 153 | static TrackManager* getInstance(void); |
---|
[3311] | 154 | |
---|
[4017] | 155 | TrackManager(TiXmlElement* root); |
---|
| 156 | |
---|
[3330] | 157 | // Methods to change the Path (initialisation) |
---|
[3332] | 158 | void workOn(unsigned int trackID); |
---|
[3836] | 159 | void workOn(const char* trackName); |
---|
| 160 | |
---|
[3522] | 161 | /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */ |
---|
| 162 | inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}; |
---|
[3433] | 163 | void setCurveType(CurveType curveType, TrackElement* trackElem); |
---|
[3836] | 164 | void setDuration(float duration, TrackElement* trackElem = NULL); |
---|
| 165 | bool addPoint(Vector newPoint, TrackElement* trackElem = NULL); |
---|
| 166 | int addHotPoint(Vector newPoint, TrackElement* trackElem = NULL); |
---|
[3837] | 167 | int setSavePoint(TrackElement* trackElem = NULL); |
---|
[3332] | 168 | void fork(unsigned int count, ...); |
---|
[3837] | 169 | void forkV(unsigned int count, int* trackIDs, TrackElement* trackElem = NULL); |
---|
| 170 | void condition(unsigned int trackID, CONDITION cond, void* subject); |
---|
| 171 | void condition(CONDITION cond, void* subject, TrackElement* trackElem = NULL); |
---|
[3332] | 172 | void join(unsigned int count, ...); |
---|
[3841] | 173 | void joinc(unsigned int count, ...); |
---|
[3332] | 174 | void joinV(unsigned int count, int* trackIDs); |
---|
[3433] | 175 | void finalize(void); |
---|
[3311] | 176 | |
---|
[3330] | 177 | // Methods to calculate the position on the Path (runtime) |
---|
[3522] | 178 | inline Vector calcPos(void) const; |
---|
| 179 | inline Vector calcDir(void) const; |
---|
[3596] | 180 | float getWidth(void) const; |
---|
[3330] | 181 | void tick(float dt); |
---|
[3331] | 182 | void jumpTo(float time); |
---|
[3522] | 183 | inline int choosePath(TrackElement* trackElem); |
---|
[3311] | 184 | |
---|
[3433] | 185 | void setBindSlave(PNode* bindSlave); |
---|
[3556] | 186 | PNode* getTrackNode(void); |
---|
[3433] | 187 | |
---|
[3350] | 188 | // DEBUG // |
---|
| 189 | void drawGraph(float dt) const; |
---|
| 190 | void debug(unsigned int level) const; |
---|
[3311] | 191 | }; |
---|
| 192 | |
---|
| 193 | #endif /* _TRACK_MANAGER_H */ |
---|