Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3844 was 3841, checked in by bensch, 20 years ago

orxonox/trunk: added a possibility to join tracks by name

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