Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: hotpoint of TrackManager loadable

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