[Orxonox-commit 7091] r11708 - in code/trunk/src: modules/overlays/hud modules/pickup orxonox/controllers

landauf at orxonox.net landauf at orxonox.net
Sat Jan 6 18:07:53 CET 2018


Author: landauf
Date: 2018-01-06 18:07:53 +0100 (Sat, 06 Jan 2018)
New Revision: 11708

Modified:
   code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc
   code/trunk/src/modules/overlays/hud/HUDPickupSystem.h
   code/trunk/src/modules/pickup/PickupManager.cc
   code/trunk/src/modules/pickup/PickupManager.h
   code/trunk/src/modules/pickup/PickupPrereqs.h
   code/trunk/src/orxonox/controllers/ActionpointController.h
Log:
[HUD_HS16] fixed issue that the hud shows pickups of ALL players/bots instead of just the own spaceship. fixed this by comparing objectIDs
note: network calls currently support only 5 arguments, so I removed representationObjectId which doesn't seem to be used (neither in C++ nor in Lua)

Modified: code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc	2018-01-06 15:34:18 UTC (rev 11707)
+++ code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc	2018-01-06 17:07:53 UTC (rev 11708)
@@ -33,11 +33,13 @@
 #include <OgreOverlayElement.h>
 #include <OgrePanelOverlayElement.h>
 
+#include "HUDPickupSystem.h"
+
 #include "core/CoreIncludes.h"
 #include "core/class/Super.h"
 #include "util/Convert.h"
-#include "HUDPickupSystem.h"
 #include "pickup/PickupManager.h"
+#include "worldentities/pawns/Pawn.h"
 
 namespace orxonox
 {
@@ -77,20 +79,27 @@
         OrxonoxOverlay::sizeChanged();
 
     }
-    
+
+    void HUDPickupSystem::changedOwner()
+    {
+        SUPER(HUDPickupSystem, changedOwner);
+
+        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
+    }
+
     void HUDPickupSystem::tick(float dt)
     {
         SUPER(HUDPickupSystem, tick, dt);
 
-        int numPickups = PickupManager::getInstance().getNumPickups();
+        std::vector<const PickupInventoryContainer*> containers = this->getPickupsForOwner();
+
         for (size_t index = 0; index < this->items_.size(); ++index)
         {
             Ogre::OverlayElement* item = this->items_[index];
 
-            if (static_cast<int>(index) < numPickups)
+            if (index < containers.size())
             {
-                const PickupInventoryContainer* container = PickupManager::getInstance().popPickup();
-                item->setMaterialName(this->getIcon(container->representationName));
+                item->setMaterialName(this->getIcon(containers[index]->representationName));
                 if (!item->getParent())
                     this->background_->addChild(item);
             }
@@ -102,8 +111,23 @@
         }
     }
 
-    std::string HUDPickupSystem::getIcon(std::string repName)
+    std::vector<const PickupInventoryContainer*> HUDPickupSystem::getPickupsForOwner() const
     {
+        std::vector<const PickupInventoryContainer*> containers;
+
+        int numPickups = PickupManager::getInstance().getNumPickups();
+        for (int i = 0; i < numPickups; ++i)
+        {
+            const PickupInventoryContainer* container = PickupManager::getInstance().popPickup();
+            if (this->owner_ && this->owner_->getObjectID() == container->carrierPawnId)
+                containers.push_back(container);
+        }
+
+        return containers;
+    }
+
+    std::string HUDPickupSystem::getIcon(const std::string& repName) const
+    {
         if(repName.find("invisible", 0)!=std::string::npos) return "Eye";
         else if(repName.find("tri", 0)!=std::string::npos) return "Asterisk";
         else if(repName.find("health", 0)!=std::string::npos || repName.find("Health", 0)!=std::string::npos) return "Cross";

Modified: code/trunk/src/modules/overlays/hud/HUDPickupSystem.h
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDPickupSystem.h	2018-01-06 15:34:18 UTC (rev 11707)
+++ code/trunk/src/modules/overlays/hud/HUDPickupSystem.h	2018-01-06 17:07:53 UTC (rev 11708)
@@ -31,6 +31,7 @@
 #define _HUDPickupSystem_H__
 
 #include "overlays/OverlaysPrereqs.h"
+#include "pickup/PickupPrereqs.h"
 
 #include <vector>
 
@@ -47,12 +48,16 @@
         virtual ~HUDPickupSystem();
 
         virtual void tick(float dt) override;
+
         virtual void sizeChanged() override;
+        virtual void changedOwner() override;
 
     private:
-        std::string getIcon(std::string repName);
+        std::vector<const PickupInventoryContainer*> getPickupsForOwner() const;
+        std::string getIcon(const std::string& repName) const;
 
         std::vector<Ogre::OverlayElement*> items_;
+        WeakPtr<Pawn> owner_;
     };
 }
 

