[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 | |
---|
| 14 | #include "stdincl.h" |
---|
[3499] | 15 | #include "curve.h" |
---|
[3530] | 16 | #include "substring.h" |
---|
[3311] | 17 | |
---|
[3499] | 18 | class PNode; |
---|
[3523] | 19 | class TrackNamer; |
---|
[3311] | 20 | |
---|
[3605] | 21 | // Static Definitions |
---|
[3331] | 22 | |
---|
[3605] | 23 | //! The Default Curve-Type to set for the whole path (if not chosen otherwise). |
---|
| 24 | #define TMAN_DEFAULT_CURVETYPE BEZIERCURVE |
---|
| 25 | #define TMAN_DEFAULT_DURATION 10 |
---|
| 26 | #define TMAN_DEFAULT_WIDTH 10 |
---|
| 27 | |
---|
[3331] | 28 | //! A Graph-Element, that holds the curve-structure of a Level. |
---|
| 29 | /** |
---|
| 30 | A TrackElement is used, to define the structure of the Track itself. |
---|
| 31 | It is a graph and not a tree, because paths can fork and join again. |
---|
| 32 | */ |
---|
| 33 | class TrackElement |
---|
| 34 | { |
---|
| 35 | public: |
---|
| 36 | TrackElement(void); |
---|
| 37 | ~TrackElement(void); |
---|
| 38 | |
---|
[3332] | 39 | TrackElement* findByID(unsigned int trackID); |
---|
[3605] | 40 | |
---|
[3525] | 41 | TrackElement* findByName(const char* trackName); |
---|
[3530] | 42 | |
---|
[3605] | 43 | bool backLoopCheck(TrackElement* trackElem); |
---|
| 44 | |
---|
| 45 | TrackElement* getChild(int childNumber); |
---|
| 46 | void setName(const char* name); |
---|
| 47 | char* getName(void) const; |
---|
| 48 | |
---|
| 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). |
---|
[3499] | 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) |
---|
[3605] | 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. |
---|
[3605] | 65 | tList<TrackElement>* children; //!< A TrackElement can have a Tree of following TrackElements. |
---|
| 66 | |
---|
| 67 | |
---|
| 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 | |
---|
| 71 | void debug(void); |
---|
| 72 | |
---|
| 73 | // CONDITION FUNCTIONS and STUFF |
---|
| 74 | void* subject; //!< The Subject the Condition should act upon. |
---|
| 75 | int (TrackElement::*condFunc)(void*); //!< Pointer to the condition function |
---|
| 76 | |
---|
| 77 | int lowest(void* nothing); |
---|
| 78 | int highest(void* nothing); |
---|
| 79 | int random(void* nothing); |
---|
| 80 | |
---|
| 81 | int leftRight(void* node); |
---|
| 82 | int nearest(void* node); |
---|
| 83 | // todo int enemyKilled(void* entity); |
---|
| 84 | |
---|
| 85 | private: |
---|
| 86 | char* name; //!< A name for the Trac. |
---|
| 87 | |
---|
[3331] | 88 | }; |
---|
| 89 | |
---|
[3605] | 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 | |
---|
[3605] | 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. |
---|
[3605] | 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. |
---|
[3605] | 141 | PNode* bindSlave; //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself. |
---|
| 142 | PNode* trackNode; //!< The main TrackNode of this Track. |
---|
[3330] | 143 | |
---|
[3525] | 144 | void initChildren(unsigned int childCount, SubString* names = NULL); |
---|
[3311] | 145 | |
---|
[3332] | 146 | TrackElement* findTrackElementByID(unsigned int trackID) const; |
---|
[3530] | 147 | TrackElement* findTrackElementByName(const char* trackName) const; |
---|
[3350] | 148 | |
---|
[3311] | 149 | public: |
---|
[3605] | 150 | virtual ~TrackManager(void); |
---|
| 151 | |
---|
[3331] | 152 | static TrackManager* getInstance(void); |
---|
[3311] | 153 | |
---|
[3330] | 154 | // Methods to change the Path (initialisation) |
---|
[3332] | 155 | void workOn(unsigned int trackID); |
---|
[3605] | 156 | /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */ |
---|
| 157 | inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}; |
---|
[3499] | 158 | void setCurveType(CurveType curveType, TrackElement* trackElem); |
---|
[3333] | 159 | void setDuration(float time); |
---|
| 160 | bool addPoint(Vector newPoint); |
---|
[3352] | 161 | bool addPoint(Vector newPoint, TrackElement* trackElem); |
---|
[3333] | 162 | int addHotPoint(Vector newPoint); |
---|
| 163 | int setSavePoint(void); |
---|
[3332] | 164 | void fork(unsigned int count, ...); |
---|
[3525] | 165 | void forkV(unsigned int count, int* trackIDs, SubString* names = NULL); |
---|
[3605] | 166 | void condition(CONDITION cond, void* subject); |
---|
| 167 | void condition(unsigned int groupID, CONDITION cond, void* subject); |
---|
[3332] | 168 | void join(unsigned int count, ...); |
---|
| 169 | void joinV(unsigned int count, int* trackIDs); |
---|
[3499] | 170 | void finalize(void); |
---|
[3530] | 171 | void forkS( const char* string); |
---|
| 172 | void joinS( const char* string); |
---|
| 173 | void workOnS( const char* string); |
---|
[3311] | 174 | |
---|
[3523] | 175 | // Method to load track data from file |
---|
[3525] | 176 | void loadTrack( TiXmlElement* root); |
---|
[3523] | 177 | |
---|
[3330] | 178 | // Methods to calculate the position on the Path (runtime) |
---|
[3605] | 179 | inline Vector calcPos(void) const; |
---|
| 180 | inline Vector calcDir(void) const; |
---|
| 181 | float getWidth(void) const; |
---|
[3330] | 182 | void tick(float dt); |
---|
[3331] | 183 | void jumpTo(float time); |
---|
[3605] | 184 | inline int choosePath(TrackElement* trackElem); |
---|
[3311] | 185 | |
---|
[3499] | 186 | void setBindSlave(PNode* bindSlave); |
---|
[3605] | 187 | PNode* getTrackNode(void); |
---|
[3499] | 188 | |
---|
[3350] | 189 | // DEBUG // |
---|
| 190 | void drawGraph(float dt) const; |
---|
| 191 | void debug(unsigned int level) const; |
---|
[3311] | 192 | }; |
---|
| 193 | |
---|
| 194 | #endif /* _TRACK_MANAGER_H */ |
---|