Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/track_manager.h @ 4242

Last change on this file since 4242 was 4220, checked in by bensch, 20 years ago

orxonox/trunk: TrackManager prepared for loading. added new overloaded functions that read in join and fork from one single string
thanks to chris, this was pretty easy… the hard part was finding the substring class :)

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;
20template<class T> class tAnimation;
21template<class T> class tList;
22
23// Static Definitions
24
25//! The Default Curve-Type to set for the whole path (if not chosen otherwise).
26#define TMAN_DEFAULT_CURVETYPE CURVE_BEZIER
27#define TMAN_DEFAULT_DURATION 10
28#define TMAN_DEFAULT_WIDTH    10
29
30//! A Graph-Element, that holds the curve-structure of a Level.
31/**
32   A TrackElement is used, to define the structure of the Track itself.
33   It is a graph and not a tree, because paths can fork and join again.
34*/
35class TrackElement
36{
37 public:
38  TrackElement(void);
39  ~TrackElement(void);
40
41  TrackElement* findByID(unsigned int trackID);
42  TrackElement* findByName(const char* trackName);
43  bool backLoopCheck(const TrackElement* trackElem, unsigned int depth = 0) const;
44
45  TrackElement* getChild(int childNumber) const;
46  void setName(const char* name);
47  const char* getName(void) const;
48
49  // atributes
50  bool isFresh;              //!< If no Points where added until now
51  bool isHotPoint;           //!< If the first node is a specialPoint;
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.
55  bool mainJoin;             //!< If the End of the Curve is joined, and this is the one Curve the others join to.
56  int ID;                    //!< The ID of this TrackElement
57  float startingTime;        //!< The time at which this Track begins.
58  float duration;            //!< The time used to cross this TrackElement (curve).
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)
61  float width;               //!< Th width of the Path. This tells the Player(s), how far he(they) can go to the left/right.
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.
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) const;
72
73  // CONDITION FUNCTIONS and STUFF
74  void* subject;             //!< The Subject the Condition should act upon.
75  int (TrackElement::*condFunc)(const void*) const; //!< Pointer to the condition function
76
77  int lowest(const void* nothing) const;
78  int highest(const void* nothing) const;
79  int random(const void* nothing) const;
80
81  int leftRight(const void* node) const;
82  int nearest(const void* node) const;
83  // todo  int enemyKilled(void* entity);
84
85 private:
86  char* name;                //!< A name for the Trac.
87 
88};
89
90//! the Condition to choose between the different ways of the game.
91enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED};
92
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.
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).
101    \li setDuration(): sets the length of the current path in seconds.
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
109    HotPoints and Joins are at the beginning of a TrackElement. \n
110    SavePoints and Forks are at the end of a TrackElement \n
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.
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
127*/
128class TrackManager : public BaseObject
129{
130 private:
131  TrackManager(void);
132
133  static TrackManager* singletonRef;  //!< There may only be one TrackManager.
134
135  TrackElement* firstTrackElem;       //!< The first TrackElement that exists.
136  TrackElement* currentTrackElem;     //!< The TrackElement we are working on.
137  CurveType curveType;                //!< The CurveType the entire TrackSystem will have.
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.
141
142  // external
143  PNode* bindSlave;                   //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself.
144  PNode* trackNode;                   //!< The main TrackNode of this Track.
145  Text* trackText;                    //!< The text to display when switching between Worlds.
146  tAnimation<Text>* textAnimation;    //!< An Animation for the Text.
147 
148  void initChildren(unsigned int childCount, TrackElement* trackElem = NULL);
149
150 public:
151  virtual ~TrackManager(void);
152
153  static TrackManager* getInstance(void);
154
155  bool load(TiXmlElement* root);
156
157  // Methods to change the Path (initialisation)
158  void workOn(unsigned int trackID);
159  void workOn(const char* trackName);
160
161  /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */
162  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);};
163  void setCurveType(CurveType curveType, TrackElement* trackElem);
164  void setDuration(float duration, TrackElement* trackElem = NULL);
165  bool addPoint(Vector newPoint, TrackElement* trackElem = NULL);
166  int addHotPoint(Vector newPoint, TrackElement* trackElem = NULL);
167  int setSavePoint(TrackElement* trackElem = NULL);
168  void fork(unsigned int count, ...);
169  void forkS(unsigned int count, ...);
170  void forkS(const char* forkString);
171  void forkV(unsigned int count, int* trackIDs, char** trackNames, TrackElement* trackElem = NULL);
172  void condition(unsigned int trackID, CONDITION cond, void* subject);
173  void condition(CONDITION cond, void* subject, TrackElement* trackElem = NULL);
174  void join(unsigned int count, ...);
175  void joinS(const char* joinString);
176  void joinS(unsigned int cound, ...);
177  void joinV(unsigned int count, int* trackIDs);
178  void finalize(void);
179
180  // Methods to calculate the position on the Path (runtime)
181  inline Vector calcPos(void) const;
182  inline Vector calcDir(void) const;
183  float getWidth(void) const;
184  void tick(float dt);
185  void jumpTo(float time);
186  inline int choosePath(TrackElement* trackElem);
187
188  void setBindSlave(PNode* bindSlave);
189  PNode* getTrackNode(void);
190
191  // DEBUG //
192  void drawGraph(float dt) const;
193  void debug(unsigned int level) const;
194};
195
196#endif /* _TRACK_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.