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, 21 years ago

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

File size: 6.4 KB
RevLine 
[3311]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"
[3499]15#include "curve.h"
[3311]16
[3499]17class PNode;
[3523]18class TrackNamer;
[3311]19
[3331]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
[3332]38  TrackElement* findByID(unsigned int trackID);
[3525]39  TrackElement* findByName(const char* trackName);
[3332]40
41  bool isFresh;              //!< If no Points where added until now
[3354]42  bool isHotPoint;           //!< If the first node is a specialPoint;
[3331]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.
[3356]46  bool mainJoin;             //!< If the End of the Curve is joined, and this is the one Curve the others join to.
[3331]47  PathCondition cond;        //!< The Split Condition;
48  int ID;                    //!< The ID of this TrackElement
[3333]49  float startingTime;        //!< The time at which this Track begins.
50  float duration;            //!< The time used to cross this TrackElement (curve).
[3499]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)
[3331]53  CurveType curveType;       //!< The CurveType this will have.
54  int nodeCount;             //!< The count of points this TrackElement has.
[3332]55  char* name;                //!< A name for the Trac.
[3331]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
[3330]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.
[3332]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).
[3333]71    \li setDuration(): sets the length of the current path in seconds.
[3330]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
[3332]79    HotPoints and Joins are at the beginning of a TrackElement. \n
80    SavePoints and Forks are at the end of a TrackElement \n
[3330]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.
[3331]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
[3330]97*/
[3331]98class TrackManager : public BaseObject
99{
[3330]100 private:
[3331]101  TrackManager(void);
102
103  static TrackManager* singletonRef;  //!< There may only be one TrackManager existing.
104  TrackElement* firstTrackElem;       //!< The first TrackElement that exists.
[3332]105  TrackElement* currentTrackElem;     //!< The TrackElement we are working on.
[3331]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.
[3499]109  PNode* bindSlave;
[3330]110 
[3525]111  void initChildren(unsigned int childCount, SubString* names = NULL);
[3311]112
[3332]113  TrackElement* findTrackElementByID(unsigned int trackID) const;
[3525]114  TrackElement* findTrackElementByName(char* trackName) const;
[3350]115 
[3311]116 public:
[3331]117  ~TrackManager(void);
118  static TrackManager* getInstance(void);
[3311]119
[3330]120  // Methods to change the Path (initialisation)
[3332]121  void workOn(unsigned int trackID);
[3499]122  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}
123  void setCurveType(CurveType curveType, TrackElement* trackElem);
[3333]124  void setDuration(float time);
125  bool addPoint(Vector newPoint);
[3352]126  bool addPoint(Vector newPoint, TrackElement* trackElem);
[3333]127  int addHotPoint(Vector newPoint);
128  int setSavePoint(void);
[3332]129  void fork(unsigned int count, ...);
[3525]130  void forkV(unsigned int count, int* trackIDs, SubString* names = NULL);
[3332]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);
[3499]134  void finalize(void);
[3523]135        void forkS( char* string);
136        void joinS( char* string);
137        void workOnS( char* string);
[3311]138
[3523]139        // Method to load track data from file
[3525]140        void loadTrack( TiXmlElement* root);
[3523]141
[3330]142  // Methods to calculate the position on the Path (runtime)
[3332]143  Vector calcPos(void) const;
144  Vector calcDir(void) const;
[3330]145  void tick(float dt);
[3331]146  void jumpTo(float time);
[3330]147  void choosePath(int graphID);
[3311]148
[3499]149  void setBindSlave(PNode* bindSlave);
150
[3350]151  // DEBUG //
152  void drawGraph(float dt) const;
153  void debug(unsigned int level) const;
[3311]154};
155
156#endif /* _TRACK_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.