summaryrefslogtreecommitdiff
path: root/src/animatedsprite.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-02 14:52:30 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-08 21:03:28 +0200
commit7de0b165f196cb0c1f983b6d2ab26ef9791a2d36 (patch)
tree86f55c00b3fe17dae950351f3c33d35e6abd5a4d /src/animatedsprite.cpp
parent59a7d5c58f8b3af21b3e19d4e78f5653bf011bfb (diff)
downloadmana-7de0b165f196cb0c1f983b6d2ab26ef9791a2d36.tar.gz
mana-7de0b165f196cb0c1f983b6d2ab26ef9791a2d36.tar.bz2
mana-7de0b165f196cb0c1f983b6d2ab26ef9791a2d36.tar.xz
mana-7de0b165f196cb0c1f983b6d2ab26ef9791a2d36.zip
Do a single logic update each frame
The logic update now uses Time::deltaTimeMs() where needed to make it framerate-independent. This means there will no longer be multiple logic calls per frame (as was usually the case with logic ticking at 100 fps whereas the game would generally run at 60 fps). At the same time, the game can be more precise at higher framerates and should now run smoother at 144 Hz, for example. Previously the game would sometimes skip logic ticks at that rate. This change affects: * Updating of animations * Being movement speed * More moving of manual time variables to Timer Notoriously, the particle system still does 100 ticks/second.
Diffstat (limited to 'src/animatedsprite.cpp')
-rw-r--r--src/animatedsprite.cpp17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 7aa475d9..ec7aa1e3 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -54,11 +54,10 @@ AnimatedSprite::~AnimatedSprite() = default;
bool AnimatedSprite::reset()
{
- bool ret = mFrameIndex !=0 || mFrameTime != 0 || mLastTime != 0;
+ bool ret = mFrameIndex !=0 || mFrameTime != 0;
mFrameIndex = 0;
mFrameTime = 0;
- mLastTime = 0;
return ret;
}
@@ -87,21 +86,13 @@ bool AnimatedSprite::play(const std::string &spriteAction)
bool AnimatedSprite::update(int time)
{
- // Avoid freaking out at first frame or when tick_time overflows
- if (time < mLastTime || mLastTime == 0)
- mLastTime = time;
-
- // If not enough time has passed yet, do nothing
- if (time <= mLastTime || !mAnimation)
+ if (!mAnimation)
return false;
- unsigned int dt = time - mLastTime;
- mLastTime = time;
-
Animation *animation = mAnimation;
Frame *frame = mFrame;
- if (!updateCurrentAnimation(dt))
+ if (!updateCurrentAnimation(time))
{
// Animation finished, reset to default
play(SpriteAction::STAND);
@@ -111,7 +102,7 @@ bool AnimatedSprite::update(int time)
return animation != mAnimation || frame != mFrame;
}
-bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
+bool AnimatedSprite::updateCurrentAnimation(int time)
{
if (!mFrame || Animation::isTerminator(*mFrame))
return false;