Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 10, 2012, 11:01:40 PM (12 years ago)
Author:
landauf
Message:

Fixed crash with MSVC if a PickupCollection was used
A depleted CollectiblePickup is now destroyed instead of being dropped
A destroyed CollectiblePickup removes itself from the PickupCollection
PickupCollection has to use a list instead of a vector because of this reason
Also PickupCollectionIdentifier needed to be changed because the number of pickups in a collection may now change
Probably also fixed a bug in PickupCollectionIdentifier::compare() because it2 was not incremented

not completely clean yet

File:
1 edited

Legend:

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

    r7533 r9290  
    3535
    3636#include "PickupCollectionIdentifier.h"
     37#include "PickupCollection.h"
    3738
    3839namespace orxonox
     
    4344        Constructor. Registers the object.
    4445    */
    45     PickupCollectionIdentifier::PickupCollectionIdentifier(Pickupable* pickup) : PickupIdentifier(pickup)
     46    PickupCollectionIdentifier::PickupCollectionIdentifier(PickupCollection* collection) : PickupIdentifier(collection)
    4647    {
    4748        RegisterObject(PickupCollectionIdentifier);
     49
     50        this->collection_ = collection;
    4851    }
    4952
     
    8083
    8184        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
    82         if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
    83             return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
     85        if(this->collection_->getPickups().size() != collectionIdentifier->collection_->getPickups().size())
     86            return this->collection_->getPickups().size()-collectionIdentifier->collection_->getPickups().size();
    8487
    8588        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
    86         std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
    87         for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
     89        std::list<CollectiblePickup*>::const_iterator it1 = this->collection_->getPickups().begin();
     90        std::list<CollectiblePickup*>::const_iterator it2 = collectionIdentifier->collection_->getPickups().begin();
     91        for( ; it1 != this->collection_->getPickups().end(); ++it1, ++it2)
    8892        {
     93            const PickupIdentifier* id1 = (*it1)->getPickupIdentifier();
     94            const PickupIdentifier* id2 = (*it2)->getPickupIdentifier();
    8995
    90             if((*it)->compare(*it2) < 0)
     96            if(id1->compare(id2) < 0)
    9197                return -1;
    92             if((*it2)->compare(*it) < 0)
     98            if(id2->compare(id1) < 0)
    9399                return 1;
    94100        }
     
    98104    }
    99105
    100     /**
    101     @brief
    102         Add a Pickupable to the PickupCollectionIdentifier.
    103     @param identifier
    104         A pointer to the PickupIdentifier of the Pickupable to be added.
    105     */
    106     void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier)
    107     {
    108         this->identifiers_.insert(identifier);
    109     }
    110 
    111106}
    112107
Note: See TracChangeset for help on using the changeset viewer.