Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 19, 2005, 7:45:28 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/physics: merged back the Trunk into the Physics-branche
merged with command:
svn merge -r 4178:HEAD ../trunk/ physics
no conflicts in relevant files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics/src/track_manager.cc

    r4178 r4223  
    2525#include "text_engine.h"
    2626#include "t_animation.h"
     27#include "substring.h"
    2728
    2829#include <stdarg.h>
     
    401402   \brief loads a trackElement from a TiXmlElement
    402403   \param root the TiXmlElement to load the Data from
    403 
    404404*/
    405405bool TrackManager::load( TiXmlElement* root)
    406406{
     407  TiXmlElement* element;
     408  TiXmlNode* container;
     409  double x, y, z, d;
     410       
     411  element = root->FirstChildElement();
     412       
     413  while( element != NULL)
     414    {
     415      if( !strcmp( element->Value(), "Point"))
     416        {
     417          container = element->FirstChild();
     418          if( container->ToText())
     419            {
     420              assert( container->Value() != NULL);
     421              if( sscanf( container->Value(), "%lf,%lf,%lf", &x, &y, &z) == 3)
     422                {
     423                  PRINTF(0)("Loaded Point: %lf,%lf,%lf (%s)\n", x, y, z, container->Value());
     424                  addPoint( Vector( x, y, z));
     425                }
     426              else
     427                {
     428                  PRINTF(0)("Invalid Point in Track (skipped)\n");
     429                }                       
     430            }
     431        }
     432      else if( !strcmp( element->Value(), "Duration"))
     433        {
     434          container = element->FirstChild();
     435          if( container->ToText())
     436            {
     437              assert( container->Value() != NULL);
     438              if( sscanf( container->Value(), "%lf", &d) == 1)
     439                {
     440                  PRINTF(5)("Loaded Duration: %lf (%s)\n", d, container->Value());
     441                  setDuration( d);
     442                }
     443              else
     444                {
     445                  PRINTF(2)("Invalid Duration in Track (skipped)\n");
     446                }                       
     447            }
     448        }
     449      else if( !strcmp( element->Value(), "SavePoint"))
     450        {
     451          PRINTF(5)("Loaded Savepoint\n");
     452          setSavePoint();
     453        }
     454      else if( !strcmp( element->Value(), "Fork"))
     455        {
     456          container = element->FirstChild();
     457          if( container->ToText())
     458            {
     459              assert( container->Value() != NULL);
     460              PRINTF(4)("Loaded Fork: %s\n", container->Value());
     461              forkS(container->Value());
     462            }
     463        }
     464      else if( !strcmp( element->Value(), "Join"))
     465        {
     466          container = element->FirstChild();
     467          if( container->ToText())
     468            {
     469              assert( container->Value() != NULL);
     470              PRINTF0("Loaded Join: %s\n", container->Value());
     471              joinS(container->Value());
     472            }
     473        }
     474      else if( !strcmp( element->Value(), "WorkOn"))
     475        {
     476          container = element->FirstChild();
     477          if( container->ToText())
     478            {
     479              assert( container->Value() != NULL);
     480              PRINTF(4)("Loaded WorkOn: %s\n", container->Value());
     481              workOn( container->Value());
     482            }
     483        }
     484               
     485      element = element->NextSiblingElement();
     486    }
    407487
    408488}
     
    620700/**
    621701   \brief adds some interessting non-linear movments through the level.
    622    \param count The Count of childrens the current HotPoint will have.
     702   \param count The Count of children the fork will produce
    623703
    624704   If no HotPoint was defined the last added Point will be rendered into a fork. \n
     
    628708{
    629709  int* trackIDs = new int[count];
    630   this->forkV(count, trackIDs);
     710  this->forkV(count, trackIDs, NULL);
    631711  va_list ID;
    632712  va_start (ID, count);
     
    640720
    641721/**
     722   \param string the String to parse.
     723   \see TrackManager::fork(unsigned int count, ...)
     724
     725   does the same as fork, but has an array of strings as an input.
     726*/
     727void TrackManager::forkS(unsigned int count, ...)
     728{
     729  int* trackIDs = new int[count];
     730  this->forkV(count, trackIDs, NULL);
     731  va_list name;
     732  va_start (name, count);
     733  for(int i = 0; i < count; i++)
     734    {
     735      this->firstTrackElem->findByID(trackIDs[i])->setName(va_arg(name, const char*));
     736    }
     737  va_end(name); 
     738  delete []trackIDs;
     739}
     740
     741/**
     742   \see TrackManager::fork(unsigned int count, ...)
     743*/
     744void TrackManager::forkS(const char* forkString)
     745{
     746  SubString strings(forkString);
     747
     748  int* trackIDs = new int[strings.getCount()];
     749  this->forkV(strings.getCount(), trackIDs, NULL);
     750
     751  for(int i = 0; i < strings.getCount(); i++)
     752    {
     753      this->firstTrackElem->findByID(trackIDs[i])->setName(strings.getString(i));
     754    } 
     755}
     756
     757/**
    642758   \brief adds some interessting non-linear movments through the level.
    643759   \param count The Count of childrens the current HotPoint will have.
    644760   \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this).
    645    \param trackElem The TrackElement to appy this to. (if NULL chose this->currentTrackElement)
     761   \param trackElem The TrackElement to appy this to. (if NULL choose this->currentTrackElement)
    646762   \see TrackManager::fork(unsigned int count, ...)
    647763*/
    648 void TrackManager::forkV(unsigned int count, int* trackIDs, TrackElement* trackElem)
     764void TrackManager::forkV(unsigned int count, int* trackIDs, char** trackNames, TrackElement* trackElem)
    649765{
    650766  if (!trackElem)
     
    738854   \brief Joins some Tracks together again.
    739855   \param count The count of trackElements to join
    740 
    741856   \see void TrackManager::join(unsigned int count, ...)
     857
    742858   The difference to void TrackManager::join(unsigned int count, ...) is, that this function takes
    743859   the Names of the TrackElements as inputs and not their ID
    744860*/
    745 void TrackManager::joinc(unsigned int count, ...)
     861void TrackManager::joinS(unsigned int count, ...)
    746862{
    747863  int* trackIDs = new int [count];
     
    750866  for(int i = 0; i < count; i++)
    751867    {
    752       char* name = va_arg (NAME, char*);
     868      const char* name = va_arg (NAME, char*);
    753869      TrackElement* tmpElem = this->firstTrackElem->findByName(name);
    754870      if (tmpElem)
     
    762878}
    763879
     880/**
     881   \see void TrackManager::join(unsigned int count, ...)
     882*/
     883void TrackManager::joinS(const char* joinString)
     884{
     885  SubString strings(joinString);
     886
     887  int* trackIDs = new int[strings.getCount()];
     888  this->joinV(strings.getCount(), trackIDs);
     889
     890  for(int i = 0; i < strings.getCount(); i++)
     891    {
     892      TrackElement* tmpElem = this->firstTrackElem->findByName(strings.getString(i));
     893      if (tmpElem)
     894        trackIDs[i] = tmpElem->ID;
     895      else
     896        PRINTF(1)("Trying to join a Track, of which the name does not exist: %s\n", strings.getString(i));
     897    }
     898
     899  this->joinV(strings.getCount(), trackIDs);
     900  delete []trackIDs;
     901}
    764902
    765903/**
     
    777915    if (!this->firstTrackElem->findByID(trackIDs[i]))
    778916      {
    779         PRINTF(1)("Error trying to Connect Paths that do not exist yet: %d\n Not Joining Anything", trackIDs[i]);
     917        PRINTF(1)("Trying to Connect Paths that do not exist yet: %d\n Not Joining Anything\n", trackIDs[i]);
    780918        return;
    781919      }
Note: See TracChangeset for help on using the changeset viewer.