summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-03 20:06:08 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-03 20:18:49 +0300
commit98c10803f79ce9decb4a431719e18bb27aac4485 (patch)
treecbe6325a1e2deafe38170565a0c1d9c3f5cb7faa
parent57a81ed6cf1c02d7ec8bfe1e6f0a1d3232309534 (diff)
downloadmanaplus-98c10803f79ce9decb4a431719e18bb27aac4485.tar.gz
manaplus-98c10803f79ce9decb4a431719e18bb27aac4485.tar.bz2
manaplus-98c10803f79ce9decb4a431719e18bb27aac4485.tar.xz
manaplus-98c10803f79ce9decb4a431719e18bb27aac4485.zip
Improve a bit animation speed.
-rw-r--r--src/animatedsprite.cpp14
-rw-r--r--src/particleemitter.cpp4
-rw-r--r--src/resources/animation.h27
-rw-r--r--src/resources/mapreader.cpp2
-rw-r--r--src/simpleanimation.cpp8
5 files changed, 22 insertions, 33 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 9bf7018a3..1014fbe46 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -85,7 +85,7 @@ bool AnimatedSprite::reset()
mLastTime = 0;
if (mAnimation)
- mFrame = mAnimation->getFrame(0);
+ mFrame = &mAnimation->mFrames[0];
else
mFrame = nullptr;
return ret;
@@ -142,7 +142,8 @@ bool AnimatedSprite::update(int time)
bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
{
- if (!mFrame || !mAnimation || Animation::isTerminator(*mFrame))
+ // move code from Animation::isTerminator(*mFrame)
+ if (!mFrame || !mAnimation || (!mFrame->image && mFrame->type == Frame::ANIMATION))
return false;
mFrameTime += time;
@@ -158,7 +159,7 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
if (mFrameIndex >= mAnimation->getLength())
mFrameIndex = 0;
- mFrame = mAnimation->getFrame(mFrameIndex);
+ mFrame = &mAnimation->mFrames[mFrameIndex];
if (!mFrame || (mFrame->type == Frame::LABEL
&& !mFrame->nextAction.empty()))
{
@@ -170,7 +171,7 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
{
for (unsigned i = 0; i < mAnimation->getLength(); i ++)
{
- Frame *frame = mAnimation->getFrame(i);
+ Frame *frame = &mAnimation->mFrames[i];
if (frame->type == Frame::LABEL
&& mFrame->nextAction == frame->nextAction)
{
@@ -179,7 +180,7 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
if (mFrameIndex >= mAnimation->getLength())
mFrameIndex = 0;
- mFrame = mAnimation->getFrame(mFrameIndex);
+ mFrame = &mAnimation->mFrames[mFrameIndex];
fail = true;
break;
@@ -195,7 +196,8 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
return true;
}
}
- else if (Animation::isTerminator(*mFrame))
+ // copy code from Animation::isTerminator(*mFrame)
+ else if (!mFrame->image && mFrame->type == Frame::ANIMATION)
{
if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand)
{
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index 5fefd3609..27eb89291 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -527,12 +527,12 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick)
newParticle = new ImageParticle(mMap, mParticleImage);
}
- else if (!mParticleRotation.empty())
+ else if (!mParticleRotation.mFrames.empty())
{
Animation *newAnimation = new Animation(mParticleRotation);
newParticle = new RotationalParticle(mMap, newAnimation);
}
- else if (!mParticleAnimation.empty())
+ else if (!mParticleAnimation.mFrames.empty())
{
Animation *newAnimation = new Animation(mParticleAnimation);
newParticle = new AnimationParticle(mMap, newAnimation);
diff --git a/src/resources/animation.h b/src/resources/animation.h
index 1d23b1608..ffa717f8c 100644
--- a/src/resources/animation.h
+++ b/src/resources/animation.h
@@ -58,6 +58,10 @@ struct Frame
*/
class Animation
{
+ friend class AnimatedSprite;
+ friend class ParticleEmitter;
+ friend class SimpleAnimation;
+
public:
Animation();
@@ -74,28 +78,10 @@ class Animation
void addTerminator(int rand);
/**
- * Returns the frame at the specified index.
- */
- Frame *getFrame(int index)
- { return &(mFrames[index]); }
-
- /**
* Returns the length of this animation in frames.
*/
- unsigned int getLength() const
- { return static_cast<unsigned>(mFrames.size()); }
-
- /**
- * Check for empty animation.
- */
- bool empty() const
- { return mFrames.empty(); }
-
- /**
- * Returns the duration of this animation.
- */
- int getDuration() const
- { return mDuration; }
+ size_t getLength() const
+ { return mFrames.size(); }
void addJump(std::string name, int rand);
@@ -113,6 +99,7 @@ class Animation
static bool isTerminator(const Frame &phase);
protected:
+
typedef std::vector<Frame> Frames;
typedef Frames::iterator FramesIter;
typedef Frames::reverse_iterator FramesRevIter;
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 3f1ef1239..fd04f015f 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -777,7 +777,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
if (ani->getLength() > 0)
{
map->addAnimation(tileGID, new TileAnimation(ani));
- logger->log("Animation length: %d", ani->getLength());
+// logger->log("Animation length: %d", ani->getLength());
}
else
{
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 89431a916..483061516 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -39,7 +39,7 @@ SimpleAnimation::SimpleAnimation(Animation *animation):
mAnimation(animation),
mAnimationTime(0),
mAnimationPhase(0),
- mCurrentFrame(mAnimation->getFrame(0)),
+ mCurrentFrame(&mAnimation->mFrames[0]),
mInitialized(true)
{
}
@@ -53,7 +53,7 @@ SimpleAnimation::SimpleAnimation(XmlNodePtr animationNode,
{
initializeAnimation(animationNode, dyePalettes);
if (mAnimation)
- mCurrentFrame = mAnimation->getFrame(0);
+ mCurrentFrame = &mAnimation->mFrames[0];
else
mCurrentFrame = nullptr;
}
@@ -90,7 +90,7 @@ void SimpleAnimation::setFrame(int frame)
if (static_cast<unsigned>(frame) >= mAnimation->getLength())
frame = mAnimation->getLength() - 1;
mAnimationPhase = frame;
- mCurrentFrame = mAnimation->getFrame(mAnimationPhase);
+ mCurrentFrame = &mAnimation->mFrames[mAnimationPhase];
}
bool SimpleAnimation::update(int timePassed)
@@ -116,7 +116,7 @@ bool SimpleAnimation::update(int timePassed)
mAnimationPhase = 0;
}
- mCurrentFrame = mAnimation->getFrame(mAnimationPhase);
+ mCurrentFrame = &mAnimation->mFrames[mAnimationPhase];
}
}
return updated;