Changeset 9318 for code/branches/presentation2012merge/src/modules/pickup
- Timestamp:
- Jul 18, 2012, 10:36:24 PM (12 years ago)
- Location:
- code/branches/presentation2012merge/src/modules/pickup
- Files:
-
- 2 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2012merge/src/modules/pickup/CMakeLists.txt
r7163 r9318 4 4 Pickup.cc 5 5 PickupCollection.cc 6 PickupCollectionIdentifier.cc7 6 PickupManager.cc 8 7 PickupRepresentation.cc -
code/branches/presentation2012merge/src/modules/pickup/Pickup.cc
r9313 r9318 36 36 #include "core/CoreIncludes.h" 37 37 #include "util/StringUtils.h" 38 39 #include "pickup/PickupIdentifier.h"40 38 41 39 #include "DroppedPickup.h" … … 86 84 /** 87 85 @brief 88 Initializes the PickupIdentififer of this Pickup.89 */90 void Pickup::initializeIdentifier(void)91 {92 this->pickupIdentifier_->addParameter("activationType", this->getActivationType());93 this->pickupIdentifier_->addParameter("durationType", this->getDurationType());94 }95 96 /**97 @brief98 86 Method for creating a Pickup object through XML. 99 87 */ … … 102 90 SUPER(Pickup, XMLPort, xmlelement, mode); 103 91 92 XMLPortParam(Pickup, "representation", setRepresentationName, getRepresentationName, xmlelement, mode); 104 93 XMLPortParam(Pickup, "activationType", setActivationTypeAsString, getActivationTypeAsString, xmlelement, mode); 105 94 XMLPortParam(Pickup, "durationType", setDurationTypeAsString, getDurationTypeAsString, xmlelement, mode); 106 107 this->initializeIdentifier();108 95 } 109 96 … … 206 193 207 194 Pickup* pickup = orxonox_cast<Pickup*>(item); 195 pickup->setRepresentationName(this->getRepresentationName()); 208 196 pickup->setActivationType(this->getActivationType()); 209 197 pickup->setDurationType(this->getDurationType()); 210 211 pickup->initializeIdentifier();212 198 } 213 199 -
code/branches/presentation2012merge/src/modules/pickup/Pickup.h
r9313 r9318 105 105 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 106 106 107 virtual const std::string& getRepresentationName() const 108 { return this->representationName_; } 109 107 110 /** 108 111 @brief Get the activation type of the Pickup. … … 150 153 151 154 protected: 152 v oid initializeIdentifier(void);155 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 153 156 154 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 157 /** 158 @brief Sets the representation name which refers to the name of the PickupRepresentation that is used to represent this pickup. 159 */ 160 inline void setRepresentationName(const std::string& name) 161 { this->representationName_ = name; } 155 162 156 163 /** … … 173 180 void initialize(void); //!< Initializes the member variables. 174 181 182 std::string representationName_; //!< The name of the associated PickupRepresentation. 175 183 pickupActivationType::Value activationType_; //!< The activation type of the Pickup. 176 184 pickupDurationType::Value durationType_; //!< The duration type of the Pickup. -
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.cc
r9296 r9318 39 39 #include "CollectiblePickup.h" 40 40 #include "DroppedPickup.h" 41 #include "PickupCollectionIdentifier.h"42 41 43 42 #include "PickupCollection.h" … … 54 53 The creator of the object. 55 54 */ 56 PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator) , pickupCollectionIdentifier_(NULL)55 PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator) 57 56 { 58 57 RegisterObject(PickupCollection); 59 58 60 this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);61 59 this->processingUsed_ = false; 62 60 this->processingPickedUp_ = false; … … 76 74 } 77 75 this->pickups_.clear(); 78 79 if(this->pickupCollectionIdentifier_ != NULL)80 this->pickupCollectionIdentifier_->destroy();81 76 } 82 77 … … 89 84 SUPER(PickupCollection, XMLPort, xmlelement, mode); 90 85 86 XMLPortParam(PickupCollection, "representation", setRepresentationName, getRepresentationName, xmlelement, mode); 91 87 XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode); 92 88 } … … 217 213 218 214 PickupCollection* pickup = orxonox_cast<PickupCollection*>(item); 215 pickup->setRepresentationName(this->getRepresentationName()); 219 216 // Clone all Pickupables this PickupCollection consist of. 220 217 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) … … 243 240 244 241 return true; 245 }246 247 /**248 @brief249 Get the PickupIdentifier of this PickupCollection.250 This is in fact the PickupCollectionIdentifier.251 @return252 Returns a pointer to the PickupIdentifier of this PickupCollection.253 */254 const PickupIdentifier* PickupCollection::getPickupIdentifier(void) const255 {256 return this->pickupCollectionIdentifier_;257 242 } 258 243 -
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.h
r9295 r9318 50 50 The PickupCollection combines different @ref orxonox::Pickupable "Pickupables" (more precisely @ref orxonox::CollectiblePickup "CollectiblePickups") to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one @ref orxonox::Pickupable "Pickupable". 51 51 52 To differentiate between different types of @ref orxonox::PickupCollection "PickupCollections" (just as we differentiate between different types of @ref orxonox::Pickupable "Pickupables") we define a new identifyer called the @ref orxonox::PickupCollectionIdentifier "PickupCollectionIdentifier" which has pretty much the same properties as the @ref orxonox::PickupIdentifier "PickupIdentifier" but extende to @ref orxonox::PickupCollection "PickupCollections".53 54 52 A PickupCollection can be created in XML as follows: 55 53 @code … … 85 83 virtual bool isTarget(const PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection. 86 84 87 virtual const PickupIdentifier* getPickupIdentifier(void) const; //!< Get the PickupIdentifier of this PickupCollection. 85 inline void setRepresentationName(const std::string& name) 86 { this->representationName_ = name; } 87 virtual const std::string& getRepresentationName() const 88 { return this->representationName_; } 88 89 89 90 bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection. … … 101 102 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 102 103 103 PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves.104 105 104 private: 106 105 void changedUsedAction(void); //!< Helper method. … … 108 107 void pickupsChanged(void); //!< Helper method. 109 108 109 std::string representationName_; //!< The name of the associated PickupRepresentation. 110 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. 111 111 -
code/branches/presentation2012merge/src/modules/pickup/PickupManager.cc
r8858 r9318 87 87 88 88 this->representations_.clear(); 89 this->representationsNetworked_.clear();90 89 91 90 // Destroying all the PickupInventoryContainers that are still there. … … 106 105 /** 107 106 @brief 108 Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode). 109 For every type of Pickupable (uniquely identified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered. 110 @param identifier 111 The PickupIdentifier identifying the Pickupable. 107 Registers a PickupRepresentation. 108 @param name 109 The representation's name. 112 110 @param representation 113 111 A pointer to the PickupRepresentation. … … 115 113 Returns true if successful and false if not. 116 114 */ 117 bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation) 118 { 119 assert(identifier); 115 bool PickupManager::registerRepresentation(const std::string& name, PickupRepresentation* representation) 116 { 120 117 assert(representation); 121 118 122 119 // If the list is not empty and Pickupable already has a Representation registered. 123 if(!this->representations_.empty() && this->representations_.find( identifier) != this->representations_.end())120 if(!this->representations_.empty() && this->representations_.find(name) != this->representations_.end()) 124 121 return false; 125 122 126 this->representations_[ identifier] = representation;123 this->representations_[name] = representation; 127 124 128 125 orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " registered with the PickupManager." << endl; … … 132 129 /** 133 130 @brief 134 Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode). 135 @param identifier 136 The PickupIdentifier identifying the Pickupable. 137 @param representation 138 A pointer to the PickupRepresentation. 131 Unegisters a PickupRepresentation. 132 @param name 133 The representation's name. 139 134 @return 140 135 Returns true if successful and false if not. 141 136 */ 142 bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation) 143 { 144 assert(identifier); 145 assert(representation); 146 147 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier); 137 bool PickupManager::unregisterRepresentation(const std::string& name) 138 { 139 std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name); 148 140 if(it == this->representations_.end()) // If the Pickupable is not registered in the first place. 149 141 return false; … … 151 143 this->representations_.erase(it); 152 144 153 orxout(verbose, context::pickups) << "PickupRepresentation &" << representation<< " unregistered with the PickupManager." << endl;145 orxout(verbose, context::pickups) << "PickupRepresentation &" << name << " unregistered with the PickupManager." << endl; 154 146 return true; 155 147 } … … 157 149 /** 158 150 @brief 159 Registers a PickupRepresentation on the host it was created. 160 @param representation 161 A pointer to the PickupRepresentation. 162 @return 163 Returns true if successful, false if not. 164 */ 165 bool PickupManager::registerRepresentation(PickupRepresentation* representation) 166 { 167 assert(representation); 168 169 // If the list is not empty and PickupRepresentation is already registered. 170 if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end()) 171 return false; 172 173 this->representationsNetworked_[representation->getObjectID()] = representation; 174 return true; 175 } 176 177 /** 178 @brief 179 Unregisters a PickupRepresentation on the host it is being destroyed (which is the same host on which it was created). 180 @param representation 181 A pointer to the Pickuprepresentation. 182 @return 183 Returns true if successful, false if not. 184 */ 185 bool PickupManager::unregisterRepresentation(PickupRepresentation* representation) 186 { 187 assert(representation); 188 189 std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID()); 190 if(it == this->representationsNetworked_.end()) // If the Pickupable is not registered in the first place. 191 return false; 192 193 this->representationsNetworked_.erase(it); 194 return true; 195 } 196 197 /** 198 @brief 199 Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. 200 @param identifier 201 The PickupIdentifier. 151 Get the PickupRepresentation with the given name. 152 @param name 153 The name of the PickupRepresentation. 202 154 @return 203 155 Returns a pointer to the PickupRepresentation. 204 156 */ 205 PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)206 { 207 std::map< const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);208 if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input PickupIdentifier.157 PickupRepresentation* PickupManager::getRepresentation(const std::string& name) 158 { 159 std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name); 160 if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input name. 209 161 { 210 162 orxout(verbose, context::pickups) << "PickupManager::getRepresentation() returned default representation." << endl; … … 353 305 { 354 306 // If there is no PickupRepresentation registered the default representation is used. 355 if(this->representations_.find(pickup->get PickupIdentifier()) == this->representations_.end())356 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pick edUp);307 if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end()) 308 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp); 357 309 else 358 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->get PickupIdentifier()]->getObjectID(), pickedUp);310 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp); 359 311 } 360 312 // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager. … … 362 314 { 363 315 // If there is no PickupRepresentation registered the default representation is used. 364 if(this->representations_.find(pickup->get PickupIdentifier()) == this->representations_.end())316 if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end()) 365 317 { 366 318 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp); … … 368 320 else 369 321 { 370 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->get PickupIdentifier()]->getObjectID(), pickedUp);322 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp); 371 323 } 372 324 } … … 388 340 The pickedUp status the Pickupable changed to. 389 341 */ 390 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp)342 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp) 391 343 { 392 344 PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host. … … 402 354 container->unusable = false; 403 355 container->representationObjectId = representationObjectId; 356 container->representationName = representationName; 404 357 // Insert the container into the pickupInventoryContainers_ list. 405 358 manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container)); … … 417 370 manager.updateGUI(); // Tell the PickupInventory that something has changed. 418 371 } 419 }420 421 /**422 @brief423 Get the PickupRepresentation of an input Pickupable.424 This method spares us the hassle to export the PickupIdentifier class to lua.425 @param pickup426 The number identifying the Pickupable whose PickupRepresentation should be returned.427 @return428 Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.429 */430 orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint32_t pickup)431 {432 // Clear and rebuild the representationsNetworked_ list.433 //TODO: Better solution?434 this->representationsNetworked_.clear();435 for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it)436 this->representationsNetworked_[it->getObjectID()] = *it;437 438 // Get the container belonging to the input pickup, if not found return the default representation.439 std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup);440 if(it == this->pickupInventoryContainers_.end())441 return this->defaultRepresentation_;442 443 // Get the PickupRepresentation of the input pickup (through the objecId of the representation stored in the PickupInventoryContainer belonging to the pickup), if not found return the default representation.444 std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId);445 if(it2 == this->representationsNetworked_.end())446 return this->defaultRepresentation_;447 448 return it2->second;449 372 } 450 373 -
code/branches/presentation2012merge/src/modules/pickup/PickupManager.h
r8706 r9318 41 41 #include "core/WeakPtr.h" 42 42 43 #include "pickup/PickupIdentifier.h"44 45 43 #include "PickupRepresentation.h" 46 44 … … 67 65 bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable. 68 66 uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable". 67 std::string representationName; //!< The name of the associated PickupRepresentation 69 68 }; 70 69 // tolua_end … … 74 73 The PickupManager class manages @ref orxonox::Pickupable "Pickupables". 75 74 76 It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to theirrespective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.)75 It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their representation-name attribute) to the respective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.) 77 76 78 77 @section PickupManagerTechnicalDetails Technical details … … 86 85 87 86 Firstly there are a number of lists (where by list I really mean any kind of ordered data structure) kept. 88 - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with @ref orxonox::PickupIdentifier "PickupIdentifiers" and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list. 89 - The @ref orxonox::PickupManager::representationsNetworked_ "representationsNetworked_" list is the networked (hence the name) equivalent to the @ref orxonox::PickupManager::representations_ "representations_" list. It links an objectId of a @ref orxonox::PickupRepresentation "PickupRepresentation" to a @ref orxonox::PickupRepresentation "PickupRepresentation". This list is maintained on all hosts, each representation registers itself (in its constructor) with the PickupManager. Since the representations are synchronised they are created on each host. The "same" instance on each host is identified by the same objectId and that is why we store the representations with the objectId as key. We can then use this list to get a @ref orxonox::PickupRepresentation "PickupRepresentation" for a specific @ref orxonox::Pickupable "Pickupable" (or more precisely a number identifiying that particular pickup, but we'll see that, when we look at the next list) on a client to be used in the PickupInventory. 87 - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with its name and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list. 90 88 - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox::PickupRepresentation "PickupRepresentation". 91 89 - The @ref orxonox::PickupManager::pickups_ "pickups_" list links a number identifiying a @ref orxonox::Pickupable "Pickupable" to a (weak pointer to a) @ref orxonox::Pickupable "Pickupable". It is only maintained by the server (or in standalone mode), to be able to use, unuse and drop @ref orxonox::Pickupable "Pickupables" through the PickupInventory. Since @ref orxonox::Pickupable "Pickupables" only exist on the server a client that wants to change a pickups status has so send a request over the network (with the number identifying the pickup) to the server and then the server facilitates the change, using this list to map from the identifyer to the actual @ref orxonox::Pickupable "Pickupable". … … 114 112 static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export 115 113 116 bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.117 bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.114 bool registerRepresentation(const std::string& name, PickupRepresentation* representation); 115 bool unregisterRepresentation(const std::string& name); 118 116 119 bool registerRepresentation(PickupRepresentation* representation); //!< Registers a PickupRepresentation on the host it was created. 120 bool unregisterRepresentation(PickupRepresentation* representation); //!< Unregisters a PickupRepresentation on the host it is being destroyed. 121 122 PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. 117 PickupRepresentation* getRepresentation(const std::string& name); // tolua_export 123 118 124 119 virtual void pickupChangedUsed(Pickupable* pickup, bool used); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state. 125 120 static void pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable); //!< Helper method to react to the change in the used status of a Pickupable. 126 121 virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state. 127 static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.122 static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable. 128 123 129 124 // Methods to be used by the PickupInventory. 130 125 public: 131 126 // tolua_begin 132 orxonox::PickupRepresentation* getPickupRepresentation(uint32_t pickup); //!< Get the PickupRepresentation of an input indentifier for Pickupable.133 134 127 int getNumPickups(void); //!< Get the number of pickups currently picked up by the player. 135 128 /** … … 163 156 PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation. 164 157 165 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types of Pickupables) and PickupRepresentations. 166 std::map<uint32_t, PickupRepresentation*> representationsNetworked_; //!< Map linking the PickupRepresentation's objectId to the PickupRepresentation itself. It is used for networking purposes. 158 std::map<std::string, PickupRepresentation*> representations_; //!< Map linking PickupRepresentations and their names. 167 159 168 160 std::map<uint32_t, PickupInventoryContainer*> pickupInventoryContainers_; //!< Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable. -
code/branches/presentation2012merge/src/modules/pickup/PickupPrereqs.h
r9269 r9318 73 73 class Pickup; 74 74 class PickupCollection; 75 class PickupCollectionIdentifier;76 75 class PickupManager; 77 76 class PickupRepresentation; -
code/branches/presentation2012merge/src/modules/pickup/PickupRepresentation.cc
r9302 r9318 52 52 This is primarily for use of the PickupManager in creating a default PickupRepresentation. 53 53 */ 54 PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL) , pickup_(NULL)54 PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL) 55 55 { 56 56 RegisterObject(PickupRepresentation); … … 64 64 Default Constructor. Registers the object and initializes its member variables. 65 65 */ 66 PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL) , pickup_(NULL)66 PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL) 67 67 { 68 68 RegisterObject(PickupRepresentation); … … 70 70 this->initialize(); 71 71 this->registerVariables(); 72 73 PickupManager::getInstance().registerRepresentation(this); // Registers the PickupRepresentation with the PickupManager.74 72 } 75 73 … … 84 82 85 83 if(this->isInitialized()) 86 { 87 if(GameMode::isMaster() && this->pickup_ != NULL) 88 { 89 PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this); 90 } 91 PickupManager::getInstance().unregisterRepresentation(this); 92 } 84 PickupManager::getInstance().unregisterRepresentation(this->getName()); 93 85 } 94 86 … … 128 120 XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode); 129 121 XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode); 130 XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);131 122 XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode); 132 133 if(GameMode::isMaster())134 {135 // Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.136 PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this);137 }138 139 if(this->spawnerRepresentation_ != NULL)140 this->spawnerRepresentation_->setVisible(false);141 123 142 124 orxout(verbose, context::pickups) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << endl; … … 172 154 } 173 155 156 void PickupRepresentation::changedName() 157 { 158 // Registers the PickupRepresentation with the PickupManager. 159 PickupManager::getInstance().unregisterRepresentation(this->getOldName()); 160 PickupManager::getInstance().registerRepresentation(this->getName(), this); 161 } 162 163 void PickupRepresentation::setSpawnerRepresentation(StaticEntity* representation) 164 { 165 this->spawnerRepresentation_ = representation; 166 if(this->spawnerRepresentation_ != NULL) 167 this->spawnerRepresentation_->setVisible(false); 168 } 169 174 170 /** 175 171 @brief -
code/branches/presentation2012merge/src/modules/pickup/PickupRepresentation.h
r9302 r9318 41 41 42 42 #include "interfaces/Pickupable.h" 43 #include "pickup/PickupIdentifier.h"44 43 #include "worldentities/StaticEntity.h" 45 44 … … 54 53 /** 55 54 @brief 56 The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentifier "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.55 The PickupRepresentation class represents a specific pickup type. It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like. 57 56 They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager". 58 57 … … 64 63 spawnerTemplate = "awesomePickupRepresentation" 65 64 inventoryRepresentation = "AwesomePickup" 66 > 67 <pickup> 68 <SomePickup /> 69 </pickup> 70 </PickupRepresentation> 65 /> 71 66 @endcode 72 67 As you might have noticed, there is a parameter called <em>spawnerTemplate</em> and also another parameter called <em>inventoryRepresentation</em>. Let's first explain the second one, <em>inventoryRepresentation</em>. … … 133 128 */ 134 129 inline const std::string& getInventoryRepresentation(void) const { return this->inventoryRepresentation_; } // tolua_export 135 /** 136 @brief Get the Pickupable represented by this PickupRepresentation. 137 @param index The index. 138 @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL. 139 */ 140 inline const Pickupable* getPickup(unsigned int index) const 141 { if(index == 0) return this->pickup_; return NULL; } 130 131 virtual void changedName(); 142 132 143 133 StaticEntity* createSpawnerRepresentation(PickupSpawner* spawner); //!< Create a spawnerRepresentation for a specific PickupSpawner. … … 168 158 @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation. 169 159 */ 170 inline void setSpawnerRepresentation(StaticEntity* representation)171 { this->spawnerRepresentation_ = representation; } 160 void setSpawnerRepresentation(StaticEntity* representation); 161 172 162 /** 173 163 @brief Set the image representing the pickup in the PickupInventory. … … 176 166 inline void setInventoryRepresentation(const std::string& image) 177 167 { this->inventoryRepresentation_ = image; } 178 /**179 @brief Set the Pickupable that is represented by this PickupRepresentation.180 @param pickup A pointer to the Pickupable.181 */182 inline void setPickup(Pickupable* pickup)183 { this->pickup_ = pickup; }184 168 185 169 private: … … 195 179 std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. 196 180 197 Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.198 199 181 }; // tolua_export 200 182 -
code/branches/presentation2012merge/src/modules/pickup/PickupSpawner.cc
r9302 r9318 95 95 else 96 96 { 97 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->get PickupIdentifier());97 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getRepresentationName()); 98 98 this->attach(representation->createSpawnerRepresentation(this)); 99 99 this->setActive(true); … … 149 149 else 150 150 { 151 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->get PickupIdentifier());151 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getRepresentationName()); 152 152 this->attach(representation->createSpawnerRepresentation(this)); 153 153 this->setActive(true); -
code/branches/presentation2012merge/src/modules/pickup/items/DamageBoostPickup.cc
r9305 r9318 38 38 #include "core/XMLPort.h" 39 39 40 #include "pickup/PickupIdentifier.h"41 40 #include "worldentities/pawns/SpaceShip.h" 42 41 … … 78 77 /** 79 78 @brief 80 Initializes the PickupIdentifier of this pickup.81 */82 void DamageBoostPickup::initializeIdentifier(void)83 {84 this->pickupIdentifier_->addParameter("duration", this->getDuration());85 this->pickupIdentifier_->addParameter("damageMultiplier", this->getDamageMultiplier());86 }87 88 /**89 @brief90 79 Method for creating a DamageBoostPickup object through XML. 91 80 */ … … 96 85 XMLPortParam(DamageBoostPickup, "duration", setDuration, getDuration, xmlelement, mode); 97 86 XMLPortParam(DamageBoostPickup, "damageMultiplier", setDamageMultiplier, getDamageMultiplier, xmlelement, mode); 98 99 this->initializeIdentifier();100 87 } 101 88 … … 196 183 pickup->setDuration(this->getDuration()); 197 184 pickup->setDamageMultiplier(this->getDamageMultiplier()); 198 pickup->initializeIdentifier();199 185 } 200 186 -
code/branches/presentation2012merge/src/modules/pickup/items/DamageBoostPickup.h
r9272 r9318 79 79 80 80 protected: 81 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.82 81 void setDamageMultiplier(float damageMultiplier); //!< Sets the DamageMultiplier according to the XML. 83 82 -
code/branches/presentation2012merge/src/modules/pickup/items/DronePickup.cc
r9313 r9318 39 39 40 40 #include "controllers/DroneController.h" 41 #include "pickup/PickupIdentifier.h"42 41 #include "worldentities/Drone.h" 43 42 #include "worldentities/pawns/Pawn.h" … … 81 80 /** 82 81 @brief 83 Initializes the PickupIdentifier of this pickup.84 */85 void DronePickup::initializeIdentifier(void)86 {87 this->pickupIdentifier_->addParameter("droneTemplate", this->getDroneTemplate());88 }89 90 /**91 @brief92 82 Method for creating a DronePickup object through XML. 93 83 */ … … 96 86 SUPER(DronePickup, XMLPort, xmlelement, mode); 97 87 XMLPortParam(DronePickup, "droneTemplate", setDroneTemplate, getDroneTemplate, xmlelement, mode); 98 99 this->initializeIdentifier();100 88 } 101 89 … … 198 186 DronePickup* pickup = orxonox_cast<DronePickup*>(item); 199 187 pickup->setDroneTemplate(this->getDroneTemplate()); 200 201 pickup->initializeIdentifier();202 188 } 203 189 } -
code/branches/presentation2012merge/src/modules/pickup/items/DronePickup.h
r9312 r9318 75 75 76 76 protected: 77 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.78 79 77 void setDroneTemplate(const std::string& templatename); //!< Set the droneTemplate. 80 78 -
code/branches/presentation2012merge/src/modules/pickup/items/HealthPickup.cc
r9312 r9318 38 38 #include "core/XMLPort.h" 39 39 40 #include "pickup/PickupIdentifier.h"41 40 #include "worldentities/pawns/Pawn.h" 42 41 … … 87 86 /** 88 87 @brief 89 Initializes the PickupIdentifier of this pickup.90 */91 void HealthPickup::initializeIdentifier(void)92 {93 this->pickupIdentifier_->addParameter("health", this->getHealth());94 this->pickupIdentifier_->addParameter("healthType", this->getHealthType());95 this->pickupIdentifier_->addParameter("healthRate", this->getHealthRate());96 }97 98 /**99 @brief100 88 Method for creating a HealthPickup object through XML. 101 89 */ … … 110 98 if(!this->isContinuous()) 111 99 this->setHealthRate(0.0f); // TODO: this logic should be inside tick(), not in XMLPort 112 113 this->initializeIdentifier();114 100 } 115 101 … … 277 263 pickup->setHealthRate(this->getHealthRate()); 278 264 pickup->setHealthType(this->getHealthType()); 279 280 pickup->initializeIdentifier();281 265 } 282 266 -
code/branches/presentation2012merge/src/modules/pickup/items/HealthPickup.h
r9312 r9318 121 121 122 122 protected: 123 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.124 125 123 void setHealth(float health); //!< Sets the health. 126 124 void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous. -
code/branches/presentation2012merge/src/modules/pickup/items/InvisiblePickup.cc
r9305 r9318 40 40 #include "core/XMLPort.h" 41 41 42 #include "pickup/PickupIdentifier.h"43 42 #include "worldentities/pawns/Pawn.h" 44 43 … … 79 78 /** 80 79 @brief 81 Initializes the PickupIdentifier of this pickup.82 */83 void InvisiblePickup::initializeIdentifier(void)84 {85 this->pickupIdentifier_->addParameter("duration", this->getDuration());86 }87 88 /**89 @brief90 80 Method for creating a HealthPickup object through XML. 91 81 */ … … 94 84 SUPER(InvisiblePickup, XMLPort, xmlelement, mode); 95 85 XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode); 96 97 this->initializeIdentifier();98 86 } 99 87 … … 157 145 InvisiblePickup* pickup = orxonox_cast<InvisiblePickup*>(item); 158 146 pickup->setDuration(this->getDuration()); 159 pickup->initializeIdentifier();160 147 } 161 148 -
code/branches/presentation2012merge/src/modules/pickup/items/InvisiblePickup.h
r7547 r9318 72 72 InvisiblePickup(BaseObject* creator); //!< Constructor. 73 73 virtual ~InvisiblePickup(); //!< Destructor. 74 74 75 75 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML. 76 76 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. … … 91 91 92 92 protected: 93 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.94 95 93 bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again. 96 94 void setDuration(float duration); //!< Sets the time the InvisibilityPickup will last. -
code/branches/presentation2012merge/src/modules/pickup/items/MetaPickup.cc
r9313 r9318 36 36 37 37 #include "interfaces/PickupCarrier.h" 38 #include "pickup/PickupIdentifier.h"39 38 #include "worldentities/pawns/Pawn.h" 40 39 … … 86 85 /** 87 86 @brief 88 Helper method to initialize the PickupIdentifier.89 */90 void MetaPickup::initializeIdentifier(void)91 {92 this->pickupIdentifier_->addParameter("metaType", this->getMetaType());93 }94 95 /**96 @brief97 87 Method for creating a MetaPickup object through XML. 98 88 */ … … 102 92 103 93 XMLPortParam(MetaPickup, "metaType", setMetaTypeAsString, getMetaTypeAsString, xmlelement, mode); 104 105 this->initializeIdentifier();106 94 } 107 95 … … 172 160 MetaPickup* pickup = orxonox_cast<MetaPickup*>(item); 173 161 pickup->setMetaType(this->getMetaType()); 174 175 pickup->initializeIdentifier();176 162 } 177 163 -
code/branches/presentation2012merge/src/modules/pickup/items/MetaPickup.h
r9312 r9318 106 106 107 107 protected: 108 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.109 110 108 /** 111 109 @brief Set the meta type of the MetaPickup. -
code/branches/presentation2012merge/src/modules/pickup/items/ShieldPickup.cc
r9305 r9318 38 38 #include "core/XMLPort.h" 39 39 40 #include "pickup/PickupIdentifier.h"41 40 #include "worldentities/pawns/Pawn.h" 42 41 … … 80 79 /** 81 80 @brief 82 Initializes the PickupIdentifier of this pickup.83 */84 void ShieldPickup::initializeIdentifier(void)85 {86 this->pickupIdentifier_->addParameter("duration", this->getDuration());87 this->pickupIdentifier_->addParameter("ShieldHealth", this->getShieldHealth());88 this->pickupIdentifier_->addParameter("ShieldAbsorption", this->getShieldAbsorption());89 }90 91 /**92 @brief93 81 Method for creating a ShieldPickup object through XML. 94 82 */ … … 100 88 XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode); 101 89 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode); 102 103 this->initializeIdentifier();104 90 } 105 91 … … 188 174 pickup->setShieldAbsorption(this->getShieldAbsorption()); 189 175 pickup->setShieldHealth(this->getShieldHealth()); 190 pickup->initializeIdentifier();191 176 } 192 177 -
code/branches/presentation2012merge/src/modules/pickup/items/ShieldPickup.h
r7547 r9318 104 104 105 105 protected: 106 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.107 106 void pickupTimerCallback(void); //!< Helper method. Is called by the Timer as soon as it expires. 108 107 -
code/branches/presentation2012merge/src/modules/pickup/items/ShrinkPickup.cc
r9305 r9318 40 40 #include "core/XMLPort.h" 41 41 42 #include "pickup/PickupIdentifier.h"43 42 #include "worldentities/pawns/Pawn.h" 44 43 … … 81 80 } 82 81 83 void ShrinkPickup::initializeIdentifier(void)84 {85 this->pickupIdentifier_->addParameter("shrinkFactor", this->getShrinkFactor());86 this->pickupIdentifier_->addParameter("duration", this->getDuration());87 this->pickupIdentifier_->addParameter("shrinkDuration", this->getShrinkDuration());88 }89 90 82 /** 91 83 @brief … … 99 91 XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode); 100 92 XMLPortParam(ShrinkPickup, "shrinkDuration", setShrinkDuration, getShrinkDuration, xmlelement, mode); 101 102 this->initializeIdentifier();103 93 } 104 94 … … 321 311 pickup->setDuration(this->getDuration()); 322 312 pickup->setShrinkDuration(this->getShrinkDuration()); 323 324 pickup->initializeIdentifier();325 313 } 326 314 } -
code/branches/presentation2012merge/src/modules/pickup/items/ShrinkPickup.h
r8858 r9318 119 119 { if(speed <= 0.0f) { orxout(internal_warning, context::pickups) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkDuration_ = speed; } 120 120 121 protected:122 void initializeIdentifier(void);123 124 121 private: 125 122 void initialize(void); … … 135 132 float currentFactor_; //!< The shrink factor that is currently applied. 136 133 float timeRemainig_; //!< The remaining shrink time. 137 134 138 135 Pawn* carrierToPawnHelper(void); 139 136 Timer durationTimer_; -
code/branches/presentation2012merge/src/modules/pickup/items/SpeedPickup.cc
r9305 r9318 38 38 #include "core/XMLPort.h" 39 39 40 #include "pickup/PickupIdentifier.h"41 40 #include "worldentities/pawns/SpaceShip.h" 42 41 … … 80 79 /** 81 80 @brief 82 Initializes the PickupIdentifier of this pickup.83 */84 void SpeedPickup::initializeIdentifier(void)85 {86 this->pickupIdentifier_->addParameter("duration", this->getDuration());87 this->pickupIdentifier_->addParameter("speedAdd", this->getSpeedAdd());88 this->pickupIdentifier_->addParameter("speedMultiply", this->getSpeedMultiply());89 }90 91 /**92 @brief93 81 Method for creating a SpeedPickup object through XML. 94 82 */ … … 100 88 XMLPortParam(SpeedPickup, "speedAdd", setSpeedAdd, getSpeedAdd, xmlelement, mode); 101 89 XMLPortParam(SpeedPickup, "speedMultiply", setSpeedMultiply, getSpeedMultiply, xmlelement, mode); 102 103 this->initializeIdentifier();104 90 } 105 91 … … 189 175 pickup->setSpeedAdd(this->getSpeedAdd()); 190 176 pickup->setSpeedMultiply(this->getSpeedMultiply()); 191 192 pickup->initializeIdentifier();193 177 } 194 178 -
code/branches/presentation2012merge/src/modules/pickup/items/SpeedPickup.h
r9269 r9318 103 103 104 104 protected: 105 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.106 105 void pickupTimerCallback(void); //!< Function that gets called when timer ends. 107 106
Note: See TracChangeset
for help on using the changeset viewer.