Skip to content

Commit

Permalink
handle freeze in decoupled animations
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Jul 9, 2024
1 parent 10d0f94 commit 7ddd4ec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/playsim/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/playsim/p_actionfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 13 additions & 1 deletion src/playsim/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -3861,6 +3861,12 @@ void AActor::Tick ()
{
special2++;
}

if(flags9 & MF9_DECOUPLEDANIMATIONS && modelData && !(modelData->curAnim.flags & ANIMOVERRIDE_NONE))
{
modelData->curAnim.startTic += 1;
}

return;
}

Expand Down Expand Up @@ -3908,6 +3914,12 @@ void AActor::Tick ()
{
special2++;
}

if(flags9 & MF9_DECOUPLEDANIMATIONS && modelData && !(modelData->curAnim.flags & ANIMOVERRIDE_NONE))
{
modelData->curAnim.startTic += 1;
}

return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/r_data/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 7ddd4ec

Please sign in to comment.