mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 09:53:54 +00:00
Update mTime when updating or reseting the animation, and refactor the animation loop
This commit is contained in:
parent
685f219560
commit
4dd01b81c6
1 changed files with 38 additions and 52 deletions
|
@ -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;
|
||||||
mTime += timepassed;
|
mSkipFrame = false;
|
||||||
recheck:
|
|
||||||
if(mTime >= mCurGroup.mLoopStop->first)
|
|
||||||
{
|
|
||||||
while(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
|
|
||||||
mCurGroup.mNext->first <= mCurGroup.mLoopStop->first)
|
|
||||||
{
|
|
||||||
if(mController)
|
|
||||||
mController->markerEvent(mCurGroup.mNext->second);
|
|
||||||
mCurGroup.mNext++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mCurGroup.mLoops > 1)
|
while(mCurGroup.mAnimState && timepassed > 0.0f)
|
||||||
{
|
{
|
||||||
mCurGroup.mLoops--;
|
float targetTime = mTime + timepassed;
|
||||||
updatePosition(mCurGroup.mLoopStop->first);
|
if(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
|
||||||
mTime = mTime - mCurGroup.mLoopStop->first + mCurGroup.mLoopStart->first;
|
mCurGroup.mNext->first <= targetTime)
|
||||||
resetPosition(mCurGroup.mLoopStart->first);
|
|
||||||
goto recheck;
|
|
||||||
}
|
|
||||||
else if(mTime >= mCurGroup.mStop->first)
|
|
||||||
{
|
|
||||||
while(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
|
|
||||||
mCurGroup.mNext->first <= mCurGroup.mStop->first)
|
|
||||||
{
|
|
||||||
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 = mNextGroup;
|
|
||||||
mNextGroup = GroupTimes();
|
|
||||||
mCurGroup.mAnimState->setEnabled(true);
|
|
||||||
resetPosition(mCurGroup.mStart->first);
|
|
||||||
goto recheck;
|
|
||||||
}
|
|
||||||
mTime = mCurGroup.mStop->first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(mCurGroup.mNext != mCurGroup.mTextKeys->end() &&
|
|
||||||
mCurGroup.mNext->first <= mTime)
|
|
||||||
{
|
{
|
||||||
|
updatePosition(mCurGroup.mNext->first);
|
||||||
|
timepassed = targetTime - mTime;
|
||||||
|
|
||||||
if(mController)
|
if(mController)
|
||||||
mController->markerEvent(mCurGroup.mNext->second);
|
mController->markerEvent(mCurGroup.mNext->second);
|
||||||
|
if(mCurGroup.mNext == mCurGroup.mLoopStop && mCurGroup.mLoops > 1)
|
||||||
|
{
|
||||||
|
mCurGroup.mLoops--;
|
||||||
|
resetPosition(mCurGroup.mLoopStart->first);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if(mCurGroup.mNext == mCurGroup.mStop)
|
||||||
|
{
|
||||||
|
if(!mNextGroup.mAnimState)
|
||||||
|
break;
|
||||||
|
|
||||||
|
mCurGroup.mAnimState->setEnabled(false);
|
||||||
|
mCurGroup = mNextGroup;
|
||||||
|
mNextGroup = GroupTimes();
|
||||||
|
mCurGroup.mAnimState->setEnabled(true);
|
||||||
|
resetPosition(mCurGroup.mStart->first);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
mCurGroup.mNext++;
|
mCurGroup.mNext++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePosition(mTime);
|
updatePosition(targetTime);
|
||||||
|
timepassed = targetTime - mTime;
|
||||||
}
|
}
|
||||||
mSkipFrame = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue