Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11005


Ignore:
Timestamp:
Dec 30, 2015, 10:31:43 PM (8 years ago)
Author:
landauf
Message:

using strongly typed enum in various classes in orxonox-library

Location:
code/branches/cpp11_v2/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/modules/overlays/OverlayText.cc

    r10999 r11005  
    111111    void OverlayText::sizeChanged()
    112112    {
    113         if (this->rotState_ == Horizontal)
     113        if (this->rotState_ == RotationState::Horizontal)
    114114            this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
    115         else if (this->rotState_ == Vertical)
     115        else if (this->rotState_ == RotationState::Vertical)
    116116            this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
    117117        else
  • code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.h

    r10817 r11005  
    4545namespace orxonox
    4646{
    47     namespace PlayerState
    48     {
    49         enum Value
    50         {
    51             Uninitialized,
    52             Joined,
    53             Alive,
    54             Dead
    55         };
    56     }
     47    enum class PlayerState
     48    {
     49        Uninitialized,
     50        Joined,
     51        Alive,
     52        Dead
     53    };
    5754
    5855    struct Player
    5956    {
    6057        PlayerInfo* info_;
    61         PlayerState::Value state_;
     58        PlayerState state_;
    6259        int frags_;
    6360        int killed_;
  • code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.cc

    r10919 r11005  
    124124                this->state_ = 0;
    125125                if (this->getShip()->isBoosting() && forward)
    126                     this->state_ = Boost;
     126                    this->state_ = EngineState::Boost;
    127127                else if (forward && !this->state_) // this->state_ == Boost
    128                     this->state_ = Normal;
     128                    this->state_ = EngineState::Normal;
    129129                else if (direction.z > 0.0 && velocity.z < 0.0)
    130                     this->state_ = Brake;
     130                    this->state_ = EngineState::Brake;
    131131                else
    132                     this->state_ = Idle;
    133 
    134                 if (this->state_ == Idle && this->getSpeedAdd() > 0)
    135                     this->state_ = Normal;
     132                    this->state_ = EngineState::Idle;
     133
     134                if (this->state_ == EngineState::Idle && this->getSpeedAdd() > 0)
     135                    this->state_ = EngineState::Normal;
    136136            }
    137137
     
    141141
    142142                float pitch = velocity.length();
    143                 if (this->state_ & Normal)
     143                if (this->state_ & EngineState::Normal)
    144144                    defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f));
    145                 if (this->state_ & Boost)
     145                if (this->state_ & EngineState::Boost)
    146146                    defEngineSndBoost_->setPitch(clamp(pitch/MAX_VELOCITY_BOOST + 1, 0.5f, 2.0f));
    147147
    148                 if (changes & Idle)
    149                 {
    150                     lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Idle);
     148                if (changes & EngineState::Idle)
     149                {
     150                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Idle);
    151151                    lua_setglobal(this->lua_->getInternalLuaState(), "idle");
    152152                }
    153                 if (changes & Normal)
    154                 {
    155                     lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Normal);
     153                if (changes & EngineState::Normal)
     154                {
     155                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Normal);
    156156                    lua_setglobal(this->lua_->getInternalLuaState(), "normal");
    157                     if (this->state_ & Normal)
     157                    if (this->state_ & EngineState::Normal)
    158158                        defEngineSndNormal_->play();
    159159                    else
    160160                        defEngineSndNormal_->stop();
    161161                }
    162                 if (changes & Brake)
    163                 {
    164                     lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Brake);
     162                if (changes & EngineState::Brake)
     163                {
     164                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Brake);
    165165                    lua_setglobal(this->lua_->getInternalLuaState(), "brake");
    166166                }
    167                 if (changes & Boost)
    168                 {
    169                     lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Boost);
     167                if (changes & EngineState::Boost)
     168                {
     169                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Boost);
    170170                    lua_setglobal(this->lua_->getInternalLuaState(), "boost");
    171                     if (this->state_ & Boost)
     171                    if (this->state_ & EngineState::Boost)
    172172                        defEngineSndBoost_->play();
    173173                    else
  • code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.h

    r10817 r11005  
    4141    {
    4242        public:
    43             enum EngineState
     43            struct EngineState
    4444            {
    45                 Idle    = 1,
    46                 Normal  = 2,
    47                 Brake   = 4,
    48                 Boost   = 8
     45                static constexpr int Idle    = 1;
     46                static constexpr int Normal  = 2;
     47                static constexpr int Brake   = 4;
     48                static constexpr int Boost   = 8;
    4949            };
    5050
  • code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.cc

    r10262 r11005  
    9898        {
    9999            switch (this->targetParam_) {
    100             case shieldhealth:
     100            case TargetParam::shieldhealth:
    101101                this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth()));
    102102                break;
    103             case boostpower:
     103            case TargetParam::boostpower:
    104104                this->parent_->getParent()->setInitialBoostPower(operate(this->parent_->getParent()->getInitialBoostPower()));
    105105                break;
    106             case boostpowerrate:
     106            case TargetParam::boostpowerrate:
    107107                this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate()));
    108108                break;
    109             case rotationthrust:
     109            case TargetParam::rotationthrust:
    110110                this->parent_->getParent()->setRotationThrust(operate(this->parent_->getParent()->getRotationThrust()));
    111111                break;
     
    120120        {
    121121            switch (this->targetParam_) {
    122             case null:
     122            case TargetParam::null:
    123123                this->parent_->getParent()->getEngineByName(targetName_)->destroy();
    124124                break;
    125             case boostfactor:
     125            case TargetParam::boostfactor:
    126126                this->parent_->getParent()->getEngineByName(targetName_)->setBoostFactor(operate(this->parent_->getParent()->getEngineByName(targetName_)->getBoostFactor()));
    127127                break;
    128             case speedfront:
     128            case TargetParam::speedfront:
    129129                this->parent_->getParent()->getEngineByName(targetName_)->setMaxSpeedFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getMaxSpeedFront()));
    130130                break;
    131             case accelerationfront:
     131            case TargetParam::accelerationfront:
    132132                this->parent_->getParent()->getEngineByName(targetName_)->setAccelerationFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getAccelerationFront()));
    133133                break;
     
    142142        {
    143143            switch (this->targetParam_) {
    144             case null:
     144            case TargetParam::null:
    145145                if (!this->parent_->getParent()->getShipPartByName(targetName_))
    146146                    return;
     
    214214            if (param == "NULL")
    215215            {
    216                 this->targetParam_ = null;
     216                this->targetParam_ = TargetParam::null;
    217217                return;
    218218            }
    219219            if (param == "boostfactor")
    220220            {
    221                 this->targetParam_ = boostfactor;
     221                this->targetParam_ = TargetParam::boostfactor;
    222222                return;
    223223            }
    224224            if (param == "speedfront")
    225225            {
    226                 this->targetParam_ = speedfront;
     226                this->targetParam_ = TargetParam::speedfront;
    227227                return;
    228228            }
    229229            if (param == "accelerationfront")
    230230            {
    231                 this->targetParam_ = accelerationfront;
     231                this->targetParam_ = TargetParam::accelerationfront;
    232232                return;
    233233            }
     
    244244            if (param == "shieldhealth")
    245245            {
    246                 this->targetParam_ = shieldhealth;
     246                this->targetParam_ = TargetParam::shieldhealth;
    247247                return;
    248248            }
    249249            if (param == "boostpower")
    250250            {
    251                 this->targetParam_ = boostpower;
     251                this->targetParam_ = TargetParam::boostpower;
    252252                return;
    253253            }
    254254            if (param == "boostpowerrate")
    255255            {
    256                 this->targetParam_ = boostpowerrate;
     256                this->targetParam_ = TargetParam::boostpowerrate;
    257257                return;
    258258            }
    259259            if (param == "rotationthrust")
    260260            {
    261                 this->targetParam_ = rotationthrust;
     261                this->targetParam_ = TargetParam::rotationthrust;
    262262                return;
    263263            }
     
    271271            if (param == "NULL")
    272272            {
    273                 this->targetParam_ = null;
     273                this->targetParam_ = TargetParam::null;
    274274                return;
    275275            }
  • code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.h

    r10817 r11005  
    8282                    List of all allowed parameters.
    8383                */
    84             enum TargetParam
     84            enum class TargetParam
    8585            {
    8686                shieldhealth,
  • code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.cc

    r10768 r11005  
    9494        this->angle_ = Degree(0.0);
    9595        this->bCorrectAspect_ = false;
    96         this->rotState_ = Horizontal;
     96        this->rotState_ = RotationState::Horizontal;
    9797        this->angleChanged(); // updates all other values as well
    9898
     
    259259            {
    260260                tempAspect = 1.0f / this->windowAspectRatio_;
    261                 rotState_ = Vertical;
     261                rotState_ = RotationState::Vertical;
    262262            }
    263263            else if (angle > 179 || angle < 1)
    264264            {
    265265                tempAspect = this->windowAspectRatio_;
    266                 rotState_ = Horizontal;
     266                rotState_ = RotationState::Horizontal;
    267267            }
    268268            else
    269269            {
    270270                tempAspect = 1.0f;
    271                 rotState_ = Inbetween;
     271                rotState_ = RotationState::Inbetween;
    272272            }
    273273
  • code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.h

    r10845 r11005  
    7979            and in between is everything else.
    8080        */
    81         enum RotationState
     81        enum class RotationState
    8282        {
    8383            Horizontal,
  • code/branches/cpp11_v2/src/orxonox/sound/BaseSound.cc

    r10765 r11005  
    4949        , volume_(0.7)
    5050        , bLooping_(false)
    51         , state_(Stopped)
     51        , state_(State::Stopped)
    5252        , pitch_ (1.0)
    5353    {
     
    6363    BaseSound::~BaseSound()
    6464    {
    65         if (this->state_ != Stopped)
     65        if (this->state_ != State::Stopped)
    6666            this->stop();
    6767        // Release buffer
     
    8383    void BaseSound::doPlay()
    8484    {
    85         this->state_ = Playing;
     85        this->state_ = State::Playing;
    8686        if (GameMode::playsSound() && this->getSourceState() != AL_PLAYING && this->soundBuffer_ != nullptr)
    8787        {
     
    102102    bool BaseSound::doStop()
    103103    {
    104         this->state_ = Stopped;
     104        this->state_ = State::Stopped;
    105105        if (alIsSource(this->audioSource_))
    106106        {
     
    123123        if (this->isStopped())
    124124            return;
    125         this->state_ = Paused;
     125        this->state_ = State::Paused;
    126126        if (alIsSource(this->audioSource_))
    127127            alSourcePause(this->audioSource_);
     
    256256        else // No source acquired so far, but might be set to playing or paused
    257257        {
    258             State state = static_cast<State>(this->state_); // save
     258            State state = this->state_; // save
    259259            if (this->isPlaying() || this->isPaused())
    260260                doPlay();
    261             if (state == Paused)
    262             {
    263                 this->state_ = Paused;
     261            if (state == State::Paused)
     262            {
     263                this->state_ = State::Paused;
    264264                doPause();
    265265            }
     
    271271        switch (this->state_)
    272272        {
    273             case Playing:
     273            case State::Playing:
    274274                this->play();
    275275                break;
    276             case Paused:
     276            case State::Paused:
    277277                this->pause();
    278278                break;
    279             case Stopped:
     279            case State::Stopped:
    280280            default:
    281281                this->stop();
  • code/branches/cpp11_v2/src/orxonox/sound/BaseSound.h

    r10771 r11005  
    5454        virtual void pause() { this->doPause(); }
    5555
    56         bool isPlaying() const { return this->state_ == Playing; }
    57         bool isPaused()  const { return this->state_ == Paused; }
    58         bool isStopped() const { return this->state_ == Stopped; }
     56        bool isPlaying() const { return this->state_ == State::Playing; }
     57        bool isPaused()  const { return this->state_ == State::Paused; }
     58        bool isStopped() const { return this->state_ == State::Stopped; }
    5959
    6060        virtual void setSource(const std::string& source);
     
    7676
    7777    protected:
    78         enum State
     78        enum class State
    7979        {
    8080            Stopped,
     
    111111        float           volume_;
    112112        bool            bLooping_;
    113         uint8_t         state_;       // This Variable is actually of type State
     113        State           state_;       // This Variable is actually of type State
    114114        float           pitch_;
    115115
  • code/branches/cpp11_v2/src/orxonox/sound/WorldSound.cc

    r9939 r11005  
    5858        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
    5959        registerVariable(pitch_,    ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
    60         registerVariable((uint8_t&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
     60        registerVariable(BaseSound::state_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
    6161    }
    6262
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.h

    r9667 r11005  
    3636namespace orxonox
    3737{
    38     namespace BaseState
     38    enum class BaseState
    3939    {
    40         enum Value
    41         {
    42             Uncontrolled,
    43             ControlTeam1,
    44             ControlTeam2,
    45         };
    46     }
     40        Uncontrolled,
     41        ControlTeam1,
     42        ControlTeam2,
     43    };
    4744
    4845
     
    5855
    5956            // Set the state of a base to whatever the argument of the function is
    60             void setState(BaseState::Value state)
     57            void setState(BaseState state)
    6158            {
    6259                this->state_ = state;
     
    6663
    6764            // Get the state of a base as a return value
    68             BaseState::Value getState() const
     65            BaseState getState() const
    6966            {
    7067                return this->state_;
     
    7572            void changeTeamColour();
    7673
    77             BaseState::Value state_;
     74            BaseState state_;
    7875    };
    7976}
Note: See TracChangeset for help on using the changeset viewer.