Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2010, 8:00:40 AM (14 years ago)
Author:
dafrick
Message:

Pickups module is now (from what I can tell after some basic testing) fully functional over the network.
However it's still a little messy, needs some cleanup and documentation.
I introduced a new class, the PickupListener, which allows reacting to pickups becoming used, unused, picked up or dropped.

Location:
code/trunk/src/modules/pickup
Files:
4 edited

Legend:

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

    r7494 r7504  
    4040#include "core/GUIManager.h"
    4141#include "core/Identifier.h"
     42#include "network/Host.h"
     43#include "network/NetworkFunction.h"
    4244#include "interfaces/PickupCarrier.h"
    4345#include "infos/PlayerInfo.h"
     
    5355    DeclareToluaInterface(Pickup);
    5456
    55     ManageScopedSingleton(PickupManager, ScopeID::Graphics, false);
     57    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
    5658
    5759    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
    5860
     61    registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork);
     62    registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork);
     63    registerStaticNetworkFunction(PickupManager::dropPickupNetworked);
     64    registerStaticNetworkFunction(PickupManager::usePickupNetworked);
     65
    5966    /**
    6067    @brief
    6168        Constructor. Registers the PickupManager and creates the default PickupRepresentation.
    6269    */
    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);
    6873
    6974        this->defaultRepresentation_ = new PickupRepresentation();
     
    8388
    8489        this->representations_.clear();
     90
     91        //TODO: Destroy properly...
    8592
    8693        COUT(3) << "PickupManager destroyed." << std::endl;
     
    103110        assert(representation);
    104111
    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.
    106113            return false;
    107114
     
    109116
    110117        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;
    111129        return true;
    112130    }
     
    137155    }
    138156
     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
    139169    /**
    140170    @brief
     
    166196        Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.
    167197    */
    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;
    174213    }
    175214
     
    183222    int PickupManager::getNumPickups(void)
    184223    {
    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();
    238226    }
    239227
     
    245233        The Pickupable to be dropped.
    246234    */
    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        }
    258260    }
    259261
     
    267269        If true the input Pickupable is used, if false it is unused.
    268270    */
    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        }
    280296    }
    281297
     
    288304        Returns true if the input Pickupable is still valid, false if not.
    289305    */
    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_++;
    296468    }
    297469
  • code/trunk/src/modules/pickup/PickupManager.h

    r7456 r7504  
    3939
    4040#include <map>
    41 #include "util/Singleton.h"
     41
    4242#include "core/WeakPtr.h"
     43
    4344#include "pickup/PickupIdentifier.h"
     45
    4446#include "PickupRepresentation.h"
    4547
    46 #include "core/OrxonoxClass.h"
     48#include "util/Singleton.h"
     49#include "interfaces/PickupListener.h"
    4750
    4851namespace orxonox // tolua_export
    4952{ // 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
    5065
    5166    /**
     
    5772    */
    5873    class _PickupExport PickupManager // tolua_export
    59         : public Singleton<PickupManager>, public OrxonoxClass
     74        : public Singleton<PickupManager>, public PickupListener
    6075    { // tolua_export
    6176        friend class Singleton<PickupManager>;
     
    6883
    6984            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);
    7086            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);
    7188            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    7289
    7390            // 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.
    7592
    7693            int getNumPickups(void); //!< Update the list of picked up Pickupables and get the number of Pickupables in the list.
     
    8097            @return Returns the next Pickupable in the list.
    8198            */
    82             orxonox::Pickupable* popPickup(void) { return (this->pickupsIterator_++)->first; }
     99            orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; }
    83100
    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.
    87104            // 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);
    88113
    89114        private:
    90115            static PickupManager* singletonPtr_s;
    91116            static const std::string guiName_s; //!< The name of the PickupInventory
     117            bool guiLoaded_;
     118            uint64_t pickupIndex_;
    92119
    93120            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    94121            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
     122            std::map<uint32_t, PickupRepresentation*> representationsNetworked_;
    95123
    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_.
    98126
    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);
    100132
    101133    }; // tolua_export
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    r7163 r7504  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "core/GameMode.h"
    3738#include "graphics/Billboard.h"
    3839#include "util/StringUtils.h"
     
    4950        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
    5051    */
    51     PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
     52    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
    5253    {
    5354        RegisterObject(PickupRepresentation);
    5455
    5556        this->initialize();
     57        this->setSyncMode(0x0);
    5658    }
    5759
     
    6062        Default Constructor. Registers the object and initializes its member variables.
    6163    */
    62     PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL), pickup_(NULL)
     64    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL), pickup_(NULL)
    6365    {
    6466        RegisterObject(PickupRepresentation);
    6567
    6668        this->initialize();
     69        this->registerVariables();
     70
     71        PickupManager::getInstance().registerRepresentation(this); //!< Registers the PickupRepresentation with the PickupManager.
    6772    }
    6873
     
    7681            this->spawnerRepresentation_->destroy();
    7782
    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        }
    8094    }
    8195
     
    90104        this->spawnerTemplate_ = "";
    91105        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);
    92113    }
    93114
     
    107128        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
    108129
    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        }
    110134
    111135        if(this->spawnerRepresentation_ != NULL)
  • code/trunk/src/modules/pickup/PickupRepresentation.h

    r7456 r7504  
    4545
    4646#include "core/BaseObject.h"
     47#include "network/synchronisable/Synchronisable.h"
    4748
    4849namespace orxonox // tolua_export
     
    5556    */
    5657    class _PickupExport PickupRepresentation // tolua_export
    57         : public BaseObject
     58        : public BaseObject, public Synchronisable
    5859    { // tolua_export
    5960
     
    146147            StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner.
    147148
     149            void registerVariables(void); //!< Register some variables for synchronisation.
     150
    148151            std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation.
    149152            std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation.
Note: See TracChangeset for help on using the changeset viewer.