Changeset 7494 for code/trunk/src/orxonox
- Timestamp:
- Sep 28, 2010, 5:31:59 PM (14 years ago)
- Location:
- code/trunk/src/orxonox
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/interfaces/CMakeLists.txt
r6524 r7494 2 2 InterfaceCompilation.cc 3 3 Pickupable.cc 4 PickupCarrier.cc 4 5 RadarViewable.cc 5 6 ) -
code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc
r7163 r7494 34 34 35 35 #include "GametypeMessageListener.h" 36 #include "PickupCarrier.h"37 36 #include "PlayerTrigger.h" 38 37 #include "RadarListener.h" … … 51 50 { 52 51 RegisterRootObject(GametypeMessageListener); 53 }54 55 //----------------------------56 // PickupCarrier57 //----------------------------58 PickupCarrier::PickupCarrier()59 {60 RegisterRootObject(PickupCarrier);61 }62 63 PickupCarrier::~PickupCarrier()64 {65 66 }67 68 void PickupCarrier::preDestroy(void)69 {70 std::set<Pickupable*>::iterator it = this->pickups_.begin();71 std::set<Pickupable*>::iterator temp;72 while(it != this->pickups_.end())73 {74 (*it)->carrierDestroyed();75 temp = it;76 it = this->pickups_.begin();77 if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure.78 {79 COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;;80 it++;81 }82 }83 84 this->pickups_.clear();85 52 } 86 53 -
code/trunk/src/orxonox/interfaces/PickupCarrier.h
r7456 r7494 38 38 #include "OrxonoxPrereqs.h" 39 39 40 #include <list>41 40 #include <set> 42 #include "Pickupable.h" 43 #include "core/Identifier.h" 44 #include "core/WeakPtr.h" 41 #include <vector> 45 42 46 43 #include "core/OrxonoxClass.h" … … 49 46 { 50 47 51 // !Forward-declarations.48 // Forward-declarations. 52 49 class PickupManager; 53 50 class Pickup; … … 60 57 /** 61 58 @brief 62 The PickupCarrier interface provides the means, for any class implementing it, to possess Pickupables. 59 The PickupCarrier interface provides the means, for any class implementing it, to possess @ref orxonox::Pickupable "Pickupables". 60 61 For a class to use the PickupCarrier interface it must implement the follwing three methods: 62 - <b>getCarrierPosition()</b> The getCarrierPosition() method returns the absolute position (in space) of the PickupCarrier. 63 64 Different PickupCarriers are structured hierarchically, a pickup can be picked up by a PickupCarrier that can't really carry that particular pickup but one of its children (or one of their children) can, and thus it gets "handed down" until it is at the right place. 65 But this structure has to be established first. 66 - <b>getCarrierChildren()</b> To this end a PickupCarrier needs to implement getCarrierChildren() which returns a list of its direct PickupCarrier children. If you need an example, have a look at @ref orxonox::Pawn "Pawn" and @ref orxonx::Engine "Engine". 67 - <b>getCarrierParent()</b> This is the method in the other direction. It returns the parent of this PickupCarrier, or NULL if the PickupCarrier is a root node in this hierarchy. 68 63 69 @author 64 70 Damian 'Mozork' Frick … … 66 72 class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass 67 73 { 68 // !So that the different Pickupables have full access to their PickupCarrier.74 // So that the different Pickupables have full access to their PickupCarrier. 69 75 friend class Pickupable; 70 76 friend class PickupManager; 71 // !Friends.77 // Friends. 72 78 friend class Pickup; 73 79 friend class HealthPickup; … … 80 86 PickupCarrier(); //!< Constructor. 81 87 virtual ~PickupCarrier(); //!< Destructor. 82 void preDestroy(void); 88 void preDestroy(void); //!< Is called before the PickupCarrier is effectively destroyed. 83 89 84 /** 85 @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable. 86 @param pickup A pointer to the Pickupable. 87 @return Returns true if the PickupCarrier or one of its children is a target, false if not. 88 */ 89 bool isTarget(const Pickupable* pickup) 90 { 91 if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target. 92 return true; 93 94 //! Go recursively through all children to check whether they are a target. 95 std::vector<PickupCarrier*>* children = this->getCarrierChildren(); 96 for(std::vector<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++) 97 { 98 if((*it)->isTarget(pickup)) 99 return true; 100 } 101 102 children->clear(); 103 delete children; 104 105 return false; 106 } 107 108 /** 109 @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable. 110 @param pickup A pounter to the Pickupable. 111 @return Returns a pointer to the PickupCarrier that is the target of the input Pickupable. 112 */ 113 PickupCarrier* getTarget(const Pickupable* pickup) 114 { 115 if(!this->isTarget(pickup)) 116 return NULL; 117 118 if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target. 119 return this; 120 121 //! Go recursively through all children to check whether they are the target. 122 std::vector<PickupCarrier*>* children = this->getCarrierChildren(); 123 for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++) 124 { 125 if(pickup->isTarget(*it)) 126 return *it; 127 } 128 129 children->clear(); 130 delete children; 131 132 return NULL; 133 } 90 bool isTarget(const Pickupable* pickup); //!< Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable. 91 PickupCarrier* getTarget(const Pickupable* pickup); //!< Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable. 134 92 135 93 /** … … 149 107 virtual std::vector<PickupCarrier*>* getCarrierChildren(void) = 0; 150 108 /** 151 @brief Get the parent of this PickupSpawner 109 @brief Get the parent of this PickupSpawner. 152 110 This method needs to be implemented by any direct derivative class of PickupCarrier. 153 111 @return Returns a pointer to the parent. … … 165 123 std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier. 166 124 167 /** 168 @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier. 169 @param pickup A pointer to the pickup to be added. 170 @return Returns true if successfull, false if the Pickupable was already present. 171 */ 172 bool addPickup(Pickupable* pickup) 173 { 174 COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl; 175 return this->pickups_.insert(pickup).second; 176 } 177 178 /** 179 @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier. 180 @param pickup A pointer to the pickup to be removed. 181 @return Returns true if successfull, false if the Pickupable was not present in the list. 182 */ 183 bool removePickup(Pickupable* pickup) 184 { 185 COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl; 186 return this->pickups_.erase(pickup) == 1; 187 } 125 bool addPickup(Pickupable* pickup); //!< Adds a Pickupable to the list of pickups that are carried by this PickupCarrier. 126 bool removePickup(Pickupable* pickup); //!< Removes a Pickupable from the list of pickups that are carried by this PickupCarrier. 188 127 189 128 }; -
code/trunk/src/orxonox/interfaces/Pickupable.cc
r7493 r7494 39 39 #include "core/CoreIncludes.h" 40 40 #include "util/Convert.h" 41 41 42 #include "infos/PlayerInfo.h" 42 43 #include "pickup/PickupIdentifier.h" 43 44 #include "worldentities/pawns/Pawn.h" 45 44 46 #include "PickupCarrier.h" 45 47 … … 130 132 this->changedUsed(); 131 133 134 //TODO: Synchronize & make safe for dedicated server. 132 135 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()"); 133 136 return true; … … 277 280 this->getCarrier()->removePickup(this); 278 281 this->changedPickedUp(); 282 283 //TODO: Synchronize & make safe for dedicated server. 279 284 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()"); 280 285 return true; … … 303 308 return false; 304 309 } 305 310 306 311 this->carrier_ = carrier; 307 312 this->changedCarrier(); -
code/trunk/src/orxonox/interfaces/Pickupable.h
r7456 r7494 50 50 @brief 51 51 An Interface (or more precisely an abstract class) to model and represent different (all kinds of) pickups. 52 53 Pickups (@ref orxonox:Pickupable "Pickupables") are objects that (quite unsurprisingly) can be picked up. Additionally they can be used and unused (transition from used to not used), and also dropped. 54 55 A class of Pickups can incorporate many different types of pickups (see @ref orxonox::PickupIdentifier "PickupIdentifier"), each type is uniquely defined by a @ref orxonox::PickupIdentifier "PickupIdentifier". Each pickup has such an identifier identiying its type. This means that two pickups of the same type have identifiers which are equal. 56 52 57 @author 53 58 Damian 'Mozork' Frick … … 63 68 64 69 /** 65 @brief Get whether the pickupis currently in use or not.66 @return Returns true if the pickupis currently in use.70 @brief Get whether the Pickupable is currently in use or not. 71 @return Returns true if the Pickupable is currently in use. 67 72 */ 68 73 inline bool isUsed(void) { return this->used_; } // tolua_export 69 74 /** 70 @brief Should be called when the pickuphas transited from used to unused or the other way around.75 @brief Should be called when the Pickupable has transited from used to unused or the other way around. 71 76 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. 72 77 */ … … 74 79 75 80 /** 76 @brief Get the carrier of the pickup.77 @return Returns a pointer to the carrier of the pickup.81 @brief Get the carrier of the Pickupable. 82 @return Returns a pointer to the carrier of the Pickupable. 78 83 */ 79 84 inline PickupCarrier* getCarrier(void) 80 85 { return this->carrier_; } 81 86 /** 82 @brief Should be called when the pickuphas changed its PickupCarrier.87 @brief Should be called when the Pickupable has changed its PickupCarrier. 83 88 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. 84 89 */ … … 91 96 inline bool isPickedUp(void) { return this->pickedUp_; } // tolua_export 92 97 /** 93 @brief Should be called when the pickuphas transited from picked up to dropped or the other way around.98 @brief Should be called when the Pickupable has transited from picked up to dropped or the other way around. 94 99 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method. 95 100 */ … … 119 124 bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable. 120 125 121 virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.126 virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this Pickupable. 122 127 bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable. 123 bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.124 bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup.128 bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this Pickupable. 129 bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this Pickupable. 125 130 126 131 Pickupable* clone(void); //!< Creates a duplicate of the Pickupable. … … 137 142 bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up. 138 143 //TODO: private? 139 bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup.144 bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the Pickupable. 140 145 141 146 //TODO: private? 142 147 virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. 143 148 144 void destroy(void); //!< Is called internally within the pickupmodule to destroy pickups.149 void destroy(void); //!< Is called internally within the Pickupable module to destroy pickups. 145 150 146 151 protected: … … 187 192 }; // tolua_export 188 193 194 //! SUPER functions. 189 195 SUPER_FUNCTION(10, Pickupable, changedUsed, false); 190 196 SUPER_FUNCTION(12, Pickupable, changedCarrier, false); -
code/trunk/src/orxonox/pickup/PickupIdentifier.cc
r7163 r7494 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "core/Identifier.h" 38 37 39 #include "interfaces/Pickupable.h" 38 40 … … 69 71 int PickupIdentifier::compare(const PickupIdentifier* identifier) const 70 72 { 71 if(identifier == NULL) 72 { 73 return 1; 74 COUT(1) << "Error in PickupIdentifier::compare: Input Identifier is NULL." << std::endl; 75 } 73 assert(identifier); 74 assert(identifier->pickup_); 75 assert(this->pickup_); 76 76 77 if(identifier->pickup_ == NULL && this->pickup_ == NULL) 78 { 79 return 0; 80 COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl; 81 } 82 83 if(identifier->pickup_ == NULL) 84 { 85 return 1; 86 COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl; 87 } 88 89 if(this->pickup_ == NULL) 90 { 91 return -1; 92 COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl; 93 } 94 95 //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames. 77 // If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames. 96 78 if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier())) 97 79 return this->pickup_->getIdentifier()->getName().compare(identifier->pickup_->getIdentifier()->getName()); 98 80 99 // !If the class is the same for both PickupIdentifiers we go on to check the parameters of the class.100 // ! If the two have a different number of parameters then obviusly something is very wrong.81 // If the class is the same for both PickupIdentifiers we go on to check the parameters of the class. 82 // If the two have a different number of parameters then obviously something is very wrong. 101 83 if(!(this->parameters_.size() == identifier->parameters_.size())) 102 84 { … … 105 87 } 106 88 107 // !We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.89 // We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings. 108 90 for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++) 109 91 { 110 // !<If a parameter present in one of the identifiers is not found in the other, once again, something is very wrong.92 // If a parameter present in one of the identifiers is not found in the other, once again, something is very wrong. 111 93 if(identifier->parameters_.find(it->first) == identifier->parameters_.end()) 112 94 { -
code/trunk/src/orxonox/pickup/PickupIdentifier.h
r7456 r7494 40 40 #include <map> 41 41 #include <string> 42 #include "core/Identifier.h"43 42 44 43 #include "core/OrxonoxClass.h" … … 49 48 /** 50 49 @brief 51 The purpose of the PickupIdentifier class is to identify different types of pickups allthough they are of the same class. 52 This allows for more generic classes (or pickups in this case) that can be a number of different pickup types and can be identified as such without the need for a lot of different classes. An example is the HealthPickup class that encompasses a wide variety of different types of health pickups, e.g a HealthPickup that adds 10 health every second for 10 seconds or a HealthPickup that adds 100 health as soon as it is picked up, a.s.o. 53 To that purpose this class provides functionality to compare two PickupIdentifier (and since all Pickupables have an Identifier through that Pickupables can be compared). It als provides functionality to add parameters that distinguish between different types of pickups in the same pickup class. 54 Lastly a struct is provided that can be used in stl containers to establish a strictly lesser ordering between PickupIdentifiers (and thus Pickupables). 50 The purpose of the PickupIdentifier class is to identify (or differentiate between) different types of pickups although they are of the same class. 51 52 This allows for more generic classes (or pickups in this case) that can be a number of different pickup types and can be identified as such without the need for a lot of different classes. 53 54 An example is the @ref orxonox::HealthPickup "HealthPickup" class that encompasses a wide variety of different types of health pickups, e.g a @ref orxonox::HealthPickup "HealthPickup" that adds 10 health every second for 10 seconds or a @ref orxonox::HealthPickup "HealthPickup" that adds 100 health as soon as it is picked up, a.s.o. 55 56 To that purpose this class provides functionality to compare two @ref orxonox::PickupIdentifier "PickupIdentifiers" (and since all @ref orxonox::Pickupable "Pickupables" have an identifier, we can use it to compare pickups). It als provides functionality to add parameters that distinguish between different types of pickups in the same pickup class. 57 58 Lastly a struct (@ref orxonox::PickupIdentifierCompare "PickupIdentifierCompare") is provided that can be used in stl containers to establish a strictly lesser ordering between @ref orxonox::PickupIdentifier "PickupIdentifiers" (and thus @ref orxonox::Pickupable "Pickupables"). 55 59 @author 56 60 Damian 'Mozork' Frick … … 75 79 /** 76 80 @brief 77 Struct that overloads the compare operation between two PickupIdentifierpointers.81 Struct that overloads the compare operation between two @ref orxonox::PickupIdentifier "PickupIdentifier" pointers. 78 82 */ 79 83 struct PickupIdentifierCompare
Note: See TracChangeset
for help on using the changeset viewer.