summaryrefslogtreecommitdiff
path: root/src/simpleanimation.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-07-23 13:46:09 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-07-23 16:02:04 +0200
commit0875b7ecb46f93e408a560f0033da392f0a4d3b2 (patch)
treee81ae8a3d4dcdfc65c2e2799b2a5bafddbba207b /src/simpleanimation.cpp
parentd562e188873276cc6b53ac3aa508ac1ef0f33527 (diff)
downloadmana-0875b7ecb46f93e408a560f0033da392f0a4d3b2.tar.gz
mana-0875b7ecb46f93e408a560f0033da392f0a4d3b2.tar.bz2
mana-0875b7ecb46f93e408a560f0033da392f0a4d3b2.tar.xz
mana-0875b7ecb46f93e408a560f0033da392f0a4d3b2.zip
Added simple sanity checks for missing animation in maps.
Fixes a bunch of crash courses for me. Reviewed-by: Freeyorp
Diffstat (limited to 'src/simpleanimation.cpp')
-rw-r--r--src/simpleanimation.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index a8d33a43..7ef433ea 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -33,14 +33,16 @@ SimpleAnimation::SimpleAnimation(Animation *animation):
mAnimation(animation),
mAnimationTime(0),
mAnimationPhase(0),
- mCurrentFrame(mAnimation->getFrame(0))
+ mCurrentFrame(mAnimation->getFrame(0)),
+ mInitialized(true)
{
}
SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode):
mAnimation(new Animation),
mAnimationTime(0),
- mAnimationPhase(0)
+ mAnimationPhase(0),
+ mInitialized(false)
{
initializeAnimation(animationNode);
mCurrentFrame = mAnimation->getFrame(0);
@@ -48,7 +50,8 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode):
SimpleAnimation::~SimpleAnimation()
{
- delete mAnimation;
+ if (mAnimation)
+ delete mAnimation;
}
bool SimpleAnimation::draw(Graphics *graphics, int posX, int posY) const
@@ -79,38 +82,55 @@ void SimpleAnimation::setFrame(int frame)
void SimpleAnimation::update(int timePassed)
{
- mAnimationTime += timePassed;
-
- while (mAnimationTime > mCurrentFrame->delay && mCurrentFrame->delay > 0)
+ if (mInitialized)
{
- mAnimationTime -= mCurrentFrame->delay;
- mAnimationPhase++;
+ mAnimationTime += timePassed;
- if (mAnimationPhase >= mAnimation->getLength())
- mAnimationPhase = 0;
+ while (mAnimationTime > mCurrentFrame->delay && mCurrentFrame->delay > 0)
+ {
+ mAnimationTime -= mCurrentFrame->delay;
+ mAnimationPhase++;
- mCurrentFrame = mAnimation->getFrame(mAnimationPhase);
+ if (mAnimationPhase >= mAnimation->getLength())
+ mAnimationPhase = 0;
+
+ mCurrentFrame = mAnimation->getFrame(mAnimationPhase);
+ }
}
}
int SimpleAnimation::getLength() const
{
- return mAnimation->getLength();
+ if (mAnimation)
+ return mAnimation->getLength();
+ else
+ return 0;
}
Image *SimpleAnimation::getCurrentImage() const
{
- return mCurrentFrame->image;
+ if (mCurrentFrame)
+ return mCurrentFrame->image;
+ else
+ return NULL;
}
void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode)
{
+ mInitialized = false;
+
+ if (!animationNode)
+ return;
+
ImageSet *imageset = ResourceManager::getInstance()->getImageSet(
XML::getProperty(animationNode, "imageset", ""),
XML::getProperty(animationNode, "width", 0),
XML::getProperty(animationNode, "height", 0)
);
+ if (!imageset)
+ return;
+
// Get animation frames
for ( xmlNodePtr frameNode = animationNode->xmlChildrenNode;
frameNode;
@@ -172,4 +192,6 @@ void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode)
mAnimation->addTerminator();
}
}
+
+ mInitialized = true;
}