From 4dae42a3efcfacd0897520a601a5d0b9c9d9021b Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Wed, 13 Oct 2021 00:04:48 +0700 Subject: [PATCH] Fixed bug with animations. - Before, if you shoot and go to the main menu, then the traces of the bullets were not removed from the map. This was because the animation stopped updating and the time kept going forward. As a result, the system believed that the animations had already passed, although in reality they had not. Now animations are tied not to their own, but to the global time counter --- engine/animation/Animation.cpp | 14 ++++---------- engine/animation/Animation.h | 3 --- engine/animation/Interpolation.h | 2 ++ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/engine/animation/Animation.cpp b/engine/animation/Animation.cpp index 458261b..d36eb36 100644 --- a/engine/animation/Animation.cpp +++ b/engine/animation/Animation.cpp @@ -6,22 +6,16 @@ bool Animation::updateState() { if(!_started) { - _startAnimationPoint = Time::time(); - _endAnimationPoint = _startAnimationPoint + _duration; _started = true; return _duration != 0; } - _timeOld = _time; // linear normalized time: - _time = (Time::time() - _startAnimationPoint)/(_endAnimationPoint - _startAnimationPoint); + _dtime = Time::deltaTime()/_duration; + _time += _dtime; - if(_looped != LoopOut::Continue || _time < 0.5) - _dtime = _time - _timeOld; - else { - _time = _timeOld; - //_intType = linear; - } + if(_looped == LoopOut::Continue && _time > 0.5) + _time = 0.5; switch (_intType) { case InterpolationType::bezier: diff --git a/engine/animation/Animation.h b/engine/animation/Animation.h index e1f4db7..62cee7b 100644 --- a/engine/animation/Animation.h +++ b/engine/animation/Animation.h @@ -26,10 +26,7 @@ public: protected: double _time = 0; // normalized time (from 0 to 1) double _dtime = 0; - double _timeOld = 0; - double _endAnimationPoint = 0; - double _startAnimationPoint = 0; double _duration = 0; bool _started = false; LoopOut _looped = LoopOut::None; diff --git a/engine/animation/Interpolation.h b/engine/animation/Interpolation.h index 90ce54c..409dccd 100644 --- a/engine/animation/Interpolation.h +++ b/engine/animation/Interpolation.h @@ -22,6 +22,8 @@ namespace Interpolation { static double dBouncing(double t, double dt); }; + + double Interpolation::Linear(double t) { if(t < 0) t = -t;