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