handle freeze in decoupled animations

This commit is contained in:
Ricardo Luís Vaz Silva 2024-07-07 10:54:49 -03:00
parent 10d0f94972
commit 7ddd4ec245
4 changed files with 21 additions and 7 deletions

View file

@ -710,7 +710,7 @@ struct AnimOverride
int flags = ANIMOVERRIDE_NONE;
float framerate;
double startTic; // when the current animation started (changing framerates counts as restarting) (or when animation starts if interpolating from previous animation)
double switchTic; // when the animation was changed -- where to interpolate the switch from
double switchOffset; // when the animation was changed -- where to interpolate the switch from
};
struct ModelOverride

View file

@ -5214,18 +5214,20 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s
self->modelData->curAnim.startFrame = startFrame < 0 ? animStart : animStart + startFrame;
self->modelData->curAnim.loopFrame = loopFrame < 0 ? animStart : animStart + loopFrame;
self->modelData->curAnim.flags = (flags&SAF_LOOP) ? ANIMOVERRIDE_LOOP : 0;
self->modelData->curAnim.switchTic = tic;
self->modelData->curAnim.framerate = (float)framerate;
if(!(flags & SAF_INSTANT))
{
self->modelData->prevAnim.startFrame = getCurrentFrame(self->modelData->prevAnim, tic);
self->modelData->curAnim.startTic = floor(tic) + interpolateTics;
int startTic = floor(tic) + interpolateTics;
self->modelData->curAnim.startTic = startTic;
self->modelData->curAnim.switchOffset = startTic - tic;
}
else
{
self->modelData->curAnim.startTic = tic;
self->modelData->curAnim.switchOffset = 0;
}
}
@ -5274,7 +5276,7 @@ void SetAnimationFrameRateInternal(AActor * self, double framerate, double ticFr
self->modelData->curAnim.startFrame = frame;
self->modelData->curAnim.startTic = tic;
self->modelData->curAnim.switchTic = tic;
self->modelData->curAnim.switchOffset = 0;
self->modelData->curAnim.framerate = (float)framerate;
}

View file

@ -1453,7 +1453,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, struct AnimOverride &a
arc("flags", ao.flags);
arc("framerate", ao.framerate);
arc("startTic", ao.startTic);
arc("switchTic", ao.switchTic);
arc("switchOffset", ao.switchOffset);
arc.EndObject();
return arc;
}
@ -3861,6 +3861,12 @@ void AActor::Tick ()
{
special2++;
}
if(flags9 & MF9_DECOUPLEDANIMATIONS && modelData && !(modelData->curAnim.flags & ANIMOVERRIDE_NONE))
{
modelData->curAnim.startTic += 1;
}
return;
}
@ -3908,6 +3914,12 @@ void AActor::Tick ()
{
special2++;
}
if(flags9 & MF9_DECOUPLEDANIMATIONS && modelData && !(modelData->curAnim.flags & ANIMOVERRIDE_NONE))
{
modelData->curAnim.startTic += 1;
}
return;
}

View file

@ -316,13 +316,13 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
if(actor->modelData && !(actor->modelData->curAnim.flags & ANIMOVERRIDE_NONE))
{
double tic = actor->Level->totaltime;
if ((ConsoleState == c_up || ConsoleState == c_rising) && (menuactive == MENU_Off || menuactive == MENU_OnNoPause) && !Level->isFrozen())
if ((ConsoleState == c_up || ConsoleState == c_rising) && (menuactive == MENU_Off || menuactive == MENU_OnNoPause) && !actor->isFrozen())
{
tic += I_GetTimeFrac();
}
if(actor->modelData->curAnim.startTic > tic)
{
inter = (tic - actor->modelData->curAnim.switchTic) / (actor->modelData->curAnim.startTic - actor->modelData->curAnim.switchTic);
inter = (tic - (actor->modelData->curAnim.startTic - actor->modelData->curAnim.switchOffset)) / actor->modelData->curAnim.switchOffset;
double nextFrame = actor->modelData->curAnim.startFrame;