1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: ... |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "track_manager.h" |
---|
20 | #include <stdarg.h> |
---|
21 | |
---|
22 | |
---|
23 | using namespace std; |
---|
24 | |
---|
25 | /** |
---|
26 | \brief initializes a TrackElement (sets the default values) |
---|
27 | */ |
---|
28 | TrackElement::TrackElement(void) |
---|
29 | { |
---|
30 | this->isFresh = true; |
---|
31 | this->isSavePoint = false; |
---|
32 | this->isFork = false; |
---|
33 | this->isJoined = false; |
---|
34 | this->cond; //!< todo think!! |
---|
35 | this->ID = -1; |
---|
36 | this->length =0; |
---|
37 | this->curveType = BEZIERCURVE; |
---|
38 | this->nodeCount = 0; |
---|
39 | childCount = 0; |
---|
40 | this->name = NULL; |
---|
41 | this->curve = NULL; |
---|
42 | this->children = NULL; |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | \brief destroys all alocated memory) |
---|
47 | \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements |
---|
48 | */ |
---|
49 | TrackElement::~TrackElement(void) |
---|
50 | { |
---|
51 | if (this->name) |
---|
52 | delete []name; |
---|
53 | if (this->curve) |
---|
54 | delete this->curve; |
---|
55 | if (this->childCount > 0) |
---|
56 | { |
---|
57 | for (int i=0; i < this->childCount; i++) |
---|
58 | delete this->children[i]; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | \brief Searches through all the TrackElements for trackID. |
---|
64 | \param trackID The ID to search for. |
---|
65 | \returns The TrackElement if Found, NULL otherwise. |
---|
66 | |
---|
67 | \todo make this more modular, to search for different things |
---|
68 | */ |
---|
69 | TrackElement* TrackElement::findByID(unsigned int trackID) |
---|
70 | { |
---|
71 | // return if Found. |
---|
72 | if (this->ID == trackID) |
---|
73 | return this; |
---|
74 | // search on. |
---|
75 | if (this->childCount > 0) |
---|
76 | for (int i=0; i < this->childCount; i++) |
---|
77 | { |
---|
78 | TrackElement* tmpElem; |
---|
79 | if ((tmpElem = this->children[i]->findByID(trackID))) |
---|
80 | return tmpElem; |
---|
81 | } |
---|
82 | else return NULL; |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | ///////////////////////////////////// |
---|
90 | ///// TRACKMANAGER ////////////////// |
---|
91 | ///////////////////////////////////// |
---|
92 | /** |
---|
93 | \brief standard constructor |
---|
94 | |
---|
95 | \todo this constructor is not jet implemented - do it |
---|
96 | */ |
---|
97 | TrackManager::TrackManager () |
---|
98 | { |
---|
99 | this->setClassName ("TrackManager"); |
---|
100 | |
---|
101 | PRINTF(3)("Initializing the TrackManager\n"); |
---|
102 | this->firstTrackElem = NULL; |
---|
103 | this->currentTrackElem = firstTrackElem; |
---|
104 | this->localTime = 0; |
---|
105 | this->maxTime = 0; |
---|
106 | this->trackElemCount = 0; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | \brief standard destructor |
---|
112 | |
---|
113 | \todo this deconstructor is not jet implemented - do it |
---|
114 | */ |
---|
115 | TrackManager::~TrackManager () |
---|
116 | { |
---|
117 | PRINTF(3)("Destruct TrackManager\n"); |
---|
118 | |
---|
119 | PRINTF(3)("Deleting all the TrackElements\n"); |
---|
120 | delete this->firstTrackElem; |
---|
121 | // we do not have a TrackManager anymore |
---|
122 | singletonRef = NULL; |
---|
123 | } |
---|
124 | |
---|
125 | TrackManager* TrackManager::singletonRef = NULL; |
---|
126 | |
---|
127 | /** |
---|
128 | \returns The reference on the TrackManager. |
---|
129 | |
---|
130 | If the TrackManager does not exist, it will be created. |
---|
131 | */ |
---|
132 | TrackManager* TrackManager::getInstance(void) |
---|
133 | { |
---|
134 | if (singletonRef) |
---|
135 | return singletonRef; |
---|
136 | else |
---|
137 | return singletonRef = new TrackManager(); |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | \brief Searches for a given trackID. |
---|
142 | \param trackID the trackID to search for. |
---|
143 | \returns The TrackElement #trackID if found, NULL otherwise. |
---|
144 | */ |
---|
145 | TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const |
---|
146 | { |
---|
147 | return firstTrackElem->findByID(trackID); |
---|
148 | } |
---|
149 | |
---|
150 | // INITIALIZE // |
---|
151 | |
---|
152 | /** |
---|
153 | \brief Sets the trackID we are working on. |
---|
154 | \param trackID the trackID we are working on |
---|
155 | */ |
---|
156 | void TrackManager::workOn(unsigned int trackID) |
---|
157 | { |
---|
158 | this->currentTrackElem = findTrackElementByID(trackID); |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | \brief Sets the Type of the Curve |
---|
163 | \brief curveType The Type to set |
---|
164 | */ |
---|
165 | void TrackManager::setCurveType(CurveType curveType) |
---|
166 | { |
---|
167 | if (!this->currentTrackElem->isFresh) |
---|
168 | { |
---|
169 | PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n"); |
---|
170 | return; |
---|
171 | } |
---|
172 | this->currentTrackElem->curveType = curveType; |
---|
173 | switch (curveType) |
---|
174 | { |
---|
175 | case BEZIERCURVE: |
---|
176 | this->currentTrackElem->curve = new BezierCurve(); |
---|
177 | break; |
---|
178 | case UPOINTCURVE: |
---|
179 | this->currentTrackElem->curve = new UPointCurve(); |
---|
180 | break; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | \brief Sets the length of the current path in seconds. |
---|
186 | \param time The length in seconds. |
---|
187 | */ |
---|
188 | |
---|
189 | void TrackManager::setLength(float time) |
---|
190 | { |
---|
191 | this->currentTrackElem->length = time; |
---|
192 | } |
---|
193 | |
---|
194 | /** |
---|
195 | \brief adds a point to the current TrackElement |
---|
196 | \param newPoint The point to add. |
---|
197 | */ |
---|
198 | void TrackManager::addPoint(Vector newPoint) |
---|
199 | { |
---|
200 | if (this->currentTrackElem->isFresh) |
---|
201 | { |
---|
202 | this->setCurveType(BEZIERCURVE); |
---|
203 | this->currentTrackElem->isFresh = false; |
---|
204 | } |
---|
205 | this->currentTrackElem->curve->addNode(newPoint); |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | \brief adds save/splitpoint. |
---|
210 | \param newPoint The point to add. |
---|
211 | */ |
---|
212 | void TrackManager::addHotPoint(Vector newPoint) |
---|
213 | { |
---|
214 | if (this->currentTrackElem->isFresh) |
---|
215 | { |
---|
216 | this->setCurveType(BEZIERCURVE); |
---|
217 | this->currentTrackElem->isFresh = false; |
---|
218 | } |
---|
219 | |
---|
220 | // \todo HotPoint Handling. |
---|
221 | this->currentTrackElem->curve->addNode(newPoint); |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | \brief Sets the last HotPoint into a savePoint. |
---|
226 | |
---|
227 | If no HotPoint was defined the last added Point will be rendered into a savePoint. \n |
---|
228 | If the HotPoint was defined as a fork the Point will \b not be set into a savePoint. |
---|
229 | */ |
---|
230 | void TrackManager::setSavePoint(void) |
---|
231 | { |
---|
232 | if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint) |
---|
233 | return; |
---|
234 | this->currentTrackElem->isSavePoint = true; |
---|
235 | |
---|
236 | this->currentTrackElem->children = new TrackElement*[1]; |
---|
237 | } |
---|
238 | |
---|
239 | /** |
---|
240 | \brief adds some interessting non-linear movments through the level. |
---|
241 | \param count The Count of childrens the current HotPoint will have. |
---|
242 | |
---|
243 | If no HotPoint was defined the last added Point will be rendered into a fork. \n |
---|
244 | If the HotPoint was defined as a savePoint the Point will \b not be set into a fork. |
---|
245 | */ |
---|
246 | void TrackManager::fork(unsigned int count, ...) |
---|
247 | { |
---|
248 | int* trackIDs = new int [count]; |
---|
249 | va_list ID; |
---|
250 | va_start (ID, count); |
---|
251 | for(int i = 0; i < count; i++) |
---|
252 | { |
---|
253 | trackIDs[i] = va_arg (ID, int); |
---|
254 | } |
---|
255 | va_end(ID); |
---|
256 | this->forkV(count, trackIDs); |
---|
257 | delete []trackIDs; |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | \brief adds some interessting non-linear movments through the level. |
---|
262 | \param count The Count of childrens the current HotPoint will have. |
---|
263 | \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this). |
---|
264 | |
---|
265 | \see void TrackManager::fork(int count, ...) |
---|
266 | |
---|
267 | \todo initialisation is wrong!! also in setSavePoint. |
---|
268 | */ |
---|
269 | void TrackManager::forkV(unsigned int count, int* trackIDs) |
---|
270 | { |
---|
271 | if (this->currentTrackElem->isSavePoint) |
---|
272 | return; |
---|
273 | this->currentTrackElem->isFork = true; |
---|
274 | |
---|
275 | this->currentTrackElem->children = new TrackElement*[count]; |
---|
276 | } |
---|
277 | |
---|
278 | /** |
---|
279 | \brief decides under what condition a certain Path will be chosen. |
---|
280 | \param groupID the ID on which to choose the preceding move |
---|
281 | \param cond \todo think about this |
---|
282 | */ |
---|
283 | void TrackManager::condition(unsigned int groupID, PathCondition cond) |
---|
284 | { |
---|
285 | |
---|
286 | } |
---|
287 | |
---|
288 | /** |
---|
289 | \brief joins some tracks together again. |
---|
290 | \param count The count of Paths to join. |
---|
291 | |
---|
292 | Join will set the localTime to the longest time a Path has to get to this Point. \n |
---|
293 | Join will join all curves to the first curve. |
---|
294 | */ |
---|
295 | void TrackManager::join(unsigned int count, ...) |
---|
296 | { |
---|
297 | int* trackIDs = new int [count]; |
---|
298 | va_list ID; |
---|
299 | va_start (ID, count); |
---|
300 | for(int i = 0; i < count; i++) |
---|
301 | { |
---|
302 | trackIDs[i] = va_arg (ID, int); |
---|
303 | } |
---|
304 | va_end(ID); |
---|
305 | this->joinV(count, trackIDs); |
---|
306 | delete []trackIDs; |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | \brief joins some tracks together again. |
---|
311 | \param count The count of Paths to join. |
---|
312 | \param trackIDs an Array with the trackID's to join |
---|
313 | |
---|
314 | \see void TrackManager::join(int count, ...) |
---|
315 | */ |
---|
316 | void TrackManager::joinV(unsigned int count, int* trackIDs) |
---|
317 | { |
---|
318 | //! \todo this |
---|
319 | } |
---|
320 | |
---|
321 | // RUNTIME // |
---|
322 | |
---|
323 | /** |
---|
324 | \brief calculates the Position for the localTime of the Track. |
---|
325 | \returns the calculated Position |
---|
326 | */ |
---|
327 | Vector TrackManager::calcPos() const |
---|
328 | { |
---|
329 | |
---|
330 | } |
---|
331 | |
---|
332 | /** |
---|
333 | \brief calculates the Rotation for the localTime of the Track. |
---|
334 | \returns the calculated Rotation |
---|
335 | */ |
---|
336 | Vector TrackManager::calcDir() const |
---|
337 | { |
---|
338 | |
---|
339 | } |
---|
340 | |
---|
341 | /** |
---|
342 | \brief Advances the local-time of the Track around dt |
---|
343 | \param dt The time about which to advance. |
---|
344 | */ |
---|
345 | void TrackManager::tick(float dt) |
---|
346 | { |
---|
347 | this->localTime += dt; |
---|
348 | } |
---|
349 | |
---|
350 | /** |
---|
351 | \brief Jumps to a certain point on the Track. |
---|
352 | \param time The time on the Track to jump to. |
---|
353 | |
---|
354 | This should be used to Jump backwards on a Track, because moving forward means to change between the Path. (it then tries to choose the default.) |
---|
355 | Max is trackLengthMax. |
---|
356 | */ |
---|
357 | void TrackManager::jumpTo(float time) |
---|
358 | { |
---|
359 | localTime = time; |
---|
360 | } |
---|
361 | |
---|
362 | /** |
---|
363 | \brief a Function that decides which Path we should follow. |
---|
364 | \param graphID The Path to choose. |
---|
365 | |
---|
366 | */ |
---|
367 | void TrackManager::choosePath(int graphID) |
---|
368 | { |
---|
369 | |
---|
370 | } |
---|
371 | |
---|