From 3bd80ab8f6ffb85515d428d4169a777b7f64f59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Mon, 8 Jan 2024 01:58:11 -0300 Subject: [PATCH] Do the same for Visual Thinkers --- src/gamedata/textures/animations.cpp | 2 +- src/playsim/p_effect.cpp | 6 ++++++ src/playsim/p_effect.h | 1 + src/rendering/hwrenderer/scene/hw_sprites.cpp | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index 58cb3f189..0fcf16a01 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -984,7 +984,7 @@ bool FTextureAnimator::InitStandaloneAnimation(FStandaloneAnimation &animInfo, F { FAnimDef * anim; animInfo.ok = false; - for(int i = 0; i < mAnimations.Size(); i++) + for(unsigned i = 0; i < mAnimations.Size(); i++) { if(mAnimations[i].BasePic == tex) { diff --git a/src/playsim/p_effect.cpp b/src/playsim/p_effect.cpp index 21aa0a0d3..ee5583fb7 100644 --- a/src/playsim/p_effect.cpp +++ b/src/playsim/p_effect.cpp @@ -1024,6 +1024,7 @@ void DVisualThinker::Construct() cursector = nullptr; PT.color = 0xffffff; spr = new HWSprite(); + AnimatedTexture.SetNull(); } DVisualThinker::DVisualThinker() @@ -1078,6 +1079,11 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, SpawnVisualThinker, SpawnVisualThink void DVisualThinker::UpdateSpriteInfo() { PT.style = ERenderStyle(GetRenderStyle()); + if((PT.flags & SPF_STANDALONE_ANIMATIONS) && PT.texture != AnimatedTexture) + { + AnimatedTexture = PT.texture; + TexAnim.InitStandaloneAnimation(PT.animData, PT.texture, Level->maptime); + } } // This runs just like Actor's, make sure to call Super.Tick() in ZScript. diff --git a/src/playsim/p_effect.h b/src/playsim/p_effect.h index 416226cab..72a470ad6 100644 --- a/src/playsim/p_effect.h +++ b/src/playsim/p_effect.h @@ -163,6 +163,7 @@ public: float PrevRoll; int16_t LightLevel; FTranslationID Translation; + FTextureID AnimatedTexture; sector_t *cursector; bool bXFlip, diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index cfc2cce50..87d3b61f5 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -1343,7 +1343,7 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s else { bool has_texture = particle->texture.isValid(); - bool custom_animated_texture = has_texture && (particle->flags & SPF_STANDALONE_ANIMATIONS) && particle->animData.ok; + bool custom_animated_texture = (particle->flags & SPF_STANDALONE_ANIMATIONS) && particle->animData.ok; int particle_style = has_texture ? 2 : gl_particles_style; // Treat custom texture the same as smooth particles @@ -1442,11 +1442,21 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t* sector) { translation = spr->Translation; - texture = TexMan.GetGameTexture(spr->PT.texture, true); const auto& vp = di->Viewpoint; double timefrac = vp.TicFrac; - if (paused || spr->isFrozen() || spr->bDontInterpolate) + + if (paused || spr->isFrozen()) + timefrac = 0.; + + bool custom_anim = ((spr->PT.flags & SPF_STANDALONE_ANIMATIONS) && spr->PT.animData.ok); + + texture = TexMan.GetGameTexture( + custom_anim + ? TexAnim.UpdateStandaloneAnimation(spr->PT.animData, di->Level->maptime + timefrac) + : spr->PT.texture, !custom_anim); + + if (spr->bDontInterpolate) timefrac = 0.; FVector3 interp = spr->InterpolatedPosition(timefrac);