Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/track/track_manager.h @ 10298

Last change on this file since 10298 was 7221, checked in by bensch, 19 years ago

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 9.2 KB
RevLine 
[4584]1/*!
[5014]2 * @file track_manager.h
3 *  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.
[3311]8*/
9
10
11#ifndef _TRACK_MANAGER_H
12#define _TRACK_MANAGER_H
13
[3495]14#include "curve.h"
[3608]15#include "base_object.h"
[3311]16
[4381]17#ifndef NULL
[4489]18#define NULL   0  //!< NULL
[4381]19#endif
20
[3845]21// Forward Definition
[3433]22class PNode;
[3845]23class Text;
[4261]24class TiXmlElement;
[3847]25template<class T> class tAnimation;
[3311]26
[3588]27// Static Definitions
28
[4489]29//! The default Curve-Type to set for the whole path (if not chosen otherwise).
[4833]30#define     TMAN_DEFAULT_CURVETYPE    CURVE_BEZIER
[4489]31//! A default value for the duration for each TrackElement
[4833]32#define     TMAN_DEFAULT_DURATION     10
[4489]33//! A default width for the width of a TrackElement
[4833]34#define     TMAN_DEFAULT_WIDTH        10
[3588]35
[3331]36//! A Graph-Element, that holds the curve-structure of a Level.
37/**
38   A TrackElement is used, to define the structure of the Track itself.
39   It is a graph and not a tree, because paths can fork and join again.
40*/
[4584]41class TrackElement : public BaseObject
[3331]42{
43 public:
[4746]44  TrackElement();
[6981]45  virtual ~TrackElement();
[3331]46
[3332]47  TrackElement* findByID(unsigned int trackID);
[7221]48  TrackElement* findByName(const std::string& trackName);
[4746]49  bool backLoopCheck() const;
[3332]50
[5313]51  TrackElement* getChild(unsigned int childNumber) const;
[3594]52
[4508]53 private:
54  bool backLoopCheckAtomic(tList<const TrackElement>* trackList) const;
[4489]55
[4508]56 public:
[3588]57  // atributes
[4489]58  bool                  isFresh;              //!< If no Points where added until now
59  bool                  isHotPoint;           //!< If the first node is a specialPoint;
60  bool                  isSavePoint;          //!< If the first node is a savePoint
61  bool                  isFork;               //!< If the first node is a Fork
62  bool                  isJoined;             //!< If the End of the Curve is joined.
63  bool                  mainJoin;             //!< If the End of the Curve is joined, and this is the one Curve the others join to.
64  int                   ID;                   //!< The ID of this TrackElement
65  float                 startingTime;         //!< The time at which this Track begins.
66  float                 duration;             //!< The time used to cross this TrackElement (curve).
67  float                 endTime;              //!< The time at which this Track ends.
68  float                 jumpTime;             //!< The Time this Track has to jump to its preceding Track (only >0 if Track isJoined==true)
69  float                 width;                //!< Th width of the Path. This tells the Player(s), how far he(they) can go to the left/right.
70  int                   nodeCount;            //!< The count of points this TrackElement has.
71  Curve*                curve;                //!< The Curve of this TrackElement
72  int                   childCount;           //!< The number of Children This TrackElement has.
73  tList<TrackElement>*  children;             //!< A TrackElement can have a Tree of following TrackElements.
[3522]74
[3588]75
[3527]76  // runtime
77  TrackElement* history;     //!< a pointer to the last TrackElement we were on. This is if you want to walk the path backwards again.
78
[4746]79  void debug() const;
[3593]80
[3522]81  // CONDITION FUNCTIONS and STUFF
82  void* subject;             //!< The Subject the Condition should act upon.
[3835]83  int (TrackElement::*condFunc)(const void*) const; //!< Pointer to the condition function
[3522]84
[3835]85  int lowest(const void* nothing) const;
86  int highest(const void* nothing) const;
87  int random(const void* nothing) const;
[3522]88
[3835]89  int leftRight(const void* node) const;
90  int nearest(const void* node) const;
[3522]91  // todo  int enemyKilled(void* entity);
[3588]92
[3331]93};
94
[3522]95//! the Condition to choose between the different ways of the game.
96enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED};
[3331]97
[3330]98//! The TrackManager handles the flow of the Players through the game.
99/**
100
101   <b>The TrackManager works as followed:</b> \n
102     \n
103   <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b>
104    \li workOn(): changes the ID that will be altered through the changes.
[3332]105    \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]106    \li setDuration(): sets the length of the current path in seconds.
[3330]107    \li addPoint(): adds a point to the Curve.
108    \li addHotPoint(): adds save/splitpoint.\n
109    \li fork(): adds some interessting non-linear movments through the level (fork will force addHotPoint if not done then).
110    \li condition(): decides under what condition a certain Path will be chosen.
111    \li join(): joins some tracks together again. Join will set the localTime to the longest time a Path has to get to this Point)
112    \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot.
113
[3332]114    HotPoints and Joins are at the beginning of a TrackElement. \n
115    SavePoints and Forks are at the end of a TrackElement \n
[3330]116    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
117\n
118   <b> 2. Runtime knows the following: </b>
119    \li calcPos(): returns the current position on the track
120    \li calcDir(): returns the current Direction the track is flying on.
121    \li tick(): makes a Step on the Path. increases localTime by dt.
122    \li choosePath(): a Function that decides which Path we should follow.
[4584]123
[3330]124   TrackManager can be handled as a StateMachine.
[3331]125   \n\n
[4584]126    Names:
[3331]127    \li TrackManager: handles Tracks
128    \li Track:        The Track that the ship can follow
129    \li Path:         one way through the Level, that is dependent on conditionals.
130    \li Conditional:  A decition making device, that chooses betwen different TrackElements for the Path.
131    \li TrackElement: A Part of A whole Track
[3330]132*/
[3331]133class TrackManager : public BaseObject
134{
[3311]135 public:
[4746]136  virtual ~TrackManager();
[4836]137  /** @returns a Pointer to the only object of this Class */
[4746]138  inline static TrackManager* getInstance() { if (!singletonRef) singletonRef = new TrackManager();  return singletonRef; };
[3544]139
[6512]140  virtual void loadParams(const TiXmlElement* root);
[3311]141
[3330]142  // Methods to change the Path (initialisation)
[3332]143  void workOn(unsigned int trackID);
[7221]144  void workOnS(const std::string& trackName);
[3836]145
[4836]146  /** \see setCurveType(CurveType curveType, TrackElement* trackElem); @param curveType the type of the Curve */
[3522]147  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);};
[3433]148  void setCurveType(CurveType curveType, TrackElement* trackElem);
[4496]149  void setDuration(float duration);
150  void setDuration(float duration, TrackElement* trackElem);
151  void addPoint(float x, float y, float z);
152  void addPointV(Vector newPoint, TrackElement* trackElem = NULL);
[4509]153  void addHotPoint(float x, float y, float z);
154  int addHotPointV(Vector newPoint, TrackElement* trackElem = NULL);
[7221]155  void setSavePointS(const std::string& nextElementName);
[4502]156  void setSavePoint(TrackElement* trackElem = NULL);
[3332]157  void fork(unsigned int count, ...);
[4220]158  void forkS(unsigned int count, ...);
[7221]159  void forkS(const std::string& forkString);
[4220]160  void forkV(unsigned int count, int* trackIDs, char** trackNames, TrackElement* trackElem = NULL);
[3837]161  void condition(unsigned int trackID, CONDITION cond, void* subject);
162  void condition(CONDITION cond, void* subject, TrackElement* trackElem = NULL);
[3332]163  void join(unsigned int count, ...);
[7221]164  void joinS(const std::string& joinString);
[4220]165  void joinS(unsigned int cound, ...);
[3332]166  void joinV(unsigned int count, int* trackIDs);
[4746]167  void finalize();
[3311]168
[3330]169  // Methods to calculate the position on the Path (runtime)
[4746]170  inline Vector calcPos() const;
171  inline Vector calcDir() const;
172  float getWidth() const;
[3330]173  void tick(float dt);
[3331]174  void jumpTo(float time);
[3522]175  inline int choosePath(TrackElement* trackElem);
[3311]176
[3433]177  void setBindSlave(PNode* bindSlave);
[4746]178  PNode* getTrackNode();
[3433]179
[3350]180  // DEBUG //
181  void drawGraph(float dt) const;
182  void debug(unsigned int level) const;
[4489]183
184 private:
[4746]185  TrackManager();
[4489]186  void initChildren(unsigned int childCount, TrackElement* trackElem = NULL);
187
188 private:
189  static TrackManager* singletonRef;           //!< There may only be one TrackManager.
190
191  TrackElement*        firstTrackElem;         //!< The first TrackElement that exists.
192  TrackElement*        currentTrackElem;       //!< The TrackElement we are working on.
193  CurveType            curveType;              //!< The CurveType the entire TrackSystem will have.
194  float                localTime;              //!< The time that has been passed since the traveling the Track.
195  float                maxTime;                //!< The maximal time the track has.
196  int                  trackElemCount;         //!< The count of TrackElements that exist.
197
198  // external
199  PNode*               bindSlave;              //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself.
200  PNode*               trackNode;              //!< The main TrackNode of this Track.
201  Text*                trackText;              //!< The text to display when switching between Worlds.
202  tAnimation<Text>*    textAnimation;          //!< An Animation for the Text. (for fading it out on trackName-change)
[3311]203};
204
205#endif /* _TRACK_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.