Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2012, 11:08:17 PM (12 years ago)
Author:
landauf
Message:

merged branch presentation2012merge back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/PickupManager.cc

    r8858 r9348  
    8787
    8888        this->representations_.clear();
    89         this->representationsNetworked_.clear();
    9089
    9190        // Destroying all the PickupInventoryContainers that are still there.
     
    106105    /**
    107106    @brief
    108         Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    109         For every type of Pickupable (uniquely identified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
    110     @param identifier
    111         The PickupIdentifier identifying the Pickupable.
     107        Registers a PickupRepresentation.
     108    @param name
     109        The representation's name.
    112110    @param representation
    113111        A pointer to the PickupRepresentation.
     
    115113        Returns true if successful and false if not.
    116114    */
    117     bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    118     {
    119         assert(identifier);
     115    bool PickupManager::registerRepresentation(const std::string& name, PickupRepresentation* representation)
     116    {
    120117        assert(representation);
    121118
    122119        // If the list is not empty and Pickupable already has a Representation registered.
    123         if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end())
     120        if(!this->representations_.empty() && this->representations_.find(name) != this->representations_.end())
    124121            return false;
    125122
    126         this->representations_[identifier] = representation;
     123        this->representations_[name] = representation;
    127124
    128125        orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " registered with the PickupManager." << endl;
     
    132129    /**
    133130    @brief
    134         Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    135     @param identifier
    136         The PickupIdentifier identifying the Pickupable.
    137     @param representation
    138         A pointer to the PickupRepresentation.
     131        Unegisters a PickupRepresentation.
     132    @param name
     133        The representation's name.
    139134    @return
    140135        Returns true if successful and false if not.
    141136    */
    142     bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    143     {
    144         assert(identifier);
    145         assert(representation);
    146 
    147         std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
     137    bool PickupManager::unregisterRepresentation(const std::string& name)
     138    {
     139        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
    148140        if(it == this->representations_.end()) // If the Pickupable is not registered in the first place.
    149141            return false;
     
    151143        this->representations_.erase(it);
    152144
    153         orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " unregistered with the PickupManager." << endl;
     145        orxout(verbose, context::pickups) << "PickupRepresentation &" << name << " unregistered with the PickupManager." << endl;
    154146        return true;
    155147    }
     
    157149    /**
    158150    @brief
    159         Registers a PickupRepresentation on the host it was created.
    160     @param representation
    161         A pointer to the PickupRepresentation.
    162     @return
    163         Returns true if successful, false if not.
    164     */
    165     bool PickupManager::registerRepresentation(PickupRepresentation* representation)
    166     {
    167         assert(representation);
    168 
    169         // If the list is not empty and PickupRepresentation is already registered.
    170         if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end())
    171             return false;
    172 
    173         this->representationsNetworked_[representation->getObjectID()] = representation;
    174         return true;
    175     }
    176 
    177     /**
    178     @brief
    179         Unregisters a PickupRepresentation on the host it is being destroyed (which is the same host on which it was created).
    180     @param representation
    181         A pointer to the Pickuprepresentation.
    182     @return
    183         Returns true if successful, false if not.
    184     */
    185     bool PickupManager::unregisterRepresentation(PickupRepresentation* representation)
    186     {
    187         assert(representation);
    188 
    189         std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID());
    190         if(it == this->representationsNetworked_.end()) // If the Pickupable is not registered in the first place.
    191             return false;
    192 
    193         this->representationsNetworked_.erase(it);
    194         return true;
    195     }
    196 
    197     /**
    198     @brief
    199         Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    200     @param identifier
    201         The PickupIdentifier.
     151        Get the PickupRepresentation with the given name.
     152    @param name
     153        The name of the PickupRepresentation.
    202154    @return
    203155        Returns a pointer to the PickupRepresentation.
    204156    */
    205     PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
    206     {
    207         std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    208         if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input PickupIdentifier.
     157    PickupRepresentation* PickupManager::getRepresentation(const std::string& name)
     158    {
     159        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
     160        if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input name.
    209161        {
    210162            orxout(verbose, context::pickups) << "PickupManager::getRepresentation() returned default representation." << endl;
     
    353305        {
    354306            // If there is no PickupRepresentation registered the default representation is used.
    355             if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
    356                 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     307            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
     308                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp);
    357309            else
    358                 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
     310                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp);
    359311        }
    360312        // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager.
     
    362314        {
    363315            // If there is no PickupRepresentation registered the default representation is used.
    364             if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
     316            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
    365317            {
    366318                callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     
    368320            else
    369321            {
    370                 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
     322                callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp);
    371323            }
    372324        }
     
    388340        The pickedUp status the Pickupable changed to.
    389341    */
    390     /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp)
     342    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp)
    391343    {
    392344        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
     
    402354            container->unusable = false;
    403355            container->representationObjectId = representationObjectId;
     356            container->representationName = representationName;
    404357            // Insert the container into the pickupInventoryContainers_ list.
    405358            manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container));
     
    417370            manager.updateGUI(); // Tell the PickupInventory that something has changed.
    418371        }
    419     }
    420 
    421     /**
    422     @brief
    423         Get the PickupRepresentation of an input Pickupable.
    424         This method spares us the hassle to export the PickupIdentifier class to lua.
    425     @param pickup
    426         The number identifying the Pickupable whose PickupRepresentation should be returned.
    427     @return
    428         Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.
    429     */
    430     orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint32_t pickup)
    431     {
    432         // Clear and rebuild the representationsNetworked_ list.
    433         //TODO: Better solution?
    434         this->representationsNetworked_.clear();
    435         for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it)
    436             this->representationsNetworked_[it->getObjectID()] = *it;
    437 
    438         // Get the container belonging to the input pickup, if not found return the default representation.
    439         std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup);
    440         if(it == this->pickupInventoryContainers_.end())
    441             return this->defaultRepresentation_;
    442 
    443         // Get the PickupRepresentation of the input pickup (through the objecId of the representation stored in the PickupInventoryContainer belonging to the pickup), if not found return the default representation.
    444         std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId);
    445         if(it2 == this->representationsNetworked_.end())
    446             return this->defaultRepresentation_;
    447 
    448         return it2->second;
    449372    }
    450373
Note: See TracChangeset for help on using the changeset viewer.