[Orxonox-commit 6348] r11005 - in code/branches/cpp11_v2/src: modules/overlays orxonox/gametypes orxonox/items orxonox/overlays orxonox/sound orxonox/worldentities/pawns

landauf at orxonox.net landauf at orxonox.net
Wed Dec 30 22:31:44 CET 2015


Author: landauf
Date: 2015-12-30 22:31:43 +0100 (Wed, 30 Dec 2015)
New Revision: 11005

Modified:
   code/branches/cpp11_v2/src/modules/overlays/OverlayText.cc
   code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.h
   code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.cc
   code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.h
   code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.cc
   code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.h
   code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.cc
   code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.h
   code/branches/cpp11_v2/src/orxonox/sound/BaseSound.cc
   code/branches/cpp11_v2/src/orxonox/sound/BaseSound.h
   code/branches/cpp11_v2/src/orxonox/sound/WorldSound.cc
   code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.h
Log:
using strongly typed enum in various classes in orxonox-library

Modified: code/branches/cpp11_v2/src/modules/overlays/OverlayText.cc
===================================================================
--- code/branches/cpp11_v2/src/modules/overlays/OverlayText.cc	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/modules/overlays/OverlayText.cc	2015-12-30 21:31:43 UTC (rev 11005)
@@ -110,9 +110,9 @@
 
     void OverlayText::sizeChanged()
     {
-        if (this->rotState_ == Horizontal)
+        if (this->rotState_ == RotationState::Horizontal)
             this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
-        else if (this->rotState_ == Vertical)
+        else if (this->rotState_ == RotationState::Vertical)
             this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
         else
             this->overlay_->setScale(size_.y, size_.y);

Modified: code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.h	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.h	2015-12-30 21:31:43 UTC (rev 11005)
@@ -44,21 +44,18 @@
 
 namespace orxonox
 {
-    namespace PlayerState
+    enum class PlayerState
     {
-        enum Value
-        {
-            Uninitialized,
-            Joined,
-            Alive,
-            Dead
-        };
-    }
+        Uninitialized,
+        Joined,
+        Alive,
+        Dead
+    };
 
     struct Player
     {
         PlayerInfo* info_;
-        PlayerState::Value state_;
+        PlayerState state_;
         int frags_;
         int killed_;
     };

Modified: code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.cc	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.cc	2015-12-30 21:31:43 UTC (rev 11005)
@@ -123,16 +123,16 @@
 
                 this->state_ = 0;
                 if (this->getShip()->isBoosting() && forward)
-                    this->state_ = Boost;
+                    this->state_ = EngineState::Boost;
                 else if (forward && !this->state_) // this->state_ == Boost
-                    this->state_ = Normal;
+                    this->state_ = EngineState::Normal;
                 else if (direction.z > 0.0 && velocity.z < 0.0)
-                    this->state_ = Brake;
+                    this->state_ = EngineState::Brake;
                 else
-                    this->state_ = Idle;
+                    this->state_ = EngineState::Idle;
 
-                if (this->state_ == Idle && this->getSpeedAdd() > 0)
-                    this->state_ = Normal;
+                if (this->state_ == EngineState::Idle && this->getSpeedAdd() > 0)
+                    this->state_ = EngineState::Normal;
             }
 
             if (GameMode::isMaster())
@@ -140,35 +140,35 @@
                 int changes = this->state_ | this->oldState_;
 
                 float pitch = velocity.length();
-                if (this->state_ & Normal)
+                if (this->state_ & EngineState::Normal)
                     defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f));
-                if (this->state_ & Boost)
+                if (this->state_ & EngineState::Boost)
                     defEngineSndBoost_->setPitch(clamp(pitch/MAX_VELOCITY_BOOST + 1, 0.5f, 2.0f));
 
-                if (changes & Idle)
+                if (changes & EngineState::Idle)
                 {
-                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Idle);
+                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Idle);
                     lua_setglobal(this->lua_->getInternalLuaState(), "idle");
                 }
-                if (changes & Normal)
+                if (changes & EngineState::Normal)
                 {
-                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Normal);
+                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Normal);
                     lua_setglobal(this->lua_->getInternalLuaState(), "normal");
