Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/track_manager.h @ 3770

Last change on this file since 3770 was 3746, checked in by chris, 20 years ago

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

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 "substring.h"
16#include "base_object.h"
17
18class PNode;
19template<class T> class tList;
20
21// Static Definitions
22
23//! The Default Curve-Type to set for the whole path (if not chosen otherwise).
24#define TMAN_DEFAULT_CURVETYPE BEZIERCURVE
25#define TMAN_DEFAULT_DURATION 10
26#define TMAN_DEFAULT_WIDTH    10
27
28//! A Graph-Element, that holds the curve-structure of a Level.
29/**
30   A TrackElement is used, to define the structure of the Track itself.
31   It is a graph and not a tree, because paths can fork and join again.
32*/
33class TrackElement
34{
35 public:
36  TrackElement(void);
37  ~TrackElement(void);
38
39  TrackElement* findByID(unsigned int trackID);
40
41  TrackElement* findByName(const char* trackName);
42       
43  bool backLoopCheck(TrackElement* trackElem);
44
45  TrackElement* getChild(int childNumber);
46  void setName(const char* name);
47  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);
72
73  // CONDITION FUNCTIONS and STUFF
74  void* subject;             //!< The Subject the Condition should act upon.
75  int (TrackElement::*condFunc)(void*); //!< Pointer to the condition function
76
77  int lowest(void* nothing);
78  int highest(void* nothing);
79  int random(void* nothing);
80
81  int leftRight(void* node);
82  int nearest(void* node);
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  PNode* bindSlave;                   //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself.
142  PNode* trackNode;                   //!< The main TrackNode of this Track.
143 
144  void initChildren(unsigned int childCount, SubString* names = NULL);
145
146  TrackElement* findTrackElementByID(unsigned int trackID) const;
147  TrackElement* findTrackElementByName(const char* trackName) const;
148 
149 public:
150  virtual ~TrackManager(void);
151
152  static TrackManager* getInstance(void);
153
154  // Methods to change the Path (initialisation)
155  void workOn(unsigned int trackID);
156  /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */
157  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);};
158  void setCurveType(CurveType curveType, TrackElement* trackElem);
159  void setDuration(float time);
160  bool addPoint(Vector newPoint);
161  bool addPoint(Vector newPoint, TrackElement* trackElem);
162  int addHotPoint(Vector newPoint);
163  int setSavePoint(void);
164  void fork(unsigned int count, ...);
165  void forkV(unsigned int count, int* trackIDs, SubString* names = NULL);
166  void condition(CONDITION cond, void* subject);
167  void condition(unsigned int groupID, CONDITION cond, void* subject);
168  void join(unsigned int count, ...);
169  void joinV(unsigned int count, int* trackIDs);
170  void finalize(void);
171        void forkS( const char* string);
172        void joinS( const char* string);
173        void workOnS( const char* string);
174
175        // Method to load track data from file
176        void loadTrack( TiXmlElement* root);
177
178  // Methods to calculate the position on the Path (runtime)
179  inline Vector calcPos(void) const;
180  inline Vector calcDir(void) const;
181  float getWidth(void) const;
182  void tick(float dt);
183  void jumpTo(float time);
184  inline int choosePath(TrackElement* trackElem);
185
186  void setBindSlave(PNode* bindSlave);
187  PNode* getTrackNode(void);
188
189  // DEBUG //
190  void drawGraph(float dt) const;
191  void debug(unsigned int level) const;
192};
193
194#endif /* _TRACK_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.