Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9973


Ignore:
Timestamp:
Jan 4, 2014, 2:56:03 PM (10 years ago)
Author:
landauf
Message:

several (potential) bugfixes in SpaceRaceController:

  • check if there is only 1 SpaceRaceManager (line 61)
  • zaehler.begin() is NOT necessarily the first checkpoint because the map is randomly sorted. use nextRaceCheckpoint_ instead (line 160)
  • don't recurse if the next checkpoint is invalid (line 198)

some cleanup in RaceCheckPoint; also fixed a potential floating point issue

Location:
code/trunk/src/modules/gametypes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/gametypes/RaceCheckPoint.cc

    r9967 r9973  
    105105        this->nextCheckpoints_.clear();
    106106
    107         if (checkpoints.x > -1)
    108         this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
    109         if (checkpoints.y > -1)
    110         this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
    111         if (checkpoints.z > -1)
    112         this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
     107        if (checkpoints.x > -0.5)
     108            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly
     109        if (checkpoints.y > -0.5)
     110            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
     111        if (checkpoints.z > -0.5)
     112            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
    113113    }
    114114
     
    146146    {
    147147        Vector3 checkpoints(-1,-1,-1); int count=0;
    148         for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){
     148        for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ )
     149        {
    149150            switch (count)
    150                         {
    151                             case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
    152                             case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
    153                             case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
    154                         }
    155                         ++count;
     151            {
     152                case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
     153                case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
     154                case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
     155            }
     156            ++count;
    156157        }
    157158        return checkpoints;
  • code/trunk/src/modules/gametypes/SpaceRaceController.cc

    r9967 r9973  
    5555        ArtificialController(context)
    5656    {
    57         RegisterObject(SpaceRaceController)
    58 ;        std::vector<RaceCheckPoint*> checkpoints;
     57        RegisterObject(SpaceRaceController);
     58        std::vector<RaceCheckPoint*> checkpoints;
    5959
    6060        virtualCheckPointIndex = -2;
     61        if (ObjectList<SpaceRaceManager>::size() != 1)
     62            orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>::size() << endl;
    6163        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
    6264        {
     
    122124        }//ausgabe
    123125        orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;*/
    124         staticRacePoints_ = findStaticCheckpoints(checkpoints);
     126        staticRacePoints_ = findStaticCheckpoints(nextRaceCheckpoint_, checkpoints);
    125127        // initialisation of currentRaceCheckpoint_
    126128        currentRaceCheckpoint_ = NULL;
     
    149151     * returns a vector of static Point (checkpoints the spaceship has to reach)
    150152     */
    151     std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(const std::vector<RaceCheckPoint*>& allCheckpoints)
     153    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(RaceCheckPoint* currentCheckpoint, const std::vector<RaceCheckPoint*>& allCheckpoints)
    152154    {
    153155        std::map<RaceCheckPoint*, int> zaehler; // counts how many times the checkpoint was reached (for simulation)
     
    156158            zaehler.insert(std::pair<RaceCheckPoint*, int>(allCheckpoints[i],0));
    157159        }
    158         int maxWays = rekSimulationCheckpointsReached(zaehler.begin()->first, zaehler);
     160        int maxWays = rekSimulationCheckpointsReached(currentCheckpoint, zaehler);
    159161
    160162        std::vector<RaceCheckPoint*> returnVec;
    161         returnVec.clear();
    162163        for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler.begin(); iter != zaehler.end(); iter++)
    163164        {
    164165            if (iter->second == maxWays)
    165166            {
    166                 //returnVec.insert(allCheckpoints[1]);
    167                 returnVec.insert(returnVec.end(), iter->first);
     167                returnVec.push_back(iter->first);
    168168            }
    169169        }
     
    189189            for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)
    190190            {
    191                 if(currentCheckpoint == findCheckpoint(*it))
     191                if (currentCheckpoint == findCheckpoint(*it))
    192192                {
    193193                    //orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
    194194                    continue;
    195195                }
    196                 if(findCheckpoint(*it) == NULL)
    197                     {orxout()<<"Problematic Point: "<<(*it)<<endl;}
    198                 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
     196                if (findCheckpoint(*it) == NULL)
     197                    orxout(internal_warning) << "Problematic Point: " << (*it) << endl;
     198                else
     199                    numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
    199200            }
    200201            zaehler[currentCheckpoint] += numberOfWays;
  • code/trunk/src/modules/gametypes/SpaceRaceController.h

    r9967 r9973  
    5050            RaceCheckPoint* nextPointFind(RaceCheckPoint*);
    5151            RaceCheckPoint* adjustNextPoint();
    52             std::vector<RaceCheckPoint*> findStaticCheckpoints(const std::vector<RaceCheckPoint*>&);
     52            std::vector<RaceCheckPoint*> findStaticCheckpoints(RaceCheckPoint*, const std::vector<RaceCheckPoint*>&);
    5353            std::vector<RaceCheckPoint*> staticCheckpoints();
    5454            int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>&);
Note: See TracChangeset for help on using the changeset viewer.