Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/track/track_manager.h @ 4318

Last change on this file since 4318 was 4262, checked in by bensch, 20 years ago

orxonox/trunk: moved around some files, and deleted the obsolete DataTank

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