Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelloader: Got the system to compile, the basic backbone now runs. What remains to be done is implementing all necessary functions to load all vital classes into a world

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