summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-12-30 21:38:56 +0300
committerAndrei Karas <akaras@inbox.ru>2015-12-30 21:55:00 +0300
commit78e438b7043eff243a21833d4709ef432eb7a818 (patch)
treecbaace2b8a39c078115cd48c803363f7a274ee51 /src/being
parent88efa77af94256992ba2c05f4d7b5b5a9d01d6e9 (diff)
downloadmanaverse-78e438b7043eff243a21833d4709ef432eb7a818.tar.gz
manaverse-78e438b7043eff243a21833d4709ef432eb7a818.tar.bz2
manaverse-78e438b7043eff243a21833d4709ef432eb7a818.tar.xz
manaverse-78e438b7043eff243a21833d4709ef432eb7a818.zip
Fix animation time for new animated sprites.
Diffstat (limited to 'src/being')
-rw-r--r--src/being/being.cpp16
-rw-r--r--src/being/compoundsprite.cpp19
-rw-r--r--src/being/compoundsprite.h8
3 files changed, 38 insertions, 5 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index e0186e6d3..26bfab3ee 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -2500,6 +2500,8 @@ void Being::setSprite(const unsigned int slot,
const ItemInfo &info = ItemDB::get(id);
const std::string &restrict filename = info.getSprite(
mGender, mSubType);
+ int lastTime = 0;
+ int startTime = 0;
AnimatedSprite *restrict equipmentSprite = nullptr;
if (!isTempSprite && mType == ActorType::Player)
@@ -2522,10 +2524,8 @@ void Being::setSprite(const unsigned int slot,
if (equipmentSprite)
{
equipmentSprite->setSpriteDirection(getSpriteDirection());
-
- // call reset here is not the best idea, but for now this is
- // only way to sync just loaded sprite
- reset();
+ startTime = getStartTime();
+ lastTime = getLastTime();
}
CompoundSprite::setSprite(slot, equipmentSprite);
@@ -2537,6 +2537,14 @@ void Being::setSprite(const unsigned int slot,
mEquippedWeapon = &ItemDB::get(id);
setAction(mAction, 0);
+ if (equipmentSprite)
+ {
+ if (lastTime > 0)
+ {
+ equipmentSprite->setLastTime(startTime);
+ equipmentSprite->update(lastTime);
+ }
+ }
}
if (!isTempSprite)
diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp
index 5b37738b2..19311fc65 100644
--- a/src/being/compoundsprite.cpp
+++ b/src/being/compoundsprite.cpp
@@ -66,6 +66,8 @@ CompoundSprite::CompoundSprite() :
mAlphaImage(nullptr),
mOffsetX(0),
mOffsetY(0),
+ mStartTime(0),
+ mLastTime(0),
mSprites(),
#ifndef USE_SDL2
mNextRedrawTime(0),
@@ -93,6 +95,8 @@ bool CompoundSprite::reset()
if (*it)
ret |= (*it)->reset();
}
+ if (ret)
+ mLastTime = 0;
mNeedsRedraw |= ret;
return ret;
}
@@ -100,18 +104,28 @@ bool CompoundSprite::reset()
bool CompoundSprite::play(const std::string &action)
{
bool ret = false;
+ bool ret2 = true;
FOR_EACH (SpriteIterator, it, mSprites)
{
if (*it)
- ret |= (*it)->play(action);
+ {
+ const bool tmpVal = (*it)->play(action);
+ ret |= tmpVal;
+ ret2 &= tmpVal;
+ }
}
mNeedsRedraw |= ret;
+ if (ret2)
+ mLastTime = 0;
return ret;
}
bool CompoundSprite::update(const int time)
{
bool ret = false;
+ if (!mLastTime)
+ mStartTime = time;
+ mLastTime = time;
FOR_EACH (SpriteIterator, it, mSprites)
{
if (*it)
@@ -207,6 +221,8 @@ bool CompoundSprite::setSpriteDirection(const SpriteDirection::Type direction)
if (*it)
ret |= (*it)->setSpriteDirection(direction);
}
+ if (ret)
+ mLastTime = 0;
mNeedsRedraw |= ret;
return ret;
}
@@ -278,6 +294,7 @@ void CompoundSprite::clear()
delete_all(imagesCache);
imagesCache.clear();
delete2(mCacheItem);
+ mLastTime = 0;
}
void CompoundSprite::ensureSize(size_t layerCount)
diff --git a/src/being/compoundsprite.h b/src/being/compoundsprite.h
index 4a7ed6fb0..babf6fc60 100644
--- a/src/being/compoundsprite.h
+++ b/src/being/compoundsprite.h
@@ -119,6 +119,12 @@ class CompoundSprite notfinal : public Sprite
static void setEnableDelay(bool b)
{ mEnableDelay = b; }
+ int getLastTime() const A_WARN_UNUSED
+ { return mLastTime; }
+
+ int getStartTime() const A_WARN_UNUSED
+ { return mStartTime; }
+
private:
void redraw() const;
@@ -137,6 +143,8 @@ class CompoundSprite notfinal : public Sprite
mutable int mOffsetX;
mutable int mOffsetY;
+ int mStartTime;
+ int mLastTime;
std::vector<Sprite*> mSprites;
#ifndef USE_SDL2
mutable int mNextRedrawTime;