Modified: code/trunk/src/modules/pickup/PickupManager.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupManager.cc	2018-01-06 15:34:18 UTC (rev 11707)
+++ code/trunk/src/modules/pickup/PickupManager.cc	2018-01-06 17:07:53 UTC (rev 11708)
@@ -300,24 +300,12 @@
         // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
         if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
         {
-            // If there is no PickupRepresentation registered the default representation is used.
-            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
-                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp);
-            else
-                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp);
+            PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), pickup->getRepresentationName(), pickedUp, pawn->getObjectID());
         }
         // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager.
         else
         {
-            // If there is no PickupRepresentation registered the default representation is used.
-            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
-            {
-                callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
-            }
-            else
-            {
-                callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp);
-            }
+            callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), pickedUp, pawn->getObjectID());
         }
 
     }
@@ -331,14 +319,14 @@
         A number identifying the Pickupable that changed its pickedUp status.
     @param usable
         Whether the Pickupable's used status can be changed to used in the PickupInventory.
-    @param representationObjectId
-        The objectId identifying (over the network) the PickupRepresentation that represents this Pickupable.
     @param representationName
         The name of the associated PickupRepresentation
     @param pickedUp
         The pickedUp status the Pickupable changed to.
+    @param carrierPawnId
+        The objectId identifier (over the network) the Pawn that carries this Pickupable
     */
-    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp)
+    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, const std::string& representationName, bool pickedUp, uint32_t carrierPawnId)
     {
         PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
         // If the Pickupable has been picked up, we create a new PickupInventoryContainer for it.
@@ -351,8 +339,8 @@
             container->pickedUp = pickedUp;
             container->usable = usable;
             container->unusable = false;
-            container->representationObjectId = representationObjectId;
             container->representationName = representationName;
+            container->carrierPawnId = carrierPawnId;
             // Insert the container into the pickupInventoryContainers_ list.
             manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container));
 

Modified: code/trunk/src/modules/pickup/PickupManager.h
===================================================================
--- code/trunk/src/modules/pickup/PickupManager.h	2018-01-06 15:34:18 UTC (rev 11707)
+++ code/trunk/src/modules/pickup/PickupManager.h	2018-01-06 17:07:53 UTC (rev 11708)
@@ -63,8 +63,8 @@
         bool pickedUp; //!< Whether the @ref orxonox::Pickupable "Pickupable" is currently picked up.
         bool usable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is usable.
         bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable.
-        uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable".
         std::string representationName; //!< The name of the associated PickupRepresentation
+        uint32_t carrierPawnId; //!< The objectId of the @ref orxonox::Pawn "Pawn" that carries the @ref orxonox::Pickupable "Pickupable".
     };
     // tolua_end
 
@@ -119,7 +119,7 @@
             virtual void pickupChangedUsed(Pickupable* pickup, bool used) override; //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
             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.
             virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp) override; //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
-            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.
+            static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, const std::string& representationName, bool pickedUp, uint32_t carrierPawnId); //!< Helper method to react to the change in the pickedUp status of a Pickupable.
 
         // Methods to be used by the PickupInventory.
         public:

Modified: code/trunk/src/modules/pickup/PickupPrereqs.h
===================================================================
--- code/trunk/src/modules/pickup/PickupPrereqs.h	2018-01-06 15:34:18 UTC (rev 11707)
+++ code/trunk/src/modules/pickup/PickupPrereqs.h	2018-01-06 17:07:53 UTC (rev 11708)
@@ -71,6 +71,7 @@
     class CollectiblePickup;
     class Pickup;
     class PickupCollection;
+    class PickupInventoryContainer;
     class PickupManager;
     class PickupRepresentation;
     class PickupSpawner;

Modified: code/trunk/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/trunk/src/orxonox/controllers/ActionpointController.h	2018-01-06 15:34:18 UTC (rev 11707)
+++ code/trunk/src/orxonox/controllers/ActionpointController.h	2018-01-06 17:07:53 UTC (rev 11708)
@@ -32,7 +32,6 @@
 #include "controllers/FightingController.h"
 #include "tools/Timer.h"
 #include "tools/interfaces/Tickable.h"
-#include "../modules/pickup/PickupSpawner.h"
 #include <map>
 
 namespace orxonox



More information about the Orxonox-commit mailing list