Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: made include more local. stdincl.h not in base_object.h anymore

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