Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability.old/src/util/track/track_manager.h @ 10371

Last change on this file since 10371 was 10088, checked in by patrick, 18 years ago

added the track subsystem to the buildprocess again, integrated it into the new basobject framework and commented out big regions of code because it didn't compile.
@beni: your work now can begin :D

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