summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--src/animatedsprite.cpp17
-rw-r--r--src/animation.cpp20
-rw-r--r--src/animation.h16
-rw-r--r--src/player.cpp16
-rw-r--r--src/player.h29
6 files changed, 83 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 2ff4a9d4..a886518b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,10 @@
* configure.ac, data/graphics/items/Makefile.am,
data/graphics/Makefile.am: Added Makefile.am to make sure the item
icons are installed.
+ * src/player.cpp, src/animation.h, src/player.h,
+ src/animatedsprite.cpp, src/animation.cpp: Applied patch by Bahamut81
+ which implements resetting of Animation, Action and AnimatedSprite.
+ This fixes the animation synchronization issues.
2006-08-25 Matthias Hartmann <hartmann.matthias@gmail.com>
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index d1201042..a7a4453c 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -48,12 +48,14 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
free(data);
if (!doc) {
- logger->error("Animation: Error while parsing animation definition file!");
+ logger->error(
+ "Animation: Error while parsing animation definition file!");
}
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) {
- logger->error("Animation: this is not a valid animation definition file!");
+ logger->error(
+ "Animation: this is not a valid animation definition file!");
}
// Get the variant
@@ -232,13 +234,14 @@ AnimatedSprite::~AnimatedSprite()
void
AnimatedSprite::reset()
{
- // Reset all defined actions (because of aliases, some will be resetted
- // multiple times)
+ // Reset all defined actions (because of aliases some will be resetted
+ // multiple times, but this doesn't matter)
for (ActionIterator i = mActions.begin(); i != mActions.end(); ++i)
{
- //TODO: If resetting everything is really a nice way of fixing the
- // synchronization issues, finish implementing this.
- //i->second->reset();
+ if (i->second)
+ {
+ i->second->reset();
+ }
}
}
diff --git a/src/animation.cpp b/src/animation.cpp
index 1213d0d6..c1b27ebd 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -27,9 +27,15 @@
#include "utils/dtor.h"
-Animation::Animation():
- mTime(0)
+Animation::Animation()
{
+ reset();
+}
+
+void
+Animation::reset()
+{
+ mTime = 0;
iCurrentPhase = mAnimationPhases.begin();
}
@@ -123,3 +129,13 @@ Action::setAnimation(int direction, Animation *animation)
mAnimations[direction] = animation;
}
+
+void
+Action::reset()
+{
+ for (AnimationIterator i = mAnimations.begin();
+ i != mAnimations.end(); ++i)
+ {
+ i->second->reset();
+ }
+}
diff --git a/src/animation.h b/src/animation.h
index c5b277b7..60dcd287 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -55,6 +55,12 @@ class Animation
*/
Animation();
+ /**
+ * Restarts the animation from the first frame.
+ */
+ void
+ reset();
+
void
addPhase(int image, unsigned int delay, int offsetX, int offsetY);
@@ -68,13 +74,13 @@ class Animation
* Returns the x offset of the current frame.
*/
int
- getOffsetX() const { return (*iCurrentPhase).offsetX; };
+ getOffsetX() const { return iCurrentPhase->offsetX; };
/**
* Returns the y offset of the current frame.
*/
int
- getOffsetY() const { return (*iCurrentPhase).offsetY; };
+ getOffsetY() const { return iCurrentPhase->offsetY; };
/**
* Returns the length of this animation.
@@ -119,6 +125,12 @@ class Action
void
setAnimation(int direction, Animation *animation);
+ /**
+ * Resets all animations associated with this action.
+ */
+ void
+ reset();
+
Animation*
getAnimation(int direction) const;
diff --git a/src/player.cpp b/src/player.cpp
index 3fe608c7..1658840a 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -98,6 +98,7 @@ Player::setSex(Uint8 sex)
mSprites[BASE_SPRITE] = new AnimatedSprite(
"graphics/sprites/player_female_base.xml", 0);
}
+ resetAnimations();
}
Being::setSex(sex);
}
@@ -114,6 +115,7 @@ Player::setHairColor(Uint16 color)
newHairSprite->setDirection(getSpriteDirection());
mSprites[HAIR_SPRITE] = newHairSprite;
+ resetAnimations();
setAction(mAction);
}
@@ -133,6 +135,7 @@ Player::setHairStyle(Uint16 style)
newHairSprite->setDirection(getSpriteDirection());
mSprites[HAIR_SPRITE] = newHairSprite;
+ resetAnimations();
setAction(mAction);
}
@@ -170,6 +173,7 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id)
equipmentSprite->setDirection(getSpriteDirection());
mSprites[position] = equipmentSprite;
+ resetAnimations();
setAction(mAction);
}
@@ -177,4 +181,14 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id)
Being::setVisibleEquipment(slot, id);
}
-
+void
+Player::resetAnimations()
+{
+ for (int i = 0; i < VECTOREND_SPRITE; i++)
+ {
+ if (mSprites[i] != NULL)
+ {
+ mSprites[i]->reset();
+ }
+ }
+}
diff --git a/src/player.h b/src/player.h
index 15e7f655..21870fb0 100644
--- a/src/player.h
+++ b/src/player.h
@@ -37,19 +37,34 @@ class Player : public Being
public:
Player(Uint32 id, Uint16 job, Map *map);
- virtual void logic();
+ virtual void
+ logic();
- virtual Type getType() const;
+ virtual Type
+ getType() const;
- virtual void drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY);
+ virtual void
+ drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY);
- virtual void setSex(Uint8 sex);
+ virtual void
+ setSex(Uint8 sex);
- virtual void setHairColor(Uint16 color);
+ virtual void
+ setHairColor(Uint16 color);
- virtual void setHairStyle(Uint16 style);
+ virtual void
+ setHairStyle(Uint16 style);
- virtual void setVisibleEquipment(Uint8 slot, Uint8 id);
+ virtual void
+ setVisibleEquipment(Uint8 slot, Uint8 id);
+
+ private:
+ /**
+ * Resets all animations associated with this player. This is used to
+ * synchronize the animations after a new one has been added.
+ */
+ void
+ resetAnimations();
};
#endif