1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 12:53:52 +00:00

Update mTime when updating or reseting the animation, and refactor the animation loop

This commit is contained in:
Chris Robinson 2013-01-16 20:14:49 -08:00
parent 685f219560
commit 4dd01b81c6

View file

@ -124,6 +124,8 @@ void Animation::setController(MWMechanics::CharacterController *controller)
void Animation::updatePosition(float time) void Animation::updatePosition(float time)
{ {
mCurGroup.mAnimState->setTimePosition(time); mCurGroup.mAnimState->setTimePosition(time);
mTime = time;
if(mNonAccumRoot) if(mNonAccumRoot)
{ {
/* Update the animation and get the non-accumulation root's difference from the /* Update the animation and get the non-accumulation root's difference from the
@ -150,9 +152,10 @@ void Animation::updatePosition(float time)
void Animation::resetPosition(float time) void Animation::resetPosition(float time)
{ {
mCurGroup.mAnimState->setTimePosition(time); mCurGroup.mAnimState->setTimePosition(time);
mTime = time;
mCurGroup.mNext = mCurGroup.mStart; mCurGroup.mNext = mCurGroup.mStart;
while(mCurGroup.mNext->first < time) while(mCurGroup.mNext != mCurGroup.mTextKeys->end() && mCurGroup.mNext->first < time)
mCurGroup.mNext++; mCurGroup.mNext++;
if(mNonAccumRoot) if(mNonAccumRoot)
@ -233,7 +236,7 @@ void Animation::playGroup(std::string groupname, int mode, int loops)
} }
times.mNext = ((mode==2) ? times.mLoopStart : times.mStart); times.mNext = ((mode==2) ? times.mLoopStart : times.mStart);
if(mode == 0 && mCurGroup.mLoops > 0) if(mode == 0 && mCurGroup.mAnimState)
mNextGroup = times; mNextGroup = times;
else else
{ {
@ -241,9 +244,8 @@ void Animation::playGroup(std::string groupname, int mode, int loops)
mCurGroup.mAnimState->setEnabled(false); mCurGroup.mAnimState->setEnabled(false);
mCurGroup = times; mCurGroup = times;
mNextGroup = GroupTimes(); mNextGroup = GroupTimes();
mTime = mCurGroup.mNext->first;
mCurGroup.mAnimState->setEnabled(true); mCurGroup.mAnimState->setEnabled(true);
resetPosition(mTime); resetPosition(mCurGroup.mNext->first);
} }
} }
@ -254,62 +256,46 @@ void Animation::skipAnim()
void Animation::runAnimation(float timepassed) void Animation::runAnimation(float timepassed)
{ {
if(mCurGroup.mAnimState && !mSkipFrame) if(mSkipFrame)
timepassed = 0.0f;
mSkipFrame = false;
while(mCurGroup.mAnimState && timepassed > 0.0f)
{ {
mTime += timepassed; float targetTime = mTime + timepassed;
recheck: if(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
if(mTime >= mCurGroup.mLoopStop->first) mCurGroup.mNext->first <= targetTime)
{
while(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
mCurGroup.mNext->first <= mCurGroup.mLoopStop->first)
{ {
updatePosition(mCurGroup.mNext->first);
timepassed = targetTime - mTime;
if(mController) if(mController)
mController->markerEvent(mCurGroup.mNext->second); mController->markerEvent(mCurGroup.mNext->second);
mCurGroup.mNext++; if(mCurGroup.mNext == mCurGroup.mLoopStop && mCurGroup.mLoops > 1)
}
if(mCurGroup.mLoops > 1)
{ {
mCurGroup.mLoops--; mCurGroup.mLoops--;
updatePosition(mCurGroup.mLoopStop->first);
mTime = mTime - mCurGroup.mLoopStop->first + mCurGroup.mLoopStart->first;
resetPosition(mCurGroup.mLoopStart->first); resetPosition(mCurGroup.mLoopStart->first);
goto recheck; continue;
} }
else if(mTime >= mCurGroup.mStop->first) else if(mCurGroup.mNext == mCurGroup.mStop)
{ {
while(mCurGroup.mNext != mCurGroup.mTextKeys->end() && if(!mNextGroup.mAnimState)
mCurGroup.mNext->first <= mCurGroup.mStop->first) break;
{
if(mController)
mController->markerEvent(mCurGroup.mNext->second);
mCurGroup.mNext++;
}
if(mNextGroup.mLoops > 0)
{
updatePosition(mCurGroup.mStop->first);
mTime = mTime - mCurGroup.mStop->first + mNextGroup.mStart->first;
mCurGroup.mAnimState->setEnabled(false); mCurGroup.mAnimState->setEnabled(false);
mCurGroup = mNextGroup; mCurGroup = mNextGroup;
mNextGroup = GroupTimes(); mNextGroup = GroupTimes();
mCurGroup.mAnimState->setEnabled(true); mCurGroup.mAnimState->setEnabled(true);
resetPosition(mCurGroup.mStart->first); resetPosition(mCurGroup.mStart->first);
goto recheck; continue;
} }
mTime = mCurGroup.mStop->first;
}
}
while(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
mCurGroup.mNext->first <= mTime)
{
if(mController)
mController->markerEvent(mCurGroup.mNext->second);
mCurGroup.mNext++; mCurGroup.mNext++;
continue;
} }
updatePosition(mTime); updatePosition(targetTime);
timepassed = targetTime - mTime;
} }
mSkipFrame = false;
} }
} }