Changeset 11704 for code/trunk/src/modules
- Timestamp:
- Jan 6, 2018, 3:16:00 AM (7 years ago)
- Location:
- code/trunk/src/modules
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/overlays/CMakeLists.txt
r11056 r11704 16 16 LINK_LIBRARIES 17 17 orxonox 18 pickup 18 19 weapons 19 20 SOURCE_FILES ${OVERLAYS_SRC_FILES} -
code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc
r11703 r11704 38 38 #include "HUDPickupSystem.h" 39 39 #include "HUDPickupItem.h" 40 #include "pickup/Pickup.h"41 40 #include "pickup/PickupManager.h" 42 41 … … 66 65 } 67 66 68 void HUDPickupSystem:: sync(std::vector<Pickupable*> p, std::map<Pickupable*, uint32_t> indexes_)67 void HUDPickupSystem::tick(float dt) 69 68 { 69 SUPER(HUDPickupSystem, tick, dt); 70 70 71 //hide all pickup symbols in HUD and delete from local map 71 72 72 for(HUDPickupItem* item : items_) 73 73 { … … 84 84 const float y = 0.075f; 85 85 86 for(Pickupable* pickup:p) 86 int numPickups = PickupManager::getInstance().getNumPickups(); 87 for (int index = 0; index < numPickups; ++index) 87 88 { 88 int index = indexes_.find(pickup)->second;89 89 int row = index / 5; 90 90 int column = index % 5; 91 91 92 const PickupInventoryContainer* container = PickupManager::getInstance().popPickup(); 93 92 94 HUDPickupItem* item = new HUDPickupItem(this->getContext()); 93 item->initializeMaterial(this->getIcon( ((Pickup*)pickup)->getRepresentationName()), offsetX+column*x, offsetY+row*y);95 item->initializeMaterial(this->getIcon(container->representationName), offsetX+column*x, offsetY+row*y); 94 96 item->setOverlayGroup(this->getOverlayGroup()); 95 97 items_.push_back(item); -
code/trunk/src/modules/overlays/hud/HUDPickupSystem.h
r11702 r11704 37 37 #include "util/OgreForwardRefs.h" 38 38 #include "overlays/OrxonoxOverlay.h" 39 #include "tools/interfaces/Tickable.h" 39 40 40 41 namespace orxonox 41 42 { 42 class _OverlaysExport HUDPickupSystem : public OrxonoxOverlay 43 class _OverlaysExport HUDPickupSystem : public OrxonoxOverlay, public Tickable 43 44 { 44 45 public: … … 46 47 virtual ~HUDPickupSystem(); 47 48 48 v oid sizeChanged();49 v oid sync(std::vector<Pickupable*> p, std::map<Pickupable*, uint32_t> indexes_);49 virtual void tick(float dt) override; 50 virtual void sizeChanged() override; 50 51 51 52 private: -
code/trunk/src/modules/pickup/CMakeLists.txt
r11353 r11704 19 19 PickupPrecompiledHeaders.h 20 20 LINK_LIBRARIES 21 overlays22 21 orxonox 23 22 SOURCE_FILES ${PICKUP_SRC_FILES} -
code/trunk/src/modules/pickup/PickupManager.cc
r11701 r11704 41 41 #include "network/Host.h" 42 42 #include "network/NetworkFunctionIncludes.h" 43 #include "core/input/KeyBinderManager.h" //for keybinding44 #include "core/input/KeyBinder.h" //for keybinding45 #include "core/command/ConsoleCommandIncludes.h"46 43 47 44 #include "infos/PlayerInfo.h" … … 51 48 #include "CollectiblePickup.h" 52 49 #include "PickupRepresentation.h" 53 #include "overlays/hud/HUDPickupSystem.h"54 50 55 51 namespace orxonox … … 67 63 68 64 RegisterAbstractClass(PickupManager).inheritsFrom<PickupListener>(); 69 70 SetConsoleCommand("useUnusePickup", &PickupManager::useUnusePickup).addShortcut().setActive(true);71 65 72 66 /** … … 265 259 assert(pickup); 266 260 267 for (HUDPickupSystem* hud : ObjectList<HUDPickupSystem>())268 pickupSystem = hud;269 270 261 if(!GameMode::isMaster()) // If this is neither standalone nor the server. 271 262 return; … … 295 286 this->indexes_[pickup] = index; 296 287 this->pickups_[index] = pickup; 297 298 this->picks.push_back(pickup);299 300 if(pickupSystem)301 pickupSystem->sync(picks, indexes_);302 303 288 } 304 289 else // If it was dropped, it is removed from the required lists. … … 308 293 index = it->second; 309 294 310 this->indexes_.erase(pickup); 311 this->pickups_.erase(index); //set to null, so that can be identified as free slot by getPickupIndex() 312 313 314 this->picks.erase(std::remove(this->picks.begin(), this->picks.end(), pickup), this->picks.end()); //remove pickup from vector 315 316 if(pickupSystem) 317 pickupSystem->sync(picks, indexes_); 295 // Remove the Pickupable from the indexes_ and pickups_ list. 296 this->indexes_.erase(it); 297 this->pickups_.erase(index); 318 298 } 319 299 … … 342 322 343 323 } 344 345 //This function is called by the command line or by the key binding346 //it uses or unuses the pickup, depending on its current state347 //or drops it (depends what you comment/uncomment)348 void PickupManager::useUnusePickup(uint32_t index)349 {350 PickupManager& manager = PickupManager::getInstance();351 352 if(!manager.pickups_.count(index)) return; //if pickup is no longer here, dont do anything353 354 Pickupable* pickup=manager.pickups_.find(index)->second;355 if(pickup==nullptr)356 {357 return; //pickup does not exist358 }359 360 //if the pickup should be dropped upon key press361 manager.dropPickup(index);362 363 //if the pickup should be used/unused upon key press364 365 // if(pickup->isUsed())366 // manager.usePickup(index, false);367 // else368 // manager.usePickup(index, true);369 }370 371 324 372 325 /** … … 448 401 Pickupable* pickupable = this->pickups_.find(pickup)->second; 449 402 if(pickupable != nullptr) 450 {451 403 pickupable->drop(); 452 453 }454 404 } 455 405 // If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server. … … 544 494 /** 545 495 @brief 546 Get a new index between 0 and 9for a Pickupable.547 If all slots are occupied, the Pickupable in the first slot will be dropped.496 Get a new index for a Pickupable. 497 This will work as long as the number of Pickupables that are picked up is sufficiently small and as long as they don't exist forever. 548 498 @return 549 499 Returns the new index. … … 551 501 uint32_t PickupManager::getPickupIndex(void) 552 502 { 553 //check if there are free slots available 554 555 for(uint32_t i=0; i<10; i++) 556 { 557 if(!pickups_.count(i)) return i; 558 } 559 //all slots are full and we have to drop sth 560 orxout(internal_info, context::pickups) << "everything was full and we have now dropped the first element" << endl; 561 this->dropPickup(0); 562 return 0; 503 if(this->pickupHighestIndex_ == uint32_t(~0x0)-1) // If we've reached the highest possible number, we wrap around. 504 this->pickupHighestIndex_ = 0; 505 return this->pickupHighestIndex_++; 563 506 } 564 507 -
code/trunk/src/modules/pickup/PickupManager.h
r11353 r11704 42 42 43 43 #include "PickupRepresentation.h" 44 #include "interfaces/Pickupable.h" 44 45 45 #include "util/Singleton.h" 46 46 #include "interfaces/PickupListener.h" 47 #include "overlays/hud/HUDPickupSystem.h"48 47 49 48 namespace orxonox // tolua_export … … 136 135 137 136 void dropPickup(uint32_t pickup); //!< Drop the input Pickupable. 138 static void useUnusePickup(uint32_t index); //tolua_export139 137 void usePickup(uint32_t pickup, bool use); //!< Use (or unuse) the input Pickupable. 140 138 /** … … 149 147 static void dropPickupNetworked(uint32_t pickup); //!< Helper method to drop the input pickup on the server. 150 148 static void usePickupNetworked(uint32_t pickup, bool use); //!< Helper method to use (or unuse) the input Pickupable on the server. 151 void setPickupSystem(HUDPickupSystem* system);152 149 153 150 private: 154 HUDPickupSystem* pickupSystem;155 std::vector<Pickupable*> picks;156 157 151 static PickupManager* singletonPtr_s; 158 152 static const std::string guiName_s; //!< The name of the PickupInventory … … 172 166 void updateGUI(void); //!< Updates the PickupInventory GUI. 173 167 uint32_t getPickupIndex(void); //!< Get a new index for a Pickupable. 174 168 175 169 }; // tolua_export 176 170
Note: See TracChangeset
for help on using the changeset viewer.