Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc decoupled animation fixes #2846

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions src/playsim/p_actionfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5130,6 +5130,7 @@ enum ESetAnimationFlags

void SetAnimationInternal(AActor * self, FName animName, double framerate, int startFrame, int loopFrame, int endFrame, int interpolateTics, int flags, double ticFrac)
{

if(!self) ThrowAbortException(X_READ_NIL, "In function parameter self");

if(!(self->flags9 & MF9_DECOUPLEDANIMATIONS))
Expand Down Expand Up @@ -5176,43 +5177,46 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s

if(!(flags & SAF_INSTANT))
{
if(self->modelData->curAnim.startTic > tic)
{
ModelAnimFrameInterp to;
float inter;
if((self->modelData->curAnim.startTic - self->modelData->curAnim.switchOffset) != int(floor(tic)))
{ // don't change interpolation data if animation switch happened in the same tic
if(self->modelData->curAnim.startTic > tic)
{
ModelAnimFrameInterp to;
float inter;

calcFrames(self->modelData->curAnim, tic, to, inter);
calcFrames(self->modelData->curAnim, tic, to, inter);

const TArray<TRS>* animationData = nullptr;
const TArray<TRS>* animationData = nullptr;

int animationid = -1;
int animationid = -1;

const FSpriteModelFrame * smf = &BaseSpriteModelFrames[self->GetClass()];
const FSpriteModelFrame * smf = &BaseSpriteModelFrames[self->GetClass()];

if (self->modelData->animationIDs.Size() > 0 && self->modelData->animationIDs[0] >= 0)
{
animationid = self->modelData->animationIDs[0];
}
else if(smf->modelsAmount > 0)
{
animationid = smf->animationIDs[0];
}
if (self->modelData->animationIDs.Size() > 0 && self->modelData->animationIDs[0] >= 0)
{
animationid = self->modelData->animationIDs[0];
}
else if(smf->modelsAmount > 0)
{
animationid = smf->animationIDs[0];
}

FModel* animation = mdl;
FModel* animation = mdl;

if (animationid >= 0)
{
animation = Models[animationid];
animationData = animation->AttachAnimationData();
}
if (animationid >= 0)
{
animation = Models[animationid];
animationData = animation->AttachAnimationData();
}

self->modelData->prevAnim = animation->PrecalculateFrame(self->modelData->prevAnim, to, inter, animationData, self->boneComponentData, 0);
}
else
{
self->modelData->prevAnim = ModelAnimFrameInterp{};
self->modelData->prevAnim = animation->PrecalculateFrame(self->modelData->prevAnim, to, inter, animationData, self->boneComponentData, 0);
}
else
{
self->modelData->prevAnim = ModelAnimFrameInterp{};

calcFrame(self->modelData->curAnim, tic, std::get<ModelAnimFrameInterp>(self->modelData->prevAnim));
calcFrame(self->modelData->curAnim, tic, std::get<ModelAnimFrameInterp>(self->modelData->prevAnim));
}
}
}
else
Expand Down Expand Up @@ -5524,7 +5528,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_ChangeModel, ChangeModelNative)

DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimation, SetAnimationNative)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);
PARAM_NAME(animName);
PARAM_FLOAT(framerate);
PARAM_INT(startFrame);
Expand All @@ -5540,7 +5544,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimation, SetAnimationNative)

DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimationUI, SetAnimationUINative)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);
PARAM_NAME(animName);
PARAM_FLOAT(framerate);
PARAM_INT(startFrame);
Expand All @@ -5556,7 +5560,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimationUI, SetAnimationUINative)

DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimationFrameRate, SetAnimationFrameRateNative)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(framerate);

SetAnimationFrameRateInternal(self, framerate, 1);
Expand All @@ -5566,7 +5570,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimationFrameRate, SetAnimationFrameRa

DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimationFrameRateUI, SetAnimationFrameRateUINative)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(framerate);

SetAnimationFrameRateInternal(self, framerate, I_GetTimeFrac());
Expand All @@ -5576,7 +5580,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetAnimationFrameRateUI, SetAnimationFrame

DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetModelFlag, SetModelFlag)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(flag);

SetModelFlag(self, flag);
Expand All @@ -5586,7 +5590,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetModelFlag, SetModelFlag)

DEFINE_ACTION_FUNCTION_NATIVE(AActor, ClearModelFlag, ClearModelFlag)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(flag);

ClearModelFlag(self, flag);
Expand All @@ -5596,7 +5600,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, ClearModelFlag, ClearModelFlag)

DEFINE_ACTION_FUNCTION_NATIVE(AActor, ResetModelFlags, ResetModelFlags)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_SELF_PROLOGUE(AActor);

ResetModelFlags(self);

Expand Down