-                    if (this->state_ & Normal)
+                    if (this->state_ & EngineState::Normal)
                         defEngineSndNormal_->play();
                     else
                         defEngineSndNormal_->stop();
                 }
-                if (changes & Brake)
+                if (changes & EngineState::Brake)
                 {
-                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Brake);
+                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Brake);
                     lua_setglobal(this->lua_->getInternalLuaState(), "brake");
                 }
-                if (changes & Boost)
+                if (changes & EngineState::Boost)
                 {
-                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Boost);
+                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & EngineState::Boost);
                     lua_setglobal(this->lua_->getInternalLuaState(), "boost");
-                    if (this->state_ & Boost)
+                    if (this->state_ & EngineState::Boost)
                         defEngineSndBoost_->play();
                     else
                         defEngineSndBoost_->stop();

Modified: code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.h	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/items/MultiStateEngine.h	2015-12-30 21:31:43 UTC (rev 11005)
@@ -40,12 +40,12 @@
     class _OrxonoxExport MultiStateEngine : public Engine
     {
         public:
-            enum EngineState
+            struct EngineState
             {
-                Idle    = 1,
-                Normal  = 2,
-                Brake   = 4,
-                Boost   = 8
+                static constexpr int Idle    = 1;
+                static constexpr int Normal  = 2;
+                static constexpr int Brake   = 4;
+                static constexpr int Boost   = 8;
             };
 
             MultiStateEngine(Context* context);

Modified: code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.cc	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.cc	2015-12-30 21:31:43 UTC (rev 11005)
@@ -97,16 +97,16 @@
         if (this->targetType_ == "ship")
         {
             switch (this->targetParam_) {
-            case shieldhealth:
+            case TargetParam::shieldhealth:
                 this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth()));
                 break;
-            case boostpower:
+            case TargetParam::boostpower:
                 this->parent_->getParent()->setInitialBoostPower(operate(this->parent_->getParent()->getInitialBoostPower()));
                 break;
-            case boostpowerrate:
+            case TargetParam::boostpowerrate:
                 this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate()));
                 break;
-            case rotationthrust:
+            case TargetParam::rotationthrust:
                 this->parent_->getParent()->setRotationThrust(operate(this->parent_->getParent()->getRotationThrust()));
                 break;
             default:
@@ -119,16 +119,16 @@
         if (this->targetType_ == "engine")
         {
             switch (this->targetParam_) {
-            case null:
+            case TargetParam::null:
                 this->parent_->getParent()->getEngineByName(targetName_)->destroy();
                 break;
-            case boostfactor:
+            case TargetParam::boostfactor:
                 this->parent_->getParent()->getEngineByName(targetName_)->setBoostFactor(operate(this->parent_->getParent()->getEngineByName(targetName_)->getBoostFactor()));
                 break;
-            case speedfront:
+            case TargetParam::speedfront:
                 this->parent_->getParent()->getEngineByName(targetName_)->setMaxSpeedFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getMaxSpeedFront()));
                 break;
-            case accelerationfront:
+            case TargetParam::accelerationfront:
                 this->parent_->getParent()->getEngineByName(targetName_)->setAccelerationFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getAccelerationFront()));
                 break;
             default:
