Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4496 was 4496, checked in by bensch, 19 years ago

orxonox/trunk: cycling read-in of parameters should work now… this is quite tricky, and the TrackManager has to be rewritten in some parts…. :(

File size: 9.3 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#ifndef NULL
18#define NULL   0  //!< NULL
19#endif
20
21// Forward Definition
22class PNode;
23class Text;
24class TiXmlElement;
25template<class T> class tAnimation;
26template<class T> class tList;
27
28// Static Definitions
29
30//! The default Curve-Type to set for the whole path (if not chosen otherwise).
31#define TMAN_DEFAULT_CURVETYPE    CURVE_BEZIER
32//! A default value for the duration for each TrackElement
33#define TMAN_DEFAULT_DURATION     10
34//! A default width for the width of a TrackElement
35#define TMAN_DEFAULT_WIDTH        10
36
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*/
42class TrackElement
43{
44 public:
45  TrackElement(void);
46  ~TrackElement(void);
47
48  TrackElement* findByID(unsigned int trackID);
49  TrackElement* findByName(const char* trackName);
50  bool backLoopCheck(const TrackElement* trackElem, unsigned int depth = 0) const;
51
52  TrackElement* getChild(int childNumber) const;
53  void setName(const char* name);
54  /** \returns the Name of this TrackElement */
55  inline const char* getName(void) const { return this->name; };
56
57
58  // atributes
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.
75
76
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
80  void debug(void) const;
81
82  // CONDITION FUNCTIONS and STUFF
83  void* subject;             //!< The Subject the Condition should act upon.
84  int (TrackElement::*condFunc)(const void*) const; //!< Pointer to the condition function
85
86  int lowest(const void* nothing) const;
87  int highest(const void* nothing) const;
88  int random(const void* nothing) const;
89
90  int leftRight(const void* node) const;
91  int nearest(const void* node) const;
92  // todo  int enemyKilled(void* entity);
93
94 private:
95  char* name;                //!< A name for the Trac.
96 
97};
98
99//! the Condition to choose between the different ways of the game.
100enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED};
101
102//! The TrackManager handles the flow of the Players through the game.
103/**
104
105   <b>The TrackManager works as followed:</b> \n
106     \n
107   <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b>
108    \li workOn(): changes the ID that will be altered through the changes.
109    \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).
110    \li setDuration(): sets the length of the current path in seconds.
111    \li addPoint(): adds a point to the Curve.
112    \li addHotPoint(): adds save/splitpoint.\n
113    \li fork(): adds some interessting non-linear movments through the level (fork will force addHotPoint if not done then).
114    \li condition(): decides under what condition a certain Path will be chosen.
115    \li join(): joins some tracks together again. Join will set the localTime to the longest time a Path has to get to this Point)
116    \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot.
117
118    HotPoints and Joins are at the beginning of a TrackElement. \n
119    SavePoints and Forks are at the end of a TrackElement \n
120    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
121\n
122   <b> 2. Runtime knows the following: </b>
123    \li calcPos(): returns the current position on the track
124    \li calcDir(): returns the current Direction the track is flying on.
125    \li tick(): makes a Step on the Path. increases localTime by dt.
126    \li choosePath(): a Function that decides which Path we should follow.
127   
128   TrackManager can be handled as a StateMachine.
129   \n\n
130    Names:
131    \li TrackManager: handles Tracks
132    \li Track:        The Track that the ship can follow
133    \li Path:         one way through the Level, that is dependent on conditionals.
134    \li Conditional:  A decition making device, that chooses betwen different TrackElements for the Path.
135    \li TrackElement: A Part of A whole Track
136*/
137class TrackManager : public BaseObject
138{
139 public:
140  virtual ~TrackManager(void);
141  /** \returns a Pointer to the only object of this Class */
142  inline static TrackManager* getInstance(void) { if (!singletonRef) singletonRef = new TrackManager();  return singletonRef; };
143
144  bool loadParams(TiXmlElement* root);
145
146  // Methods to change the Path (initialisation)
147  void workOn(unsigned int trackID);
148  void workOn(const char* trackName);
149
150  /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */
151  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);};
152  void setCurveType(CurveType curveType, TrackElement* trackElem);
153  void setDuration(float duration);
154  void setDuration(float duration, TrackElement* trackElem);
155  void addPoint(float x, float y, float z);
156  void addPointV(Vector newPoint, TrackElement* trackElem = NULL);
157  int addHotPoint(Vector newPoint, TrackElement* trackElem = NULL);
158  void setSavePoint(int isLoadable);
159  int setSavePoint(TrackElement* trackElem = NULL);
160  void fork(unsigned int count, ...);
161  void forkS(unsigned int count, ...);
162  void forkS(const char* forkString);
163  void forkV(unsigned int count, int* trackIDs, char** trackNames, TrackElement* trackElem = NULL);
164  void condition(unsigned int trackID, CONDITION cond, void* subject);
165  void condition(CONDITION cond, void* subject, TrackElement* trackElem = NULL);
166  void join(unsigned int count, ...);
167  void joinS(const char* joinString);
168  void joinS(unsigned int cound, ...);
169  void joinV(unsigned int count, int* trackIDs);
170  void finalize(void);
171
172  // Methods to calculate the position on the Path (runtime)
173  inline Vector calcPos(void) const;
174  inline Vector calcDir(void) const;
175  float getWidth(void) const;
176  void tick(float dt);
177  void jumpTo(float time);
178  inline int choosePath(TrackElement* trackElem);
179
180  void setBindSlave(PNode* bindSlave);
181  PNode* getTrackNode(void);
182
183  // DEBUG //
184  void drawGraph(float dt) const;
185  void debug(unsigned int level) const;
186
187 private:
188  TrackManager(void);
189  void initChildren(unsigned int childCount, TrackElement* trackElem = NULL);
190
191 private:
192  static TrackManager* singletonRef;           //!< There may only be one TrackManager.
193
194  TrackElement*        firstTrackElem;         //!< The first TrackElement that exists.
195  TrackElement*        currentTrackElem;       //!< The TrackElement we are working on.
196  CurveType            curveType;              //!< The CurveType the entire TrackSystem will have.
197  float                localTime;              //!< The time that has been passed since the traveling the Track.
198  float                maxTime;                //!< The maximal time the track has.
199  int                  trackElemCount;         //!< The count of TrackElements that exist.
200
201  // external
202  PNode*               bindSlave;              //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself.
203  PNode*               trackNode;              //!< The main TrackNode of this Track.
204  Text*                trackText;              //!< The text to display when switching between Worlds.
205  tAnimation<Text>*    textAnimation;          //!< An Animation for the Text. (for fading it out on trackName-change)
206};
207
208#endif /* _TRACK_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.