Changeset 7504
- Timestamp:
- Oct 6, 2010, 8:00:40 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/data/gui/scripts/PickupInventory.lua
r7163 r7504 45 45 local useButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/UseButton") 46 46 local dropButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/DropButton") 47 if orxonox.PickupManager:getInstance():isValidPickup(pickup ) == false then47 if orxonox.PickupManager:getInstance():isValidPickup(pickup.pickup) == false then 48 48 useButton:setEnabled(false) 49 49 dropButton:setEnabled(false) … … 51 51 else 52 52 useButton:setEnabled(true) 53 if pickup :isUsed()== true then53 if pickup.inUse == true then 54 54 useButton:setText("unuse") 55 55 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked") 56 if pickup :isUsable()== false then56 if pickup.usable == false then 57 57 useButton:setEnabled(false) 58 58 end … … 60 60 useButton:setText("use") 61 61 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked") 62 if pickup :isUnusable()== false then62 if pickup.unusable == false then 63 63 useButton:setEnabled(false) 64 64 end 65 65 end 66 66 67 if pickup :isPickedUp()== false then67 if pickup.pickedUp == false then 68 68 useButton:setEnabled(false) 69 69 dropButton:setEnabled(false) … … 108 108 109 109 function P.createPickupEntry(index, pickup) 110 local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup )110 local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup.pickup) 111 111 112 112 local name = "orxonox/PickupInventory/Box/Pickup" .. index … … 133 133 useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+10),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2))) 134 134 useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) 135 if pickup :isUsed()== false then135 if pickup.inUse == false then 136 136 useButton:setText("use") 137 137 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked") 138 if pickup :isUsable()== false then138 if pickup.usable == false then 139 139 useButton:setEnabled(false) 140 140 end … … 142 142 useButton:setText("unuse") 143 143 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked") 144 if pickup :isUnusable()== false then144 if pickup.unusable == false then 145 145 useButton:setEnabled(false) 146 146 end … … 193 193 function P.createDetailsWindow(pickupIndex) 194 194 local pickup = P.pickupsList[pickupIndex] 195 local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup )195 local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup.pickup) 196 196 197 197 local index = P.getNewDetailNumber() … … 238 238 useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10),CEGUI.UDim(1, -40))) 239 239 useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight))) 240 if pickup :isUsed()== false then240 if pickup.inUse == false then 241 241 useButton:setText("use") 242 242 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked") 243 if pickup :isUsable()== false then243 if pickup.usable == false then 244 244 useButton:setEnabled(false) 245 245 end … … 247 247 useButton:setText("unuse") 248 248 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked") 249 if pickup :isUnusable()== false then249 if pickup.unusable == false then 250 250 useButton:setEnabled(false) 251 251 end … … 277 277 function P.InventoryUseButton_clicked(e) 278 278 local pickupIndex = P.windowToPickupHelper(e) 279 orxonox.PickupManager:getInstance():usePickup(P.pickupsList[pickupIndex], true) 279 local pickup = P.pickupsList[pickupIndex] 280 orxonox.PickupManager:getInstance():usePickup(pickup.pickup, true) 280 281 end 281 282 282 283 function P.InventoryUnuseButton_clicked(e) 283 284 local pickupIndex = P.windowToPickupHelper(e) 284 orxonox.PickupManager:getInstance():usePickup(P.pickupsList[pickupIndex], false) 285 local pickup = P.pickupsList[pickupIndex] 286 orxonox.PickupManager:getInstance():usePickup(pickup.pickup, false) 285 287 end 286 288 287 289 function P.InventoryDropButton_clicked(e) 288 290 local pickupIndex = P.windowToPickupHelper(e) 289 orxonox.PickupManager:getInstance():dropPickup(P.pickupsList[pickupIndex]) 291 local pickup = P.pickupsList[pickupIndex] 292 orxonox.PickupManager:getInstance():dropPickup(pickup.pickup) 290 293 end 291 294 … … 297 300 function P.InventoryUseDetailButton_clicked(e) 298 301 local pickupIndex = P.windowToPickupHelper(e) 299 orxonox.PickupManager:getInstance():usePickup(P.detailPickups[pickupIndex], true) 302 local pickup = P.detailPickups[pickupIndex] 303 orxonox.PickupManager:getInstance():usePickup(pickup.pickup, true) 300 304 end 301 305 302 306 function P.InventoryUnuseDetailButton_clicked(e) 303 307 local pickupIndex = P.windowToPickupHelper(e) 304 orxonox.PickupManager:getInstance():usePickup(P.detailPickups[pickupIndex], false) 308 local pickup = P.detailPickups[pickupIndex] 309 orxonox.PickupManager:getInstance():usePickup(pickup.pickup, false) 305 310 end 306 311 307 312 function P.InventoryDropDetailButton_clicked(e) 308 313 local pickupIndex = P.windowToPickupHelper(e) 309 orxonox.PickupManager:getInstance():dropPickup(P.detailPickups[pickupIndex]) 314 local pickup = P.detailPickups[pickupIndex] 315 orxonox.PickupManager:getInstance():dropPickup(pickup.pickup) 310 316 end 311 317 -
code/trunk/src/modules/notifications/NotificationManager.cc
r7489 r7504 249 249 // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications. 250 250 bool bAll = set.find(NotificationManager::ALL) != set.end(); 251 std::multimap<std::time_t, Notification*>* map ;251 std::multimap<std::time_t, Notification*>* map = NULL; 252 252 if(bAll) 253 253 this->notificationLists_[index] = &this->allNotificationsList_; -
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. -
code/trunk/src/orxonox/CMakeLists.txt
r7401 r7504 61 61 MoodManager.h 62 62 controllers/HumanController.h 63 interfaces/Pickupable.h64 63 infos/PlayerInfo.h 65 64 sound/SoundManager.h -
code/trunk/src/orxonox/interfaces/CMakeLists.txt
r7494 r7504 3 3 Pickupable.cc 4 4 PickupCarrier.cc 5 PickupListener.cc 5 6 RadarViewable.cc 6 7 ) -
code/trunk/src/orxonox/interfaces/Pickupable.cc
r7494 r7504 34 34 #include "Pickupable.h" 35 35 36 #include "core/LuaState.h"37 #include "core/GUIManager.h"38 36 #include "core/Identifier.h" 39 37 #include "core/CoreIncludes.h" … … 45 43 46 44 #include "PickupCarrier.h" 45 #include "PickupListener.h" 47 46 48 47 namespace orxonox … … 130 129 131 130 this->used_ = used; 131 132 // Notify all the PickupListeners of the change. 133 PickupListener::broadcastPickupChangedUsed(this, used); 134 132 135 this->changedUsed(); 133 136 134 //TODO: Synchronize & make safe for dedicated server. 135 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()"); 137 136 138 return true; 137 139 } … … 222 224 return false; 223 225 } 224 226 225 227 this->setPickedUp(true); 226 228 COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl; … … 277 279 278 280 this->pickedUp_ = pickedUp; 281 282 // Notify all the PickupListeners of the change. 283 PickupListener::broadcastPickupChangedPickedUp(this, pickedUp); 284 279 285 if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier. 280 286 this->getCarrier()->removePickup(this); 281 287 this->changedPickedUp(); 282 288 283 //TODO: Synchronize & make safe for dedicated server.284 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");285 289 return true; 286 290 } -
code/trunk/src/orxonox/interfaces/Pickupable.h
r7494 r7504 44 44 #include "Rewardable.h" 45 45 46 namespace orxonox // tolua_export47 { // tolua_export46 namespace orxonox 47 { 48 48 49 49 /** … … 58 58 Damian 'Mozork' Frick 59 59 */ 60 class _OrxonoxExport Pickupable // tolua_export 61 : virtual public OrxonoxClass, public Rewardable 62 { // tolua_export 60 class _OrxonoxExport Pickupable : virtual public OrxonoxClass, public Rewardable 61 { 63 62 protected: 64 63 Pickupable(); //!< Default constructor. … … 71 70 @return Returns true if the Pickupable is currently in use. 72 71 */ 73 inline bool isUsed(void) { return this->used_; } // tolua_export 72 inline bool isUsed(void) 73 { return this->used_; } 74 74 /** 75 75 @brief Should be called when the Pickupable has transited from used to unused or the other way around. … … 94 94 @return Returns true if the Pickupable is currently picked up, false if not. 95 95 */ 96 inline bool isPickedUp(void) { return this->pickedUp_; } // tolua_export 96 inline bool isPickedUp(void) 97 { return this->pickedUp_; } 97 98 /** 98 99 @brief Should be called when the Pickupable has transited from picked up to dropped or the other way around. … … 105 106 @return Returns true if it can be used. 106 107 */ 107 inline bool isUsable(void) { return this->enabled_; } // tolua_export 108 108 inline bool isUsable(void) 109 { return this->enabled_; } 110 109 111 /** 110 112 @brief Returns whether the Pickupable can be unused. 111 113 @return Returns true if it can be unused. 112 114 */ 113 inline bool isUnusable(void) { return this->enabled_; } // tolua_export 115 inline bool isUnusable(void) 116 { return this->enabled_; } 114 117 115 118 /** … … 190 193 virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player. 191 194 192 }; // tolua_export195 }; 193 196 194 197 //! SUPER functions. … … 196 199 SUPER_FUNCTION(12, Pickupable, changedCarrier, false); 197 200 SUPER_FUNCTION(13, Pickupable, changedPickedUp, false); 198 } // tolua_export201 } 199 202 200 203 #endif /* _Pickupable_H__ */
Note: See TracChangeset
for help on using the changeset viewer.