Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 10, 2016, 1:54:11 PM (9 years ago)
Author:
landauf
Message:

merged branch cpp11_v2 into cpp11_v3

Location:
code/branches/cpp11_v3
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v3

  • code/branches/cpp11_v3/src/modules/pong/Pong.cc

    r9939 r11054  
    6464        RegisterObject(Pong);
    6565
    66         this->center_ = 0;
    67         this->ball_ = 0;
    68         this->bat_[0] = 0;
    69         this->bat_[1] = 0;
     66        this->center_ = nullptr;
     67        this->ball_ = nullptr;
     68        this->bat_[0] = nullptr;
     69        this->bat_[1] = nullptr;
    7070
    7171        this->setHUDTemplate("PongHUD");
     
    103103    void Pong::cleanup()
    104104    {
    105         if (this->ball_ != NULL) // Destroy the ball, if present.
     105        if (this->ball_ != nullptr) // Destroy the ball, if present.
    106106        {
    107107            this->ball_->destroy();
    108             this->ball_ = 0;
     108            this->ball_ = nullptr;
    109109        }
    110110
     
    112112        for (size_t i = 0; i < 2; ++i)
    113113        {
    114             if (this->bat_[0] != NULL)
     114            if (this->bat_[0] != nullptr)
    115115            {
    116116                this->bat_[0]->destroy();
    117                 this->bat_[0] = 0;
     117                this->bat_[0] = nullptr;
    118118            }
    119119        }
     
    127127    void Pong::start()
    128128    {
    129         if (this->center_ != NULL) // There needs to be a PongCenterpoint, i.e. the area the game takes place.
    130         {
    131             if (this->ball_ == NULL) // If there is no ball, create a new ball.
     129        if (this->center_ != nullptr) // There needs to be a PongCenterpoint, i.e. the area the game takes place.
     130        {
     131            if (this->ball_ == nullptr) // If there is no ball, create a new ball.
    132132            {
    133133                this->ball_ = new PongBall(this->center_->getContext());
     
    145145
    146146            // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
    147             for (size_t i = 0; i < 2; ++i)
     147            for (WeakPtr<orxonox::PongBat>& bat : this->bat_)
    148148            {
    149                 if (this->bat_[i] == NULL)
     149                if (bat == nullptr)
    150150                {
    151                     this->bat_[i] = new PongBat(this->center_->getContext());
    152                     this->bat_[i]->addTemplate(this->center_->getBattemplate());
     151                    bat = new PongBat(this->center_->getContext());
     152                    bat->addTemplate(this->center_->getBattemplate());
    153153                }
    154154            }
     
    211211    {
    212212        // first spawn human players to assign always the left bat to the player in singleplayer
    213         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    214             if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
    215                 this->spawnPlayer(it->first);
     213        for (const auto& mapEntry : this->players_)
     214            if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
     215                this->spawnPlayer(mapEntry.first);
    216216        // now spawn bots
    217         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    218             if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
    219                 this->spawnPlayer(it->first);
     217        for (const auto& mapEntry : this->players_)
     218            if (!mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
     219                this->spawnPlayer(mapEntry.first);
    220220    }
    221221
     
    231231
    232232        // If the first (left) bat has no player.
    233         if (this->bat_[0]->getPlayer() == NULL)
     233        if (this->bat_[0]->getPlayer() == nullptr)
    234234        {
    235235            player->startControl(this->bat_[0]);
     
    237237        }
    238238        // If the second (right) bat has no player.
    239         else if (this->bat_[1]->getPlayer() == NULL)
     239        else if (this->bat_[1]->getPlayer() == nullptr)
    240240        {
    241241            player->startControl(this->bat_[1]);
     
    247247
    248248        // If the player is an AI, it receives a pointer to the ball.
    249         if (player->getController() != NULL && player->getController()->isA(Class(PongAI)))
     249        if (player->getController() != nullptr && player->getController()->isA(Class(PongAI)))
    250250        {
    251251            PongAI* ai = orxonox_cast<PongAI*>(player->getController());
     
    262262        Deathmatch::playerScored(player, score);
    263263
    264         if (this->center_ != NULL) // If there is a centerpoint.
     264        if (this->center_ != nullptr) // If there is a centerpoint.
    265265        {
    266266            // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks.
     
    271271
    272272            // Also announce, that the player has scored.
    273             if (player != NULL)
     273            if (player != nullptr)
    274274                this->gtinfo_->sendAnnounceMessage(player->getName() + " scored");
    275275        }
    276276
    277277        // If there is a ball present, reset its position, velocity and acceleration.
    278         if (this->ball_ != NULL)
     278        if (this->ball_ != nullptr)
    279279        {
    280280            this->ball_->setPosition(Vector3::ZERO);
     
    285285
    286286        // If there are bats reset them to the middle position.
    287         if (this->bat_[0] != NULL && this->bat_[1] != NULL)
     287        if (this->bat_[0] != nullptr && this->bat_[1] != nullptr)
    288288        {
    289289            this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
     
    292292
    293293        // If a player gets enough points, he won the game -> end of game
    294         PlayerInfo* winningPlayer = NULL;
     294        PlayerInfo* winningPlayer = nullptr;
    295295        if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_)
    296296            winningPlayer = this->getLeftPlayer();
     
    314314    void Pong::startBall()
    315315    {
    316         if (this->ball_ != NULL && this->center_ != NULL)
     316        if (this->ball_ != nullptr && this->center_ != nullptr)
    317317            this->ball_->setSpeed(this->center_->getBallSpeed());
    318318    }
     
    322322        Get the left player.
    323323    @return
    324         Returns a pointer to the player playing on the left. If there is no left player, NULL is returned.
     324        Returns a pointer to the player playing on the left. If there is no left player, nullptr is returned.
    325325    */
    326326    PlayerInfo* Pong::getLeftPlayer() const
    327327    {
    328         if (this->bat_ != NULL && this->bat_[0] != NULL)
     328        if (this->bat_ != nullptr && this->bat_[0] != nullptr)
    329329            return this->bat_[0]->getPlayer();
    330330        else
    331             return 0;
     331            return nullptr;
    332332    }
    333333
     
    336336        Get the right player.
    337337    @return
    338         Returns a pointer to the player playing on the right. If there is no right player, NULL is returned.
     338        Returns a pointer to the player playing on the right. If there is no right player, nullptr is returned.
    339339    */
    340340    PlayerInfo* Pong::getRightPlayer() const
    341341    {
    342         if (this->bat_ != NULL && this->bat_[1] != NULL)
     342        if (this->bat_ != nullptr && this->bat_[1] != nullptr)
    343343            return this->bat_[1]->getPlayer();
    344344        else
    345             return 0;
     345            return nullptr;
    346346    }
    347347}
  • code/branches/cpp11_v3/src/modules/pong/Pong.h

    r9667 r11054  
    6868            virtual ~Pong(); //!< Destructor. Cleans up, if initialized.
    6969
    70             virtual void start(); //!< Starts the Pong minigame.
    71             virtual void end(); ///!< Ends the Pong minigame.
     70            virtual void start() override; //!< Starts the Pong minigame.
     71            virtual void end() override; ///!< Ends the Pong minigame.
    7272
    73             virtual void spawnPlayer(PlayerInfo* player); //!< Spawns the input player.
     73            virtual void spawnPlayer(PlayerInfo* player) override; //!< Spawns the input player.
    7474
    75             virtual void playerScored(PlayerInfo* player, int score = 1); //!< Is called when the player scored.
     75            virtual void playerScored(PlayerInfo* player, int score = 1) override; //!< Is called when the player scored.
    7676
    7777            /**
     
    8787
    8888        protected:
    89             virtual void spawnPlayersIfRequested(); //!< Spawns players, and fills the rest up with bots.
     89            virtual void spawnPlayersIfRequested() override; //!< Spawns players, and fills the rest up with bots.
    9090
    9191            void startBall(); //!< Starts the ball with some default speed.
  • code/branches/cpp11_v3/src/modules/pong/PongAI.cc

    r11018 r11054  
    5757        RegisterObject(PongAI);
    5858
    59         this->ball_ = 0;
     59        this->ball_ = nullptr;
    6060        this->ballDirection_ = Vector2::ZERO;
    6161        this->ballEndPosition_ = 0;
     
    7777    PongAI::~PongAI()
    7878    {
    79         for (std::list<std::pair<Timer*, char> >::iterator it = this->reactionTimers_.begin(); it != this->reactionTimers_.end(); ++it)
    80             delete it->first;
     79        for (std::pair<Timer*, char>& pair : this->reactionTimers_)
     80            delete pair.first;
    8181    }
    8282
     
    101101    {
    102102        // If either the ball, or the controllable entity (i.e. the bat) don't exist (or aren't set).
    103         if (this->ball_  == NULL || this->getControllableEntity() == NULL)
     103        if (this->ball_  == nullptr || this->getControllableEntity() == nullptr)
    104104            return;
    105105
     
    362362            // Add a new Timer
    363363            Timer* timer = new Timer(delay, false, createExecutor(createFunctor(&PongAI::delayedMove, this)));
    364             this->reactionTimers_.push_back(std::pair<Timer*, char>(timer, direction));
     364            this->reactionTimers_.emplace_back(timer, direction);
    365365        }
    366366        else
  • code/branches/cpp11_v3/src/modules/pong/PongAI.h

    r9667 r11054  
    6666            void setConfigValues();
    6767
    68             virtual void tick(float dt); //!< Implements the behavior of the PongAI (i.e. its intelligence).
     68            virtual void tick(float dt) override; //!< Implements the behavior of the PongAI (i.e. its intelligence).
    6969
    7070            /**
     
    8989            float strength_; //!< The strength of the AI. Ranging from 0 to 1.
    9090
    91             std::list<std::pair<Timer*, char> > reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires.
     91            std::list<std::pair<Timer*, char>> reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires.
    9292            char movement_; //!< The planned movement.
    9393            char oldMove_; //!< The previous movement.
  • code/branches/cpp11_v3/src/modules/pong/PongBall.cc

    r9945 r11054  
    6161        this->speed_ = 0;
    6262        this->accelerationFactor_ = 1.0f;
    63         this->bat_ = 0;
     63        this->bat_ = nullptr;
    6464        this->bDeleteBats_ = false;
    6565        this->batID_ = new unsigned int[2];
     
    8282             else
    8383             {
    84                  this->defScoreSound_ = 0;
    85                  this->defBatSound_ = 0;
    86                  this->defBoundarySound_ = 0;
     84                 this->defScoreSound_ = nullptr;
     85                 this->defBatSound_ = nullptr;
     86                 this->defBoundarySound_ = nullptr;
    8787             }
    8888    }
     
    163163            float distance = 0;
    164164
    165             if (this->bat_ != NULL) // If there are bats.
     165            if (this->bat_ != nullptr) // If there are bats.
    166166            {
    167167                // If the right boundary has been crossed.
    168                 if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL)
     168                if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != nullptr)
    169169                {
    170170                    // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
     
    195195                }
    196196                // If the left boundary has been crossed.
    197                 else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL)
     197                else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != nullptr)
    198198                {
    199199                    // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
     
    285285    {
    286286        // Make space for the bats, if they don't exist, yet.
    287         if (this->bat_ == NULL)
     287        if (this->bat_ == nullptr)
    288288        {
    289289            this->bat_ = new WeakPtr<PongBat>[2];
  • code/branches/cpp11_v3/src/modules/pong/PongBall.h

    r9939 r11054  
    6363            virtual ~PongBall();
    6464
    65             virtual void tick(float dt);
     65            virtual void tick(float dt) override;
    6666
    67             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     67            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    6868
    6969            /**
  • code/branches/cpp11_v3/src/modules/pong/PongBat.h

    r9667 r11054  
    6060            virtual ~PongBat() {}
    6161
    62             virtual void tick(float dt);
     62            virtual void tick(float dt) override;
    6363
    64             virtual void moveFrontBack(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
    65             virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
     64            virtual void moveFrontBack(const Vector2& value) override; //!< Overloaded the function to steer the bat up and down.
     65            virtual void moveRightLeft(const Vector2& value) override; //!< Overloaded the function to steer the bat up and down.
    6666
    67             virtual void changedPlayer(); //!< Is called when the player changed.
     67            virtual void changedPlayer() override; //!< Is called when the player changed.
    6868
    6969            /**
  • code/branches/cpp11_v3/src/modules/pong/PongCenterpoint.cc

    r10624 r11054  
    8484    void PongCenterpoint::checkGametype()
    8585    {
    86         if (this->getGametype() != NULL && this->getGametype()->isA(Class(Pong)))
     86        if (this->getGametype() != nullptr && this->getGametype()->isA(Class(Pong)))
    8787        {
    8888            Pong* pongGametype = orxonox_cast<Pong*>(this->getGametype());
  • code/branches/cpp11_v3/src/modules/pong/PongCenterpoint.h

    r10624 r11054  
    124124            virtual ~PongCenterpoint() {}
    125125
    126             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method to create a PongCenterpoint through XML.
     126            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Method to create a PongCenterpoint through XML.
    127127
    128128            /**
  • code/branches/cpp11_v3/src/modules/pong/PongScore.cc

    r10624 r11054  
    5555        RegisterObject(PongScore);
    5656
    57         this->owner_ = 0;
     57        this->owner_ = nullptr;
    5858
    5959        this->bShowName_ = false;
     
    9797
    9898        // If the owner is set. The owner being a Pong game.
    99         if (this->owner_ != NULL)
     99        if (this->owner_ != nullptr)
    100100        {
    101101            if (!this->owner_->hasEnded())
     
    113113
    114114            // Save the name and score of each player as a string.
    115             if (player1_ != NULL)
     115            if (player1_ != nullptr)
    116116            {
    117117                name1 = player1_->getName();
    118118                score1 = multi_cast<std::string>(this->owner_->getScore(player1_));
    119119            }
    120             if (player2_ != NULL)
     120            if (player2_ != nullptr)
    121121            {
    122122                name2 = player2_->getName();
     
    128128            if (this->bShowLeftPlayer_)
    129129            {
    130                 if (this->bShowName_ && this->bShowScore_ && player1_ != NULL)
     130                if (this->bShowName_ && this->bShowScore_ && player1_ != nullptr)
    131131                    output1 = name1 + " - " + score1;
    132132                else if (this->bShowScore_)
     
    139139            if (this->bShowRightPlayer_)
    140140            {
    141                 if (this->bShowName_ && this->bShowScore_ && player2_ != NULL)
     141                if (this->bShowName_ && this->bShowScore_ && player2_ != nullptr)
    142142                    output2 = score2 + " - " + name2;
    143143                else if (this->bShowScore_)
     
    163163    @brief
    164164        Is called when the owner changes.
    165         Sets the owner to NULL, if it is not a pointer to a Pong game.
     165        Sets the owner to nullptr, if it is not a pointer to a Pong game.
    166166    */
    167167    void PongScore::changedOwner()
     
    169169        SUPER(PongScore, changedOwner);
    170170
    171         if (this->getOwner() != NULL && this->getOwner()->getGametype())
     171        if (this->getOwner() != nullptr && this->getOwner()->getGametype())
    172172            this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype());
    173173        else
    174             this->owner_ = 0;
     174            this->owner_ = nullptr;
    175175    }
    176176}
  • code/branches/cpp11_v3/src/modules/pong/PongScore.h

    r9939 r11054  
    6060            virtual ~PongScore();
    6161
    62             virtual void tick(float dt); //!< Creates and sets the caption to be displayed by the PongScore.
    63             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    64             virtual void changedOwner(); //!< Is called when the owner changes.
     62            virtual void tick(float dt) override; //!< Creates and sets the caption to be displayed by the PongScore.
     63            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
     64            virtual void changedOwner() override; //!< Is called when the owner changes.
    6565
    6666            /**
Note: See TracChangeset for help on using the changeset viewer.