diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-11-14 22:51:09 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-11-14 22:51:09 +0000 |
commit | 29bedd4da7e21b6dc644c8aa69d096db1516ea7b (patch) | |
tree | c33d35513bbf069e4e39c604bc2200ce100856e1 /src/animation.cpp | |
parent | 82f587f2f3795898ed4fb7b125bf34b7e13de7cd (diff) | |
download | mana-client-29bedd4da7e21b6dc644c8aa69d096db1516ea7b.tar.gz mana-client-29bedd4da7e21b6dc644c8aa69d096db1516ea7b.tar.bz2 mana-client-29bedd4da7e21b6dc644c8aa69d096db1516ea7b.tar.xz mana-client-29bedd4da7e21b6dc644c8aa69d096db1516ea7b.zip |
Resolve Image* of animation phase at load time instead of storing just the
spriteset index and looking it up later (checking validity should still be
added). Also calculate animation length during loading instead of summing it up
each time it is requested.
Diffstat (limited to 'src/animation.cpp')
-rw-r--r-- | src/animation.cpp | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/src/animation.cpp b/src/animation.cpp index bca4bb58..a91bdf8d 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -27,7 +27,8 @@ #include "utils/dtor.h" -Animation::Animation() +Animation::Animation(): + mLength(0) { reset(); } @@ -39,7 +40,6 @@ Animation::reset() iCurrentPhase = mAnimationPhases.begin(); } - bool Animation::update(unsigned int time) { @@ -68,29 +68,28 @@ Animation::update(unsigned int time) return true; } - -int +const AnimationPhase* Animation::getCurrentPhase() const { - return mAnimationPhases.empty() ? -1 : iCurrentPhase->image; + return mAnimationPhases.empty() ? NULL : &(*iCurrentPhase); } - void -Animation::addPhase(int image, unsigned int delay, int offsetX, int offsetY) +Animation::addPhase(Image *image, unsigned int delay, int offsetX, int offsetY) { - //add new phase to animation list + // Add new phase to animation list AnimationPhase newPhase = { image, delay, offsetX, offsetY}; mAnimationPhases.push_back(newPhase); - //reset animation circle + mLength += delay; + // Reset animation circle iCurrentPhase = mAnimationPhases.begin(); } void Animation::addTerminator() { - AnimationPhase terminator = { -1, 0, 0, 0}; + AnimationPhase terminator = { NULL, 0, 0, 0}; mAnimationPhases.push_back(terminator); iCurrentPhase = mAnimationPhases.begin(); } @@ -98,20 +97,5 @@ Animation::addTerminator() bool Animation::isTerminator(AnimationPhase candidate) { - return (candidate.image < 0); -} - -int -Animation::getLength() -{ - if (mAnimationPhases.empty()) - return 0; - - std::list<AnimationPhase>::iterator i; - int length = 0; - for (i = mAnimationPhases.begin(); i != mAnimationPhases.end(); i++) - { - length += i->delay; - } - return length; + return (candidate.image == NULL); } |