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.

Location:
code/branches/modularships/src/orxonox/worldentities/pawns
Files:
4 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}
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h

    r10019 r10023  
    4848    /**
    4949    @brief
    50         The ModularSpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
     50        The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
     51        The ModularSpaceShip is an extension of a @ref orxonox::SpaceShip SpaceShip, which uses @ref orxonox::ShipPart ShipParts to allow entities attached to it to be destroyed individually.
    5152
    5253        There are several parameters that define the behavior of the ModularSpaceShip>
     
    5657        - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated.
    5758
    58         As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip. Here is a (primitive) example of a ModularSpaceShip defined in XML:
     59        As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip.
     60        In order to assign attached entities to a ShipPart, a ShipPart with the same name as the corresponding entity needs to be created in the <parts> tag.
     61        Here is a (primitive) example of a ModularSpaceShip defined in XML:
    5962        @code
    6063        <ModularSpaceShip
     
    7780            angularDamping    = 0.9999999
    7881            >
     82                <attached>
     83                    <StaticEntity name="wing"  . . .  />
     84                    <StaticEntity name="tail" . . . />
     85                </attached>
     86                <parts>
     87                    <ShipPart name="wing" . . . />
     88                    <ShipPart name="tail" . . . />
     89                </parts>
    7990                <engines>
    8091                    <Engine />
     
    8596
    8697    @author
    87         Fabian 'x3n' Landau
     98        Fabian 'x3n' Landau, Noe Pedrazzini
    8899    */
    89100    class _OrxonoxExport ModularSpaceShip : public SpaceShip
     
    105116            ShipPart* getShipPart(unsigned int index);
    106117            bool hasShipPart(ShipPart* part) const;
     118            void removeShipPart(ShipPart* part);
    107119
    108120            virtual void updatePartAssignment();
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc

    r10011 r10023  
    252252    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    253253    {
    254         orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
    255 
    256         int collisionShapeIndex = this->isMyCollisionShape(cs);
    257         orxout() << collisionShapeIndex << endl;
     254        //FIXME: (noep) remove debug
     255        //orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
     256
     257        //int collisionShapeIndex = this->isMyCollisionShape(cs);
     258        //orxout() << collisionShapeIndex << endl;
    258259
    259260        // Applies multiplier given by the DamageBoost Pickup.
     
    587588        // List all attached Objects
    588589        orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
    589         for (int i=0; i<10; i++)
     590        for (int i=0; i<50; i++)
    590591        {
    591592            if (this->getAttachedObject(i)==NULL)
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h

    r10019 r10023  
    229229            unsigned int numexplosionchunks_;
    230230
    231             virtual int isMyCollisionShape(const btCollisionShape* cs);
     231            virtual int isMyCollisionShape(const btCollisionShape* cs); // FIXME: (noep) remove debug
    232232            void printBtChildShapes(btCompoundShape* cs, int indent, int subshape); // FIXME: (noep) remove debug
    233233            void printSpaces(int num);   // FIXME: (noep) remove debug
Note: See TracChangeset for help on using the changeset viewer.