Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 6, 2018, 3:16:00 AM (6 years ago)
Author:
landauf
Message:

[HUD_HS16] fixed wrong dependency between overlays and pickup module: pickup should NOT depend on overlays; instead overlays should use pickup.

also reverted all changes from HUD_HS16 in PickupManager for several reasons:

  • calling HUDPickupSystem is not necessary anymore due to the fixed dependencies
  • adding a console command is not necessary because there is already a full GUI for this purpose (press F4)
  • limiting the number of pickups to 10 is a bad idea because PickupManager manages pickups for ALL players in the game
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/PickupManager.cc

    r11701 r11704  
    4141#include "network/Host.h"
    4242#include "network/NetworkFunctionIncludes.h"
    43 #include "core/input/KeyBinderManager.h"    //for keybinding
    44 #include "core/input/KeyBinder.h"           //for keybinding
    45 #include "core/command/ConsoleCommandIncludes.h"
    4643
    4744#include "infos/PlayerInfo.h"
     
    5148#include "CollectiblePickup.h"
    5249#include "PickupRepresentation.h"
    53 #include "overlays/hud/HUDPickupSystem.h"
    5450
    5551namespace orxonox
     
    6763
    6864    RegisterAbstractClass(PickupManager).inheritsFrom<PickupListener>();
    69 
    70     SetConsoleCommand("useUnusePickup", &PickupManager::useUnusePickup).addShortcut().setActive(true);
    7165
    7266    /**
     
    265259        assert(pickup);
    266260
    267         for (HUDPickupSystem* hud : ObjectList<HUDPickupSystem>())
    268             pickupSystem = hud;
    269        
    270261        if(!GameMode::isMaster()) // If this is neither standalone nor the server.
    271262            return;
     
    295286            this->indexes_[pickup] = index;
    296287            this->pickups_[index] = pickup;
    297 
    298             this->picks.push_back(pickup);
    299 
    300             if(pickupSystem)
    301                 pickupSystem->sync(picks, indexes_);
    302            
    303288        }
    304289        else // If it was dropped, it is removed from the required lists.
     
    308293            index = it->second;
    309294
    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);
    318298        }
    319299
     
    342322
    343323    }
    344 
    345     //This function is called by the command line or by the key binding
    346     //it uses or unuses the pickup, depending on its current state
    347     //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 anything
    353 
    354         Pickupable* pickup=manager.pickups_.find(index)->second;
    355         if(pickup==nullptr)
    356         {
    357             return;                       //pickup does not exist
    358         }
    359 
    360         //if the pickup should be dropped upon key press
    361         manager.dropPickup(index);
    362 
    363         //if the pickup should be used/unused upon key press
    364 
    365         // if(pickup->isUsed())
    366         //     manager.usePickup(index, false);
    367         // else
    368         //     manager.usePickup(index, true);
    369     }
    370 
    371324
    372325    /**
     
    448401            Pickupable* pickupable = this->pickups_.find(pickup)->second;
    449402            if(pickupable != nullptr)
    450             {
    451403                pickupable->drop();
    452 
    453             }
    454404        }
    455405        // If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server.
     
    544494    /**
    545495    @brief
    546         Get a new index between 0 and 9 for 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.
    548498    @return
    549499        Returns the new index.
     
    551501    uint32_t PickupManager::getPickupIndex(void)
    552502    {
    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_++;
    563506    }
    564507
Note: See TracChangeset for help on using the changeset viewer.