From b3067c0e3f217db656e4535f430c6312487bbfb0 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 16 Nov 2022 17:53:40 +0200 Subject: [PATCH] Attemts to improve timing of ranged attacks: - when computing number of steps/frames to display projectile round to nearest instead of rounding down - end projectile animation only *after* last step was shown --- client/battle/CBattleAnimations.cpp | 4 +++- client/battle/CBattleInterface.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/battle/CBattleAnimations.cpp b/client/battle/CBattleAnimations.cpp index 7e9b9f88e..935e02a92 100644 --- a/client/battle/CBattleAnimations.cpp +++ b/client/battle/CBattleAnimations.cpp @@ -814,7 +814,9 @@ bool CShootingAnimation::init() if (attackedStack) { double animSpeed = AnimationControls::getProjectileSpeed(); // flight speed of projectile - spi.lastStep = static_cast(sqrt(static_cast((destPos.x - spi.x) * (destPos.x - spi.x) + (destPos.y - spi.y) * (destPos.y - spi.y))) / animSpeed); + double distanceSquared = (destPos.x - spi.x) * (destPos.x - spi.x) + (destPos.y - spi.y) * (destPos.y - spi.y); + double distance = sqrt(distanceSquared); + spi.lastStep = std::round(distance / animSpeed); if(spi.lastStep == 0) spi.lastStep = 1; spi.dx = (destPos.x - spi.x) / spi.lastStep; diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index 304608dea..7c112e624 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -3269,7 +3269,7 @@ void CBattleInterface::showProjectiles(SDL_Surface *to) // Update projectile ++it->step; - if (it->step == it->lastStep) + if (it->step > it->lastStep) { toBeDeleted.insert(toBeDeleted.end(), it); }