Changeset 7504 for code/trunk/src/modules/pickup
- Timestamp:
- Oct 6, 2010, 8:00:40 AM (14 years ago)
- Location:
- code/trunk/src/modules/pickup
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/pickup/PickupManager.cc
r7494 r7504 40 40 #include "core/GUIManager.h" 41 41 #include "core/Identifier.h" 42 #include "network/Host.h" 43 #include "network/NetworkFunction.h" 42 44 #include "interfaces/PickupCarrier.h" 43 45 #include "infos/PlayerInfo.h" … … 53 55 DeclareToluaInterface(Pickup); 54 56 55 ManageScopedSingleton(PickupManager, ScopeID:: Graphics, false);57 ManageScopedSingleton(PickupManager, ScopeID::Root, false); 56 58 57 59 /*static*/ const std::string PickupManager::guiName_s = "PickupInventory"; 58 60 61 registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork); 62 registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork); 63 registerStaticNetworkFunction(PickupManager::dropPickupNetworked); 64 registerStaticNetworkFunction(PickupManager::usePickupNetworked); 65 59 66 /** 60 67 @brief 61 68 Constructor. Registers the PickupManager and creates the default PickupRepresentation. 62 69 */ 63 PickupManager::PickupManager() : defaultRepresentation_(NULL) 64 { 65 RegisterRootObject(PickupManager); 66 67 GUIManager::getInstance().loadGUI(PickupManager::guiName_s); 70 PickupManager::PickupManager() : guiLoaded_(false), pickupIndex_(0), defaultRepresentation_(NULL) 71 { 72 RegisterObject(PickupManager); 68 73 69 74 this->defaultRepresentation_ = new PickupRepresentation(); … … 83 88 84 89 this->representations_.clear(); 90 91 //TODO: Destroy properly... 85 92 86 93 COUT(3) << "PickupManager destroyed." << std::endl; … … 103 110 assert(representation); 104 111 105 if( this->representations_.find(identifier) != this->representations_.end()) // If the Pickupable already has a Representation registered.112 if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end()) // If the Pickupable already has a Representation registered. 106 113 return false; 107 114 … … 109 116 110 117 COUT(4) << "PickupRepresentation &" << representation << " registered with the PickupManager." << std::endl; 118 return true; 119 } 120 121 bool PickupManager::registerRepresentation(PickupRepresentation* representation) 122 { 123 assert(representation); 124 125 if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end()) // If the PickupRepresentation is already registered. 126 return false; 127 128 this->representationsNetworked_[representation->getObjectID()] = representation; 111 129 return true; 112 130 } … … 137 155 } 138 156 157 bool PickupManager::unregisterRepresentation(PickupRepresentation* representation) 158 { 159 assert(representation); 160 161 std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID()); 162 if(it == this->representationsNetworked_.end()) //!< If the Pickupable is not registered in the first place. 163 return false; 164 165 this->representationsNetworked_.erase(it); 166 return true; 167 } 168 139 169 /** 140 170 @brief … … 166 196 Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred. 167 197 */ 168 orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(orxonox::Pickupable* pickup) 169 { 170 if(pickup != NULL) 171 return this->getRepresentation(pickup->getPickupIdentifier()); 172 173 return NULL; 198 orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint64_t pickup) 199 { 200 this->representationsNetworked_.clear(); 201 for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it) 202 this->representationsNetworked_[it->getObjectID()] = *it; 203 204 std::map<uint64_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup); 205 if(it == this->pickupInventoryContainers_.end()) 206 return this->defaultRepresentation_; 207 208 std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId); 209 if(it2 == this->representationsNetworked_.end()) 210 return this->defaultRepresentation_; 211 212 return it2->second; 174 213 } 175 214 … … 183 222 int PickupManager::getNumPickups(void) 184 223 { 185 this->pickupsList_.clear(); // Clear the list if Pickupables. 186 187 PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s); 188 PickupCarrier* carrier = NULL; 189 if (player != NULL) 190 carrier = orxonox_cast<PickupCarrier*>(player->getControllableEntity()); 191 else 192 return 0; 193 194 std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier); // Get a list of all the entities which carry the players Pickupables. 195 // Iterate through all the carriers and add their Pickupable to the list. 196 for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++) 197 { 198 std::set<Pickupable*> pickups = (*it)->getPickups(); 199 for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++) 200 { 201 CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(*pickup); 202 // If the Pickupable is in a PickupCollection it is not added to the list and thus not displayed in the PickupInventory. 203 if(collectible == NULL || !collectible->isInCollection()) 204 this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup))); 205 } 206 } 207 delete carriers; 208 209 this->pickupsIterator_ = this->pickupsList_.begin(); //Set the iterator to the start of the list. 210 return this->pickupsList_.size(); 211 } 212 213 /** 214 @brief 215 Helper method. Get all the PickupCarriers that carry Pickupables, recursively. 216 @param carrier 217 The PickupCarrier whose children should be added to the list of PickupCarriers. 218 @param carriers 219 The list of PickupCarriers, used in "recursive-mode". 220 For the first instance this is just NULL (which is default and can be omitted) upon which a new list is allocated. 221 @return 222 Returns the list of PickupCarriers. 223 */ 224 std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier, std::vector<PickupCarrier*>* carriers) 225 { 226 if(carriers == NULL) // Create a new list if no list was passed. 227 carriers = new std::vector<PickupCarrier*>(); 228 229 carriers->insert(carriers->end(), carrier); // Add the input PickupCarrier to the list. 230 231 std::vector<PickupCarrier*>* children = carrier->getCarrierChildren(); // Get the children of the input PickupCarrier. 232 // Iterate through the children and add them (and their children) to the list by recursively executing getAllCarriers(). 233 for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++) 234 this->getAllCarriers(*it, carriers); 235 delete children; 236 237 return carriers; 224 this->pickupsIterator_ = this->pickupInventoryContainers_.begin(); 225 return this->pickupInventoryContainers_.size(); 238 226 } 239 227 … … 245 233 The Pickupable to be dropped. 246 234 */ 247 void PickupManager::dropPickup(orxonox::Pickupable* pickup) 248 { 249 if(pickup == NULL) 250 return; 251 252 std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup); // Get the WeakPointer of the Pickupable. 253 // If either the input Pickupable is not in the PickupManagers list or it no longer exists, the method returns. 254 if(it == this->pickupsList_.end() || it->second.get() == NULL) 255 return; 256 257 pickup->drop(); // The Pickupable is dropped. 235 void PickupManager::dropPickup(uint64_t pickup) 236 { 237 if(GameMode::isMaster() && !this->pickups_.empty()) 238 { 239 Pickupable* pickupable = this->pickups_.find(pickup)->second->get(); 240 if(pickupable != NULL) 241 pickupable->drop(); 242 } 243 else 244 { 245 callStaticNetworkFunction(PickupManager::dropPickupNetworked, 0, pickup); 246 } 247 } 248 249 /*static*/ void PickupManager::dropPickupNetworked(uint64_t pickup) 250 { 251 if(GameMode::isServer()) 252 { 253 PickupManager& manager = PickupManager::getInstance(); 254 if(manager.pickups_.empty()) 255 return; 256 Pickupable* pickupable = manager.pickups_.find(pickup)->second->get(); 257 if(pickupable != NULL) 258 pickupable->drop(); 259 } 258 260 } 259 261 … … 267 269 If true the input Pickupable is used, if false it is unused. 268 270 */ 269 void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use) 270 { 271 if(pickup == NULL) 272 return; 273 274 std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup); // Get the WeakPointer of the Pickupable. 275 // If either the input Pickupable is not in the PickupManagers list or it no longer exists, the method returns. 276 if(it == this->pickupsList_.end() || it->second.get() == NULL) 277 return; 278 279 pickup->setUsed(use); // The Pickupable is used (or unused). 271 void PickupManager::usePickup(uint64_t pickup, bool use) 272 { 273 if(GameMode::isMaster() && !this->pickups_.empty()) 274 { 275 Pickupable* pickupable = this->pickups_.find(pickup)->second->get(); 276 if(pickupable != NULL) 277 pickupable->setUsed(use); 278 } 279 else 280 { 281 callStaticNetworkFunction(PickupManager::usePickupNetworked, 0, pickup, use); 282 } 283 } 284 285 /*static*/ void PickupManager::usePickupNetworked(uint64_t pickup, bool use) 286 { 287 if(GameMode::isServer()) 288 { 289 PickupManager& manager = PickupManager::getInstance(); 290 if(manager.pickups_.empty()) 291 return; 292 Pickupable* pickupable = manager.pickups_.find(pickup)->second->get(); 293 if(pickupable != NULL) 294 pickupable->setUsed(use); 295 } 280 296 } 281 297 … … 288 304 Returns true if the input Pickupable is still valid, false if not. 289 305 */ 290 bool PickupManager::isValidPickup(orxonox::Pickupable* pickup) 291 { 292 std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup); // Get the WeakPointer of the Pickupable. 293 if(it == this->pickupsList_.end()) // If the Pickupable is not in the PickupManager's list. 294 return false; 295 return it->second.get() != NULL; // Returns whether the Pickupable still exists. 306 bool PickupManager::isValidPickup(uint64_t pickup) 307 { 308 return this->pickups_.find(pickup) != this->pickups_.end(); 309 } 310 311 void PickupManager::pickupChangedUsed(Pickupable* pickup, bool used) 312 { 313 assert(pickup); 314 315 if(!GameMode::isMaster()) // If this is neither standalone nor the server. 316 return; 317 318 CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup); 319 // If the Picupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is. 320 if(collectible != NULL && collectible->isInCollection()) 321 return; 322 323 PickupCarrier* carrier = pickup->getCarrier(); 324 while(carrier->getCarrierParent() != NULL) 325 carrier = carrier->getCarrierParent(); 326 Pawn* pawn = orxonox_cast<Pawn*>(carrier); 327 if(pawn == NULL) 328 return; 329 PlayerInfo* info = pawn->getPlayer(); 330 if(info == NULL) 331 return; 332 unsigned int clientId = info->getClientID(); 333 334 std::map<Pickupable*, uint64_t>::iterator it = this->indexes_.find(pickup); 335 assert(it != this->indexes_.end()); 336 337 uint64_t index = it->second; 338 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 339 { 340 PickupManager::pickupChangedUsedNetwork(index, used, pickup->isUsable(), pickup->isUnusable()); 341 } 342 else 343 { 344 callStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork, clientId, index, used, pickup->isUsable(), pickup->isUnusable()); 345 } 346 } 347 348 /*static*/ void PickupManager::pickupChangedUsedNetwork(uint64_t pickup, bool inUse, bool usable, bool unusable) 349 { 350 PickupManager& manager = PickupManager::getInstance(); 351 if(manager.pickupInventoryContainers_.find(pickup) == manager.pickupInventoryContainers_.end()) 352 { 353 COUT(1) << "Error: Pickupable &(" << pickup << ") was not registered with PickupManager for the PickupInventory, when it changed used." << std::endl; 354 return; 355 } 356 357 manager.pickupInventoryContainers_[pickup]->inUse = inUse; 358 manager.pickupInventoryContainers_[pickup]->usable = usable; 359 manager.pickupInventoryContainers_[pickup]->unusable = unusable; 360 361 manager.updateGUI(); 362 } 363 364 void PickupManager::pickupChangedPickedUp(Pickupable* pickup, bool pickedUp) 365 { 366 assert(pickup); 367 368 if(!GameMode::isMaster()) 369 return; 370 371 CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup); 372 // If the Picupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is. 373 if(collectible != NULL && collectible->isInCollection()) 374 return; 375 376 PickupCarrier* carrier = pickup->getCarrier(); 377 while(carrier->getCarrierParent() != NULL) 378 carrier = carrier->getCarrierParent(); 379 Pawn* pawn = orxonox_cast<Pawn*>(carrier); 380 if(pawn == NULL) 381 return; 382 PlayerInfo* info = pawn->getPlayer(); 383 if(info == NULL) 384 return; 385 unsigned int clientId = info->getClientID(); 386 387 uint64_t index = 0; 388 if(pickedUp) 389 { 390 index = this->getPickupIndex(); 391 this->indexes_[pickup] = index; 392 this->pickups_[index] = new WeakPtr<Pickupable>(pickup); 393 } 394 else 395 { 396 std::map<Pickupable*, uint64_t>::iterator it = this->indexes_.find(pickup); 397 index = it->second; 398 WeakPtr<Pickupable>* ptr = this->pickups_[index]; 399 this->indexes_.erase(it); 400 this->pickups_.erase(index); 401 delete ptr; 402 } 403 404 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 405 { 406 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp); 407 } 408 else 409 { 410 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp); 411 } 412 413 } 414 415 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint64_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp) 416 { 417 PickupManager& manager = PickupManager::getInstance(); 418 if(pickedUp) 419 { 420 PickupInventoryContainer* container = new PickupInventoryContainer; 421 container->pickup = pickup; 422 container->inUse = false; 423 container->pickedUp = pickedUp; 424 container->usable = usable; 425 container->unusable = false; 426 container->representationObjectId = representationObjectId; 427 manager.pickupInventoryContainers_.insert(std::pair<uint64_t, PickupInventoryContainer*>(pickup, container)); 428 429 if(GameMode::showsGraphics()) 430 { 431 if(!manager.guiLoaded_) 432 { 433 GUIManager::getInstance().loadGUI(PickupManager::guiName_s); 434 manager.guiLoaded_ = true; 435 } 436 GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()"); 437 } 438 } 439 else 440 { 441 std::map<uint64_t, PickupInventoryContainer*>::iterator it = manager.pickupInventoryContainers_.find(pickup); 442 if(it != manager.pickupInventoryContainers_.end()) 443 delete it->second; 444 manager.pickupInventoryContainers_.erase(pickup); 445 446 manager.updateGUI(); 447 } 448 } 449 450 inline void PickupManager::updateGUI(void) 451 { 452 if(GameMode::showsGraphics()) 453 { 454 if(!this->guiLoaded_) 455 { 456 GUIManager::getInstance().loadGUI(PickupManager::guiName_s); 457 this->guiLoaded_ = true; 458 } 459 GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()"); 460 } 461 } 462 463 uint64_t PickupManager::getPickupIndex(void) 464 { 465 if(this->pickupIndex_ == uint64_t(~0x0)-1) 466 this->pickupIndex_ = 0; 467 return this->pickupIndex_++; 296 468 } 297 469 -
code/trunk/src/modules/pickup/PickupManager.h
r7456 r7504 39 39 40 40 #include <map> 41 #include "util/Singleton.h" 41 42 42 #include "core/WeakPtr.h" 43 43 44 #include "pickup/PickupIdentifier.h" 45 44 46 #include "PickupRepresentation.h" 45 47 46 #include "core/OrxonoxClass.h" 48 #include "util/Singleton.h" 49 #include "interfaces/PickupListener.h" 47 50 48 51 namespace orxonox // tolua_export 49 52 { // tolua_export 53 54 // tolua_begin 55 struct PickupInventoryContainer 56 { 57 uint64_t pickup; 58 bool inUse; 59 bool pickedUp; 60 bool usable; 61 bool unusable; 62 uint32_t representationObjectId; 63 }; 64 // tolua_end 50 65 51 66 /** … … 57 72 */ 58 73 class _PickupExport PickupManager // tolua_export 59 : public Singleton<PickupManager>, public OrxonoxClass74 : public Singleton<PickupManager>, public PickupListener 60 75 { // tolua_export 61 76 friend class Singleton<PickupManager>; … … 68 83 69 84 bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 85 bool registerRepresentation(PickupRepresentation* representation); 70 86 bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 87 bool unregisterRepresentation(PickupRepresentation* representation); 71 88 PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. 72 89 73 90 // tolua_begin 74 orxonox::PickupRepresentation* getPickupRepresentation( orxonox::Pickupable*pickup); //!< Get the PickupRepresentation of an input Pickupable.91 orxonox::PickupRepresentation* getPickupRepresentation(uint64_t pickup); //!< Get the PickupRepresentation of an input Pickupable. 75 92 76 93 int getNumPickups(void); //!< Update the list of picked up Pickupables and get the number of Pickupables in the list. … … 80 97 @return Returns the next Pickupable in the list. 81 98 */ 82 orxonox::Pickup able* popPickup(void) { return (this->pickupsIterator_++)->first; }99 orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; } 83 100 84 void dropPickup( orxonox::Pickupable*pickup); //!< Drop the input Pickupable.85 void usePickup( orxonox::Pickupable*pickup, bool use); //!< Use (or unuse) the input Pickupable.86 bool isValidPickup( orxonox::Pickupable*pickup); //!< Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.101 void dropPickup(uint64_t pickup); //!< Drop the input Pickupable. 102 void usePickup(uint64_t pickup, bool use); //!< Use (or unuse) the input Pickupable. 103 bool isValidPickup(uint64_t pickup); //!< Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists. 87 104 // tolua_end 105 106 static void dropPickupNetworked(uint64_t pickup); 107 static void usePickupNetworked(uint64_t pickup, bool use); 108 109 virtual void pickupChangedUsed(Pickupable* pickup, bool used); 110 static void pickupChangedUsedNetwork(uint64_t pickup, bool inUse, bool usable, bool unusable); 111 virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); 112 static void pickupChangedPickedUpNetwork(uint64_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); 88 113 89 114 private: 90 115 static PickupManager* singletonPtr_s; 91 116 static const std::string guiName_s; //!< The name of the PickupInventory 117 bool guiLoaded_; 118 uint64_t pickupIndex_; 92 119 93 120 PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation. 94 121 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations. 122 std::map<uint32_t, PickupRepresentation*> representationsNetworked_; 95 123 96 std::map< Pickupable*, WeakPtr<Pickupable> > pickupsList_; //!< A list of all the picked up Pickupables.97 std::map< Pickupable*, WeakPtr<Pickupable>>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.124 std::map<uint64_t, PickupInventoryContainer*> pickupInventoryContainers_; 125 std::map<uint64_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_. 98 126 99 std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier, std::vector<PickupCarrier*>* carriers = NULL); //!< Helper method. Get all the PickupCarriers that carry Pickupables, recursively. 127 std::map<uint64_t, WeakPtr<Pickupable>*> pickups_; 128 std::map<Pickupable*, uint64_t> indexes_; 129 130 void updateGUI(void); 131 uint64_t getPickupIndex(void); 100 132 101 133 }; // tolua_export -
code/trunk/src/modules/pickup/PickupRepresentation.cc
r7163 r7504 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "core/GameMode.h" 37 38 #include "graphics/Billboard.h" 38 39 #include "util/StringUtils.h" … … 49 50 This is primarily for use of the PickupManager in creating a default PickupRepresentation. 50 51 */ 51 PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL), pickup_(NULL)52 PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL), pickup_(NULL) 52 53 { 53 54 RegisterObject(PickupRepresentation); 54 55 55 56 this->initialize(); 57 this->setSyncMode(0x0); 56 58 } 57 59 … … 60 62 Default Constructor. Registers the object and initializes its member variables. 61 63 */ 62 PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL), pickup_(NULL)64 PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL), pickup_(NULL) 63 65 { 64 66 RegisterObject(PickupRepresentation); 65 67 66 68 this->initialize(); 69 this->registerVariables(); 70 71 PickupManager::getInstance().registerRepresentation(this); //!< Registers the PickupRepresentation with the PickupManager. 67 72 } 68 73 … … 76 81 this->spawnerRepresentation_->destroy(); 77 82 78 if(this->pickup_ != NULL) 79 PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this); 83 if(this->isInitialized()) 84 { 85 if(GameMode::isMaster() && this->pickup_ != NULL) 86 { 87 PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this); 88 } 89 if(!GameMode::isMaster()) 90 { 91 PickupManager::getInstance().unregisterRepresentation(this); 92 } 93 } 80 94 } 81 95 … … 90 104 this->spawnerTemplate_ = ""; 91 105 this->inventoryRepresentation_ = "Default"; 106 } 107 108 void PickupRepresentation::registerVariables(void) 109 { 110 registerVariable(this->description_, VariableDirection::ToClient); 111 registerVariable(this->name_, VariableDirection::ToClient); 112 registerVariable(this->inventoryRepresentation_, VariableDirection::ToClient); 92 113 } 93 114 … … 107 128 XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode); 108 129 109 PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents. 130 if(GameMode::isMaster()) 131 { 132 PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents. 133 } 110 134 111 135 if(this->spawnerRepresentation_ != NULL) -
code/trunk/src/modules/pickup/PickupRepresentation.h
r7456 r7504 45 45 46 46 #include "core/BaseObject.h" 47 #include "network/synchronisable/Synchronisable.h" 47 48 48 49 namespace orxonox // tolua_export … … 55 56 */ 56 57 class _PickupExport PickupRepresentation // tolua_export 57 : public BaseObject 58 : public BaseObject, public Synchronisable 58 59 { // tolua_export 59 60 … … 146 147 StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner. 147 148 149 void registerVariables(void); //!< Register some variables for synchronisation. 150 148 151 std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation. 149 152 std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation.
Note: See TracChangeset
for help on using the changeset viewer.