[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" |
---|
| 15 | |
---|
[3433] | 16 | class PNode; |
---|
[3311] | 17 | |
---|
[3331] | 18 | //! condition for choosing a certain Path. \todo implement a useful way. |
---|
| 19 | struct PathCondition |
---|
| 20 | { |
---|
| 21 | |
---|
| 22 | }; |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | //! A Graph-Element, that holds the curve-structure of a Level. |
---|
| 26 | /** |
---|
| 27 | A TrackElement is used, to define the structure of the Track itself. |
---|
| 28 | It is a graph and not a tree, because paths can fork and join again. |
---|
| 29 | */ |
---|
| 30 | class TrackElement |
---|
| 31 | { |
---|
| 32 | public: |
---|
| 33 | TrackElement(void); |
---|
| 34 | ~TrackElement(void); |
---|
| 35 | |
---|
[3332] | 36 | TrackElement* findByID(unsigned int trackID); |
---|
| 37 | |
---|
| 38 | bool isFresh; //!< If no Points where added until now |
---|
[3354] | 39 | bool isHotPoint; //!< If the first node is a specialPoint; |
---|
[3331] | 40 | bool isSavePoint; //!< If the first node is a savePoint |
---|
| 41 | bool isFork; //!< If the first node is a Fork |
---|
| 42 | bool isJoined; //!< If the End of the Curve is joined. |
---|
[3356] | 43 | bool mainJoin; //!< If the End of the Curve is joined, and this is the one Curve the others join to. |
---|
[3331] | 44 | PathCondition cond; //!< The Split Condition; |
---|
| 45 | int ID; //!< The ID of this TrackElement |
---|
[3333] | 46 | float startingTime; //!< The time at which this Track begins. |
---|
| 47 | float duration; //!< The time used to cross this TrackElement (curve). |
---|
[3433] | 48 | float endTime; //!< The time at which this Track ends. |
---|
| 49 | float jumpTime; //!< The Time this Track has to jump to its preceding Track (only >0 if Track isJoined==true) |
---|
[3331] | 50 | CurveType curveType; //!< The CurveType this will have. |
---|
| 51 | int nodeCount; //!< The count of points this TrackElement has. |
---|
[3332] | 52 | char* name; //!< A name for the Trac. |
---|
[3331] | 53 | Curve* curve; //!< The Curve of this TrackElement |
---|
| 54 | int childCount; //!< The number of Children This TrackElement has. |
---|
| 55 | TrackElement** children; //!< A TrackElement can have a Tree of following TrackElements. |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
[3330] | 60 | //! The TrackManager handles the flow of the Players through the game. |
---|
| 61 | /** |
---|
| 62 | |
---|
| 63 | <b>The TrackManager works as followed:</b> \n |
---|
| 64 | \n |
---|
| 65 | <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b> |
---|
| 66 | \li workOn(): changes the ID that will be altered through the changes. |
---|
[3332] | 67 | \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] | 68 | \li setDuration(): sets the length of the current path in seconds. |
---|
[3330] | 69 | \li addPoint(): adds a point to the Curve. |
---|
| 70 | \li addHotPoint(): adds save/splitpoint.\n |
---|
| 71 | \li fork(): adds some interessting non-linear movments through the level (fork will force addHotPoint if not done then). |
---|
| 72 | \li condition(): decides under what condition a certain Path will be chosen. |
---|
| 73 | \li join(): joins some tracks together again. Join will set the localTime to the longest time a Path has to get to this Point) |
---|
| 74 | \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot. |
---|
| 75 | |
---|
[3332] | 76 | HotPoints and Joins are at the beginning of a TrackElement. \n |
---|
| 77 | SavePoints and Forks are at the end of a TrackElement \n |
---|
[3330] | 78 | 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 |
---|
| 79 | \n |
---|
| 80 | <b> 2. Runtime knows the following: </b> |
---|
| 81 | \li calcPos(): returns the current position on the track |
---|
| 82 | \li calcDir(): returns the current Direction the track is flying on. |
---|
| 83 | \li tick(): makes a Step on the Path. increases localTime by dt. |
---|
| 84 | \li choosePath(): a Function that decides which Path we should follow. |
---|
| 85 | |
---|
| 86 | TrackManager can be handled as a StateMachine. |
---|
[3331] | 87 | \n\n |
---|
| 88 | Names: |
---|
| 89 | \li TrackManager: handles Tracks |
---|
| 90 | \li Track: The Track that the ship can follow |
---|
| 91 | \li Path: one way through the Level, that is dependent on conditionals. |
---|
| 92 | \li Conditional: A decition making device, that chooses betwen different TrackElements for the Path. |
---|
| 93 | \li TrackElement: A Part of A whole Track |
---|
[3330] | 94 | */ |
---|
[3331] | 95 | class TrackManager : public BaseObject |
---|
| 96 | { |
---|
[3330] | 97 | private: |
---|
[3331] | 98 | TrackManager(void); |
---|
| 99 | |
---|
| 100 | static TrackManager* singletonRef; //!< There may only be one TrackManager existing. |
---|
| 101 | TrackElement* firstTrackElem; //!< The first TrackElement that exists. |
---|
[3332] | 102 | TrackElement* currentTrackElem; //!< The TrackElement we are working on. |
---|
[3331] | 103 | float localTime; //!< The time that has been passed since the traveling the Track. |
---|
| 104 | float maxTime; //!< The maximal time the track has. |
---|
| 105 | int trackElemCount; //!< The count of TrackElements that exist. |
---|
[3433] | 106 | PNode* bindSlave; |
---|
[3330] | 107 | |
---|
[3335] | 108 | void initChildren(unsigned int childCount); |
---|
[3311] | 109 | |
---|
[3332] | 110 | TrackElement* findTrackElementByID(unsigned int trackID) const; |
---|
[3350] | 111 | |
---|
[3311] | 112 | public: |
---|
[3331] | 113 | ~TrackManager(void); |
---|
| 114 | static TrackManager* getInstance(void); |
---|
[3311] | 115 | |
---|
[3330] | 116 | // Methods to change the Path (initialisation) |
---|
[3332] | 117 | void workOn(unsigned int trackID); |
---|
[3433] | 118 | inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);} |
---|
| 119 | void setCurveType(CurveType curveType, TrackElement* trackElem); |
---|
[3333] | 120 | void setDuration(float time); |
---|
| 121 | bool addPoint(Vector newPoint); |
---|
[3352] | 122 | bool addPoint(Vector newPoint, TrackElement* trackElem); |
---|
[3333] | 123 | int addHotPoint(Vector newPoint); |
---|
| 124 | int setSavePoint(void); |
---|
[3332] | 125 | void fork(unsigned int count, ...); |
---|
| 126 | void forkV(unsigned int count, int* trackIDs); |
---|
| 127 | void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!! |
---|
| 128 | void join(unsigned int count, ...); |
---|
| 129 | void joinV(unsigned int count, int* trackIDs); |
---|
[3433] | 130 | void finalize(void); |
---|
[3311] | 131 | |
---|
[3330] | 132 | // Methods to calculate the position on the Path (runtime) |
---|
[3332] | 133 | Vector calcPos(void) const; |
---|
| 134 | Vector calcDir(void) const; |
---|
[3330] | 135 | void tick(float dt); |
---|
[3331] | 136 | void jumpTo(float time); |
---|
[3330] | 137 | void choosePath(int graphID); |
---|
[3311] | 138 | |
---|
[3433] | 139 | void setBindSlave(PNode* bindSlave); |
---|
| 140 | |
---|
[3350] | 141 | // DEBUG // |
---|
| 142 | void drawGraph(float dt) const; |
---|
| 143 | void debug(unsigned int level) const; |
---|
[3311] | 144 | }; |
---|
| 145 | |
---|
| 146 | #endif /* _TRACK_MANAGER_H */ |
---|