@@ -141,7 +141,7 @@
         if (this->targetType_ == "part")
         {
             switch (this->targetParam_) {
-            case null:
+            case TargetParam::null:
                 if (!this->parent_->getParent()->getShipPartByName(targetName_))
                     return;
                 this->parent_->getParent()->getShipPartByName(targetName_)->setEventExecution(false);
@@ -213,22 +213,22 @@
         {
             if (param == "NULL")
             {
-                this->targetParam_ = null;
+                this->targetParam_ = TargetParam::null;
                 return;
             }
             if (param == "boostfactor")
             {
-                this->targetParam_ = boostfactor;
+                this->targetParam_ = TargetParam::boostfactor;
                 return;
             }
             if (param == "speedfront")
             {
-                this->targetParam_ = speedfront;
+                this->targetParam_ = TargetParam::speedfront;
                 return;
             }
             if (param == "accelerationfront")
             {
-                this->targetParam_ = accelerationfront;
+                this->targetParam_ = TargetParam::accelerationfront;
                 return;
             }
 
@@ -243,22 +243,22 @@
         {
             if (param == "shieldhealth")
             {
-                this->targetParam_ = shieldhealth;
+                this->targetParam_ = TargetParam::shieldhealth;
                 return;
             }
             if (param == "boostpower")
             {
-                this->targetParam_ = boostpower;
+                this->targetParam_ = TargetParam::boostpower;
                 return;
             }
             if (param == "boostpowerrate")
             {
-                this->targetParam_ = boostpowerrate;
+                this->targetParam_ = TargetParam::boostpowerrate;
                 return;
             }
             if (param == "rotationthrust")
             {
-                this->targetParam_ = rotationthrust;
+                this->targetParam_ = TargetParam::rotationthrust;
                 return;
             }
 
@@ -270,7 +270,7 @@
         {
             if (param == "NULL")
             {
-                this->targetParam_ = null;
+                this->targetParam_ = TargetParam::null;
                 return;
             }
 

Modified: code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.h	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/items/PartDestructionEvent.h	2015-12-30 21:31:43 UTC (rev 11005)
@@ -81,7 +81,7 @@
                 @brief
                     List of all allowed parameters.
                 */
-            enum TargetParam
+            enum class TargetParam
             {
                 shieldhealth,
                 maxshieldhealth,

Modified: code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.cc	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.cc	2015-12-30 21:31:43 UTC (rev 11005)
@@ -93,7 +93,7 @@
         this->position_ = Vector2(0.0f, 0.0f);
         this->angle_ = Degree(0.0);
         this->bCorrectAspect_ = false;
-        this->rotState_ = Horizontal;
+        this->rotState_ = RotationState::Horizontal;
         this->angleChanged(); // updates all other values as well
 
         setBackgroundMaterial("");
@@ -258,17 +258,17 @@
             if (angle > 89.0f && angle < 91.0f)
             {
                 tempAspect = 1.0f / this->windowAspectRatio_;
-                rotState_ = Vertical;
+                rotState_ = RotationState::Vertical;
             }
             else if (angle > 179 || angle < 1)
             {
                 tempAspect = this->windowAspectRatio_;
-                rotState_ = Horizontal;
+                rotState_ = RotationState::Horizontal;
             }
             else
             {
                 tempAspect = 1.0f;
-                rotState_ = Inbetween;
+                rotState_ = RotationState::Inbetween;
             }
 
             // note: this is only an approximation that is mostly valid when the

Modified: code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.h	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/overlays/OrxonoxOverlay.h	2015-12-30 21:31:43 UTC (rev 11005)
@@ -78,7 +78,7 @@
             Horizontal means 0/180 degrees, Vertical is 90/270 degrees
             and in between is everything else.
         */
-        enum RotationState
+        enum class RotationState
         {
             Horizontal,
             Vertical,

Modified: code/branches/cpp11_v2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/sound/BaseSound.cc	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/sound/BaseSound.cc	2015-12-30 21:31:43 UTC (rev 11005)
@@ -48,7 +48,7 @@
         : bPooling_(false)
         , volume_(0.7)
         , bLooping_(false)
-        , state_(Stopped)
+        , state_(State::Stopped)
         , pitch_ (1.0)
     {
         RegisterObject(BaseSound);
@@ -62,7 +62,7 @@
 
     BaseSound::~BaseSound()
     {
-        if (this->state_ != Stopped)
+        if (this->state_ != State::Stopped)
             this->stop();
         // Release buffer
         if (this->soundBuffer_ != nullptr)
@@ -82,7 +82,7 @@
 
     void BaseSound::doPlay()
     {
-        this->state_ = Playing;
+        this->state_ = State::Playing;
         if (GameMode::playsSound() && this->getSourceState() != AL_PLAYING && this->soundBuffer_ != nullptr)
         {
             if (!alIsSource(this->audioSource_))
@@ -101,7 +101,7 @@
 
     bool BaseSound::doStop()
     {
-        this->state_ = Stopped;
+        this->state_ = State::Stopped;
         if (alIsSource(this->audioSource_))
         {
             alSourceStop(this->audioSource_);
@@ -122,7 +122,7 @@
     {
         if (this->isStopped())
             return;
-        this->state_ = Paused;
+        this->state_ = State::Paused;
         if (alIsSource(this->audioSource_))
             alSourcePause(this->audioSource_);
     }
@@ -255,12 +255,12 @@
         }
         else // No source acquired so far, but might be set to playing or paused
         {
-            State state = static_cast<State>(this->state_); // save
+            State state = this->state_; // save
             if (this->isPlaying() || this->isPaused())
                 doPlay();
-            if (state == Paused)
+            if (state == State::Paused)
             {
-                this->state_ = Paused;
+                this->state_ = State::Paused;
                 doPause();
             }
         }
@@ -270,13 +270,13 @@
     {
         switch (this->state_)
         {
-            case Playing:
+            case State::Playing:
                 this->play();
                 break;
-            case Paused:
+            case State::Paused:
                 this->pause();
                 break;
-            case Stopped:
+            case State::Stopped:
             default:
                 this->stop();
                 break;

Modified: code/branches/cpp11_v2/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/sound/BaseSound.h	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/sound/BaseSound.h	2015-12-30 21:31:43 UTC (rev 11005)
@@ -53,9 +53,9 @@
         virtual bool stop()  { return this->doStop(); } // returns true if the sound source was destroyed
         virtual void pause() { this->doPause(); }
 
-        bool isPlaying() const { return this->state_ == Playing; }
-        bool isPaused()  const { return this->state_ == Paused; }
-        bool isStopped() const { return this->state_ == Stopped; }
+        bool isPlaying() const { return this->state_ == State::Playing; }
+        bool isPaused()  const { return this->state_ == State::Paused; }
+        bool isStopped() const { return this->state_ == State::Stopped; }
 
         virtual void setSource(const std::string& source);
         virtual const std::string& getSource() const
@@ -75,7 +75,7 @@
         void setPitch(float pitch);
 
     protected:
-        enum State
+        enum class State
         {
             Stopped,
             Playing,
@@ -110,7 +110,7 @@
         std::string     source_;
         float           volume_;
         bool            bLooping_;
-        uint8_t         state_;       // This Variable is actually of type State
+        State           state_;       // This Variable is actually of type State
         float           pitch_;
 
     private:

Modified: code/branches/cpp11_v2/src/orxonox/sound/WorldSound.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/sound/WorldSound.cc	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/sound/WorldSound.cc	2015-12-30 21:31:43 UTC (rev 11005)
@@ -57,7 +57,7 @@
         registerVariable(source_,   ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged));
         registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
         registerVariable(pitch_,    ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
-        registerVariable((uint8_t&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
+        registerVariable(BaseSound::state_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
     }
 
     void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)

Modified: code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.h	2015-12-30 21:07:09 UTC (rev 11004)
+++ code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.h	2015-12-30 21:31:43 UTC (rev 11005)
@@ -35,15 +35,12 @@
 
 namespace orxonox
 {
-    namespace BaseState
+    enum class BaseState
     {
-        enum Value
-        {
-            Uncontrolled,
-            ControlTeam1,
-            ControlTeam2,
-        };
-    }
+        Uncontrolled,
+        ControlTeam1,
+        ControlTeam2,
+    };
 
 
     class _OrxonoxExport TeamBaseMatchBase : public Pawn
@@ -57,7 +54,7 @@
 
 
             // Set the state of a base to whatever the argument of the function is
-            void setState(BaseState::Value state)
+            void setState(BaseState state)
             {
                 this->state_ = state;
                 this->changeTeamColour();
@@ -65,7 +62,7 @@
 
 
             // Get the state of a base as a return value
-            BaseState::Value getState() const
+            BaseState getState() const
             {
                 return this->state_;
             }
@@ -74,7 +71,7 @@
         protected:
             void changeTeamColour();
 
-            BaseState::Value state_;
+            BaseState state_;
     };
 }
 




More information about the Orxonox-commit mailing list