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/CollectiblePickup.cc

    r7494 r9290  
    4545        Registers the object and initializes variables.
    4646    */
    47     CollectiblePickup::CollectiblePickup() : isInCollection_(false)
     47    CollectiblePickup::CollectiblePickup() : collection_(NULL)
    4848    {
    4949        RegisterObject(CollectiblePickup);
    50 
    51         this->collection_ = NULL;
    5250    }
    5351
     
    5856    CollectiblePickup::~CollectiblePickup()
    5957    {
    60 
    61     }
    62 
    63     /**
    64     @brief
    65         Is called by OrxonoxClass::destroy() before the object is actually destroyed.
    66     */
    67     void CollectiblePickup::preDestroy(void)
    68     {
    69         this->Pickupable::preDestroy();
    70 
    71         // The PickupCollection has to be destroyed as well.
    72         if(this->isInCollection())
    73             this->collection_->Pickupable::destroy();
    74     }
    75 
    76     /**
    77     @brief
    78         Destroys a Pickupable.
    79     */
    80     void CollectiblePickup::destroyPickup(void)
    81     {
    82         if(!this->isInCollection()) // If the CollectiblePickup is not in a PickupCollection the destroyPickup method of Pickupable is called.
    83             this->Pickupable::destroyPickup();
    84         else // Else the ColectiblePickup is dropped and disabled,
    85         {
    86             this->drop(false);
    87             if(this->isInCollection() && this->isEnabled()) // It is only disabled if it is enabled and still ina PickupCollection after having been dropped.
    88             {
    89                 this->setDisabled();
    90                 this->collection_->pickupDisabled();
    91             }
    92         }
     58        if (this->isInCollection())
     59            this->collection_->removePickupable(this);
    9360    }
    9461
     
    13198    /**
    13299    @brief
    133         Adds this CollectiblePickup to the input PickupCollection.
     100        Notifies this CollectiblePickup that it was added to a PickupCollection.
    134101    @param collection
    135102        A pointer to the PickupCollection to which the CollectiblePickup should be added.
    136     @return
    137         Returns true if the CollectiblePickup was successfully added to the PickupCollection.
    138103    */
    139     bool CollectiblePickup::addToCollection(PickupCollection* collection)
     104    void CollectiblePickup::wasAddedToCollection(PickupCollection* collection)
    140105    {
    141         if(this->isInCollection() || collection == NULL) //If the CollectiblePickup already is in a PickupCollection or if the input pointer is NULL.
    142             return false;
    143 
    144         this->isInCollection_ = true;
    145106        this->collection_ = collection;
    146         return true;
    147107    }
    148108
    149109    /**
    150110    @brief
    151         Removes this CollectiblePickup from its PickupCollection.
    152     @return
    153         Returns true if the CollectiblePickup was succcessfully removed.
     111        Notifies this CollectiblePickup that it was removed from its PickupCollection.
    154112    */
    155     bool CollectiblePickup::removeFromCollection(void)
     113    void CollectiblePickup::wasRemovedFromCollection(void)
    156114    {
    157         if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection.
    158             return false;
    159 
    160         this->isInCollection_ = false;
    161115        this->collection_ = NULL;
    162         return true;
    163116    }
    164 
    165117}
Note: See TracChangeset for help on using the changeset viewer.