Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/track_manager.cc @ 3591

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

orxonox/trunk: debug.h some cleanup

File size: 23.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_TRACK_MANAGER
17
18#include "track_manager.h"
19
20#include "p_node.h"
21
22#include "track_node.h"
23
24#include <stdarg.h>
25
26using namespace std;
27
28/**
29   \brief initializes a TrackElement (sets the default values)
30*/
31TrackElement::TrackElement(void)
32{
33  this->isFresh = true;
34  this->isHotPoint = false;
35  this->isSavePoint = false;
36  this->isFork = false;
37  this->isJoined = false;
38  this->mainJoin = false;
39  this->ID = -1;
40  this->startingTime = 0;
41  this->duration = TMAN_DEFAULT_DURATION;
42  this->endTime = 1;
43  this->jumpTime = 0;
44  this->nodeCount = 0;
45  this->childCount = 0;
46  this->name = NULL;
47  this->curve = NULL;
48  this->children = NULL;
49
50  this->history = NULL;
51
52  this->condFunc = &TrackElement::random;
53}
54
55/**
56    \brief destroys all alocated memory)
57    \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements
58*/
59TrackElement::~TrackElement(void)
60{
61  if (this->name)
62    delete []name;
63  if (this->curve)
64    delete this->curve;
65  if ((!this->isJoined &&this->childCount > 0) || (this->isJoined && this->mainJoin))
66    {
67      for (int i=0; i < this->childCount; i++)
68        delete this->children[i];
69      delete this->children;
70    }
71}
72
73/**
74   \brief Searches through all the TrackElements for trackID.
75   \param trackID The ID to search for.
76   \returns The TrackElement if Found, NULL otherwise.
77   
78   \todo make this more modular, to search for different things
79*/
80TrackElement* TrackElement::findByID(unsigned int trackID)
81{
82  // return if Found.
83  if (this->ID == trackID)
84    return this;
85  // search on.
86  if (this->childCount > 0)
87    for (int i=0; i < this->childCount; i++)
88      {
89        TrackElement* tmpElem;
90        if ((tmpElem = this->children[i]->findByID(trackID)))
91          return tmpElem;
92      }
93  else return NULL;
94}
95
96
97/**
98   \brief checks if there are any BackLoops in the Track
99   \param trackElem the trackElement to check about
100   it simply does this by looking if the current trackElem is found again somewhere else in the Track
101*/
102bool TrackElement::backLoopCheck(TrackElement* trackElem)
103{
104  if (this->childCount == 0)
105    return true;
106  else
107    {
108      for (int i = 0; i < this->childCount; i++)
109        if(!this->children[i]->backLoopCheck(trackElem))
110          return false;
111     
112      return true;
113    }
114}
115
116/**
117   \param name the Name to set.
118*/
119void TrackElement::setName(const char* name)
120{
121  //  delete the old name
122  if (this->name)
123    delete []this->name;
124  // if a name was given already.
125  if (name)
126    {
127      this->name = new char[strlen(name)+1];
128      strcpy(this->name, name);
129    }
130  else 
131    this->name = NULL;
132}
133
134/**
135   \returns The name of this TrackElement
136*/
137char* TrackElement::getName(void) const
138{
139  return this->name;
140}
141
142
143/**
144   \brief CONDITION that chooses the first child for the decision (static)
145   \param nothing Nothing in this function
146   \returns the chosen child
147*/
148int TrackElement::lowest(void* nothing)
149{
150  return 0;
151}
152
153/**
154   \brief CONDITION that chooses the last child for the decision (static)
155   \param nothing Nothing in this function
156   \returns the chosen child
157*/
158int TrackElement::highest(void* nothing)
159{ 
160  return this->childCount-1;
161}
162
163/**
164   \brief CONDITION that chooses a random child for the decision (static)
165   \param nothing Nothing in this function
166   \returns the chosen child
167*/
168int TrackElement::random(void* nothing)
169{
170  int i = (int)floor ((float)rand()/(float)RAND_MAX * (float)this->childCount);
171  if (i >= this->childCount)
172    return this->childCount-1;
173  else 
174    return i;
175}
176
177/**
178   \brief CONDITION that chooses child 0, if the node(probably Player)
179   is left of its parent (z<0)) and 1/right otherwise.
180   \param node The node to act upon.
181   \returns the chosen child
182*/
183int TrackElement::leftRight(void* node)
184{
185  PNode* tmpNode = (PNode*)node;
186
187  if (tmpNode->getRelCoor().z < 0)
188    return 0;
189  else 
190    return 1;
191}
192
193
194/**
195   \brief CONDITION that chooses the child, that has the nearest distance to the node (probably player).
196   \param node The node to act upon.
197   \returns the chosen child
198
199   This is rather dangerous, because one must carefully set the points on the curve.
200   The best Way is to set the nodes as wide away of each other as possible,
201   but take into consideration, that if the nodes are to far from a center node, the center will be chosen.
202   (play with this!!).
203*/
204int TrackElement::nearest(void* node)
205{
206  PNode* tmpNode = (PNode*)node;
207
208  Vector nodeRelCoord = tmpNode->getRelCoor();
209  float minDist = 100000000;
210  int nodeNumber = 0;
211  for (int i = 0; i < this->childCount; i++)
212    {
213      float dist = (nodeRelCoord - this->children[i]->curve->getNode(4)).len();
214      if (dist < minDist)
215        {
216          minDist = dist;
217          nodeNumber = i;
218        }
219    }
220  PRINTF(3)("PathDecision with nearest algorithm: %d\n", nodeNumber);
221  return nodeNumber;
222}
223
224
225
226/////////////////////////////////////
227///// TRACKMANAGER //////////////////
228/////////////////////////////////////
229/**
230   \brief standard constructor
231
232*/
233TrackManager::TrackManager(void)
234{
235  this->setClassName ("TrackManager");
236 
237  singletonRef = this;
238
239  PRINTF(3)("Initializing the TrackManager\n");
240  this->firstTrackElem = new TrackElement();
241  this->firstTrackElem->ID = 1;
242  this->currentTrackElem = firstTrackElem;
243  this->localTime = 0;
244  this->maxTime = 0;
245  this->trackElemCount = 1;
246  this->bindSlave = this->trackNode = new TrackNode();
247}
248
249
250/**
251   \brief standard destructor
252*/
253TrackManager::~TrackManager(void)
254{
255  PRINTF(3)("Destruct TrackManager\n");
256
257  PRINTF(3)("Deleting all the TrackElements\n");
258  delete this->firstTrackElem;
259
260  // we do not have a TrackManager anymore
261  singletonRef = NULL;
262}
263
264//! Singleton Reference to TrackManager
265TrackManager* TrackManager::singletonRef = NULL;
266
267/**
268   \returns The reference on the TrackManager.
269
270   If the TrackManager does not exist, it will be created.
271*/
272TrackManager* TrackManager::getInstance(void) 
273{
274  if (!singletonRef)
275    singletonRef = new TrackManager();
276  return singletonRef;
277}
278
279/**
280   \brief reserves Space for childCount children
281   \param childCount The Count of children to make space for.
282*/
283void TrackManager::initChildren(unsigned int childCount)
284{
285  this->currentTrackElem->childCount = childCount;
286  this->currentTrackElem->mainJoin = true;
287  this->currentTrackElem->children = new TrackElement*[childCount];
288  for (int i=0; i<childCount; i++)
289    {
290      this->currentTrackElem->children[i] = new TrackElement();
291      this->currentTrackElem->children[i]->ID = ++trackElemCount;
292      this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
293      this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->children[i]);
294    }
295  if (childCount == 1)
296    this->currentTrackElem->children[0]->setName(this->currentTrackElem->getName());
297}
298
299/**
300   \brief Searches for a given trackID.
301   \param trackID the trackID to search for.
302   \returns The TrackElement #trackID if found, NULL otherwise.
303*/
304TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const
305{
306  return firstTrackElem->findByID(trackID);
307}
308
309// INITIALIZE //
310
311/**
312   \brief Sets the trackID we are working on.
313   \param trackID the trackID we are working on
314*/
315void TrackManager::workOn(unsigned int trackID)
316{
317  TrackElement* tmpElem = findTrackElementByID(trackID);
318  if (tmpElem)
319    this->currentTrackElem = tmpElem;
320  else
321    printf("TrackElement not Found, leaving unchanged\n");
322  printf("now Working on %d\n", this->currentTrackElem->ID);
323
324}
325
326/**
327   \brief Sets the Type of the Curve
328   \param curveType The Type to set
329   \param trackElem the TrackElement that should get a new Curve.
330*/
331void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem)
332{
333  if (!trackElem->isFresh)
334    {
335      PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n");
336      return;
337    }
338  this->curveType = curveType;
339  switch (curveType)
340    {
341    case BEZIERCURVE:
342      trackElem->curve = new BezierCurve();
343      break;
344    case UPOINTCURVE:
345      trackElem->curve = new UPointCurve();
346      break;
347    }
348}
349
350/**
351   \brief Sets the duration of the current path in seconds.
352   \param time The duration in seconds.
353*/
354
355void TrackManager::setDuration(float time)
356{
357  this->currentTrackElem->duration = time;
358  this->currentTrackElem->endTime = this->currentTrackElem->startingTime + time;
359}
360
361/**
362   \brief adds a point to the current TrackElement
363   \param newPoint The point to add.
364*/
365bool TrackManager::addPoint(Vector newPoint)
366{
367  return this->addPoint(newPoint, this->currentTrackElem);
368}
369
370/**
371   \brief adds a point to trackElem
372   \param newPoint The point to add.
373   \param trackElem The TrackElement to add the Point to
374*/
375bool TrackManager::addPoint(Vector newPoint, TrackElement* trackElem)
376{
377  if (trackElem->isFresh)
378    {
379      this->setCurveType(TMAN_DEFAULT_CURVETYPE, trackElem);
380      trackElem->isFresh = false;
381    }
382  trackElem->curve->addNode(newPoint);
383  trackElem->nodeCount++;
384}
385
386/**
387   \brief adds save/splitpoint.
388   \param newPoint The point to add.
389   \returns A Pointer to a newly appended Curve
390*/
391int TrackManager::addHotPoint(Vector newPoint)
392{
393  printf("setting up a HotPoint\n");
394  if (this->currentTrackElem->isFresh)
395    {
396      this->setCurveType(BEZIERCURVE);
397      this->currentTrackElem->isFresh = false;
398    }
399
400  // \todo HotPoint Handling.
401  this->currentTrackElem->curve->addNode(newPoint);
402  this->currentTrackElem->nodeCount++;
403  this->initChildren(1);
404  this->currentTrackElem = this->currentTrackElem->children[0];
405}
406
407/**
408   \brief Sets the last HotPoint into a savePoint.
409   \returns A Pointer to a newly appended Curve
410   
411   If no HotPoint was defined the last added Point will be rendered into a savePoint. \n
412   If the HotPoint was defined as a fork the Point will \b not be set into a savePoint.
413*/
414int TrackManager::setSavePoint(void)
415{
416  printf("setting up a SavePoint.\n");
417  if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint)
418    return this->currentTrackElem->children[1]->ID;
419  this->currentTrackElem->isSavePoint = true;
420  this->currentTrackElem->isHotPoint = true;
421
422  this->initChildren(1);
423  this->currentTrackElem = this->currentTrackElem->children[0];
424}
425
426/**
427   \brief adds some interessting non-linear movments through the level.
428   \param count The Count of childrens the current HotPoint will have.
429
430   If no HotPoint was defined the last added Point will be rendered into a fork. \n
431   If the HotPoint was defined as a savePoint the Point will \b not be set into a fork.
432*/
433void TrackManager::fork(unsigned int count, ...)
434{
435  int* trackIDs = new int[count];
436  this->forkV(count, trackIDs);
437  va_list ID;
438  va_start (ID, count);
439  for(int i = 0; i < count; i++)
440    {
441      *va_arg (ID, int*) = trackIDs[i];
442    }
443  va_end(ID); 
444  delete []trackIDs;
445}
446
447/**
448   \brief adds some interessting non-linear movments through the level.
449   \param count The Count of childrens the current HotPoint will have.
450   \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this).
451
452   \see void TrackManager::fork(int count, ...)
453
454   \todo initialisation is wrong!! also in setSavePoint.
455*/
456void TrackManager::forkV(unsigned int count, int* trackIDs)
457{
458  printf("Forking with %d children\n", count);
459  if (this->currentTrackElem->isSavePoint)
460    return;
461  this->currentTrackElem->isFork = true;
462  this->currentTrackElem->isHotPoint = true;
463  for(int i = 0; i < count; i++)
464    trackIDs[i]=this->trackElemCount+1+i;
465  this->initChildren(count);
466}
467
468/**
469   \brief decides under what condition a certain Path will be chosen.
470   \param cond the CONDITION of the decision
471   \param subject the Subject that will be decided upon with CONDITION cond.
472*/
473void TrackManager::condition(CONDITION cond, void* subject)
474{
475  this->condition(this->currentTrackElem->ID, cond, subject);
476}
477/**
478   \brief decides under what condition a certain Path will be chosen.
479   \param groupID the ID on which to choose the preceding move
480   \param cond the CONDITION of the decision
481   \param subject the Subject that will be decided upon with CONDITION cond.
482*/
483void TrackManager::condition(unsigned int groupID, CONDITION cond, void* subject)
484{
485  TrackElement* tmpElem = this->findTrackElementByID(groupID);
486 
487  switch (cond)
488    {
489    case LOWEST:
490      tmpElem->condFunc = &TrackElement::lowest;
491      break;
492    case HIGHEST:
493      tmpElem->condFunc = &TrackElement::highest;
494      break;
495    case RANDOM: 
496      tmpElem->condFunc = &TrackElement::random;
497      break;
498    case LEFTRIGHT:
499      tmpElem->condFunc = &TrackElement::leftRight;
500      break;
501    case NEAREST:
502      tmpElem->condFunc = &TrackElement::nearest;
503      break;
504    case ENEMYKILLED:
505      break;
506    }
507  tmpElem->subject=subject;
508}
509
510
511/**
512   \brief joins some tracks together again.
513   \param count The count of Paths to join.
514
515   Join will set the localTime to the longest time a Path has to get to this Point. \n
516   Join will join all curves to the first curve, meaning that all the tangents will be matched.
517*/
518void TrackManager::join(unsigned int count, ...)
519{
520  int* trackIDs = new int [count];
521  va_list ID;
522  va_start (ID, count);
523  for(int i = 0; i < count; i++)
524    {
525      trackIDs[i] = va_arg (ID, int);
526    }
527  va_end(ID);
528  this->joinV(count, trackIDs);
529  delete []trackIDs;
530}
531
532/**
533   \brief joins some tracks together again.
534   \param count The count of Paths to join.
535   \param trackIDs an Array with the trackID's to join
536
537   \see void TrackManager::join(int count, ...)
538*/
539void TrackManager::joinV(unsigned int count, int* trackIDs)
540{
541  printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
542
543  // checking if there is a back-loop-connection and ERROR if it is.
544  TrackElement* tmpTrackElem = this->findTrackElementByID(trackIDs[0]);
545  if (!tmpTrackElem->backLoopCheck(tmpTrackElem))
546    PRINTF(1)("Backloop connection detected at joining trackElements\n");
547
548  // chanching work-on to temporary value. going back at the end.
549  int tmpCurrentWorkingID = this->currentTrackElem->ID;
550  this->workOn(trackIDs[0]);
551  TrackElement* firstJoint = this->currentTrackElem;
552  float tmpLatestTime = firstJoint->endTime;
553
554  Vector tmpEndPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount());
555  Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1);
556  Vector tmpc2Point = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-2);
557  firstJoint->isJoined = true;
558  //  firstJoint->mainJoin = true;
559  if(!firstJoint->isHotPoint)
560    this->setSavePoint();
561  // Timing:
562  for (int i = 0; i < count; i++)
563    {
564      TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
565      if (tmpJoinElem->childCount == 0
566          && tmpJoinElem->endTime > tmpLatestTime)
567        tmpLatestTime = tmpJoinElem->endTime;
568    }
569  // time the main Join.
570  firstJoint->jumpTime = tmpLatestTime - firstJoint->endTime;
571 
572  // Joining:
573  for (int i = 1; i < count; i++)
574    {
575      TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
576      if (tmpJoinElem->childCount > 0)
577        printf("!!This Curve has children, and as such will not be joined!!\n You can try joining other childless TrackElements to this one!");
578      else
579        {
580          this->addPoint(tmpc2Point, tmpJoinElem);
581          this->addPoint(tmpTangentPoint, tmpJoinElem);
582          this->addPoint(tmpEndPoint, tmpJoinElem);
583          // time all other Joins
584          tmpJoinElem->jumpTime = tmpLatestTime - tmpJoinElem->endTime;
585         
586          //Copying Joint-Info
587          tmpJoinElem->children = firstJoint->children;
588          tmpJoinElem->childCount = firstJoint->childCount;
589          tmpJoinElem->isSavePoint = firstJoint->isSavePoint;
590          tmpJoinElem->isFork = firstJoint->isFork;
591
592          tmpJoinElem->isJoined = true;
593        }
594    }
595  if(firstJoint->childCount > 0)
596    for(int i = 0; i < firstJoint->childCount; i++)
597      {
598        printf("Setting startingTime of %d to %f.\n", firstJoint->children[i]->ID, tmpLatestTime);
599        firstJoint->children[i]->startingTime = tmpLatestTime;
600        firstJoint->children[i]->endTime = tmpLatestTime+firstJoint->children[i]->duration;
601      } 
602
603  // returning to the TrackElement we were working on.
604  this->workOn(tmpCurrentWorkingID);
605}
606
607/**
608   \brief finalizes the TrackSystem. after this it will not be editable anymore
609
610   \todo check for any inconsistencies, output errors
611*/
612void TrackManager::finalize(void)
613{
614  for (int i = 1; i<= trackElemCount ;i++)
615    {
616      TrackElement* tmpElem = findTrackElementByID(i);
617      if (tmpElem->childCount>0 && tmpElem->mainJoin)
618        {
619          for (int j = 0; j < tmpElem->childCount; j++)
620            {
621             
622              // c1-continuity
623              tmpElem->children[j]->curve->addNode(tmpElem->children[j]->curve->getNode(0) +
624                                                   ((tmpElem->children[j]->curve->getNode(0) - 
625                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
626                                                    ),2);
627              tmpElem->children[j]->nodeCount++;
628              // c2-continuity
629              tmpElem->children[j]->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
630                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
631                                                   tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
632              tmpElem->children[j]->nodeCount++;                                                   
633              printf("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
634                     tmpElem->ID, tmpElem->nodeCount,
635                     tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
636                     tmpElem->children[j]->ID, tmpElem->children[j]->nodeCount,
637                     tmpElem->children[j]->curve->calcAcc(0).x, tmpElem->children[j]->curve->calcAcc(0).y, tmpElem->children[j]->curve->calcAcc(0).z);
638            }
639        }
640    }
641}
642
643
644// RUNTIME //
645
646/**
647   \brief calculates the Position for the localTime of the Track.
648   \returns the calculated Position
649*/
650Vector TrackManager::calcPos() const
651{
652  //  PRINTF(0)("TrackElement:%d, localTime: %f\n",this->currentTrackElem->ID, this->localTime);
653  return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
654}
655
656/**
657   \brief calculates the Rotation for the localTime of the Track.
658   \returns the calculated Rotation
659*/
660Vector TrackManager::calcDir() const
661{
662  return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
663}
664
665/**
666   \brief Advances the local-time of the Track around dt
667   \param dt The time about which to advance.
668
669   This function also checks, if the TrackElement has to be changed.
670*/
671void TrackManager::tick(float dt)
672{
673  dt /= 1000;
674  PRINTF(4)("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);
675  if (this->localTime <= this->firstTrackElem->duration)
676    this->jumpTo(this->localTime);
677  this->localTime += dt;
678  if (this->localTime > this->currentTrackElem->endTime
679      && this->currentTrackElem->children)
680    {
681      if (this->currentTrackElem->jumpTime != 0.0)
682        this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
683      // jump to the next TrackElement and also set the history of the new Element to the old one.
684      TrackElement* tmpHistoryElem = this->currentTrackElem;
685      this->currentTrackElem = this->currentTrackElem->children[this->choosePath(this->currentTrackElem)];
686      this->currentTrackElem->history = tmpHistoryElem;
687    }
688  if (this->bindSlave)
689    {
690      Vector tmp = this->calcPos();
691      Quaternion quat = Quaternion(this->calcDir(), Vector(this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).x,1,this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).z)); 
692
693      Vector v(0.0, 1.0, 0.0);
694      Quaternion q(-PI/2, v);
695      quat = quat * q;
696
697      this->bindSlave->setAbsCoor(&tmp);
698      this->bindSlave->setAbsDir(&quat);
699    }
700}
701
702/**
703   \brief Jumps to a certain point on the Track.
704   \param time The time on the Track to jump to.
705
706   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.)
707   Max is trackLengthMax.
708*/
709void TrackManager::jumpTo(float time)
710{
711  if (time == 0)
712    this->currentTrackElem = this->firstTrackElem;
713  this->localTime = time;
714}
715
716/**
717   \brief a Function that decides which Path we should follow.
718   \param trackElem The Path to choose.
719   
720*/
721int TrackManager::choosePath(TrackElement* trackElem)
722{
723  return (trackElem->*(trackElem->condFunc))(trackElem->subject);
724}
725
726/**
727   \brief Sets the PNode, that should be moved along the Tack
728   \param bindSlave the PNode to set
729*/
730void TrackManager::setBindSlave(PNode* bindSlave)
731{
732  this->bindSlave = bindSlave;
733}
734
735/**
736   \returns the main TrackNode
737*/
738PNode* TrackManager::getTrackNode(void)
739{
740  return this->trackNode;
741}
742
743// DEBUG //
744
745/**
746   \brief Imports a model of the Graph into the OpenGL-environment.
747   \param dt The Iterator used in seconds for Painting the Graph.
748
749   This is for testing facility only. Do this if you want to see the Path inside the Level.
750   eventually this will all be packed into a gl-list.
751*/
752void TrackManager::drawGraph(float dt) const
753{
754
755  for (int i = 1; i <= trackElemCount; i++)
756    {
757      glBegin(GL_LINE_STRIP);
758      TrackElement* tmpElem = this->findTrackElementByID(i);
759      if (tmpElem->curve)
760        for(float f = 0.0; f < 1.0; f+=dt)
761          {
762            //      printf("%f, %f, %f\n",trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z);
763            Vector tmpVector = tmpElem->curve->calcPos(f);
764            glVertex3f(tmpVector.x, tmpVector.y, tmpVector.z);
765          }
766  glEnd();
767    }
768}
769
770/**
771   \brief outputs debug information about the trackManager
772   \param level how much debug
773*/
774void TrackManager::debug(unsigned int level) const
775{
776  PRINT(0)("=========================================\n");
777  PRINT(0)("= CLASS TRACKMANAGER::debug information =\n");
778  PRINT(0)("=========================================\n");
779  //  PRINT(0)("Status is: %
780  PRINT(0)(" Consists of %d elements\n", this->trackElemCount);
781  PRINT(0)(" localTime is: %f\n", this->localTime);
782  if (level >= 2)
783    {
784      for (int i = 1; i <= trackElemCount; i++)
785        {
786          TrackElement* tmpElem = this->findTrackElementByID(i);
787          PRINT(0)("--== TrackElement:%i ==--", tmpElem->ID);
788          if(tmpElem->getName())
789            PRINT(0)("Name: %s::", tmpElem->getName());
790          if(tmpElem->isFresh)
791            PRINT(0)("  -- has not jet eddited in any way --\n");
792          PRINT(0)("\n   TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);
793          PRINT(0)("   consists of %d Points\n", tmpElem->nodeCount);
794          if (tmpElem->childCount == 0)
795            PRINT(0)("   has no child\n");
796          else if (tmpElem->childCount == 1)
797            PRINT(0)("   has 1 child: =%d=\n", tmpElem->children[0]->ID);
798          else if (tmpElem->childCount > 1)
799            {
800              PRINT(0)("   has %d children: ", tmpElem->childCount);
801              for(int i = 0; i < tmpElem->childCount; i++)
802                PRINT(0)("=%d= ", tmpElem->children[i]->ID);
803              PRINT(0)("\n");
804            }
805
806          if(tmpElem->isHotPoint)
807            PRINT(0)("   is a special Point:\n");
808          if(tmpElem->isSavePoint)
809            PRINT(0)("    is a SavePoint\n");
810          if(tmpElem->isFork)
811            {
812              PRINT(0)("    is A Fork with with %d children.\n", tmpElem->childCount);
813            }
814          if(tmpElem->isJoined)
815            PRINT(0)("   is Joined at the End\n");
816
817          if(!tmpElem->backLoopCheck(tmpElem)) /* this should not happen */
818            PRINT(2)(" THERE IS A BACKLOOP TO THIS ELEMENT\n");
819        }
820    }
821  PRINT(0)("-----------------------------------------\n");
822}
Note: See TracBrowser for help on using the repository browser.