Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3766 was 3608, checked in by patrick, 20 years ago

orxonox/trunk: now there is a real speedup in compiling time when dependencies are modified: just realy only includes, what is needed. Byside the speedup, there is more overview! never add an orxonox class to stdincl.h if it doesn't have to be

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