Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/soundEngine/src/track_manager.h @ 3542

Last change on this file since 3542 was 3495, checked in by bensch, 20 years ago

orxonox/trunk: taken curve and matrix out of stdincl.h because they are not needed very often.

File size: 6.1 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//! condition for choosing a certain Path. \todo implement a useful way.
20struct PathCondition
21{
22 
23};
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
39  bool isFresh;              //!< If no Points where added until now
40  bool isHotPoint;           //!< If the first node is a specialPoint;
41  bool isSavePoint;          //!< If the first node is a savePoint
42  bool isFork;               //!< If the first node is a Fork
43  bool isJoined;             //!< If the End of the Curve is joined.
44  bool mainJoin;             //!< If the End of the Curve is joined, and this is the one Curve the others join to.
45  PathCondition cond;        //!< The Split Condition;
46  int ID;                    //!< The ID of this TrackElement
47  float startingTime;        //!< The time at which this Track begins.
48  float duration;            //!< The time used to cross this TrackElement (curve).
49  float endTime;             //!< The time at which this Track ends.
50  float jumpTime;            //!< The Time this Track has to jump to its preceding Track (only >0 if Track isJoined==true)
51  CurveType curveType;       //!< The CurveType this will have.
52  int nodeCount;             //!< The count of points this TrackElement has.
53  char* name;                //!< A name for the Trac.
54  Curve* curve;              //!< The Curve of this TrackElement
55  int childCount;            //!< The number of Children This TrackElement has.
56  TrackElement** children;   //!< A TrackElement can have a Tree of following TrackElements.
57};
58
59
60
61//! The TrackManager handles the flow of the Players through the game.
62/**
63
64   <b>The TrackManager works as followed:</b> \n
65     \n
66   <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b>
67    \li workOn(): changes the ID that will be altered through the changes.
68    \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).
69    \li setDuration(): sets the length of the current path in seconds.
70    \li addPoint(): adds a point to the Curve.
71    \li addHotPoint(): adds save/splitpoint.\n
72    \li fork(): adds some interessting non-linear movments through the level (fork will force addHotPoint if not done then).
73    \li condition(): decides under what condition a certain Path will be chosen.
74    \li join(): joins some tracks together again. Join will set the localTime to the longest time a Path has to get to this Point)
75    \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot.
76
77    HotPoints and Joins are at the beginning of a TrackElement. \n
78    SavePoints and Forks are at the end of a TrackElement \n
79    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
80\n
81   <b> 2. Runtime knows the following: </b>
82    \li calcPos(): returns the current position on the track
83    \li calcDir(): returns the current Direction the track is flying on.
84    \li tick(): makes a Step on the Path. increases localTime by dt.
85    \li choosePath(): a Function that decides which Path we should follow.
86   
87   TrackManager can be handled as a StateMachine.
88   \n\n
89    Names:
90    \li TrackManager: handles Tracks
91    \li Track:        The Track that the ship can follow
92    \li Path:         one way through the Level, that is dependent on conditionals.
93    \li Conditional:  A decition making device, that chooses betwen different TrackElements for the Path.
94    \li TrackElement: A Part of A whole Track
95*/
96class TrackManager : public BaseObject
97{
98 private:
99  TrackManager(void);
100
101  static TrackManager* singletonRef;  //!< There may only be one TrackManager existing.
102  TrackElement* firstTrackElem;       //!< The first TrackElement that exists.
103  TrackElement* currentTrackElem;     //!< The TrackElement we are working on.
104  float localTime;                    //!< The time that has been passed since the traveling the Track.
105  float maxTime;                      //!< The maximal time the track has.
106  int trackElemCount;                 //!< The count of TrackElements that exist.
107  PNode* bindSlave;
108 
109  void initChildren(unsigned int childCount);
110
111  TrackElement* findTrackElementByID(unsigned int trackID) const;
112 
113 public:
114  ~TrackManager(void);
115  static TrackManager* getInstance(void);
116
117  // Methods to change the Path (initialisation)
118  void workOn(unsigned int trackID);
119  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}
120  void setCurveType(CurveType curveType, TrackElement* trackElem);
121  void setDuration(float time);
122  bool addPoint(Vector newPoint);
123  bool addPoint(Vector newPoint, TrackElement* trackElem);
124  int addHotPoint(Vector newPoint);
125  int setSavePoint(void);
126  void fork(unsigned int count, ...);
127  void forkV(unsigned int count, int* trackIDs);
128  void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!!
129  void join(unsigned int count, ...);
130  void joinV(unsigned int count, int* trackIDs);
131  void finalize(void);
132
133  // Methods to calculate the position on the Path (runtime)
134  Vector calcPos(void) const;
135  Vector calcDir(void) const;
136  void tick(float dt);
137  void jumpTo(float time);
138  void choosePath(int graphID);
139
140  void setBindSlave(PNode* bindSlave);
141
142  // DEBUG //
143  void drawGraph(float dt) const;
144  void debug(unsigned int level) const;
145};
146
147#endif /* _TRACK_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.