From c250477347c2a9cb9062e727acd5816ff380537d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Fri, 29 Nov 2024 13:54:17 -0300 Subject: [PATCH] misc decoupled animation fixes --- src/playsim/p_actionfunctions.cpp | 74 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index ea7090c1dfa..8d50993d90e 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -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; + 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* animationData = nullptr; + const TArray* 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(self->modelData->prevAnim)); + calcFrame(self->modelData->curAnim, tic, std::get(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);