Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/trackManager/src/track_manager.h @ 3515

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

orxonox/branches/trackManager: now ability to set LEFT-RIGHT decision for nodes

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