Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3590 was 3588, checked in by bensch, 20 years ago

orxonox/trunk: name-fix for TrackManager and minor fix in Curve.
There has also been a little fix in the light-class: light is a BaseObject not a World-Entity

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