1 #include "animation/linear_animation_instance.hpp"
2 #include "animation/loop.hpp"
7 LinearAnimationInstance::LinearAnimationInstance(LinearAnimation* animation) :
8 m_Animation(animation),
9 m_Time(animation->enableWorkArea() ? (float) animation->workStart() / animation->fps() : 0),
14 bool LinearAnimationInstance::advance(float elapsedSeconds)
16 LinearAnimation& animation = *m_Animation;
17 m_Time += elapsedSeconds * animation.speed() * m_Direction;
19 int fps = animation.fps();
21 float frames = m_Time * fps;
23 int start = animation.enableWorkArea() ? animation.workStart() : 0;
25 animation.enableWorkArea() ? animation.workEnd() : animation.duration();
26 int range = end - start;
28 bool keepGoing = true;
31 switch (animation.loop())
38 m_Time = frames / fps;
45 frames = m_Time * fps;
46 frames = start + std::fmod(frames - start, range);
47 m_Time = frames / fps;
54 if (m_Direction == 1 && frames >= end)
57 frames = end + (end - frames);
58 m_Time = frames / fps;
61 else if (m_Direction == -1 && frames < start)
64 frames = start + (start - frames);
65 m_Time = frames / fps;
70 // we're within the range, we can stop fixing. We do this in
71 // a loop to fix conditions when time has advanced so far
72 // that we've ping-ponged back and forth a few times in a
73 // single frame. We want to accomodate for this in cases
74 // where animations are not advanced on regular intervals.
85 void LinearAnimationInstance::time(float value)