Changeset 6538 for code/trunk/src/modules
- Timestamp:
- Mar 16, 2010, 6:15:45 PM (15 years ago)
- Location:
- code/trunk/src/modules/pickup
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/pickup/PickupCollection.cc
r6533 r6538 28 28 29 29 /** 30 @file 30 @file PickupCollection.cc 31 31 @brief Implementation of PickupCollection. 32 32 */ 33 33 34 #include "PickupCollection.h"35 36 34 #include "core/CoreIncludes.h" 37 #include "core/Template.h"38 35 #include "core/XMLPort.h" 39 36 #include "interfaces/PickupCarrier.h" 40 37 #include "DroppedPickup.h" 41 42 38 #include "PickupCollectionIdentifier.h" 39 40 #include "PickupCollection.h" 43 41 44 42 namespace orxonox … … 60 58 /** 61 59 @brief 62 Destructor. 60 Destructor. Iterates through all Pickupables this PickupCollection consists of and destroys them if they haven't been already. 63 61 */ 64 62 PickupCollection::~PickupCollection() … … 85 83 } 86 84 85 /** 86 @brief 87 Initializes the PickupIdentifier for this pickup. 88 */ 87 89 void PickupCollection::initializeIdentifier(void) 88 90 { … … 93 95 } 94 96 97 /** 98 @brief 99 Is called when the pickup has transited from used to unused or the other way around. 100 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. 101 */ 102 void PickupCollection::changedUsed(void) 103 { 104 SUPER(PickupCollection, changedUsed); 105 106 //! Change used for all Pickupables this PickupCollection consists of. 107 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 108 { 109 (*it).get()->setUsed(this->isUsed()); 110 } 111 } 112 113 /** 114 @brief 115 Is called when the pickup has changed its PickupCarrier. 116 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. 117 */ 118 void PickupCollection::changedCarrier(void) 119 { 120 SUPER(PickupCollection, changedCarrier); 121 122 //! Change the PickupCarrier for all Pickupables this PickupCollection consists of. 123 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 124 { 125 (*it).get()->setCarrier(this->getCarrier()); 126 } 127 } 128 129 /** 130 @brief 131 Is called when the pickup has transited from picked up to dropped or the other way around. 132 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method. 133 */ 134 void PickupCollection::changedPickedUp() 135 { 136 SUPER(PickupCollection, changedPickedUp); 137 138 //! Change the pickedUp status for all Pickupables this PickupCollection consists of. 139 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 140 { 141 (*it).get()->setPickedUp(this->isPickedUp()); 142 } 143 } 144 145 /** 146 @brief 147 Creates a duplicate of the input OrxonoxClass. 148 This method needs to be implemented by any Class inheriting from Pickupable. 149 @param item 150 A reference to a pointer to the OrxonoxClass that is to be duplicated. 151 */ 152 void PickupCollection::clone(OrxonoxClass*& item) 153 { 154 if(item == NULL) 155 item = new PickupCollection(this); 156 157 SUPER(PickupCollection, clone, item); 158 159 PickupCollection* pickup = dynamic_cast<PickupCollection*>(item); 160 //! Clone allPickupables this PickupCollection consist of. 161 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 162 { 163 Pickupable* newPickup = (*it).get()->clone(); 164 pickup->addPickupable(newPickup); 165 } 166 167 pickup->initializeIdentifier(); 168 } 169 170 /** 171 @brief 172 Get whether a given class, represented by the input Identifier, is a target of this PickupCollection. 173 @param identifier 174 A pointer to the PickupIdentifier of the PickupCarrier we want to know of, whether it is a target of this PickupCollection. 175 @return 176 Returns true if the PickupCarrier identified by the input PickupIdentififer it is a target of this PickupCollection, false if not. 177 */ 178 bool PickupCollection::isTarget(Identifier* identifier) const 179 { 180 for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 181 { 182 if(!(*it).get()->isTarget(identifier)) 183 return false; 184 } 185 186 return true; 187 } 188 189 /** 190 @brief 191 Get the PickupIdentifier of this PickupCollection. 192 This is in fact the PickupCollectionIdentifier. 193 @return 194 Returns a pointer to the PickupIdentifier of this PickupCollection. 195 */ 196 const PickupIdentifier* PickupCollection::getPickupIdentifier(void) 197 { 198 return this->pickupCollectionIdentifier_; 199 } 200 201 /** 202 @brief 203 Add the input Pickupable to list of Pickupables combined by this PickupCollection. 204 @param pickup 205 The Pickupable to be added. 206 @return 207 Returns true if successful, 208 */ 209 bool PickupCollection::addPickupable(Pickupable* pickup) 210 { 211 if(pickup == NULL) 212 return false; 213 214 WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid. 215 this->pickups_.push_back(ptr); 216 return true; 217 } 218 219 /** 220 @brief 221 Get the Pickupable at the given index. 222 @param index 223 The index the Pickupable is fetched from. 224 @return 225 Returns a pointer to the Pickupable at the index given by index. 226 */ 227 const Pickupable* PickupCollection::getPickupable(unsigned int index) 228 { 229 return this->pickups_[index].get(); 230 } 231 95 232 /** 96 233 @brief … … 109 246 } 110 247 111 /**112 @brief113 Add the input Pickupable to list of Pickupables combined by this PickupCollection.114 @param pickup115 The Pickupable to be added.116 @return117 Returns true if successful,118 */119 bool PickupCollection::addPickupable(Pickupable* pickup)120 {121 if(pickup == NULL)122 return false;123 124 WeakPtr<Pickupable> ptr = pickup;125 this->pickups_.push_back(ptr);126 return true;127 }128 129 /**130 @brief131 Get the Pickupable at the given index.132 @param index133 The index the Pickupable is fetched from.134 @return135 Returns a pointer to the Pickupable at the index given by index.136 */137 const Pickupable* PickupCollection::getPickupable(unsigned int index)138 {139 return this->pickups_[index].get(); //TODO. Does this work?140 }141 142 void PickupCollection::changedUsed(void)143 {144 SUPER(PickupCollection, changedUsed);145 146 //! Change used for all Pickupables this PickupCollection consists of.147 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)148 {149 (*it).get()->setUsed(this->isUsed());150 }151 }152 153 void PickupCollection::changedCarrier(void)154 {155 SUPER(PickupCollection, changedCarrier);156 157 //! Change used for all Pickupables this PickupCollection consists of.158 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)159 {160 (*it).get()->setCarrier(this->getCarrier());161 }162 }163 164 void PickupCollection::changedPickedUp()165 {166 SUPER(PickupCollection, changedPickedUp);167 168 //! Change the carrier for all Pickupables this PickupCollection consists of.169 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)170 {171 (*it).get()->setPickedUp(this->isPickedUp());172 }173 }174 175 void PickupCollection::clone(OrxonoxClass*& item)176 {177 if(item == NULL)178 item = new PickupCollection(this);179 180 SUPER(PickupCollection, clone, item);181 182 PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);183 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)184 {185 Pickupable* newPickup = (*it).get()->clone();186 pickup->addPickupable(newPickup);187 }188 189 pickup->initializeIdentifier();190 }191 192 bool PickupCollection::isTarget(Identifier* identifier) const193 {194 for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)195 {196 if(!(*it).get()->isTarget(identifier))197 return false;198 }199 200 return true;201 }202 203 const PickupIdentifier* PickupCollection::getPickupIdentifier(void)204 {205 return this->pickupCollectionIdentifier_;206 }207 208 248 } -
code/trunk/src/modules/pickup/PickupCollection.h
r6533 r6538 27 27 */ 28 28 29 /** 30 @file PickupCollection.h 31 @brief Declaration of PickupCollection. 32 */ 33 29 34 #ifndef _PickupCollection_H__ 30 35 #define _PickupCollection_H__ … … 34 39 #include "interfaces/Pickupable.h" 35 40 #include "core/BaseObject.h" 36 #include "core/XMLPort.h"37 41 38 42 #include <list> … … 52 56 public: 53 57 54 PickupCollection(BaseObject* creator); 55 virtual ~PickupCollection(); 58 PickupCollection(BaseObject* creator); //!< Default Constructor. 59 virtual ~PickupCollection(); //!< Destructor. 56 60 57 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates an instance of this Class through XML. 58 62 59 virtual void changedUsed(void); 60 virtual void changedCarrier(void); 61 virtual void changedPickedUp(void); 63 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 64 virtual void changedCarrier(void); //!< Is called when the pickup has changed its PickupCarrier. 65 virtual void changedPickedUp(void); //!< Is called when the pickup has transited from picked up to dropped or the other way around. 62 66 63 virtual void clone(OrxonoxClass*& item); 67 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 64 68 65 virtual bool isTarget(Identifier* identifier) const; 69 virtual bool isTarget(Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection. 66 70 67 virtual const PickupIdentifier* getPickupIdentifier(void); 71 virtual const PickupIdentifier* getPickupIdentifier(void); //!< Get the PickupIdentifier of this PickupCollection. 68 72 69 bool addPickupable(Pickupable* pickup); 70 const Pickupable* getPickupable(unsigned int index); 73 bool addPickupable(Pickupable* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection. 74 const Pickupable* getPickupable(unsigned int index); //!< Get the Pickupable at the given index. 71 75 72 76 protected: 73 void initializeIdentifier(void); 77 void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup. 74 78 75 79 virtual bool createSpawner(const Vector3& position); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 76 80 77 PickupCollectionIdentifier* pickupCollectionIdentifier_; 81 PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves. 78 82 79 83 private: 80 84 81 std::vector<WeakPtr<Pickupable> > pickups_; 85 std::vector<WeakPtr<Pickupable> > 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. 82 86 83 87 }; -
code/trunk/src/modules/pickup/PickupCollectionIdentifier.cc
r6524 r6538 21 21 * 22 22 * Author: 23 * ...23 * Damian 'Mozork' Frick 24 24 * Co-authors: 25 25 * ... … … 27 27 */ 28 28 29 #include "PickupCollectionIdentifier.h" 29 /** 30 @file PickupCollectionIdentifier.cc 31 @brief Implementation of PickupCollectionIdentifier. 32 */ 30 33 31 34 #include "core/CoreIncludes.h" 35 36 #include "PickupCollectionIdentifier.h" 32 37 33 38 namespace orxonox 34 39 { 35 40 41 /** 42 @brief 43 Constructor. Registers the object. 44 */ 36 45 PickupCollectionIdentifier::PickupCollectionIdentifier(Pickupable* pickup) : PickupIdentifier(pickup) 37 46 { … … 39 48 } 40 49 50 /** 51 @brief 52 Destructor. 53 */ 41 54 PickupCollectionIdentifier::~PickupCollectionIdentifier() 42 55 { … … 44 57 } 45 58 59 /** 60 @brief 61 Compares a PickupCollectionIdentifier with a PickupIdentifier and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b), where a is a PickupCollectionIdentifier and b is just some PickupIdentifier. 62 @param identifier 63 Pointer to the second PickupIdentifier, b. 64 @return 65 Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b. 66 */ 46 67 int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const 47 68 { 69 //! Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier. 48 70 PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier); 49 71 const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp); 72 73 //! If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared. 50 74 if(collectionIdentifier == NULL) 51 75 { … … 53 77 } 54 78 79 //! If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller. 55 80 if(this->identifiers_.size() != collectionIdentifier->identifiers_.size()) 56 81 return this->identifiers_.size()-collectionIdentifier->identifiers_.size(); 57 82 83 //! Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller. 58 84 std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin(); 59 85 for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++) … … 66 92 } 67 93 94 //! Means they are equal. 68 95 return 0; 69 96 } 70 97 98 /** 99 @brief 100 Add a Pickupable to the PickupCollectionIdentifier. 101 @param 102 A pointer to the PickupIdentifier of the Pickupable to be added. 103 */ 71 104 void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier) 72 105 { -
code/trunk/src/modules/pickup/PickupCollectionIdentifier.h
r6524 r6538 21 21 * 22 22 * Author: 23 * ...23 * Damian 'Mozork' Frick 24 24 * Co-authors: 25 25 * ... 26 26 * 27 */ 28 29 /** 30 @file PickupCollectionIdentifier.h 31 @brief Declaration of PickupCollectionIdentifier. 27 32 */ 28 33 … … 33 38 34 39 #include "pickup/PickupIdentifier.h" 40 35 41 #include <set> 36 42 … … 38 44 { 39 45 46 /** 47 @brief 48 The PickupCollectionIdentifier is the specialization of the PickupIdentifier for the PickupCollection class. 49 It identifies PickupCollections based on the different Pickupables they consist of. 50 Pickupables can be added to the PickupCollectionIdentifier via the addPickup method. 51 @author 52 Damian 'Mozork' Frick 53 */ 40 54 class _PickupExport PickupCollectionIdentifier : public PickupIdentifier 41 55 { 42 56 43 57 public: 44 PickupCollectionIdentifier(Pickupable* pickup); 45 ~PickupCollectionIdentifier(); 58 PickupCollectionIdentifier(Pickupable* pickup); //!< Constructor. 59 ~PickupCollectionIdentifier(); //!< Destructor. 46 60 47 virtual int compare(const PickupIdentifier* identifier) const; 61 virtual int compare(const PickupIdentifier* identifier) const; //!< Compares a PickupCollectionIdentifier with a PickupIdentifier. 48 62 49 void addPickup(const PickupIdentifier* identifier); 63 void addPickup(const PickupIdentifier* identifier); //!< Add a Pickupable to the PickupCollectionIdentifier. 50 64 51 65 private: 52 std::set<const PickupIdentifier*, PickupIdentifierCompare> identifiers_; 66 std::set<const PickupIdentifier*, PickupIdentifierCompare> identifiers_; //!< The set of PickupIdentifiers of the Pickupables the PickupCollection with this PickupCollectionIdentifier consists of, ordered by the rule set by PickupIdentifierCompare. 53 67 54 68 }; -
code/trunk/src/modules/pickup/items/MetaPickup.cc
r6524 r6538 28 28 29 29 /** 30 @file 30 @file MetaPickup.cc 31 31 @brief Implementation of the MetaPickup class. 32 32 */ … … 43 43 CreateFactory(MetaPickup); 44 44 45 //! Setting the static variables to their values. 45 46 /*static*/ const std::string MetaPickup::metaTypeNone_s = "none"; 46 47 /*static*/ const std::string MetaPickup::metaTypeUse_s = "use"; … … 49 50 /** 50 51 @brief 51 Constructor. 52 Constructor. Registers and initializes the object. 52 53 */ 53 54 MetaPickup::MetaPickup(BaseObject* creator) : Pickup(creator) … … 55 56 RegisterObject(MetaPickup); 56 57 58 this->initialize(); 59 } 60 61 /** 62 @brief 63 Destructor. 64 */ 65 MetaPickup::~MetaPickup() 66 { 67 68 } 69 70 /** 71 @brief 72 Initializes the object. 73 */ 74 void MetaPickup::initialize(void) 75 { 57 76 this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier()); 77 58 78 this->setActivationTypeDirect(pickupActivationType::immediate); 59 79 this->setDurationTypeDirect(pickupDurationType::once); … … 61 81 } 62 82 63 MetaPickup::~MetaPickup() 64 { 65 66 } 67 83 /** 84 @brief 85 Helper method to initialize the PickupIdentifier. 86 */ 68 87 void MetaPickup::initializeIdentifier(void) 69 88 { … … 73 92 } 74 93 94 /** 95 @brief 96 Method for creating a MetaPickup object through XML. 97 */ 75 98 void MetaPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) 76 99 { … … 82 105 } 83 106 107 /** 108 @brief 109 Is called when the pickup has transited from used to unused or the other way around. 110 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. 111 */ 84 112 void MetaPickup::changedUsed(void) 85 113 { 86 114 SUPER(MetaPickup, changedUsed); 87 115 116 //! If the MetaPickup transited to used. 88 117 if(this->isUsed()) 89 118 { … … 92 121 { 93 122 std::set<Pickupable*> pickups = carrier->getPickups(); 123 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending o the meta type. 94 124 for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++) 95 125 { … … 114 144 } 115 145 } 116 146 147 /** 148 @brief 149 Creates a duplicate of the input OrxonoxClass. 150 @param item 151 A pointer to the Orxonox class. 152 */ 153 void MetaPickup::clone(OrxonoxClass*& item) 154 { 155 if(item == NULL) 156 item = new MetaPickup(this); 157 158 SUPER(MetaPickup, clone, item); 159 160 MetaPickup* pickup = dynamic_cast<MetaPickup*>(item); 161 pickup->setMetaTypeDirect(this->getMetaTypeDirect()); 162 163 pickup->initializeIdentifier(); 164 } 165 166 /** 167 @brief 168 Get the meta type of this MetaPickup. 169 @return 170 Returns a string with the meta type of the MetaPickup. 171 */ 117 172 const std::string& MetaPickup::getMetaType(void) 118 173 { … … 130 185 } 131 186 187 /** 188 @brief 189 Set the meta type of this MetaPickup. 190 @param type 191 A string with the type to be set. 192 */ 132 193 void MetaPickup::setMetaType(const std::string& type) 133 194 { … … 146 207 } 147 208 148 void MetaPickup::clone(OrxonoxClass*& item)149 {150 if(item == NULL)151 item = new MetaPickup(this);152 153 SUPER(MetaPickup, clone, item);154 155 MetaPickup* pickup = dynamic_cast<MetaPickup*>(item);156 pickup->setMetaTypeDirect(this->getMetaTypeDirect());157 158 pickup->initializeIdentifier();159 }160 161 209 } -
code/trunk/src/modules/pickup/items/MetaPickup.h
r6524 r6538 28 28 29 29 /** 30 @file 30 @file MetaPickup.h 31 31 @brief Definition of the MetaPickup class. 32 32 */ … … 62 62 63 63 public: 64 MetaPickup(BaseObject* creator); 65 virtual ~MetaPickup(); 64 MetaPickup(BaseObject* creator); //!< Constructor. Registers and initializes the object. 65 virtual ~MetaPickup(); //!< Destructor. 66 66 67 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.67 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a MetaPickup object through XML. 68 68 69 69 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 70 70 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 71 71 72 /** 73 @brief Returns the meta type of the MetaPickup. 74 @return Returns an enum with the meta type of the MetaPickup. 75 */ 72 76 inline pickupMetaType::Value getMetaTypeDirect(void) 73 77 { return this->metaType_; } 74 const std::string& getMetaType(void); 78 const std::string& getMetaType(void); //!< Get the meta type of this MetaPickup. 75 79 76 80 protected: 81 void initialize(void); //!< Initializes the object. 77 82 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 78 83 84 /** 85 @brief Set the meta type of the MetaPickup. 86 @param type The meta type as an enum. 87 */ 79 88 inline void setMetaTypeDirect(pickupMetaType::Value type) 80 89 { this->metaType_ = type; } 81 void setMetaType(const std::string& type); 90 void setMetaType(const std::string& type); //!< Set the meta type of this MetaPickup. 82 91 83 92 private: 84 93 void initialize(void); //!< Initializes the member variables. 85 94 86 pickupMetaType::Value metaType_; 95 pickupMetaType::Value metaType_; //!< The meta type of the MetaPickup, determines which actions are taken. 96 97 //! Static strings for the meta types. 87 98 static const std::string metaTypeNone_s; 88 99 static const std::string metaTypeUse_s;
Note: See TracChangeset
for help on using the changeset viewer.