Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 9, 2014, 9:50:45 PM (11 years ago)
Author:
noep
Message:

ShipParts can "die" and detach the corresponding Entity while doing so. Issue: The Entity being detached while a hit on a collisionshape is being handled causes a runtime-error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10019 r10023  
    8888                if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
    8989                {
     90                    // The Entity is added to the part's entityList_
    9091                    this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
     92                    // An entry in the partMap_ is created, assigning the part to the entity.
     93                    this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), this->partList_[j]);
    9194                    orxout() << "A matching part-entity-pair with name " << this->partList_[j]->getName() << " was found!" << endl;
    9295                    this->partList_[j]->printEntities(); // FIXME: (noep) remove debug
     
    9497            }
    9598        }
     99
     100        orxout() << "List of all assignments:" << endl;
     101        for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
     102                {
     103                    orxout() << "Entity: " << it->first << "   Part: " << it->second << endl;
     104                }
    96105    }
    97106
     
    143152        orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
    144153
    145         // List all attached Objects
     154
     155            // Print all attached objects & parts
     156        /*
    146157        orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
    147         for (int i=0; i<10; i++)
     158
     159        for (int i=0; i<50; i++)
    148160        {
    149161            if (this->getAttachedObject(i)==NULL)
     
    157169        {
    158170            orxout() << "  " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;
    159         }
     171        }*/
     172
    160173
    161174        //int collisionShapeIndex = this->isMyCollisionShape(cs);
    162175        //orxout() << collisionShapeIndex << endl;
    163176
    164         orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
     177        //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
     178
     179        orxout() << "CP_start" << endl;
    165180
    166181        if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
    167182            this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
    168         //else
    169         //    SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
     183        else
     184            SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
     185
     186        orxout() << "CP_end" << endl;
    170187
    171188        /*
     
    208225        OrxAssert(part != NULL, "The ShipPart cannot be NULL.");
    209226        this->partList_.push_back(part);
     227        part->setParent(this);
    210228        //part->addToSpaceShip(this); //FIXME: (noep) add
    211229        this->updatePartAssignment();
     
    242260    }
    243261
     262    void ModularSpaceShip::removeShipPart(ShipPart* part)
     263    {
     264        // Remove the part from the partList_
     265        std::vector<ShipPart*>::iterator it = this->partList_.begin();
     266        for(unsigned int i = 0; i < this->partList_.size(); i++)
     267        {
     268            if(this->partList_[i] == part)
     269                this->partList_.erase(it);
     270            it++;
     271        }
     272        // Remove the part-entity assignment and detach the Entity of this ShipPart
     273        for (std::map<StaticEntity*, ShipPart*>::iterator itt = this->partMap_.begin(); itt != this->partMap_.end(); ++itt)
     274        {
     275            if (itt->second == part)
     276            {
     277                this->detach(itt->first);
     278                this->partMap_.erase(itt);
     279            }
     280        }
     281    }
     282
    244283}
Note: See TracChangeset for help on using the changeset viewer.