From 0c9882956afe8ad20b9673af0adf2e1627fd571b Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 22 Aug 2016 22:58:24 +0200 Subject: [PATCH] Add AnimState::shouldLoop() --- apps/openmw/mwrender/animation.cpp | 32 ++++++++++++------------------ apps/openmw/mwrender/animation.hpp | 5 +++++ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index a0b68fd6c..29407bc2d 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1023,7 +1023,7 @@ namespace MWRender { float targetTime; - if (state.getTime() < state.mLoopStopTime || state.mLoopCount == 0) + if (!state.shouldLoop()) { targetTime = state.getTime() + timepassed; if(textkey == textkeys.end() || textkey->first > targetTime) @@ -1048,27 +1048,21 @@ namespace MWRender ++textkey; } } - - if(state.getTime() >= state.mLoopStopTime) + if(state.shouldLoop()) { - if (!state.mLoopingEnabled) - state.mLoopCount = 0; - else if (state.mLoopCount > 0) - { - state.mLoopCount--; - state.setTime(state.mLoopStartTime); - state.mPlaying = true; - - textkey = textkeys.lower_bound(state.getTime()); - while(textkey != textkeys.end() && textkey->first <= state.getTime()) - { - handleTextKey(state, stateiter->first, textkey, textkeys); - ++textkey; - } + state.mLoopCount--; + state.setTime(state.mLoopStartTime); + state.mPlaying = true; - if(state.getTime() >= state.mLoopStopTime) - break; + textkey = textkeys.lower_bound(state.getTime()); + while(textkey != textkeys.end() && textkey->first <= state.getTime()) + { + handleTextKey(state, stateiter->first, textkey, textkeys); + ++textkey; } + + if(state.getTime() >= state.mLoopStopTime) + break; } if(timepassed <= 0.0f) diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 4eeb5d943..749890ae5 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -205,6 +205,11 @@ protected: { *mTime = time; } + + bool shouldLoop() const + { + return getTime() >= mLoopStopTime && mLoopingEnabled && mLoopCount > 0; + } }; typedef std::map AnimStateMap; AnimStateMap mStates;