Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/track_manager.h @ 3605

Last change on this file since 3605 was 3596, checked in by bensch, 20 years ago

orxonox/trunk: borders for the Player, so he cannot move out of the line

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