Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelloader: removed excess class usage adn messed with makefile definitions

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