misc decoupled animation fixes

This commit is contained in:
Ricardo Luís Vaz Silva 2024-11-29 13:54:17 -03:00
parent 72ed0c4377
commit 8311e77a26

View file

@ -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))
@ -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;
calcFrames(self->modelData->curAnim, tic, to, inter);
const TArray<TRS>* animationData = nullptr;
int animationid = -1;
const FSpriteModelFrame * smf = &BaseSpriteModelFrames[self->GetClass()];
if (self->modelData->animationIDs.Size() > 0 && self->modelData->animationIDs[0] >= 0)
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)
{
animationid = self->modelData->animationIDs[0];
ModelAnimFrameInterp to;
float inter;
calcFrames(self->modelData->curAnim, tic, to, inter);
const TArray<TRS>* animationData = nullptr;
int animationid = -1;
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];
}
FModel* animation = mdl;
if (animationid >= 0)
{
animation = Models[animationid];
animationData = animation->AttachAnimationData();
}
self->modelData->prevAnim = animation->PrecalculateFrame(self->modelData->prevAnim, to, inter, animationData, self->boneComponentData, 0);
}
else if(smf->modelsAmount > 0)
else
{
animationid = smf->animationIDs[0];
self->modelData->prevAnim = ModelAnimFrameInterp{};
calcFrame(self->modelData->curAnim, tic, std::get<ModelAnimFrameInterp>(self->modelData->prevAnim));
}
FModel* animation = mdl;
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{};
calcFrame(self->modelData->curAnim, tic, std::get<ModelAnimFrameInterp>(self->modelData->prevAnim));
}
}
else
@ -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);
@ -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);
@ -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);
@ -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());
@ -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);
@ -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);
@ -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);