aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorDenis Kasak2009-07-18 02:53:37 +0000
committerDenis Kasak2009-07-18 02:53:37 +0000
commitadf9e91e1fd1bc9e23147ef4ce100a5343a23ffa (patch)
tree203e0c4a11586e148bdd9fe55cba7dea7107fb0d /engines
parent8e1f29630869481f88911476d900f421fa0c2164 (diff)
downloadscummvm-rg350-adf9e91e1fd1bc9e23147ef4ce100a5343a23ffa.tar.gz
scummvm-rg350-adf9e91e1fd1bc9e23147ef4ce100a5343a23ffa.tar.bz2
scummvm-rg350-adf9e91e1fd1bc9e23147ef4ce100a5343a23ffa.zip
* Added Animation::getFrame()
* Added support for sorting animations when Z is changed later on (AnimationManager::sortAnimations()) * Added support for relative coordinates (Animation::setRelative()) * Fixed bug where AnimationManager::deleteOverlays() deleted all animations svn-id: r42579
Diffstat (limited to 'engines')
-rw-r--r--engines/draci/animation.cpp91
-rw-r--r--engines/draci/animation.h11
2 files changed, 94 insertions, 8 deletions
diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp
index 2a333445ec..74bd8c0534 100644
--- a/engines/draci/animation.cpp
+++ b/engines/draci/animation.cpp
@@ -31,6 +31,8 @@ namespace Draci {
Animation::Animation(DraciEngine *vm) : _vm(vm) {
_id = kUnused;
_z = 0;
+ _relX = 0;
+ _relY = 0;
_playing = false;
_looping = false;
_tick = _vm->_system->getMillis();
@@ -45,6 +47,17 @@ bool Animation::isLooping() {
return _looping;
}
+void Animation::setRelative(int relx, int rely) {
+
+ // Delete the previous frame
+ Common::Rect frameRect = _frames[_currentFrame]->getRect();
+ frameRect.translate(_relX, _relY);
+ _vm->_screen->getSurface()->markDirtyRect(frameRect);
+
+ _relX = relx;
+ _relY = rely;
+}
+
void Animation::setLooping(bool looping) {
_looping = looping;
debugC(7, kDraciAnimationDebugLevel, "Setting looping to %d on animation %d",
@@ -57,9 +70,13 @@ void Animation::nextFrame(bool force) {
if (getFramesNum() < 2 || !_playing)
return;
- Common::Rect frameRect = _frames[_currentFrame]->getRect();
Drawable *frame = _frames[_currentFrame];
+ Common::Rect frameRect = frame->getRect();
+
+ // Translate rectangle to compensate for relative coordinates
+ frameRect.translate(_relX, _relY);
+
if (force || (_tick + frame->getDelay() <= _vm->_system->getMillis())) {
// If we are at the last frame and not looping, stop the animation
// The animation is also restarted to frame zero
@@ -97,7 +114,18 @@ void Animation::drawFrame(Surface *surface) {
_frames[_currentFrame]->draw(surface, false);
}
else {
- _frames[_currentFrame]->draw(surface, true);
+ Drawable *ptr = _frames[_currentFrame];
+ int x = ptr->getX();
+ int y = ptr->getY();
+ int newX = x + _relX;
+ int newY = y + _relY;
+
+ ptr->setX(newX);
+ ptr->setY(newY);
+ ptr->draw(surface, true);
+
+ ptr->setX(x);
+ ptr->setY(y);
}
}
@@ -129,13 +157,23 @@ void Animation::addFrame(Drawable *frame) {
_frames.push_back(frame);
}
+Drawable *Animation::getFrame(int frameNum) {
+
+ // If no argument is passed, return the current frame
+ if (frameNum == kCurrentFrame) {
+ return _frames[_currentFrame];
+ } else {
+ return _frames[frameNum];
+ }
+}
+
uint Animation::getFramesNum() {
return _frames.size();
}
void Animation::deleteFrames() {
- for (uint i = 0; i < getFramesNum(); ++i) {
+ for (int i = getFramesNum() - 1; i >= 0; --i) {
delete _frames[i];
_frames.pop_back();
}
@@ -168,6 +206,11 @@ void AnimationManager::play(int id) {
void AnimationManager::stop(int id) {
Animation *anim = getAnimation(id);
+ // Clean up the last frame that was drawn before stopping
+ Common::Rect frameRect = anim->getFrame()->getRect();
+ frameRect.translate(anim->_relX, anim->_relY);
+ _vm->_screen->getSurface()->markDirtyRect(frameRect);
+
if (anim) {
anim->setPlaying(false);
@@ -215,6 +258,8 @@ void AnimationManager::drawScene(Surface *surf) {
// Fill the screen with colour zero since some rooms may rely on the screen being black
_vm->_screen->getSurface()->fill(0);
+ sortAnimations();
+
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
@@ -227,10 +272,42 @@ void AnimationManager::drawScene(Surface *surf) {
}
}
+void AnimationManager::sortAnimations() {
+ Common::List<Animation *>::iterator cur;
+ Common::List<Animation *>::iterator next;
+
+ cur = _animations.begin();
+
+ // If the list is empty, we're done
+ if (cur == _animations.end())
+ return;
+
+ while(1) {
+ next = cur;
+ next++;
+
+ // If we are at the last element, we're done
+ if (next == _animations.end())
+ break;
+
+ // If we find an animation out of order, reinsert it
+ if ((*next)->getZ() < (*cur)->getZ()) {
+
+ Animation *anim = *cur;
+ _animations.erase(cur);
+
+ insertAnimation(anim);
+ }
+
+ // Advance to next animation
+ cur = next;
+ }
+}
+
void AnimationManager::deleteAnimation(int id) {
Common::List<Animation *>::iterator it;
-
+
for (it = _animations.begin(); it != _animations.end(); ++it) {
if ((*it)->getID() == id) {
(*it)->deleteFrames();
@@ -245,10 +322,10 @@ void AnimationManager::deleteOverlays() {
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
- if((*it)->getID() == kOverlayImage)
+ if ((*it)->getID() == kOverlayImage) {
(*it)->deleteFrames();
-
- _animations.erase(it);
+ _animations.erase(it);
+ }
}
}
diff --git a/engines/draci/animation.h b/engines/draci/animation.h
index fea7fb3f89..66988482f0 100644
--- a/engines/draci/animation.h
+++ b/engines/draci/animation.h
@@ -32,6 +32,8 @@ namespace Draci {
enum { kOverlayImage = -1, kUnused = -2 };
+enum { kCurrentFrame = -1 };
+
class DraciEngine;
class Animation {
@@ -50,6 +52,7 @@ public:
void drawFrame(Surface *surface);
void addFrame(Drawable *frame);
+ Drawable *getFrame(int frameNum = kCurrentFrame);
uint getFramesNum();
void deleteFrames();
@@ -59,6 +62,11 @@ public:
bool isLooping();
void setLooping(bool looping);
+ void setRelative(int relx, int rely);
+
+ int _relX;
+ int _relY;
+
private:
uint nextFrameNum();
@@ -66,6 +74,7 @@ private:
int _id;
uint _currentFrame;
uint _z;
+
uint _tick;
bool _playing;
bool _looping;
@@ -96,7 +105,7 @@ public:
Animation *getAnimation(int id);
private:
-
+ void sortAnimations();
void insertAnimation(Animation *anim);
DraciEngine *_vm;