Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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                }
Note: See TracChangeset for help on using the changeset viewer.