[Orxonox-commit 5310] r9973 - code/trunk/src/modules/gametypes

landauf at orxonox.net landauf at orxonox.net
Sat Jan 4 14:56:03 CET 2014


Author: landauf
Date: 2014-01-04 14:56:03 +0100 (Sat, 04 Jan 2014)
New Revision: 9973

Modified:
   code/trunk/src/modules/gametypes/RaceCheckPoint.cc
   code/trunk/src/modules/gametypes/SpaceRaceController.cc
   code/trunk/src/modules/gametypes/SpaceRaceController.h
Log:
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

Modified: code/trunk/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/trunk/src/modules/gametypes/RaceCheckPoint.cc	2014-01-04 13:28:19 UTC (rev 9972)
+++ code/trunk/src/modules/gametypes/RaceCheckPoint.cc	2014-01-04 13:56:03 UTC (rev 9973)
@@ -104,12 +104,12 @@
     {
         this->nextCheckpoints_.clear();
 
-        if (checkpoints.x > -1)
-        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
-        if (checkpoints.y > -1)
-        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
-        if (checkpoints.z > -1)
-        this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
+        if (checkpoints.x > -0.5)
+            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
+        if (checkpoints.y > -0.5)
+            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5));
+        if (checkpoints.z > -0.5)
+            this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));
     }
 
     PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const
@@ -145,14 +145,15 @@
     Vector3 RaceCheckPoint::getNextCheckpointsAsVector3()
     {
         Vector3 checkpoints(-1,-1,-1); int count=0;
-        for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){
+        for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ )
+        {
             switch (count)
-                        {
-                            case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
-                            case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
-                            case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
-                        }
-                        ++count;
+            {
+                case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break;
+                case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break;
+                case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break;
+            }
+            ++count;
         }
         return checkpoints;
     }

Modified: code/trunk/src/modules/gametypes/SpaceRaceController.cc
===================================================================
--- code/trunk/src/modules/gametypes/SpaceRaceController.cc	2014-01-04 13:28:19 UTC (rev 9972)
+++ code/trunk/src/modules/gametypes/SpaceRaceController.cc	2014-01-04 13:56:03 UTC (rev 9973)
@@ -54,10 +54,12 @@
     SpaceRaceController::SpaceRaceController(Context* context) :
         ArtificialController(context)
     {
-        RegisterObject(SpaceRaceController)
-;        std::vector<RaceCheckPoint*> checkpoints;
+        RegisterObject(SpaceRaceController);
+        std::vector<RaceCheckPoint*> checkpoints;
 
         virtualCheckPointIndex = -2;
+        if (ObjectList<SpaceRaceManager>::size() != 1)
+            orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>::size() << endl;
         for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
         {
             checkpoints = it->getAllCheckpoints();
@@ -121,7 +123,7 @@
 
         }//ausgabe
         orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;*/
-        staticRacePoints_ = findStaticCheckpoints(checkpoints);
+        staticRacePoints_ = findStaticCheckpoints(nextRaceCheckpoint_, checkpoints);
         // initialisation of currentRaceCheckpoint_
         currentRaceCheckpoint_ = NULL;
 
@@ -148,23 +150,21 @@
      * called from constructor 'SpaceRaceController'
      * returns a vector of static Point (checkpoints the spaceship has to reach)
      */
-    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(const std::vector<RaceCheckPoint*>& allCheckpoints)
+    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(RaceCheckPoint* currentCheckpoint, const std::vector<RaceCheckPoint*>& allCheckpoints)
     {
         std::map<RaceCheckPoint*, int> zaehler; // counts how many times the checkpoint was reached (for simulation)
         for (unsigned int i = 0; i < allCheckpoints.size(); i++)
         {
             zaehler.insert(std::pair<RaceCheckPoint*, int>(allCheckpoints[i],0));
         }
-        int maxWays = rekSimulationCheckpointsReached(zaehler.begin()->first, zaehler);
+        int maxWays = rekSimulationCheckpointsReached(currentCheckpoint, zaehler);
 
         std::vector<RaceCheckPoint*> returnVec;
-        returnVec.clear();
         for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler.begin(); iter != zaehler.end(); iter++)
         {
             if (iter->second == maxWays)
             {
-                //returnVec.insert(allCheckpoints[1]);
-                returnVec.insert(returnVec.end(), iter->first);
+                returnVec.push_back(iter->first);
             }
         }
         return returnVec;
@@ -188,14 +188,15 @@
             int numberOfWays = 0; // counts number of ways from this Point to the last point
             for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)
             {
-                if(currentCheckpoint == findCheckpoint(*it))
+                if (currentCheckpoint == findCheckpoint(*it))
                 {
                     //orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
                     continue;
                 }
-                if(findCheckpoint(*it) == NULL)
-                    {orxout()<<"Problematic Point: "<<(*it)<<endl;}
-                numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
+                if (findCheckpoint(*it) == NULL)
+                    orxout(internal_warning) << "Problematic Point: " << (*it) << endl;
+                else
+                    numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
             }
             zaehler[currentCheckpoint] += numberOfWays;
             return numberOfWays; // returns the number of ways from this point to the last one

Modified: code/trunk/src/modules/gametypes/SpaceRaceController.h
===================================================================
--- code/trunk/src/modules/gametypes/SpaceRaceController.h	2014-01-04 13:28:19 UTC (rev 9972)
+++ code/trunk/src/modules/gametypes/SpaceRaceController.h	2014-01-04 13:56:03 UTC (rev 9973)
@@ -49,7 +49,7 @@
             float distanceSpaceshipToCheckPoint(RaceCheckPoint*);
             RaceCheckPoint* nextPointFind(RaceCheckPoint*);
             RaceCheckPoint* adjustNextPoint();
-            std::vector<RaceCheckPoint*> findStaticCheckpoints(const std::vector<RaceCheckPoint*>&);
+            std::vector<RaceCheckPoint*> findStaticCheckpoints(RaceCheckPoint*, const std::vector<RaceCheckPoint*>&);
             std::vector<RaceCheckPoint*> staticCheckpoints();
             int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>&);
             // same as SpaceRaceManager, but needed to add virtuell Checkpoints ( Checkpoints which don't exist but needed to avoid collisions with big Objects)




More information about the Orxonox-commit mailing list