Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 30, 2015, 1:59:38 PM (8 years ago)
Author:
landauf
Message:

using strongly typed enum class in pickups and triggers.

Location:
code/branches/cpp11_v2/src/modules/pickup
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/modules/pickup/Pickup.cc

    r9667 r10998  
    7878    void Pickup::initialize(void)
    7979    {
    80         this->activationType_ = pickupActivationType::immediate;
    81         this->durationType_ = pickupDurationType::once;
     80        this->activationType_ = PickupActivationType::immediate;
     81        this->durationType_ = PickupDurationType::once;
    8282    }
    8383
     
    105105        switch(this->getActivationType())
    106106        {
    107             case pickupActivationType::immediate:
     107            case PickupActivationType::immediate:
    108108                return activationTypeImmediate_s;
    109             case pickupActivationType::onUse:
     109            case PickupActivationType::onUse:
    110110                return activationTypeOnUse_s;
    111111            default:
     
    124124        switch(this->getDurationType())
    125125        {
    126             case pickupDurationType::once:
     126            case PickupDurationType::once:
    127127                return durationTypeOnce_s;
    128             case pickupDurationType::continuous:
     128            case PickupDurationType::continuous:
    129129                return durationTypeContinuous_s;
    130130            default:
     
    142142    {
    143143        if(type == Pickup::activationTypeImmediate_s)
    144             this->setActivationType(pickupActivationType::immediate);
     144            this->setActivationType(PickupActivationType::immediate);
    145145        else if(type == Pickup::activationTypeOnUse_s)
    146             this->setActivationType(pickupActivationType::onUse);
     146            this->setActivationType(PickupActivationType::onUse);
    147147        else
    148148            orxout(internal_error, context::pickups) << "Invalid activationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
     
    158158    {
    159159        if(type == Pickup::durationTypeOnce_s)
    160             this->setDurationType(pickupDurationType::once);
     160            this->setDurationType(PickupDurationType::once);
    161161        else if(type == Pickup::durationTypeContinuous_s)
    162             this->setDurationType(pickupDurationType::continuous);
     162            this->setDurationType(PickupDurationType::continuous);
    163163        else
    164164            orxout(internal_error, context::pickups) << "Invalid durationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
  • code/branches/cpp11_v2/src/modules/pickup/Pickup.h

    r10817 r10998  
    5353    @ingroup Pickup
    5454    */
    55     namespace pickupActivationType
     55    enum class PickupActivationType
    5656    {
    57         enum Value
    58         {
    59             immediate, //!< Means that the @ref orxonox::Pickup "Pickup" will be used immediately after pickup.
    60             onUse, //!< Means that the @ref orxonox::Pickup "Pickup" will be used at a later point trough some external influence.
    61         };
    62     }
     57        immediate, //!< Means that the @ref orxonox::Pickup "Pickup" will be used immediately after pickup.
     58        onUse, //!< Means that the @ref orxonox::Pickup "Pickup" will be used at a later point trough some external influence.
     59    };
    6360
    6461    /**
     
    6865    @ingroup Pickup
    6966    */
    70     namespace pickupDurationType
     67    enum class PickupDurationType
    7168    {
    72         enum Value
    73         {
    74             once, //!< Means that the @ref orxonox::Pickup "Pickup" will be used only once at a singular time instant.
    75             continuous, //!< Means that the @ref orxonox::Pickup "Pickup" will be used over a continuous timespan.
    76         };
    77     }
     69        once, //!< Means that the @ref orxonox::Pickup "Pickup" will be used only once at a singular time instant.
     70        continuous, //!< Means that the @ref orxonox::Pickup "Pickup" will be used over a continuous timespan.
     71    };
    7872
    7973    /**
     
    112106            @return Returns the activation type of the Pickup.
    113107            */
    114             inline pickupActivationType::Value getActivationType(void) const
     108            inline PickupActivationType getActivationType(void) const
    115109                { return this->activationType_; }
    116110            /**
     
    118112            @return Returns the duration type of the Pickup.
    119113            */
    120             inline pickupDurationType::Value getDurationType(void) const
     114            inline PickupDurationType getDurationType(void) const
    121115                { return this->durationType_; }
    122116
     
    129123            */
    130124            inline bool isImmediate(void) const
    131                 { return this->getActivationType() == pickupActivationType::immediate; }
     125                { return this->getActivationType() == PickupActivationType::immediate; }
    132126            /**
    133127            @brief Get whether the activation type is 'onUse'.
     
    135129            */
    136130            inline bool isOnUse(void) const
    137                 { return this->getActivationType() == pickupActivationType::onUse; }
     131                { return this->getActivationType() == PickupActivationType::onUse; }
    138132            /**
    139133            @brief Get whether the duration type is 'once'.
     
    141135            */
    142136            inline bool isOnce(void) const
    143                 { return this->getDurationType() == pickupDurationType::once; }
     137                { return this->getDurationType() == PickupDurationType::once; }
    144138            /**
    145139            @brief Get whether the duration type is 'continuous'.
     
    147141            */
    148142            inline bool isContinuous(void) const
    149                 { return this->getDurationType() == pickupDurationType::continuous; }
     143                { return this->getDurationType() == PickupDurationType::continuous; }
    150144
    151145            virtual void changedPickedUp(void) override; //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
     
    164158            @param type The activation type of the Pickup.
    165159            */
    166             inline void setActivationType(pickupActivationType::Value type)
     160            inline void setActivationType(PickupActivationType type)
    167161                { this->activationType_ = type; }
    168162            /**
     
    170164            @param type The duration type of the Pickup.
    171165            */
    172             inline void setDurationType(pickupDurationType::Value type)
     166            inline void setDurationType(PickupDurationType type)
    173167                { this->durationType_ = type; }
    174168
     
    180174
    181175            std::string representationName_; //!< The name of the associated PickupRepresentation.
    182             pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
    183             pickupDurationType::Value durationType_; //!< The duration type of the Pickup.
     176            PickupActivationType activationType_; //!< The activation type of the Pickup.
     177            PickupDurationType durationType_; //!< The duration type of the Pickup.
    184178
    185179            //! Strings for the activation and duration types.
  • code/branches/cpp11_v2/src/modules/pickup/items/DronePickup.cc

    r10765 r10998  
    7474    {
    7575        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
    76         this->setDurationType(pickupDurationType::once);
     76        this->setDurationType(PickupDurationType::once);
    7777        this->droneTemplate_ = "";
    7878    }
  • code/branches/cpp11_v2/src/modules/pickup/items/HealthPickup.cc

    r10765 r10998  
    7777        this->health_ = 0.0f;
    7878        this->healthRate_ = 0.0f;
    79         this->healthType_ = pickupHealthType::limited;
     79        this->healthType_ = PickupHealthType::limited;
    8080        this->maxHealthSave_ = 0.0f;
    8181        this->maxHealthOverwrite_ = 0.0f;
     
    127127            switch(this->getHealthType())
    128128            {
    129                 case pickupHealthType::permanent:
     129                case PickupHealthType::permanent:
    130130                    if(pawn->getMaxHealth() < fullHealth)
    131131                        pawn->setMaxHealth(fullHealth);
    132                 case pickupHealthType::limited:
     132                case PickupHealthType::limited:
    133133                    pawn->addHealth(health);
    134134                    break;
    135                 case pickupHealthType::temporary:
     135                case PickupHealthType::temporary:
    136136                    if(pawn->getMaxHealth() > fullHealth)
    137137                    {
     
    174174                switch(this->getHealthType())
    175175                {
    176                     case pickupHealthType::permanent:
     176                    case PickupHealthType::permanent:
    177177                        health = pawn->getHealth()+this->getHealth();
    178178                        if(pawn->getMaxHealth() < health)
    179179                            pawn->setMaxHealth(health);
    180                     case pickupHealthType::limited:
     180                    case PickupHealthType::limited:
    181181                        pawn->addHealth(this->getHealth());
    182182                        break;
    183                     case pickupHealthType::temporary:
     183                    case PickupHealthType::temporary:
    184184                        health = pawn->getHealth()+this->getHealth();
    185185                        if(pawn->getMaxHealth() < health)
     
    201201        else
    202202        {
    203             if(this->getHealthType() == pickupHealthType::temporary)
     203            if(this->getHealthType() == PickupHealthType::temporary)
    204204            {
    205205                PickupCarrier* carrier = this->getCarrier();
     
    256256        switch(this->getHealthType())
    257257        {
    258             case pickupHealthType::limited:
     258            case PickupHealthType::limited:
    259259                return HealthPickup::healthTypeLimited_s;
    260             case pickupHealthType::temporary:
     260            case PickupHealthType::temporary:
    261261                return HealthPickup::healthTypeTemporary_s;
    262             case pickupHealthType::permanent:
     262            case PickupHealthType::permanent:
    263263                return HealthPickup::healthTypePermanent_s;
    264264            default:
     
    308308    {
    309309        if(type == HealthPickup::healthTypeLimited_s)
    310             this->setHealthType(pickupHealthType::limited);
     310            this->setHealthType(PickupHealthType::limited);
    311311        else if(type == HealthPickup::healthTypeTemporary_s)
    312             this->setHealthType(pickupHealthType::temporary);
     312            this->setHealthType(PickupHealthType::temporary);
    313313        else if(type == HealthPickup::healthTypePermanent_s)
    314             this->setHealthType(pickupHealthType::permanent);
     314            this->setHealthType(PickupHealthType::permanent);
    315315        else
    316316            orxout(internal_error, context::pickups) << "Invalid healthType '" << type << "' in HealthPickup." << endl;
  • code/branches/cpp11_v2/src/modules/pickup/items/HealthPickup.h

    r9667 r10998  
    5151    @ingroup PickupItems
    5252    */
    53     namespace pickupHealthType
     53    enum class PickupHealthType
    5454    {
    55         enum Value
    56         {
    57             limited, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" only increases the users health to its maximum health.
    58             temporary, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" temporarily increases the users health even above its maximum health, but only as long as it is in use.
    59             permanent //!< Means that the @ref orxonox::HealthPickup "HealthPickup" increases the users health even above its maximum health and increases the maximum health permanently such that it matches the new health.
    60         };
    61     }
     55        limited, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" only increases the users health to its maximum health.
     56        temporary, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" temporarily increases the users health even above its maximum health, but only as long as it is in use.
     57        permanent //!< Means that the @ref orxonox::HealthPickup "HealthPickup" increases the users health even above its maximum health and increases the maximum health permanently such that it matches the new health.
     58    };
    6259
    6360    /**
     
    115112            @return Returns the health type as an enum.
    116113            */
    117             inline pickupHealthType::Value getHealthType(void) const
     114            inline PickupHealthType getHealthType(void) const
    118115                { return this->healthType_; }
    119116            const std::string& getHealthTypeAsString(void) const; //!< Get the health type of this pickup.
     
    127124            @param type The type of this pickup as an enum.
    128125            */
    129             inline void setHealthType(pickupHealthType::Value type)
     126            inline void setHealthType(PickupHealthType type)
    130127                { this->healthType_ = type; }
    131128            void setHealthTypeAsString(const std::string& type); //!< Set the type of the HealthPickup.
     
    139136            float maxHealthSave_; //!< Helper to remember what the actual maxHealth of the Pawn was before we changed it.
    140137            float maxHealthOverwrite_; //!< Helper to remember with which value we overwrote the maxHealh, to detect if someone else changed it as well.
    141             pickupHealthType::Value healthType_; //!< The type of the HealthPickup.
     138            PickupHealthType healthType_; //!< The type of the HealthPickup.
    142139
    143140            //! Strings for the health types.
  • code/branches/cpp11_v2/src/modules/pickup/items/MetaPickup.cc

    r10916 r10998  
    7979        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
    8080
    81         this->setDurationType(pickupDurationType::once);
    82         this->metaType_ = pickupMetaType::none;
     81        this->setDurationType(PickupDurationType::once);
     82        this->metaType_ = PickupMetaType::none;
    8383    }
    8484
     
    104104
    105105        // If the MetaPickup transited to used, and the metaType is not none.
    106         if(this->isUsed() && this->metaType_ != pickupMetaType::none)
     106        if(this->isUsed() && this->metaType_ != PickupMetaType::none)
    107107        {
    108108            PickupCarrier* carrier = this->getCarrier();
    109             if(this->getMetaType() != pickupMetaType::none && carrier != nullptr)
     109            if(this->getMetaType() != PickupMetaType::none && carrier != nullptr)
    110110            {
    111111                // If the metaType is destroyCarrier, then the PickupCarrier is destroyed.
    112                 if(this->getMetaType() == pickupMetaType::destroyCarrier)
     112                if(this->getMetaType() == PickupMetaType::destroyCarrier)
    113113                {
    114114                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
     
    124124
    125125                    // If the metaType is use, then the Pickupable is set to used.
    126                     if(this->getMetaType() == pickupMetaType::use && !pickup->isUsed())
     126                    if(this->getMetaType() == PickupMetaType::use && !pickup->isUsed())
    127127                    {
    128128                        pickup->setUsed(true);
    129129                    }
    130130                    // If the metaType is drop, then the Pickupable is dropped.
    131                     else if(this->getMetaType() == pickupMetaType::drop)
     131                    else if(this->getMetaType() == PickupMetaType::drop)
    132132                    {
    133133                        pickup->drop();
    134134                    }
    135135                    // If the metaType is destroy, then the Pickupable is destroyed.
    136                     else if(this->getMetaType() == pickupMetaType::destroy)
     136                    else if(this->getMetaType() == PickupMetaType::destroy)
    137137                    {
    138138                        pickup->Pickupable::destroy();
     
    154154        switch(this->getMetaType())
    155155        {
    156             case pickupMetaType::none:
     156            case PickupMetaType::none:
    157157                return MetaPickup::metaTypeNone_s;
    158             case pickupMetaType::use:
     158            case PickupMetaType::use:
    159159                return MetaPickup::metaTypeUse_s;
    160             case pickupMetaType::drop:
     160            case PickupMetaType::drop:
    161161                return MetaPickup::metaTypeDrop_s;
    162             case pickupMetaType::destroy:
     162            case PickupMetaType::destroy:
    163163                return MetaPickup::metaTypeDestroy_s;
    164             case pickupMetaType::destroyCarrier:
     164            case PickupMetaType::destroyCarrier:
    165165                return MetaPickup::metaTypeDestroyCarrier_s;
    166166            default:
     
    179179        if(type == MetaPickup::metaTypeNone_s)
    180180        {
    181             this->setMetaType(pickupMetaType::none);
     181            this->setMetaType(PickupMetaType::none);
    182182        }
    183183        else if(type == MetaPickup::metaTypeUse_s)
    184184        {
    185             this->setMetaType(pickupMetaType::use);
     185            this->setMetaType(PickupMetaType::use);
    186186        }
    187187        else if(type == MetaPickup::metaTypeDrop_s)
    188188        {
    189             this->setMetaType(pickupMetaType::drop);
     189            this->setMetaType(PickupMetaType::drop);
    190190        }
    191191        else if(type == MetaPickup::metaTypeDestroy_s)
    192192        {
    193             this->setMetaType(pickupMetaType::destroy);
     193            this->setMetaType(PickupMetaType::destroy);
    194194        }
    195195        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
    196196        {
    197             this->setMetaType(pickupMetaType::destroyCarrier);
     197            this->setMetaType(PickupMetaType::destroyCarrier);
    198198        }
    199199        else
  • code/branches/cpp11_v2/src/modules/pickup/items/MetaPickup.h

    r9667 r10998  
    4848    @ingroup PickupItems
    4949    */
    50     namespace pickupMetaType
     50    enum class PickupMetaType
    5151    {
    52         enum Value
    53         {
    54             none, //!< The @ref orxonox::MetaPickup "MetaPickup" does nothing.
    55             use, //!< The @ref orxonox::MetaPickup "MetaPickup" uses all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
    56             drop, //!< The @ref orxonox::MetaPickup "MetaPickup" drops all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
    57             destroy, //!< The @ref orxonox::MetaPickup "MetaPickup" destroys all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
    58             destroyCarrier //!< The @ref orxonox::MetaPickup "MetaPickup" destroys the @ref orxonox::PickupCarrier "PickupCarrier".
    59         };
    60     }
     52        none, //!< The @ref orxonox::MetaPickup "MetaPickup" does nothing.
     53        use, //!< The @ref orxonox::MetaPickup "MetaPickup" uses all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
     54        drop, //!< The @ref orxonox::MetaPickup "MetaPickup" drops all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
     55        destroy, //!< The @ref orxonox::MetaPickup "MetaPickup" destroys all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
     56        destroyCarrier //!< The @ref orxonox::MetaPickup "MetaPickup" destroys the @ref orxonox::PickupCarrier "PickupCarrier".
     57    };
    6158
    6259    /**
     
    10097            @return Returns an enum with the meta type of the MetaPickup.
    10198            */
    102             inline pickupMetaType::Value getMetaType(void) const
     99            inline PickupMetaType getMetaType(void) const
    103100                { return this->metaType_; }
    104101            const std::string& getMetaTypeAsString(void) const; //!< Get the meta type of this MetaPickup.
     
    109106            @param type The meta type as an enum.
    110107            */
    111             inline void setMetaType(pickupMetaType::Value type)
     108            inline void setMetaType(PickupMetaType type)
    112109                { this->metaType_ =  type; }
    113110            void setMetaTypeAsString(const std::string& type); //!< Set the meta type of this MetaPickup.
     
    116113            void initialize(void); //!< Initializes the member variables.
    117114
    118             pickupMetaType::Value metaType_; //!< The meta type of the MetaPickup, determines which actions are taken.
     115            PickupMetaType metaType_; //!< The meta type of the MetaPickup, determines which actions are taken.
    119116
    120117            //! Static strings for the meta types.
Note: See TracChangeset for help on using the changeset viewer.