[Scummvm-cvs-logs] SF.net SVN: scummvm:[42652] scummvm/branches/gsoc2009-draci/engines/draci
dkasak13 at users.sourceforge.net
dkasak13 at users.sourceforge.net
Wed Jul 22 09:18:00 CEST 2009
Revision: 42652
http://scummvm.svn.sourceforge.net/scummvm/?rev=42652&view=rev
Author: dkasak13
Date: 2009-07-22 07:18:00 +0000 (Wed, 22 Jul 2009)
Log Message:
-----------
* Stopped AnimationManager::drawScene() from marking its own dirtiness.
* Instead, Animation::nextFrame() marks both the old and the new frame dirty. This makes it possible to only update the real screen when the animation changes and results in a pretty big speedup.
* Added utility method Animation::markDirtyRect() which takes a (Surface *) and marks a dirty rect on it for the current frame.
* Fixed artifacts when moving the dragon.
Modified Paths:
--------------
scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
scummvm/branches/gsoc2009-draci/engines/draci/animation.h
scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp 2009-07-22 05:03:34 UTC (rev 42651)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp 2009-07-22 07:18:00 UTC (rev 42652)
@@ -50,12 +50,8 @@
void Animation::setRelative(int relx, int rely) {
// Delete the previous frame
- Common::Rect frameRect;
+ markDirtyRect(_vm->_screen->getSurface());
- frameRect = getFrame()->getRect();
- frameRect.translate(_relX, _relY);
- _vm->_screen->getSurface()->markDirtyRect(frameRect);
-
_relX = relx;
_relY = rely;
}
@@ -66,6 +62,18 @@
looping, _id);
}
+void Animation::markDirtyRect(Surface *surface) {
+ // Fetch the current frame's rectangle
+ Drawable *frame = _frames[_currentFrame];
+ Common::Rect frameRect = frame->getRect();
+
+ // Translate rectangle to compensate for relative coordinates
+ frameRect.translate(_relX, _relY);
+
+ // Mark the rectangle dirty on the surface
+ surface->markDirtyRect(frameRect);
+}
+
void Animation::nextFrame(bool force) {
// If there's only one or no frames, or if the animation is not playing, return
@@ -73,13 +81,8 @@
return;
Drawable *frame = _frames[_currentFrame];
-
- Common::Rect frameRect;
- frameRect = frame->getRect();
+ Surface *surface = _vm->_screen->getSurface();
- // 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
@@ -87,9 +90,14 @@
_currentFrame = 0;
setPlaying(false);
} else {
- _vm->_screen->getSurface()->markDirtyRect(frameRect);
+ // Mark old frame dirty so it gets deleted
+ markDirtyRect(surface);
+
_currentFrame = nextFrameNum();
_tick = _vm->_system->getMillis();
+
+ // Fetch new frame and mark it dirty
+ markDirtyRect(surface);
}
}
@@ -131,7 +139,7 @@
frame->setY(newY);
// Draw frame
- frame->drawScaled(surface, true);
+ frame->drawScaled(surface, false);
// Revert back to old coordinates
frame->setX(x);
@@ -215,6 +223,9 @@
void AnimationManager::play(int id) {
Animation *anim = getAnimation(id);
+ // Mark the first frame dirty so it gets displayed
+ anim->markDirtyRect(_vm->_screen->getSurface());
+
if (anim) {
anim->setPlaying(true);
@@ -226,13 +237,8 @@
Animation *anim = getAnimation(id);
// Clean up the last frame that was drawn before stopping
- Common::Rect frameRect;
+ anim->markDirtyRect(_vm->_screen->getSurface());
- frameRect = anim->getFrame()->getRect();
-
- frameRect.translate(anim->getRelativeX(), anim->getRelativeY());
- _vm->_screen->getSurface()->markDirtyRect(frameRect);
-
if (anim) {
anim->setPlaying(false);
Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.h 2009-07-22 05:03:34 UTC (rev 42651)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.h 2009-07-22 07:18:00 UTC (rev 42652)
@@ -66,6 +66,8 @@
int getRelativeX();
int getRelativeY();
+ void markDirtyRect(Surface *surface);
+
private:
uint nextFrameNum();
Modified: scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/game.cpp 2009-07-22 05:03:34 UTC (rev 42651)
+++ scummvm/branches/gsoc2009-draci/engines/draci/game.cpp 2009-07-22 07:18:00 UTC (rev 42652)
@@ -181,8 +181,23 @@
double scaleX = _currentRoom._pers0 + _currentRoom._persStep * y;
double scaleY = scaleX;
- Drawable *frame;
+ // Set the Z coordinate for the dragon's animation
+ anim->setZ(y+1);
+ // Fetch current frame
+ Drawable *frame = anim->getFrame();
+
+ // Fetch base height of the frame
+ uint height = frame->getHeight();
+
+ // We naturally want the dragon to position its feet to the location of the
+ // click but sprites are drawn from their top-left corner so we subtract
+ // the current height of the dragon's sprite
+ // We also need to do this before we change the frames' scaled dimensions
+ // so setRelative() can correctly delete the old frame
+ y -= scaleY * height;
+ anim->setRelative(x, y);
+
// Set the scaled dimensions for all frames
for (uint i = 0; i < anim->getFramesNum(); ++i) {
frame = anim->getFrame(i);
@@ -194,15 +209,6 @@
frame->setScaled(scaledWidth, scaledHeight);
}
- // Set the Z coordinate for the dragon's animation
- anim->setZ(y+1);
-
- // We naturally want the dragon to position its feet to the location of the
- // click but sprites are drawn from their top-left corner so we subtract
- // the current height of the dragon's sprite
- y -= frame->getScaledHeight();
- anim->setRelative(x, y);
-
// Play the animation
_vm->_anims->play(animID);
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