Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9295


Ignore:
Timestamp:
Jun 12, 2012, 11:42:43 PM (12 years ago)
Author:
landauf
Message:

removed fancy counters because they will get out of sync way too easily if pickups are added or removed
performance is not really an issue here and not worth the hassle

Location:
code/branches/presentation2012merge/src/modules/pickup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012merge/src/modules/pickup/PickupCollection.cc

    r9294 r9295  
    5959
    6060        this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);
    61         this->usedCounter_ = 0;
    62         this->pickedUpCounter_ = 0;
    63         this->disabledCounter_ = 0;
    6461        this->processingUsed_ = false;
    6562        this->processingPickedUp_ = false;
     
    124121            return;
    125122
     123        size_t numPickupsEnabled = 0;
     124        size_t numPickupsInUse = 0;
     125        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     126        {
     127            if ((*it)->isEnabled())
     128                ++numPickupsEnabled;
     129            if ((*it)->isUsed())
     130                ++numPickupsInUse;
     131        }
     132
    126133        // If all the pickups are not in use but the PickupCollection is.
    127         if(this->usedCounter_ == 0 && this->isUsed())
     134        if(numPickupsInUse == 0 && this->isUsed())
    128135            this->setUsed(false);
    129136
    130137        // If all the enabled pickups are in use but the PickupCollection is not.
    131         if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed())
     138        if(numPickupsInUse > 0 && numPickupsInUse == numPickupsEnabled && !this->isUsed())
    132139            this->setUsed(true);
    133140    }
     
    182189
    183190        // If at least all the enabled pickups of this PickupCollection are no longer picked up.
    184         if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp())
     191        bool isOnePickupEnabledAndPickedUp = false;
     192        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     193        {
     194            if ((*it)->isEnabled() && (*it)->isPickedUp())
     195            {
     196                isOnePickupEnabledAndPickedUp = true;
     197                break;
     198            }
     199        }
     200        if(!isOnePickupEnabledAndPickedUp && this->isPickedUp())
    185201            this->Pickupable::destroy();
    186         else if(!this->isPickedUp()) // If the PickupCollection is no longer picked up.
    187             this->pickedUpCounter_ = 0;
    188202    }
    189203
     
    258272        this->pickups_.push_back(pickup);
    259273        pickup->wasAddedToCollection(this);
     274        this->pickupsChanged();
    260275        return true;
    261276    }
     
    295310                this->pickups_.erase(it);
    296311                pickup->wasRemovedFromCollection();
     312                this->pickupsChanged();
    297313                return true;
    298314            }
     
    310326    void PickupCollection::pickupChangedUsed(bool changed)
    311327    {
    312         if(changed)
    313             this->usedCounter_++;
    314         else
    315             this->usedCounter_--;
    316 
    317328        this->changedUsedAction();
    318329    }
     
    327338    void PickupCollection::pickupChangedPickedUp(bool changed)
    328339    {
    329         if(changed)
    330             this->pickedUpCounter_++;
    331         else
    332             this->pickedUpCounter_--;
    333 
    334340        this->changedPickedUpAction();
    335341    }
     
    342348    void PickupCollection::pickupDisabled(void)
    343349    {
    344         this->disabledCounter_++;
     350    }
     351
     352    /**
     353    @brief
     354        Helpfer function if the number of pickups in this collection has changed.
     355    */
     356    void PickupCollection::pickupsChanged(void)
     357    {
     358        this->changedUsedAction();
     359        this->changedPickedUpAction();
    345360    }
    346361
  • code/branches/presentation2012merge/src/modules/pickup/PickupCollection.h

    r9290 r9295  
    106106            void changedUsedAction(void); //!< Helper method.
    107107            void changedPickedUpAction(void); //!< Helper method.
     108            void pickupsChanged(void); //!< Helper method.
    108109
    109110            std::list<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
    110 
    111             unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use.
    112             unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up.
    113             unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled.
    114111
    115112            bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent.
Note: See TracChangeset for help on using the changeset viewer.