Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3522 in orxonox.OLD


Ignore:
Timestamp:
Mar 13, 2005, 12:05:07 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the important files of the trackManager to the trunk
It was not anymore possible to merge.

this is not so big a problem, as I only coded inside the track_manager, track_node files. But it will be if we try to merge other branches back to the trunk

Location:
orxonox/trunk/src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r3521 r3522  
    3333                 camera.cc \
    3434                 track_manager.cc \
     35                 track_node.cc \
    3536                 light.cc \
    3637                 story_entities/story_entity.cc \
     
    7273                 message_structures.h \
    7374                 light.h \
     75                 track_manager.h \
     76                 track_node.h \
    7477                 story_entities/story_entity.h \
    7578                 story_entities/story_def.h \
  • orxonox/trunk/src/story_entities/world.cc

    r3521 r3522  
    116116      trackManager->addPoint(Vector(30,0,5));
    117117      trackManager->addPoint(Vector(40,0,5));
    118       trackManager->setDuration(2);
    119       trackManager->setSavePoint();
    120       trackManager->addPoint(Vector(50,10,10));
    121       trackManager->addPoint(Vector(60,0, 10));
    122       trackManager->addPoint(Vector(70,0, 10));
    123       trackManager->addPoint(Vector(80,0,-10));
    124       trackManager->addPoint(Vector(90,0,-10));
     118      trackManager->setDuration(4);
     119      int fork11, fork12, fork13;
     120      trackManager->fork(3, &fork11, &fork12, &fork13);
     121      trackManager->workOn(fork11);
     122      trackManager->addPoint(Vector(70, 0, -10));
     123      trackManager->addPoint(Vector(100, 0, -15));
     124      trackManager->addPoint(Vector(300, 0, -15));
     125      trackManager->setDuration(10);
     126      trackManager->workOn(fork12);
     127      trackManager->addPoint(Vector(70,  0, 0));
     128      trackManager->addPoint(Vector(100, 0, 0));
     129      trackManager->addPoint(Vector(120,10, 0));
     130      trackManager->addPoint(Vector(150,10, 0));
     131      trackManager->addPoint(Vector(180,15, 0));
     132      trackManager->addPoint(Vector(200,10, 0));
     133      trackManager->setDuration(7);
     134      trackManager->workOn(fork13);
     135      trackManager->addPoint(Vector(70,  0, 10));
     136      trackManager->addPoint(Vector(100, 0, 30));
     137      trackManager->addPoint(Vector(120,-10, 30));
     138      trackManager->addPoint(Vector(150,-10, 30));
     139      trackManager->setDuration(10);
     140      trackManager->join(2, fork12, fork13);
     141
     142      trackManager->workOn(5);
     143      trackManager->addPoint(Vector(250, 20, 10));
     144      trackManager->addPoint(Vector(290, 20, 10));
    125145      trackManager->setDuration(5);
    126146      trackManager->setSavePoint();
    127       trackManager->addPoint(Vector(110,0,5));
    128       trackManager->addPoint(Vector(120,0, 10));
    129       trackManager->addPoint(Vector(130,0, 10));
    130       trackManager->addPoint(Vector(140,0,-10));
    131       trackManager->addPoint(Vector(150,0,-10));
    132       trackManager->setDuration(3);
    133       int fork11, fork12, fork13, fork14;
    134       trackManager->fork(4, &fork11, &fork12, &fork13, &fork14);
    135       trackManager->workOn(fork11);
    136       trackManager->addPoint(Vector(170, 0, -15));
    137       trackManager->addPoint(Vector(180, 0, -15));
    138       trackManager->setDuration(3);
    139       trackManager->workOn(fork12);
    140       trackManager->addPoint(Vector(170, 0, 10));
    141       trackManager->addPoint(Vector(180, 0, 10));
    142       trackManager->addPoint(Vector(190,2,5));
    143       trackManager->addPoint(Vector(200,2,5));
    144       trackManager->setDuration(7);
    145       int fork21, fork22;
    146       trackManager->fork(2, &fork21, &fork22);
    147       trackManager->workOn(fork21);
    148       trackManager->addPoint(Vector(220, 10,-10));
    149       trackManager->addPoint(Vector(230, 0,-10));
    150       trackManager->addPoint(Vector(240, 0, 2));
    151       trackManager->addPoint(Vector(250, 0, 0));
    152       trackManager->addPoint(Vector(260, 0, 5));
    153       trackManager->setDuration(3);
    154       trackManager->join(2, fork12, fork11);
    155       trackManager->workOn(fork22);
    156       trackManager->addPoint(Vector(220, -10,10));
    157       trackManager->addPoint(Vector(230, 0, 10));
    158       trackManager->addPoint(Vector(240, 0, 10));
    159       trackManager->addPoint(Vector(250, 0, 5));
    160       trackManager->setDuration(6);
    161       trackManager->workOn(fork13);
    162       trackManager->addPoint(Vector(200,-10,5));
    163       trackManager->addPoint(Vector(250,-10,5));
    164       trackManager->setDuration(3);
    165       trackManager->workOn(fork14);
    166       trackManager->addPoint(Vector(200,15,0));
    167       trackManager->addPoint(Vector(210,0,10));
    168       trackManager->setDuration(1);
    169       trackManager->join(4, fork21, fork22, fork13, fork14);
    170       trackManager->workOn(10);
    171       trackManager->addPoint(Vector(250,-10,5));
    172       trackManager->addPoint(Vector(260,-10,5));
     147      trackManager->addPoint(Vector(350, 20, 10));
     148      trackManager->addPoint(Vector(360, 20, 10));
     149      trackManager->addPoint(Vector(370, 20, 10));
     150      trackManager->setDuration(5);
     151
     152      trackManager->join(2, 6, fork11);
     153
    173154      trackManager->finalize();
     155
    174156     
    175157      /*monitor progress*/
     
    249231            this->glmis->step();
    250232
     233            trackManager->setBindSlave(env);
     234            trackManager->condition(1, NEAREST, myPlayer);
     235
    251236            break;
    252237          }
  • orxonox/trunk/src/track_manager.cc

    r3495 r3522  
    2020
    2121#include <stdarg.h>
     22#include "p_node.h"
    2223
    2324using namespace std;
     
    3435  this->isJoined = false;
    3536  this->mainJoin = false;
    36   this->cond; //!< todo think!!
    3737  this->ID = -1;
    3838  this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager.
     
    4646  this->curve = NULL;
    4747  this->children = NULL;
     48  this->condFunc = &TrackElement::random;
    4849}
    4950
     
    9091
    9192
     93/**
     94   \brief checks if there are any BackLoops in the Track
     95   \param trackElem the trackElement to check about
     96   it simply does this by looking if the current trackElem is found again somewhere else in the Track
     97*/
     98bool TrackElement::backLoopCheck(TrackElement* trackElem)
     99{
     100  if (this->childCount == 0)
     101    return true;
     102  else
     103    {
     104      for (int i = 0; i < this->childCount; i++)
     105        if(!this->children[i]->backLoopCheck(trackElem))
     106          return false;
     107     
     108      return true;
     109    }
     110}
     111
     112/**
     113   \brief CONDITION that chooses the first child for the decision (static)
     114   \param nothing Nothing in this function
     115   \returns the chosen child
     116*/
     117int TrackElement::lowest(void* nothing)
     118{
     119  return 0;
     120}
     121
     122/**
     123   \brief CONDITION that chooses the last child for the decision (static)
     124   \param nothing Nothing in this function
     125   \returns the chosen child
     126*/
     127int TrackElement::highest(void* nothing)
     128{
     129  return this->childCount-1;
     130}
     131
     132/**
     133   \brief CONDITION that chooses a random child for the decision (static)
     134   \param nothing Nothing in this function
     135   \returns the chosen child
     136*/
     137int TrackElement::random(void* nothing)
     138{
     139  int i = (int)floor ((float)rand()/(float)RAND_MAX * (float)this->childCount);
     140  if (i >= this->childCount)
     141    return this->childCount-1;
     142  else
     143    return i;
     144}
     145
     146/**
     147   \brief CONDITION that chooses child 0, if the node(probably Player)
     148   is left of its parent (z<0)) and 1/right otherwise.
     149   \param node The node to act upon.
     150   \returns the chosen child
     151*/
     152int TrackElement::leftRight(void* node)
     153{
     154  PNode* tmpNode = (PNode*)node;
     155
     156  if (tmpNode->getRelCoor().z < 0)
     157    return 0;
     158  else
     159    return 1;
     160}
     161
     162
     163/**
     164   \brief CONDITION that chooses the child, that has the nearest distance to the node (probably player).
     165   \param node The node to act upon.
     166   \returns the chosen child
     167
     168   This is rather dangerous, because one must carefully set the points on the curve.
     169   The best Way is to set the nodes as wide away of each other as possible,
     170   but take into consideration, that if the nodes are to far from a center node, the center will be chosen.
     171   (play with this!!).
     172*/
     173int TrackElement::nearest(void* node)
     174{
     175  PNode* tmpNode = (PNode*)node;
     176
     177  Vector nodeRelCoord = tmpNode->getRelCoor();
     178  float minDist = 100000000;
     179  int nodeNumber = 0;
     180  for (int i = 0; i < this->childCount; i++)
     181    {
     182      float dist = (nodeRelCoord - this->children[i]->curve->getNode(4)).len();
     183      if (dist < minDist)
     184        {
     185          minDist = dist;
     186          nodeNumber = i;
     187        }
     188    }
     189  PRINTF(3)("PathDecision with nearest algorithm: %d\n", nodeNumber);
     190  return nodeNumber;
     191}
    92192
    93193
     
    139239TrackManager* TrackManager::getInstance(void)
    140240{
    141   if (singletonRef)
    142     return singletonRef;
     241  if (TrackManager::singletonRef)
     242    return TrackManager::singletonRef;
    143243  else
    144     return singletonRef = new TrackManager();
     244    return TrackManager::singletonRef = new TrackManager();
    145245}
    146246
     
    192292/**
    193293   \brief Sets the Type of the Curve
    194    \brief curveType The Type to set
     294   \param curveType The Type to set
     295   \param trackElem the TrackElement that should get a new Curve.
    195296*/
    196297void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem)
     
    333434/**
    334435   \brief decides under what condition a certain Path will be chosen.
     436   \param cond the CONDITION of the decision
     437   \param subject the Subject that will be decided upon with CONDITION cond.
     438*/
     439void TrackManager::condition(CONDITION cond, void* subject)
     440{
     441  this->condition(this->currentTrackElem->ID, cond, subject);
     442}
     443/**
     444   \brief decides under what condition a certain Path will be chosen.
    335445   \param groupID the ID on which to choose the preceding move
    336    \param cond \todo think about this
    337 */
    338 void TrackManager::condition(unsigned int groupID, PathCondition cond)
    339 {
     446   \param cond the CONDITION of the decision
     447   \param subject the Subject that will be decided upon with CONDITION cond.
     448*/
     449void TrackManager::condition(unsigned int groupID, CONDITION cond, void* subject)
     450{
     451  TrackElement* tmpElem = this->findTrackElementByID(groupID);
    340452 
    341 }
     453  switch (cond)
     454    {
     455    case LOWEST:
     456      tmpElem->condFunc = &TrackElement::lowest;
     457      break;
     458    case HIGHEST:
     459      tmpElem->condFunc = &TrackElement::highest;
     460      break;
     461    case RANDOM:
     462      tmpElem->condFunc = &TrackElement::random;
     463      break;
     464    case LEFTRIGHT:
     465      tmpElem->condFunc = &TrackElement::leftRight;
     466      break;
     467    case NEAREST:
     468      tmpElem->condFunc = &TrackElement::nearest;
     469      break;
     470    case ENEMYKILLED:
     471      break;
     472    }
     473  tmpElem->subject=subject;
     474}
     475
    342476
    343477/**
     
    372506{
    373507  printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
     508
     509  // checking if there is a back-loop-connection and ERROR if it is.
     510  TrackElement* tmpTrackElem = this->findTrackElementByID(trackIDs[0]);
     511  if (!tmpTrackElem->backLoopCheck(tmpTrackElem))
     512    PRINTF(1)("Backloop connection detected at joining trackElements\n");
    374513
    375514  // chanching work-on to temporary value. going back at the end.
     
    506645      && this->currentTrackElem->children)
    507646    {
    508       if (this->currentTrackElem->jumpTime > 0) 
     647      if (this->currentTrackElem->jumpTime > 0)
    509648        this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
    510       this->currentTrackElem = this->currentTrackElem->children[0];
     649      this->currentTrackElem = this->currentTrackElem->children[this->choosePath(this->currentTrackElem)];
    511650    }
    512651  if (this->bindSlave)
     
    535674/**
    536675   \brief a Function that decides which Path we should follow.
    537    \param graphID The Path to choose.
     676   \param trackElem The Path to choose.
    538677   
    539678*/
    540 void TrackManager::choosePath(int graphID)
    541 {
    542 
     679int TrackManager::choosePath(TrackElement* trackElem)
     680{
     681  return (trackElem->*(trackElem->condFunc))(trackElem->subject);
    543682}
    544683
     
    587726void TrackManager::debug(unsigned int level) const
    588727{
    589   printf("::CLASS TRACKMANAGER::debug information::\n");
    590   //  printf("Status is: %
    591   printf(" Consists of %d elements\n", this->trackElemCount);
    592   printf(" localTime is: %f\n", this->localTime);
     728  PRINT(0)("=========================================\n");
     729  PRINT(0)("= CLASS TRACKMANAGER::debug information =\n");
     730  PRINT(0)("=========================================\n");
     731  //  PRINT(0)("Status is: %
     732  PRINT(0)(" Consists of %d elements\n", this->trackElemCount);
     733  PRINT(0)(" localTime is: %f\n", this->localTime);
    593734  if (level >= 2)
    594735    {
     
    596737        {
    597738          TrackElement* tmpElem = this->findTrackElementByID(i);
    598           printf("  ::TrackElement:%i::", tmpElem->ID);
     739          PRINT(0)("--== TrackElement:%i ==--", tmpElem->ID);
    599740          if(tmpElem->name)
    600             printf("name:%s::", tmpElem->name);
     741            PRINT(0)("Name: %s::", tmpElem->name);
    601742          if(tmpElem->isFresh)
    602             printf("   has not jet eddited in any way\n");
    603           printf("\n   TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);
    604           printf("   consists of %d Points\n", tmpElem->nodeCount);
     743            PRINT(0)("  -- has not jet eddited in any way --\n");
     744          PRINT(0)("\n   TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);
     745          PRINT(0)("   consists of %d Points\n", tmpElem->nodeCount);
    605746          if (tmpElem->childCount == 0)
    606             printf("   has no child\n");           
     747            PRINT(0)("   has no child\n");
    607748          else if (tmpElem->childCount == 1)
    608             printf("   has 1 child: ==%d==\n", tmpElem->children[0]->ID);
     749            PRINT(0)("   has 1 child: =%d=\n", tmpElem->children[0]->ID);
    609750          else if (tmpElem->childCount > 1)
    610751            {
    611               printf("   has %d children: ", tmpElem->childCount);
     752              PRINT(0)("   has %d children: ", tmpElem->childCount);
    612753              for(int i = 0; i < tmpElem->childCount; i++)
    613                 printf("=%d= ", tmpElem->children[i]->ID);
    614               printf("\n");
     754                PRINT(0)("=%d= ", tmpElem->children[i]->ID);
     755              PRINT(0)("\n");
    615756            }
    616757
    617758          if(tmpElem->isHotPoint)
    618             printf("   is a special Point:\n");
     759            PRINT(0)("   is a special Point:\n");
    619760          if(tmpElem->isSavePoint)
    620             printf("    is a SavePoint\n");
     761            PRINT(0)("    is a SavePoint\n");
    621762          if(tmpElem->isFork)
    622763            {
    623               printf("    is A Fork with with %d children.\n", tmpElem->childCount);
     764              PRINT(0)("    is A Fork with with %d children.\n", tmpElem->childCount);
    624765            }
    625766          if(tmpElem->isJoined)
    626             printf("   is Joined at the End\n");
     767            PRINT(0)("   is Joined at the End\n");
     768
     769          if(!tmpElem->backLoopCheck(tmpElem)) /* this should not happen */
     770            PRINT(2)(" THERE IS A BACKLOOP TO THIS ELEMENT\n");
    627771        }
    628772    }
    629 }
     773  PRINT(0)("-----------------------------------------\n");
     774}
  • orxonox/trunk/src/track_manager.h

    r3495 r3522  
    1717class PNode;
    1818
    19 //! condition for choosing a certain Path. \todo implement a useful way.
    20 struct PathCondition
    21 {
    22  
    23 };
    24  
    25 
    2619//! A Graph-Element, that holds the curve-structure of a Level.
    2720/**
     
    3629
    3730  TrackElement* findByID(unsigned int trackID);
     31  bool backLoopCheck(TrackElement* trackElem);
    3832
    3933  bool isFresh;              //!< If no Points where added until now
     
    4337  bool isJoined;             //!< If the End of the Curve is joined.
    4438  bool mainJoin;             //!< If the End of the Curve is joined, and this is the one Curve the others join to.
    45   PathCondition cond;        //!< The Split Condition;
    4639  int ID;                    //!< The ID of this TrackElement
    4740  float startingTime;        //!< The time at which this Track begins.
     
    5548  int childCount;            //!< The number of Children This TrackElement has.
    5649  TrackElement** children;   //!< A TrackElement can have a Tree of following TrackElements.
     50
     51  // CONDITION FUNCTIONS and STUFF
     52  void* subject;             //!< The Subject the Condition should act upon.
     53  int (TrackElement::*condFunc)(void*); //!< Pointer to the condition function
     54
     55  int lowest(void* nothing);
     56  int highest(void* nothing);
     57  int random(void* nothing);
     58
     59  int leftRight(void* node);
     60  int nearest(void* node);
     61  // todo  int enemyKilled(void* entity);
    5762};
    5863
    59 
     64//! the Condition to choose between the different ways of the game.
     65enum CONDITION {LOWEST, HIGHEST, RANDOM, LEFTRIGHT, NEAREST, ENEMYKILLED};
    6066
    6167//! The TrackManager handles the flow of the Players through the game.
     
    105111  float maxTime;                      //!< The maximal time the track has.
    106112  int trackElemCount;                 //!< The count of TrackElements that exist.
    107   PNode* bindSlave;
     113  PNode* bindSlave;                   //!< The node that is slave to the TrackManager. This node will be moved while update the TrackManager, and must NOT move itself.
    108114 
    109115  void initChildren(unsigned int childCount);
     
    117123  // Methods to change the Path (initialisation)
    118124  void workOn(unsigned int trackID);
    119   inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);}
     125  /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */
     126  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);};
    120127  void setCurveType(CurveType curveType, TrackElement* trackElem);
    121128  void setDuration(float time);
     
    126133  void fork(unsigned int count, ...);
    127134  void forkV(unsigned int count, int* trackIDs);
    128   void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!!
     135  void condition(CONDITION cond, void* subject);
     136  void condition(unsigned int groupID, CONDITION cond, void* subject);
    129137  void join(unsigned int count, ...);
    130138  void joinV(unsigned int count, int* trackIDs);
     
    132140
    133141  // Methods to calculate the position on the Path (runtime)
    134   Vector calcPos(void) const;
    135   Vector calcDir(void) const;
     142  inline Vector calcPos(void) const;
     143  inline Vector calcDir(void) const;
    136144  void tick(float dt);
    137145  void jumpTo(float time);
    138   void choosePath(int graphID);
     146  inline int choosePath(TrackElement* trackElem);
    139147
    140148  void setBindSlave(PNode* bindSlave);
Note: See TracChangeset for help on using the changeset viewer.