diff options
-rw-r--r-- | src/being/being.cpp | 16 | ||||
-rw-r--r-- | src/being/compoundsprite.cpp | 19 | ||||
-rw-r--r-- | src/being/compoundsprite.h | 8 | ||||
-rw-r--r-- | src/net/ea/playerrecv.cpp | 1 | ||||
-rw-r--r-- | src/resources/sprite/animatedsprite.h | 3 |
5 files changed, 42 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; diff --git a/src/net/ea/playerrecv.cpp b/src/net/ea/playerrecv.cpp index 5c207b973..cc588ac1b 100644 --- a/src/net/ea/playerrecv.cpp +++ b/src/net/ea/playerrecv.cpp @@ -115,6 +115,7 @@ void PlayerRecv::processPlayerWarp(Net::MessageIn &msg) localPlayer->setTileCoords(x, y); localPlayer->updatePets(); localPlayer->navigateClean(); + localPlayer->reset(); } logger->log("Adjust scrolling by %d:%d", scrollOffsetX, scrollOffsetY); diff --git a/src/resources/sprite/animatedsprite.h b/src/resources/sprite/animatedsprite.h index 03b276a9b..752e66eee 100644 --- a/src/resources/sprite/animatedsprite.h +++ b/src/resources/sprite/animatedsprite.h @@ -112,6 +112,9 @@ class AnimatedSprite final : public Sprite static void setEnableCache(const bool b) { mEnableCache = b; } + void setLastTime(const int time) + { mLastTime = time; } + #ifdef UNITTESTS SpriteDef *getSprite() restrict2 { return mSprite; } |