From 3f4c66681e381f38db6dd25ffc78a931801e9030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Tue, 4 Feb 2025 17:36:01 -0300 Subject: [PATCH] more misc animation fixes --- src/playsim/p_actionfunctions.cpp | 62 ++++++++++++++++++------------- src/r_data/models.cpp | 15 ++++---- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index 1f18209bb..43b85f936 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -5159,9 +5159,34 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s tic += ticFrac; } - FModel * mdl = Models[(self->modelData->models.Size() > 0 && self->modelData->models[0].modelID >= 0) ? self->modelData->models[0].modelID : BaseSpriteModelFrames[self->GetClass()].modelIDs[0]]; + int animID = -1; + + + if(self->modelData->animationIDs.Size() > 0 && self->modelData->animationIDs[0] >= 0) + { + animID = self->modelData->animationIDs[0]; + } + else + { + animID = BaseSpriteModelFrames[self->GetClass()].animationIDs[0]; + } + + FModel * animation = nullptr; + if (animID >= 0 && animID < Models.Size()) + { + animation = Models[animID]; + } + else if(self->modelData->models.Size() && self->modelData->models[0].modelID >= 0 && self->modelData->models[0].modelID < Models.Size()) + { + animation = Models[self->modelData->models[0].modelID]; + } + else + { + animation = Models[BaseSpriteModelFrames[self->GetClass()].modelIDs[0]]; + } + + int animStart = animation->FindFirstFrame(animName); - int animStart = mdl->FindFirstFrame(animName); if(animStart == FErr_NotFound) { self->modelData->curAnim.flags = MODELANIM_NONE; @@ -5186,28 +5211,7 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s calcFrames(self->modelData->curAnim, tic, to, inter); - const TArray* 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(); - } + const TArray* animationData = animation->AttachAnimationData(); self->modelData->prevAnim = animation->PrecalculateFrame(self->modelData->prevAnim, to, inter, animationData); } @@ -5224,11 +5228,11 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s self->modelData->prevAnim = nullptr; } - int animEnd = mdl->FindLastFrame(animName); + int animEnd = animation->FindLastFrame(animName); if(framerate < 0) { - framerate = mdl->FindFramerate(animName); + framerate = animation->FindFramerate(animName); } int len = animEnd - animStart; @@ -5474,6 +5478,12 @@ void ChangeModelNative( if(generatorindex != -1) mobj->modelData->modelFrameGenerators[modelindex] = generatorindex; } + if(!(mobj->modelData->curAnim.flags & MODELANIM_NONE) && animationindex == 0 && (mobj->modelData->animationIDs.Size() == 0 || mobj->modelData->animationIDs[0] != queryAnimation)) + { // reset current animation if animation file changes + mobj->modelData->curAnim.flags |= MODELANIM_NONE; + mobj->modelData->prevAnim = nullptr; + } + if(mobj->modelData->animationIDs.Size() == animationindex) { mobj->modelData->animationIDs.Push(queryAnimation); diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 73c332a14..e6abe7630 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -163,7 +163,7 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod // so we make the "undistorted" behavior opt-in if (smf_flags & MDL_CORRECTPIXELSTRETCH) { - stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; + stretch = (smf->modelIDs[0] >= 0 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; objectToWorldMatrix.scale(1, stretch, 1); } @@ -204,7 +204,7 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod if (!(smf_flags & MDL_CORRECTPIXELSTRETCH)) { - stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; + stretch = (smf->modelIDs[0] >= 0 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; objectToWorldMatrix.scale(1, stretch, 1); } @@ -412,7 +412,6 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr TArray surfaceskinids; - const TArray *boneData; int boneStartingPosition = -1; bool evaluatedSingle = false; @@ -538,9 +537,11 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr bool nextFrame = smfNext && modelframe != modelframenext; + // [RL0] while per-model animations aren't done, DECOUPLEDANIMATIONS does the same as MODELSAREATTACHMENTS if(!evaluatedSingle) { + const TArray *boneData = nullptr; FModel* animation = mdl; const TArray* animationData = nullptr; @@ -552,7 +553,7 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr if(is_decoupled) { - if(decoupled_frame.frame1 != -1) + if(decoupled_frame.frame1 >= 0) { boneData = animation->CalculateBones(actor->modelData->prevAnim, decoupled_frame, inter, animationData); } @@ -567,8 +568,6 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr boneStartingPosition = boneData ? renderer->UploadBones(*boneData) : -1; evaluatedSingle = true; } - - boneData = nullptr; } mdl->RenderFrame(renderer, tex, modelframe, nextFrame ? modelframenext : modelframe, nextFrame ? inter : -1.f, translation, ssidp, boneStartingPosition, actor); @@ -1002,10 +1001,10 @@ void ParseModelDefLump(int Lump) if (isframe) { sc.MustGetString(); - if (smf.modelIDs[index] != -1) + if (smf.modelIDs[index] >= 0) { FModel *model = Models[smf.modelIDs[index]]; - if (smf.animationIDs[index] != -1) + if (smf.animationIDs[index] >= 0) { model = Models[smf.animationIDs[index]]; }