Changeset 9295
- Timestamp:
- Jun 12, 2012, 11:42:43 PM (13 years ago)
- Location:
- code/branches/presentation2012merge/src/modules/pickup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.cc
r9294 r9295 59 59 60 60 this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this); 61 this->usedCounter_ = 0;62 this->pickedUpCounter_ = 0;63 this->disabledCounter_ = 0;64 61 this->processingUsed_ = false; 65 62 this->processingPickedUp_ = false; … … 124 121 return; 125 122 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 126 133 // 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()) 128 135 this->setUsed(false); 129 136 130 137 // 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()) 132 139 this->setUsed(true); 133 140 } … … 182 189 183 190 // 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()) 185 201 this->Pickupable::destroy(); 186 else if(!this->isPickedUp()) // If the PickupCollection is no longer picked up.187 this->pickedUpCounter_ = 0;188 202 } 189 203 … … 258 272 this->pickups_.push_back(pickup); 259 273 pickup->wasAddedToCollection(this); 274 this->pickupsChanged(); 260 275 return true; 261 276 } … … 295 310 this->pickups_.erase(it); 296 311 pickup->wasRemovedFromCollection(); 312 this->pickupsChanged(); 297 313 return true; 298 314 } … … 310 326 void PickupCollection::pickupChangedUsed(bool changed) 311 327 { 312 if(changed)313 this->usedCounter_++;314 else315 this->usedCounter_--;316 317 328 this->changedUsedAction(); 318 329 } … … 327 338 void PickupCollection::pickupChangedPickedUp(bool changed) 328 339 { 329 if(changed)330 this->pickedUpCounter_++;331 else332 this->pickedUpCounter_--;333 334 340 this->changedPickedUpAction(); 335 341 } … … 342 348 void PickupCollection::pickupDisabled(void) 343 349 { 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(); 345 360 } 346 361 -
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.h
r9290 r9295 106 106 void changedUsedAction(void); //!< Helper method. 107 107 void changedPickedUpAction(void); //!< Helper method. 108 void pickupsChanged(void); //!< Helper method. 108 109 109 110 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.114 111 115 112 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.