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