Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3522 in orxonox.OLD for orxonox/trunk/src/track_manager.cc


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.