Changeset 9290 for code/branches/presentation2012merge
- Timestamp:
- Jun 10, 2012, 11:01:40 PM (13 years ago)
- Location:
- code/branches/presentation2012merge/src/modules/pickup
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2012merge/src/modules/pickup/CollectiblePickup.cc
r7494 r9290 45 45 Registers the object and initializes variables. 46 46 */ 47 CollectiblePickup::CollectiblePickup() : isInCollection_(false)47 CollectiblePickup::CollectiblePickup() : collection_(NULL) 48 48 { 49 49 RegisterObject(CollectiblePickup); 50 51 this->collection_ = NULL;52 50 } 53 51 … … 58 56 CollectiblePickup::~CollectiblePickup() 59 57 { 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); 93 60 } 94 61 … … 131 98 /** 132 99 @brief 133 Adds this CollectiblePickup to the inputPickupCollection.100 Notifies this CollectiblePickup that it was added to a PickupCollection. 134 101 @param collection 135 102 A pointer to the PickupCollection to which the CollectiblePickup should be added. 136 @return137 Returns true if the CollectiblePickup was successfully added to the PickupCollection.138 103 */ 139 bool CollectiblePickup::addToCollection(PickupCollection* collection)104 void CollectiblePickup::wasAddedToCollection(PickupCollection* collection) 140 105 { 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;145 106 this->collection_ = collection; 146 return true;147 107 } 148 108 149 109 /** 150 110 @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. 154 112 */ 155 bool CollectiblePickup::removeFromCollection(void)113 void CollectiblePickup::wasRemovedFromCollection(void) 156 114 { 157 if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection.158 return false;159 160 this->isInCollection_ = false;161 115 this->collection_ = NULL; 162 return true;163 116 } 164 165 117 } -
code/branches/presentation2012merge/src/modules/pickup/CollectiblePickup.h
r7547 r9290 55 55 class _PickupExport CollectiblePickup : public Pickupable 56 56 { 57 friend class PickupCollection; 57 58 58 59 public: … … 68 69 */ 69 70 bool isInCollection(void) const 70 { return this->isInCollection_; } 71 72 bool addToCollection(PickupCollection* collection); //!< Adds this CollectiblePickup to the input PickupCollection. 73 bool removeFromCollection(void); //!< Removes this CollectiblePickup from its PickupCollection. 71 { return this->collection_ != NULL; } 74 72 75 73 void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. 76 74 77 pr otected:78 v irtual void preDestroy(void); //!< Is called by OrxonoxClass::destroy() before the object is actually destroyed.79 v irtual void destroyPickup(void); //!< Destroys a Pickupable.75 private: 76 void wasAddedToCollection(PickupCollection* collection); 77 void wasRemovedFromCollection(void); 80 78 81 private:82 bool isInCollection_; //!< True if the CollectiblePickup is in a PickupCollection.83 79 PickupCollection* collection_; //!< A pointer to the PickupCollection this CollectiblePickup is in. 84 85 80 }; 86 81 } -
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.cc
r9279 r9290 70 70 Destructor. Iterates through all Pickupables this PickupCollection consists of and destroys them if they haven't been already. 71 71 */ 72 PickupCollection::~ 72 PickupCollection::~PickupCollection() 73 73 { 74 74 // Destroy all Pickupables constructing this PickupCollection. 75 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)76 { 77 (*it)-> removeFromCollection();78 (*it)->destroy ();75 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 76 { 77 (*it)->wasRemovedFromCollection(); 78 (*it)->destroyPickup(); 79 79 } 80 80 this->pickups_.clear(); … … 93 93 94 94 XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode); 95 96 this->initializeIdentifier();97 }98 99 /**100 @brief101 Initializes the PickupIdentifier for this pickup.102 */103 void PickupCollection::initializeIdentifier(void)104 {105 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)106 {107 this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());108 }109 95 } 110 96 … … 120 106 this->processingUsed_ = true; 121 107 // Change used for all Pickupables this PickupCollection consists of. 122 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)108 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 123 109 (*it)->setUsed(this->isUsed()); 124 110 … … 157 143 158 144 // Change the PickupCarrier for all Pickupables this PickupCollection consists of. 159 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)145 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 160 146 { 161 147 if(this->getCarrier() == NULL) … … 177 163 this->processingPickedUp_ = true; 178 164 // Change the pickedUp status for all Pickupables this PickupCollection consists of. 179 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)180 (* it)->setPickedUp(this->isPickedUp());165 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ) 166 (*(it++))->setPickedUp(this->isPickedUp()); 181 167 182 168 this->processingPickedUp_ = false; … … 220 206 PickupCollection* pickup = orxonox_cast<PickupCollection*>(item); 221 207 // Clone all Pickupables this PickupCollection consist of. 222 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)208 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 223 209 { 224 210 Pickupable* newPickup = (*it)->clone(); … … 226 212 pickup->addPickupable(collectible); 227 213 } 228 229 pickup->initializeIdentifier();230 214 } 231 215 … … 240 224 bool PickupCollection::isTarget(const PickupCarrier* carrier) const 241 225 { 242 for(std:: vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)226 for(std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 243 227 { 244 228 if(!carrier->isTarget(*it)) … … 274 258 return false; 275 259 276 pickup->addToCollection(this);277 260 this->pickups_.push_back(pickup); 261 pickup->wasAddedToCollection(this); 278 262 return true; 279 263 } … … 289 273 const Pickupable* PickupCollection::getPickupable(unsigned int index) const 290 274 { 291 return this->pickups_[index]; 275 unsigned int count = 0; 276 for (std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 277 { 278 if (count == index) 279 return *it; 280 else 281 ++count; 282 } 283 return NULL; 284 } 285 286 /** 287 @brief 288 Removes the Pickup from the Collection. 289 @param pickup 290 The Pickup to be removed. 291 @return 292 Returns true if the pickup was in the collection. 293 */ 294 bool PickupCollection::removePickupable(CollectiblePickup* pickup) 295 { 296 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 297 { 298 if (*it == pickup) 299 { 300 this->pickups_.erase(it); 301 pickup->wasRemovedFromCollection(); 302 return true; 303 } 304 } 305 return false; 292 306 } 293 307 -
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.h
r8351 r9290 89 89 bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection. 90 90 const Pickupable* getPickupable(unsigned int index) const; //!< Get the Pickupable at the given index. 91 bool removePickupable(CollectiblePickup* pickup); //!< Removes the input Pickupable from the list of Pickupables in this PickupCollection. 92 93 inline const std::list<CollectiblePickup*>& getPickups() const 94 { return this->pickups_; } 91 95 92 96 void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value. … … 95 99 96 100 protected: 97 void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup.98 99 101 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 100 102 … … 105 107 void changedPickedUpAction(void); //!< Helper method. 106 108 107 std:: vector<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.109 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. 108 110 109 111 unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use. -
code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.cc
r7533 r9290 35 35 36 36 #include "PickupCollectionIdentifier.h" 37 #include "PickupCollection.h" 37 38 38 39 namespace orxonox … … 43 44 Constructor. Registers the object. 44 45 */ 45 PickupCollectionIdentifier::PickupCollectionIdentifier(Pickup able* pickup) : PickupIdentifier(pickup)46 PickupCollectionIdentifier::PickupCollectionIdentifier(PickupCollection* collection) : PickupIdentifier(collection) 46 47 { 47 48 RegisterObject(PickupCollectionIdentifier); 49 50 this->collection_ = collection; 48 51 } 49 52 … … 80 83 81 84 // 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(); 84 87 85 88 // 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) 88 92 { 93 const PickupIdentifier* id1 = (*it1)->getPickupIdentifier(); 94 const PickupIdentifier* id2 = (*it2)->getPickupIdentifier(); 89 95 90 if( (*it)->compare(*it2) < 0)96 if(id1->compare(id2) < 0) 91 97 return -1; 92 if( (*it2)->compare(*it) < 0)98 if(id2->compare(id1) < 0) 93 99 return 1; 94 100 } … … 98 104 } 99 105 100 /**101 @brief102 Add a Pickupable to the PickupCollectionIdentifier.103 @param identifier104 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 111 106 } 112 107 -
code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.h
r8729 r9290 61 61 62 62 public: 63 PickupCollectionIdentifier(Pickup able* pickup); //!< Constructor.63 PickupCollectionIdentifier(PickupCollection* pickup); //!< Constructor. 64 64 ~PickupCollectionIdentifier(); //!< Destructor. 65 65 66 66 virtual int compare(const PickupIdentifier* identifier) const; //!< Compares a PickupCollectionIdentifier with a PickupIdentifier. 67 67 68 void addPickup(const PickupIdentifier* identifier); //!< Add a @ref orxonox::Pickupable "Pickupable" to the PickupCollectionIdentifier.69 70 68 private: 71 std::set<const PickupIdentifier*, PickupIdentifierCompare> identifiers_; //!< The set of PickupIdentifiers of the @ref orxonox::Pickupable "Pickupables", the @ref orxonox::PickupCollection "PickupCollection" with this PickupCollectionIdentifier consists of, ordered by the rule set by @ref orxonox::PickupIdentifierCompare "PickupIdentifierCompare".69 PickupCollection* collection_; 72 70 73 71 };
Note: See TracChangeset
for help on using the changeset viewer.