From d0643d266a30b7f6d9900878be18adee4162d95d Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 19 Nov 2019 15:34:21 +0400 Subject: [PATCH] Do not use fallthrough in switches --- apps/openmw/mwmechanics/character.cpp | 35 ++++++++------- apps/openmw/mwmechanics/obstacle.cpp | 65 +++++++++++---------------- 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index e6223ac54a..96f2a19ac1 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1773,23 +1773,25 @@ bool CharacterController::updateWeaponState(CharacterState& idle) 0, mAttackType+" min attack", mAttackType+" max attack", 0.999f, 0); break; case UpperCharState_StartToMinAttack: - { - // If actor is already stopped preparing attack, do not play the "min attack -> max attack" part. - // Happens if the player did not hold the attack button. - // Note: if the "min attack"->"max attack" is a stub, "play" it anyway. Attack strength will be random. - float minAttackTime = mAnimation->getTextKeyTime(mCurrentWeapon+": "+mAttackType+" "+"min attack"); - float maxAttackTime = mAnimation->getTextKeyTime(mCurrentWeapon+": "+mAttackType+" "+"max attack"); - if (mAttackingOrSpell || minAttackTime == maxAttackTime) - { - start = mAttackType+" min attack"; - stop = mAttackType+" max attack"; - mUpperBodyState = UpperCharState_MinAttackToMaxAttack; - break; - } - playSwishSound(0.0f); - } - // Fall-through case UpperCharState_MaxAttackToMinHit: + { + if (mUpperBodyState == UpperCharState_StartToMinAttack) + { + // If actor is already stopped preparing attack, do not play the "min attack -> max attack" part. + // Happens if the player did not hold the attack button. + // Note: if the "min attack"->"max attack" is a stub, "play" it anyway. Attack strength will be random. + float minAttackTime = mAnimation->getTextKeyTime(mCurrentWeapon+": "+mAttackType+" "+"min attack"); + float maxAttackTime = mAnimation->getTextKeyTime(mCurrentWeapon+": "+mAttackType+" "+"max attack"); + if (mAttackingOrSpell || minAttackTime == maxAttackTime) + { + start = mAttackType+" min attack"; + stop = mAttackType+" max attack"; + mUpperBodyState = UpperCharState_MinAttackToMaxAttack; + break; + } + playSwishSound(0.0f); + } + if(mAttackType == "shoot") { start = mAttackType+" min hit"; @@ -1802,6 +1804,7 @@ bool CharacterController::updateWeaponState(CharacterState& idle) } mUpperBodyState = UpperCharState_MinHitToHit; break; + } case UpperCharState_MinHitToHit: if(mAttackType == "shoot") { diff --git a/apps/openmw/mwmechanics/obstacle.cpp b/apps/openmw/mwmechanics/obstacle.cpp index c3da92e31b..2c131ccaef 100644 --- a/apps/openmw/mwmechanics/obstacle.cpp +++ b/apps/openmw/mwmechanics/obstacle.cpp @@ -127,54 +127,39 @@ namespace MWMechanics mDistSameSpot = DIST_SAME_SPOT * actor.getClass().getSpeed(actor); const float distSameSpot = mDistSameSpot * duration; - const bool samePosition = (pos - mPrev).length2() < distSameSpot * distSameSpot; + const bool samePosition = (pos - mPrev).length2() < distSameSpot * distSameSpot; mPrev = pos; - switch(mWalkState) + if (mWalkState != State_Evade) { - case State_Norm: + if(!samePosition) { - if(!samePosition) - break; - else - mWalkState = State_CheckStuck; + mWalkState = State_Norm; + mStuckDuration = 0; + mEvadeDuration = 0; + return; } - /* FALL THROUGH */ - case State_CheckStuck: + + mWalkState = State_CheckStuck; + mStuckDuration += duration; + // consider stuck only if position unchanges for a period + if(mStuckDuration < DURATION_SAME_SPOT) + return; // still checking, note duration added to timer + else { - if(!samePosition) - { - mWalkState = State_Norm; - mStuckDuration = 0; - break; - } - else - { - mStuckDuration += duration; - // consider stuck only if position unchanges for a period - if(mStuckDuration < DURATION_SAME_SPOT) - break; // still checking, note duration added to timer - else - { - mStuckDuration = 0; - mWalkState = State_Evade; - chooseEvasionDirection(); - } - } + mStuckDuration = 0; + mWalkState = State_Evade; + chooseEvasionDirection(); } - /* FALL THROUGH */ - case State_Evade: - { - mEvadeDuration += duration; - if(mEvadeDuration >= DURATION_TO_EVADE) - { - // tried to evade, assume all is ok and start again - mWalkState = State_Norm; - mEvadeDuration = 0; - } - } - /* NO DEFAULT CASE */ + } + + mEvadeDuration += duration; + if(mEvadeDuration >= DURATION_TO_EVADE) + { + // tried to evade, assume all is ok and start again + mWalkState = State_Norm; + mEvadeDuration = 0; } }