[Scummvm-cvs-logs] SF.net SVN: scummvm:[42579] scummvm/branches/gsoc2009-draci/engines/draci
dkasak13 at users.sourceforge.net
dkasak13 at users.sourceforge.net
Sat Jul 18 04:53:37 CEST 2009
Revision: 42579
http://scummvm.svn.sourceforge.net/scummvm/?rev=42579&view=rev
Author: dkasak13
Date: 2009-07-18 02:53:37 +0000 (Sat, 18 Jul 2009)
Log Message:
-----------
* 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
Modified Paths:
--------------
scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
scummvm/branches/gsoc2009-draci/engines/draci/animation.h
Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp 2009-07-18 01:22:43 UTC (rev 42578)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp 2009-07-18 02:53:37 UTC (rev 42579)
@@ -31,6 +31,8 @@
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 @@
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 @@
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 @@
_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 @@
_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::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 @@
// 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::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 @@
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);
+ }
}
}
Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.h 2009-07-18 01:22:43 UTC (rev 42578)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.h 2009-07-18 02:53:37 UTC (rev 42579)
@@ -32,6 +32,8 @@
enum { kOverlayImage = -1, kUnused = -2 };
+enum { kCurrentFrame = -1 };
+
class DraciEngine;
class Animation {
@@ -50,6 +52,7 @@
void drawFrame(Surface *surface);
void addFrame(Drawable *frame);
+ Drawable *getFrame(int frameNum = kCurrentFrame);
uint getFramesNum();
void deleteFrames();
@@ -59,6 +62,11 @@
bool isLooping();
void setLooping(bool looping);
+ void setRelative(int relx, int rely);
+
+ int _relX;
+ int _relY;
+
private:
uint nextFrameNum();
@@ -66,6 +74,7 @@
int _id;
uint _currentFrame;
uint _z;
+
uint _tick;
bool _playing;
bool _looping;
@@ -96,7 +105,7 @@
Animation *getAnimation(int id);
private:
-
+ void sortAnimations();
void insertAnimation(Animation *anim);
DraciEngine *_vm;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list