Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2890


Ignore:
Timestamp:
Apr 2, 2009, 8:42:11 PM (15 years ago)
Author:
landauf
Message:
  • Added overlay element for the Pong Gametype
  • Changed the type of the overlay's owner to BaseObject (former ControllableEntity) to allow other classes to own an overlay (for example a Gametype)
  • OverlayGroup does now use a std::set instead of a std::map to store it's overlay elements. Therefore a name is not anymore compulsory for an overlay element.
Location:
code/trunk/src/orxonox
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/gametypes/Gametype.cc

    r2839 r2890  
    229229        if (it != this->players_.end())
    230230            it->second.frags_++;
     231    }
     232
     233    int Gametype::getScore(PlayerInfo* player) const
     234    {
     235        std::map<PlayerInfo*, Player>::const_iterator it = this->players_.find(player);
     236        if (it != this->players_.end())
     237            return it->second.frags_;
     238        else
     239            return 0;
    231240    }
    232241
  • code/trunk/src/orxonox/objects/gametypes/Gametype.h

    r2839 r2890  
    107107                { return this->players_; }
    108108
     109            int getScore(PlayerInfo* player) const;
     110
    109111            inline void registerSpawnPoint(SpawnPoint* spawnpoint)
    110112                { this->spawnpoints_.insert(spawnpoint); }
  • code/trunk/src/orxonox/objects/gametypes/Pong.cc

    r2885 r2890  
    5353        this->bat_[0] = 0;
    5454        this->bat_[1] = 0;
     55
     56        this->setHUDTemplate("PongHUD");
    5557
    5658        this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall)));
     
    181183            this->ball_->setSpeed(this->center_->getBallSpeed());
    182184    }
     185
     186    PlayerInfo* Pong::getLeftPlayer() const
     187    {
     188        if (this->bat_ && this->bat_[0])
     189            return this->bat_[0]->getPlayer();
     190        else
     191            return 0;
     192    }
     193
     194    PlayerInfo* Pong::getRightPlayer() const
     195    {
     196        if (this->bat_ && this->bat_[1])
     197            return this->bat_[1]->getPlayer();
     198        else
     199            return 0;
     200    }
    183201}
  • code/trunk/src/orxonox/objects/gametypes/Pong.h

    r2826 r2890  
    5353                { this->center_ = center; }
    5454
     55            PlayerInfo* getLeftPlayer() const;
     56            PlayerInfo* getRightPlayer() const;
     57
    5558        protected:
    5659            void startBall();
  • code/trunk/src/orxonox/objects/infos/HumanPlayer.cc

    r2826 r2890  
    173173        if (this->humanHud_)
    174174            this->humanHud_->setOwner(this->getControllableEntity());
    175 
    176         if (this->gametypeHud_)
    177             this->gametypeHud_->setOwner(this->getControllableEntity());
    178175    }
    179176
     
    206203            this->gametypeHud_ = new OverlayGroup(this);
    207204            this->gametypeHud_->addTemplate(this->gametypeHudTemplate_);
    208             this->gametypeHud_->setOwner(this->getControllableEntity());
     205            this->gametypeHud_->setOwner(this->getGametype());
    209206        }
    210207    }
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.h

    r2662 r2890  
    154154        virtual void changedVisibility();
    155155
    156         inline void setOwner(ControllableEntity* owner)
     156        inline void setOwner(BaseObject* owner)
    157157        {
    158158            if (this->owner_ != owner)
     
    162162            }
    163163        }
    164         inline ControllableEntity* getOwner() const
     164        inline BaseObject* getOwner() const
    165165            { return this->owner_; }
    166166        virtual void changedOwner() {}
     
    206206            We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */
    207207        static std::map<std::string, OrxonoxOverlay*> overlays_s;
    208         ControllableEntity* owner_;
     208        BaseObject* owner_;
    209209        OverlayGroup* group_;
    210210  };
  • code/trunk/src/orxonox/overlays/OverlayGroup.cc

    r2662 r2890  
    6363    OverlayGroup::~OverlayGroup()
    6464    {
    65         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    66             delete it->second;
     65        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     66            delete (*it);
    6767    }
    6868
     
    8383    }
    8484
    85     //! Scales every element in the map.
     85    //! Scales every element in the set.
    8686    void OverlayGroup::setScale(const Vector2& scale)
    8787    {
    88         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    89             (*it).second->scale(scale / this->scale_);
     88        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     89            (*it)->scale(scale / this->scale_);
    9090        this->scale_ = scale;
    9191    }
    9292
    93     //! Scrolls every element in the map.
     93    //! Scrolls every element in the set.
    9494    void OverlayGroup::setScroll(const Vector2& scroll)
    9595    {
    96         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    97             (*it).second->scroll(scroll - this->scroll_);
     96        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     97            (*it)->scroll(scroll - this->scroll_);
    9898        this->scroll_ = scroll;
    9999    }
     
    101101    /**
    102102    @brief
    103         Adds an element to the map (used when loading with XMLPort).
     103        Adds an element to the set (used when loading with XMLPort).
    104104    @remarks
    105105        The names of the OrxonoxOverlays have to be unique!
     
    107107    void OverlayGroup::addElement(OrxonoxOverlay* element)
    108108    {
    109         if (hudElements_.find(element->getName()) != hudElements_.end())
    110         {
    111             COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
    112         }
    113         else
    114         {
    115             hudElements_[element->getName()] = element;
    116             element->setVisible(this->isVisible());
    117             if (this->owner_)
    118                 element->setOwner(this->owner_);
    119         }
     109        hudElements_.insert(element);
     110        element->setVisible(this->isVisible());
     111        if (this->owner_)
     112            element->setOwner(this->owner_);
    120113    }
    121114
     
    125118        if (index < this->hudElements_.size())
    126119        {
    127             std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
     120            std::set<OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
    128121            for (unsigned int i = 0; i != index; ++it, ++i)
    129122                ;
    130             return (*it).second;
     123            return (*it);
    131124        }
    132125        else
     
    137130    void OverlayGroup::changedVisibility()
    138131    {
    139         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    140             (*it).second->setVisible(this->isVisible());
     132        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     133            (*it)->setVisible(this->isVisible());
    141134    }
    142135
    143     void OverlayGroup::setOwner(ControllableEntity* owner)
     136    void OverlayGroup::setOwner(BaseObject* owner)
    144137    {
    145138        this->owner_ = owner;
    146139
    147         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    148             (*it).second->setOwner(owner);
     140        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     141            (*it)->setOwner(owner);
    149142    }
    150143
  • code/trunk/src/orxonox/overlays/OverlayGroup.h

    r2662 r2890  
    3737#include "OrxonoxPrereqs.h"
    3838
    39 #include <map>
     39#include <set>
    4040#include <OgrePrerequisites.h>
    4141#include "core/BaseObject.h"
     
    6464        static void scrollGroup(const std::string& name, const Vector2& scroll);
    6565
    66         inline const std::map<std::string, OrxonoxOverlay*>& getOverlays() const
     66        inline const std::set<OrxonoxOverlay*>& getOverlays() const
    6767            { return this->hudElements_; }
    6868
    6969        void changedVisibility();
    7070
    71         void setOwner(ControllableEntity* owner);
    72         inline ControllableEntity* getOwner() const
     71        void setOwner(BaseObject* owner);
     72        inline BaseObject* getOwner() const
    7373            { return this->owner_; }
    7474
     
    8989
    9090    private:
    91         std::map<std::string, OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
    92         Vector2 scale_;                                         //!< Current scale (independent of the elements).
    93         Vector2 scroll_;                                        //!< Current scrolling offset.
    94         ControllableEntity* owner_;                             //!< The owner of this OverlayGroup
     91        std::set<OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
     92        Vector2 scale_;                            //!< Current scale (independent of the elements).
     93        Vector2 scroll_;                           //!< Current scrolling offset.
     94        BaseObject* owner_;                        //!< The owner of this OverlayGroup
    9595    };
    9696}
  • code/trunk/src/orxonox/overlays/hud/CMakeLists.txt

    r2710 r2890  
    77  ChatOverlay.cc
    88  GametypeStatus.cc
     9  PongScore.cc
    910)
Note: See TracChangeset for help on using the changeset viewer.