Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 6 and Version 7 of code/doc/Pickups


Ignore:
Timestamp:
Mar 19, 2010, 6:30:32 PM (15 years ago)
Author:
dafrick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Pickups

    v6 v7  
    179179Please be aware, that these three methods are methods registered with Super, meaning, that whenever overloading them, don't forget to call SUPER(MyClass, myMethod);
    180180
    181  * a
     181 * clone() The clone() method creates a new pickup of the same type as the pickup it is cloned from. So the cloned pickup is not exactly the same, as it doesn't necessarily completely reflect the status of the pickup it is cloned from, but all the parameters and their values, that distinguish different types of this pickup class. It needs to be implemented by every pickup class. And it is best if this is done in a very specific way. Below is shown how:
     182{{{
     183void MyPickup::clone(OrxonoxClass*& item)
     184{
     185    if(item == NULL)
     186        item = new MyPickup(this);
     187       
     188    SUPER(MyPickup, clone, item);
     189       
     190    MyPickup* pickup = dynamic_cast<MyPickup*>(item);
     191    // Here you should set all the important parameters (that destinguis the different types of this pickup), e.g.
     192    pickup->setSomeParameter(this->getSomeParameter());
     193       
     194    // You must also initialize the identifier of the new pickup, conveniently this is normally done in a member function called initializeIdentifier() and so just this method is called here.
     195    pickup->initializeIdentifier();
     196}
     197}}}
     198 * initializeIdentifier() The initializeIdentifier() method initializes (or more simply put, creates) the PickupIdentifier of the instance of your pickup. Since the important values of the parameters are not yet available in the constructor of your pickup this initializeIdentifier() method must be called as soon as they are available, which normally is in the XMLPort() method, and the clone() method, as seen above. In the initializeIdentifier method you need to register each parameter that is important for the type of your pickup to its identifier, this is normally done as follows:
     199{{{
     200void Pickup::initializeIdentifier(void)
     201{       
     202    // If the get method returns a string.
     203    std::string val1 = this->getSomeParameter();
     204    std::string type1 = "someParameter";
     205    this->pickupIdentifier_->addParameter(type1, val1);
     206       
     207    // If the get method doesn't return a string
     208    std::stringstream stream;
     209    stream << this->getSomeOtherParameter();
     210    std::string type2 = "someOtherParameter";
     211    std::string val2 = stream.str();
     212    this->pickupIdentifier_->addParameter(type2, val2);
     213}
     214}}}
     215Be aware, this only works for parameters that are simple enough, meaning with pointers for example it will, naturally, not work.
    182216
    183217=== Making your object pickupable ===
     218
     219work in progress..