Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5806


Ignore:
Timestamp:
Sep 27, 2009, 4:13:13 AM (15 years ago)
Author:
landauf
Message:
  • The gametype pointer in BaseObject is now also a SmartPtr
  • The GametypeInfo object in Gametype is now a pointer instead of a member object to prevent double free (once deleted by the unloader and once when the gametype gets destroyed)
  • GSLevel sets the Gametype of all HumanPlayer objects to 0 because they don't get deleted and would prevent the Gametype from being destroyed.
  • Fixed a bug in HumanPlayer when Gametype is set to 0

Unloading seems to work with bots now.

Location:
code/branches/core5/src
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/BaseObject.h

    r5805 r5806  
    138138            inline const SmartPtr<Scene>& getScene() const { return this->scene_; }
    139139
    140             inline void setGametype(Gametype* gametype)
     140            inline void setGametype(const SmartPtr<Gametype>& gametype)
    141141            {
    142142                if (gametype != this->gametype_)
     
    147147                }
    148148            }
    149             inline Gametype* getGametype() const { return this->gametype_; }
     149            inline const SmartPtr<Gametype>& getGametype() const { return this->gametype_; }
    150150            inline Gametype* getOldGametype() const { return this->oldGametype_; }
    151151            virtual void changedGametype() {}
     
    196196            BaseObject*            creator_;
    197197            SmartPtr<Scene>        scene_;
    198             Gametype*              gametype_;
     198            SmartPtr<Gametype>     gametype_;
    199199            Gametype*              oldGametype_;
    200200            std::set<Template*>    templates_;
  • code/branches/core5/src/modules/gamestates/GSLevel.cc

    r5805 r5806  
    5252#include "LevelManager.h"
    5353#include "PlayerManager.h"
     54#include "infos/HumanPlayer.h"
    5455
    5556namespace orxonox
     
    242243    void GSLevel::unloadLevel()
    243244    {
     245        for (ObjectList<HumanPlayer>::iterator it = ObjectList<HumanPlayer>::begin(); it; ++it)
     246            it->setGametype(0);
     247       
    244248        Loader::unload(startFile_s);
    245249
  • code/branches/core5/src/modules/objects/triggers/CheckPoint.cc

    r5738 r5806  
    8585        DistanceTrigger::triggered(bIsTriggered);
    8686
    87         Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype());
     87        Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype().get());
    8888        if (gametype)
    8989        {
  • code/branches/core5/src/modules/overlays/hud/TeamBaseMatchScore.cc

    r5738 r5806  
    118118
    119119        if (this->getOwner() && this->getOwner()->getGametype())
    120             this->owner_ = orxonox_cast<TeamBaseMatch*>(this->getOwner()->getGametype());
     120            this->owner_ = orxonox_cast<TeamBaseMatch*>(this->getOwner()->getGametype().get());
    121121        else
    122122            this->owner_ = 0;
  • code/branches/core5/src/modules/overlays/hud/UnderAttackHealthBar.cc

    r5800 r5806  
    7878            this->owner_ = player;
    7979
    80             UnderAttack* ua = orxonox_cast<UnderAttack*>(player->getGametype());
     80            UnderAttack* ua = orxonox_cast<UnderAttack*>(player->getGametype().get());
    8181            if (ua)
    8282            {
  • code/branches/core5/src/modules/pong/Pong.cc

    r5800 r5806  
    158158
    159159            if (player)
    160                 this->gtinfo_.sendAnnounceMessage(player->getName() + " scored");
     160                this->gtinfo_->sendAnnounceMessage(player->getName() + " scored");
    161161        }
    162162
  • code/branches/core5/src/modules/pong/PongCenterpoint.cc

    r5738 r5806  
    7373        if (this->getGametype() && this->getGametype()->isA(Class(Pong)))
    7474        {
    75             Pong* pong_gametype = orxonox_cast<Pong*>(this->getGametype());
     75            Pong* pong_gametype = orxonox_cast<Pong*>(this->getGametype().get());
    7676            pong_gametype->setCenterpoint(this);
    7777        }
  • code/branches/core5/src/modules/pong/PongScore.cc

    r5738 r5806  
    133133
    134134        if (this->getOwner() && this->getOwner()->getGametype())
    135             this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype());
     135            this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype().get());
    136136        else
    137137            this->owner_ = 0;
  • code/branches/core5/src/orxonox/gametypes/Asteroids.cc

    r5738 r5806  
    5454        if (this->time_ < 0 && !this->hasEnded() && this->timerIsActive_)
    5555        {
    56             this->gtinfo_.sendAnnounceMessage("Time's up - you have lost the match!");
     56            this->gtinfo_->sendAnnounceMessage("Time's up - you have lost the match!");
    5757            this->end();
    5858        }
     
    6363        if (victim && victim->getPlayer())
    6464        {
    65             this->gtinfo_.sendAnnounceMessage("You're dead - you have lost the match!");
     65            this->gtinfo_->sendAnnounceMessage("You're dead - you have lost the match!");
    6666            this->end();
    6767        }
  • code/branches/core5/src/orxonox/gametypes/Gametype.cc

    r5801 r5806  
    4747    CreateUnloadableFactory(Gametype);
    4848
    49     Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator)
     49    Gametype::Gametype(BaseObject* creator) : BaseObject(creator)
    5050    {
    5151        RegisterObject(Gametype);
    52 
    53         this->setGametype(this);
     52       
     53        this->gtinfo_ = new GametypeInfo(creator);
     54
     55        this->setGametype(SmartPtr<Gametype>(this, false));
    5456
    5557        this->defaultControllableEntity_ = Class(Spectator);
     
    7678        else
    7779            this->scoreboard_ = 0;
     80    }
     81   
     82    Gametype::~Gametype()
     83    {
     84        if (this->isInitialized())
     85            this->gtinfo_->destroy();
    7886    }
    7987
     
    100108        }
    101109
    102         if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
    103             this->gtinfo_.startCountdown_ -= dt;
    104 
    105         if (!this->gtinfo_.bStarted_)
     110        if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
     111            this->gtinfo_->startCountdown_ -= dt;
     112
     113        if (!this->gtinfo_->bStarted_)
    106114            this->checkStart();
    107         else if (!this->gtinfo_.bEnded_)
     115        else if (!this->gtinfo_->bEnded_)
    108116            this->spawnDeadPlayersIfRequested();
    109117
     
    115123        this->addBots(this->numberOfBots_);
    116124
    117         this->gtinfo_.bStarted_ = true;
     125        this->gtinfo_->bStarted_ = true;
    118126
    119127        this->spawnPlayersIfRequested();
     
    122130    void Gametype::end()
    123131    {
    124         this->gtinfo_.bEnded_ = true;
     132        this->gtinfo_->bEnded_ = true;
    125133
    126134        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     
    243251
    244252                        if (killer->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
    245                             this->gtinfo_.sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
     253                            this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
    246254                        if (victim->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
    247                             this->gtinfo_.sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
     255                            this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
    248256                    }
    249257                }
     
    308316                it->second.state_ = PlayerState::Dead;
    309317
    310                 if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
     318                if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
    311319                {
    312320                    this->spawnPlayerAsDefaultPawn(it->first);
     
    319327    void Gametype::checkStart()
    320328    {
    321         if (!this->gtinfo_.bStarted_)
    322         {
    323             if (this->gtinfo_.bStartCountdownRunning_)
    324             {
    325                 if (this->gtinfo_.startCountdown_ <= 0)
    326                 {
    327                     this->gtinfo_.bStartCountdownRunning_ = false;
    328                     this->gtinfo_.startCountdown_ = 0;
     329        if (!this->gtinfo_->bStarted_)
     330        {
     331            if (this->gtinfo_->bStartCountdownRunning_)
     332            {
     333                if (this->gtinfo_->startCountdown_ <= 0)
     334                {
     335                    this->gtinfo_->bStartCountdownRunning_ = false;
     336                    this->gtinfo_->startCountdown_ = 0;
    329337                    this->start();
    330338                }
     
    349357                    if (allplayersready && hashumanplayers)
    350358                    {
    351                         this->gtinfo_.startCountdown_ = this->initialStartCountdown_;
    352                         this->gtinfo_.bStartCountdownRunning_ = true;
     359                        this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
     360                        this->gtinfo_->bStartCountdownRunning_ = true;
    353361                    }
    354362                }
  • code/branches/core5/src/orxonox/gametypes/Gametype.h

    r5776 r5806  
    6868        public:
    6969            Gametype(BaseObject* creator);
    70             virtual ~Gametype() {}
     70            virtual ~Gametype();
    7171
    7272            void setConfigValues();
     
    7575
    7676            inline const GametypeInfo* getGametypeInfo() const
    77                 { return &this->gtinfo_; }
     77                { return this->gtinfo_; }
    7878
    7979            inline bool hasStarted() const
    80                 { return this->gtinfo_.bStarted_; }
     80                { return this->gtinfo_->bStarted_; }
    8181            inline bool hasEnded() const
    82                 { return this->gtinfo_.bEnded_; }
     82                { return this->gtinfo_->bEnded_; }
    8383
    8484            virtual void start();
     
    114114
    115115            inline bool isStartCountdownRunning() const
    116                 { return this->gtinfo_.bStartCountdownRunning_; }
     116                { return this->gtinfo_->bStartCountdownRunning_; }
    117117            inline float getStartCountdown() const
    118                 { return this->gtinfo_.startCountdown_; }
     118                { return this->gtinfo_->startCountdown_; }
    119119
    120120            inline void setHUDTemplate(const std::string& name)
    121                 { this->gtinfo_.hudtemplate_ = name; }
     121                { this->gtinfo_->hudtemplate_ = name; }
    122122            inline const std::string& getHUDTemplate() const
    123                 { return this->gtinfo_.hudtemplate_; }
     123                { return this->gtinfo_->hudtemplate_; }
    124124
    125125            void addBots(unsigned int amount);
     
    163163            virtual void spawnDeadPlayersIfRequested();
    164164
    165             GametypeInfo gtinfo_;
     165            SmartPtr<GametypeInfo> gtinfo_;
    166166
    167167            bool bAutoStart_;
  • code/branches/core5/src/orxonox/gametypes/TeamBaseMatch.cc

    r5738 r5806  
    6767                {
    6868                    base->setState(BaseState::ControlTeam1);
    69                     this->gtinfo_.sendAnnounceMessage("The red team captured a base");
     69                    this->gtinfo_->sendAnnounceMessage("The red team captured a base");
    7070                }
    7171                if (teamnr == 1)
    7272                {
    7373                    base->setState(BaseState::ControlTeam2);
    74                     this->gtinfo_.sendAnnounceMessage("The blue team captured a base");
     74                    this->gtinfo_->sendAnnounceMessage("The blue team captured a base");
    7575                }
    7676            }
     
    194194
    195195                if (it->second == winningteam)
    196                     this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
     196                    this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
    197197                else
    198                     this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
     198                    this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
    199199            }
    200200
  • code/branches/core5/src/orxonox/gametypes/UnderAttack.cc

    r5738 r5806  
    8181
    8282                if (it->second == 0)
    83                     this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
     83                    this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
    8484                else
    85                     this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
     85                    this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
    8686            }
    8787        }
     
    164164
    165165                    if (it->second == 1)
    166                         this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
     166                        this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
    167167                    else
    168                         this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
     168                        this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
    169169                }
    170170            }
     
    178178                Host::Broadcast(message);
    179179*/
    180                 this->gtinfo_.sendAnnounceMessage(message);
     180                this->gtinfo_->sendAnnounceMessage(message);
    181181
    182182                if (timesequence_ >= 30 && timesequence_ <= 60)
  • code/branches/core5/src/orxonox/infos/HumanPlayer.cc

    r5801 r5806  
    162162
    163163        if (this->isInitialized() && this->isLocalPlayer())
    164             if (this->getGametype()->getHUDTemplate() != "")
     164        {
     165            if (this->getGametype() && this->getGametype()->getHUDTemplate() != "")
    165166                this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate());
     167            else
     168                this->setGametypeHUDTemplate("");
     169        }
    166170    }
    167171
  • code/branches/core5/src/orxonox/worldentities/pawns/Destroyer.cc

    r5738 r5806  
    4040        RegisterObject(Destroyer);
    4141
    42         UnderAttack* gametype = orxonox_cast<UnderAttack*>(this->getGametype());
     42        UnderAttack* gametype = orxonox_cast<UnderAttack*>(this->getGametype().get());
    4343        if (gametype)
    4444        {
  • code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc

    r5738 r5806  
    4545        this->state_ = BaseState::Uncontrolled;
    4646
    47         TeamBaseMatch* gametype = orxonox_cast<TeamBaseMatch*>(this->getGametype());
     47        TeamBaseMatch* gametype = orxonox_cast<TeamBaseMatch*>(this->getGametype().get());
    4848        if (gametype)
    4949        {
     
    5858        this->fireEvent();
    5959
    60         TeamDeathmatch* gametype = orxonox_cast<TeamDeathmatch*>(this->getGametype());
     60        TeamDeathmatch* gametype = orxonox_cast<TeamDeathmatch*>(this->getGametype().get());
    6161        if (!gametype)
    6262            return;
Note: See TracChangeset for help on using the changeset viewer.