summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2006-09-13 23:17:54 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2006-09-13 23:17:54 +0000
commitc4529dbd7b7f8f3ae5009d35010139e7f1b68deb (patch)
treebf9faa892228e389e34e379ebd306c7fa09a00a6
parent4423d208ad7dc1ed3967d715642595f4fd1e6faf (diff)
downloadmana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.tar.gz
mana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.tar.bz2
mana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.tar.xz
mana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.zip
some improvements at the animation system
-rw-r--r--ChangeLog7
-rw-r--r--src/animatedsprite.cpp47
-rw-r--r--src/animatedsprite.h3
3 files changed, 43 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index b0d71167..5e8145ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-09-14 Philipp Sehmisch <tmw@crushnet.org>
+
+ * src/animation.h, src/animatedsprite.h,
+ data/graphics/sprites/weapon.xml: Some modifications at the animation
+ system. No more "undefined action foo" warnings in the tmw.log. Not
+ visible actions must now be declared explicitely.
+
2006-09-14 Björn Steinbrink <B.Steinbrink@gmx.de>
* src/main.cpp: Fix up the player selection command line option.
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index a7a4453c..a6d8eaf7 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -92,11 +92,6 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
std::string name = getProperty(node, "name", "");
std::string imageset = getProperty(node, "imageset", "");
- if (name.empty())
- {
- logger->log("Warning: unnamed action in %s",
- animationFile.c_str());
- }
if (mSpritesets.find(imageset) == mSpritesets.end()) {
logger->log("Warning: imageset \"%s\" not defined in %s",
imageset.c_str(),
@@ -108,8 +103,27 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
Action *action = new Action();
- action->setSpriteset(mSpritesets[imageset]);
- mActions[makeSpriteAction(name)] = action;
+ action->setSpriteset(mSpritesets[imageset]);
+
+ SpriteAction actionname = makeSpriteAction(name);
+ if (actionname == ACTION_INVALID)
+ {
+
+ logger->log("Warning: Unknown action \"%s\" defined in %s",
+ name.c_str(),
+ animationFile.c_str());
+ continue;
+ }
+ else {
+ mActions[makeSpriteAction(name)] = action;
+
+ // When first action set it as default direction
+ if (mActions.empty())
+ {
+ mActions[ACTION_DEFAULT] = action;
+ }
+ };
+
// get animations
for (xmlNodePtr animationNode = node->xmlChildrenNode;
@@ -161,6 +175,7 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
} // for node
// Complete missing actions
+ substituteAction(ACTION_STAND, ACTION_DEFAULT);
substituteAction(ACTION_WALK, ACTION_STAND);
substituteAction(ACTION_WALK, ACTION_RUN);
substituteAction(ACTION_ATTACK, ACTION_STAND);
@@ -278,11 +293,12 @@ AnimatedSprite::update(int time)
if (time < mLastTime || mLastTime == 0)
mLastTime = time;
- // If not enough time have passed yet, do nothing
+ // If not enough time has passed yet, do nothing
if (time > mLastTime && mAction)
{
- Animation *animation = mAction->getAnimation(mDirection);
- animation->update((unsigned int)((time - mLastTime) * mSpeed));
+ Animation *animation = mAction->getAnimation(mDirection);
+ if (animation != NULL) {
+ animation->update((unsigned int)((time - mLastTime) * mSpeed));}
mLastTime = time;
}
}
@@ -293,7 +309,9 @@ AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const
if (!mAction)
return false;
- Animation *animation = mAction->getAnimation(mDirection);
+ Animation *animation = mAction->getAnimation(mDirection);
+ if (animation == NULL) return false;
+
int phase = animation->getCurrentPhase();
if (phase < 0)
return false;
@@ -319,7 +337,10 @@ AnimatedSprite::getHeight() const
SpriteAction
AnimatedSprite::makeSpriteAction(const std::string& action)
-{
+{
+ if (action == "" || action == "default") {
+ return ACTION_DEFAULT;
+ }
if (action == "stand") {
return ACTION_STAND;
}
@@ -363,7 +384,7 @@ AnimatedSprite::makeSpriteAction(const std::string& action)
return ACTION_DEAD;
}
else {
- return ACTION_DEFAULT;
+ return ACTION_INVALID;
}
}
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index 89394d6c..c860b46d 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -50,7 +50,8 @@ enum SpriteAction
ACTION_SIT,
ACTION_SLEEP,
ACTION_HURT,
- ACTION_DEAD
+ ACTION_DEAD,
+ ACTION_INVALID
};
enum SpriteDirection