Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3523 was 3523, checked in by chris, 19 years ago

orxonox/branches/levelloader: Implemented support for loading tracks in the WorldDataFiles

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