Browse Source

SceneGraph: prefix private Animable members with an underscore.

And minor other coding style updates. This code is old, wow!
pull/231/head
Vladimír Vondruš 8 years ago
parent
commit
72a3d67902
  1. 9
      src/Magnum/SceneGraph/Animable.h
  2. 56
      src/Magnum/SceneGraph/Animable.hpp

9
src/Magnum/SceneGraph/Animable.h

@ -169,7 +169,7 @@ template<UnsignedInt dimensions, class T> class Animable: public AbstractGrouped
Float duration() const { return _duration; } Float duration() const { return _duration; }
/** @brief Animation state */ /** @brief Animation state */
AnimationState state() const { return currentState; } AnimationState state() const { return _currentState; }
/** /**
* @brief Set animation state * @brief Set animation state
@ -318,12 +318,11 @@ template<UnsignedInt dimensions, class T> class Animable: public AbstractGrouped
private: private:
Float _duration; Float _duration;
Float startTime, pauseTime; Float _startTime, _pauseTime;
AnimationState previousState; AnimationState _previousState, _currentState;
AnimationState currentState;
bool _repeated; bool _repeated;
UnsignedShort _repeatCount; UnsignedShort _repeatCount;
UnsignedShort repeats; UnsignedShort _repeats;
}; };
/** /**

56
src/Magnum/SceneGraph/Animable.hpp

@ -36,20 +36,20 @@
namespace Magnum { namespace SceneGraph { namespace Magnum { namespace SceneGraph {
template<UnsignedInt dimensions, class T> Animable<dimensions, T>::Animable(AbstractObject<dimensions, T>& object, AnimableGroup<dimensions, T>* group): AbstractGroupedFeature<dimensions, Animable<dimensions, T>, T>(object, group), _duration(0.0f), startTime(Constants::inf()), pauseTime(-Constants::inf()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} template<UnsignedInt dimensions, class T> Animable<dimensions, T>::Animable(AbstractObject<dimensions, T>& object, AnimableGroup<dimensions, T>* group): AbstractGroupedFeature<dimensions, Animable<dimensions, T>, T>{object, group}, _duration{0.0f}, _startTime{Constants::inf()}, _pauseTime{-Constants::inf()}, _previousState{AnimationState::Stopped}, _currentState{AnimationState::Stopped}, _repeated{false}, _repeatCount{0}, _repeats{0} {}
template<UnsignedInt dimensions, class T> Animable<dimensions, T>::~Animable() {} template<UnsignedInt dimensions, class T> Animable<dimensions, T>::~Animable() {}
template<UnsignedInt dimensions, class T> Animable<dimensions, T>& Animable<dimensions, T>::setState(AnimationState state) { template<UnsignedInt dimensions, class T> Animable<dimensions, T>& Animable<dimensions, T>::setState(AnimationState state) {
if(currentState == state) return *this; if(_currentState == state) return *this;
/* Not allowed (for sanity) */ /* Not allowed (for sanity) */
if(previousState == AnimationState::Stopped && state == AnimationState::Paused) if(_previousState == AnimationState::Stopped && state == AnimationState::Paused)
return *this; return *this;
/* Wake up the group in case no animations are running */ /* Wake up the group in case no animations are running */
animables()->wakeUp = true; animables()->wakeUp = true;
currentState = state; _currentState = state;
return *this; return *this;
} }
@ -70,67 +70,67 @@ template<UnsignedInt dimensions, class T> void AnimableGroup<dimensions, T>::ste
/* The animation was stopped recently, just decrease count of running /* The animation was stopped recently, just decrease count of running
animations if the animation was running before */ animations if the animation was running before */
if(animable.previousState != AnimationState::Stopped && animable.currentState == AnimationState::Stopped) { if(animable._previousState != AnimationState::Stopped && animable._currentState == AnimationState::Stopped) {
if(animable.previousState == AnimationState::Running) if(animable._previousState == AnimationState::Running)
--_runningCount; --_runningCount;
animable.previousState = AnimationState::Stopped; animable._previousState = AnimationState::Stopped;
animable.animationStopped(); animable.animationStopped();
continue; continue;
/* The animation was paused recently, set pause time to previous frame time */ /* The animation was paused recently, set pause time to previous frame time */
} else if(animable.previousState == AnimationState::Running && animable.currentState == AnimationState::Paused) { } else if(animable._previousState == AnimationState::Running && animable._currentState == AnimationState::Paused) {
animable.previousState = AnimationState::Paused; animable._previousState = AnimationState::Paused;
animable.pauseTime = time; animable._pauseTime = time;
--_runningCount; --_runningCount;
animable.animationPaused(); animable.animationPaused();
continue; continue;
/* Skip the rest for not running animations */ /* Skip the rest for not running animations */
} else if(animable.currentState != AnimationState::Running) { } else if(animable._currentState != AnimationState::Running) {
CORRADE_INTERNAL_ASSERT(animable.previousState == animable.currentState); CORRADE_INTERNAL_ASSERT(animable._previousState == animable._currentState);
continue; continue;
/* The animation was started recently, set start time to previous frame /* The animation was started recently, set start time to previous frame
time, reset repeat count */ time, reset repeat count */
} else if(animable.previousState == AnimationState::Stopped) { } else if(animable._previousState == AnimationState::Stopped) {
animable.previousState = AnimationState::Running; animable._previousState = AnimationState::Running;
animable.startTime = time; animable._startTime = time;
animable.repeats = 0; animable._repeats = 0;
++_runningCount; ++_runningCount;
animable.animationStarted(); animable.animationStarted();
/* The animation was resumed recently, add pause duration to start time */ /* The animation was resumed recently, add pause duration to start time */
} else if(animable.previousState == AnimationState::Paused) { } else if(animable._previousState == AnimationState::Paused) {
animable.previousState = AnimationState::Running; animable._previousState = AnimationState::Running;
animable.startTime += time - animable.pauseTime; animable._startTime += time - animable._pauseTime;
++_runningCount; ++_runningCount;
animable.animationResumed(); animable.animationResumed();
} }
CORRADE_INTERNAL_ASSERT(animable.previousState == AnimationState::Running); CORRADE_INTERNAL_ASSERT(animable._previousState == AnimationState::Running);
/* Animation time exceeded duration */ /* Animation time exceeded duration */
if(animable._duration != 0.0f && time-animable.startTime > animable._duration) { if(animable._duration != 0.0f && time-animable._startTime > animable._duration) {
/* Not repeated or repeat count exceeded, stop */ /* Not repeated or repeat count exceeded, stop */
if(!animable._repeated || animable.repeats+1 == animable._repeatCount) { if(!animable._repeated || animable._repeats + 1 == animable._repeatCount) {
animable.previousState = AnimationState::Stopped; animable._previousState = AnimationState::Stopped;
animable.currentState = AnimationState::Stopped; animable._currentState = AnimationState::Stopped;
--_runningCount; --_runningCount;
animable.animationStopped(); animable.animationStopped();
continue; continue;
} }
/* Increase repeat count and add duration to startTime */ /* Increase repeat count and add duration to startTime */
++animable.repeats; ++animable._repeats;
animable.startTime += animable._duration; animable._startTime += animable._duration;
} }
/* Animation is still running, perform animation step */ /* Animation is still running, perform animation step */
CORRADE_ASSERT(time-animable.startTime >= 0.0f, CORRADE_ASSERT(time - animable._startTime >= 0.0f,
"SceneGraph::AnimableGroup::step(): animation was started in future - probably wrong time passed", ); "SceneGraph::AnimableGroup::step(): animation was started in future - probably wrong time passed", );
CORRADE_ASSERT(delta >= 0.0f, CORRADE_ASSERT(delta >= 0.0f,
"SceneGraph::AnimableGroup::step(): negative delta passed", ); "SceneGraph::AnimableGroup::step(): negative delta passed", );
animable.animationStep(time - animable.startTime, delta); animable.animationStep(time - animable._startTime, delta);
} }
CORRADE_INTERNAL_ASSERT((_runningCount <= AnimableGroup<dimensions, T>::size())); CORRADE_INTERNAL_ASSERT((_runningCount <= AnimableGroup<dimensions, T>::size()));

Loading…
Cancel
Save