Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3754 was 3608, checked in by patrick, 20 years ago

orxonox/trunk: now there is a real speedup in compiling time when dependencies are modified: just realy only includes, what is needed. Byside the speedup, there is more overview! never add an orxonox class to stdincl.h if it doesn't have to be

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