Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9967 for code/trunk/src


Ignore:
Timestamp:
Jan 3, 2014, 10:14:03 PM (11 years ago)
Author:
landauf
Message:

call by reference instead of value

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

Legend:

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

    r9964 r9967  
    6060        this->bIsLast_ = false;
    6161        this->timeLimit_ = 0;
    62         //this->players_ = vector<PlayerInfo*>();
    63 
    64         //orxout(user_status) << "test" << std::endl;
    6562    }
    6663
  • code/trunk/src/modules/gametypes/SpaceRaceController.cc

    r9965 r9967  
    149149     * returns a vector of static Point (checkpoints the spaceship has to reach)
    150150     */
    151     std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints)
    152     {
    153         std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoint was reached (for simulation)
     151    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(const std::vector<RaceCheckPoint*>& allCheckpoints)
     152    {
     153        std::map<RaceCheckPoint*, int> zaehler; // counts how many times the checkpoint was reached (for simulation)
    154154        for (unsigned int i = 0; i < allCheckpoints.size(); i++)
    155155        {
    156             zaehler->insert(std::pair<RaceCheckPoint*, int>(allCheckpoints[i],0));
    157         }
    158         int maxWays = rekSimulationCheckpointsReached(zaehler->begin()->first, zaehler);
     156            zaehler.insert(std::pair<RaceCheckPoint*, int>(allCheckpoints[i],0));
     157        }
     158        int maxWays = rekSimulationCheckpointsReached(zaehler.begin()->first, zaehler);
    159159
    160160        std::vector<RaceCheckPoint*> returnVec;
    161161        returnVec.clear();
    162         for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler->begin(); iter != zaehler->end(); iter++)
     162        for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler.begin(); iter != zaehler.end(); iter++)
    163163        {
    164164            if (iter->second == maxWays)
     
    168168            }
    169169        }
    170         delete zaehler;
    171170        return returnVec;
    172171    }
     
    176175     * return how many ways go from the given Checkpoint to the last Checkpoint (of the Game)
    177176     */
    178     int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::map<RaceCheckPoint*, int>* zaehler)
     177    int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::map<RaceCheckPoint*, int>& zaehler)
    179178    {
    180179
     
    182181        {// last point reached
    183182
    184             (*zaehler)[currentCheckpoint] += 1;
     183            zaehler[currentCheckpoint] += 1;
    185184            return 1; // 1 Way form the last point to this one
    186185        }
     
    199198                numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
    200199            }
    201             (*zaehler)[currentCheckpoint] += numberOfWays;
     200            zaehler[currentCheckpoint] += numberOfWays;
    202201            return numberOfWays; // returns the number of ways from this point to the last one
    203202        }
     
    245244     * returns the distance between "currentPosition" and the next static checkpoint that can be reached from "currentCheckPoint"
    246245     */
    247     float SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, Vector3 currentPosition)
     246    float SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, const Vector3& currentPosition)
    248247    {
    249248        // find: looks if the currentCheckPoint is a staticCheckPoint (staticCheckPoint is the same as: static Point)
     
    295294    }
    296295
    297     /*RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition )
     296    /*RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , const Vector3& virtualCheckPointPosition )
    298297    {
    299298        orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl;
     
    393392
    394393    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
    395     bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse)
     394    bool SpaceRaceController::vergleicheQuader(const Vector3& pointToPoint, const Vector3& groesse)
    396395    {
    397396        if(abs(pointToPoint.x) < groesse.x)
     
    405404    }
    406405
    407     bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2,std::vector<StaticEntity*> allObjects)
     406    bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
    408407    {
    409408
     
    413412        btScalar radiusObject;
    414413
    415         for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
     414        for (std::vector<StaticEntity*>::const_iterator it = allObjects.begin(); it != allObjects.end(); ++it)
    416415        {
    417416            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)
     
    434433    }
    435434
    436     /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, std::vector<StaticEntity*> allObjects)
     435    /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
    437436    {
    438437        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
  • code/trunk/src/modules/gametypes/SpaceRaceController.h

    r9966 r9967  
    4141        public:
    4242            SpaceRaceController(Context* context);
     43            virtual ~SpaceRaceController();
    4344            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    44             virtual ~SpaceRaceController();
    4545            virtual void tick(float dt);
    4646
    4747        private:
    48             float recCalculateDistance(RaceCheckPoint*, Vector3 currentPosition);
     48            float recCalculateDistance(RaceCheckPoint*, const Vector3& currentPosition);
    4949            float distanceSpaceshipToCheckPoint(RaceCheckPoint*);
    5050            RaceCheckPoint* nextPointFind(RaceCheckPoint*);
    5151            RaceCheckPoint* adjustNextPoint();
    52             std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<RaceCheckPoint*>);
     52            std::vector<RaceCheckPoint*> findStaticCheckpoints(const std::vector<RaceCheckPoint*>&);
    5353            std::vector<RaceCheckPoint*> staticCheckpoints();
    54             int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>*);
     54            int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>&);
    5555            // same as SpaceRaceManager, but needed to add virtuell Checkpoints ( Checkpoints which don't exist but needed to avoid collisions with big Objects)
    5656            RaceCheckPoint* findCheckpoint(int index) const;
    57             //RaceCheckPoint * addVirtualCheckPoint(RaceCheckPoint*, int , Vector3);
     57            //RaceCheckPoint * addVirtualCheckPoint(RaceCheckPoint*, int , const Vector3&);
    5858            //void placeVirtualCheckpoints(RaceCheckPoint*, RaceCheckPoint*);
    59             bool vergleicheQuader(Vector3, Vector3);
    60             bool directLinePossible(RaceCheckPoint*, RaceCheckPoint*, std::vector<StaticEntity*>);
    61             //void computeVirtualCheckpoint(RaceCheckPoint*, RaceCheckPoint*, std::vector<StaticEntity*>);
     59            bool vergleicheQuader(const Vector3&, const Vector3&);
     60            bool directLinePossible(RaceCheckPoint*, RaceCheckPoint*, const std::vector<StaticEntity*>&);
     61            //void computeVirtualCheckpoint(RaceCheckPoint*, RaceCheckPoint*, const std::vector<StaticEntity*>&);
    6262
    6363            std::vector<RaceCheckPoint*> staticRacePoints_;
Note: See TracChangeset for help on using the changeset viewer.