diff options
author | Denis Kasak | 2009-07-12 19:32:01 +0000 |
---|---|---|
committer | Denis Kasak | 2009-07-12 19:32:01 +0000 |
commit | 77a810c0c9beed930a4b0ffe8e715bd22d7be448 (patch) | |
tree | d8bd831705b8959818705c685e3acc630f3ae8ba | |
parent | eef64cc737fd9a4877822281c88395b73f0720f7 (diff) | |
download | scummvm-rg350-77a810c0c9beed930a4b0ffe8e715bd22d7be448.tar.gz scummvm-rg350-77a810c0c9beed930a4b0ffe8e715bd22d7be448.tar.bz2 scummvm-rg350-77a810c0c9beed930a4b0ffe8e715bd22d7be448.zip |
Moved the delay mechanism from Animation to Drawable since each frame in an animation can have a different delay.
svn-id: r42427
-rw-r--r-- | engines/draci/animation.cpp | 15 | ||||
-rw-r--r-- | engines/draci/animation.h | 3 | ||||
-rw-r--r-- | engines/draci/game.cpp | 8 | ||||
-rw-r--r-- | engines/draci/sprite.cpp | 3 | ||||
-rw-r--r-- | engines/draci/sprite.h | 8 |
5 files changed, 20 insertions, 17 deletions
diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp index d48560a550..c3f5a2dc95 100644 --- a/engines/draci/animation.cpp +++ b/engines/draci/animation.cpp @@ -33,7 +33,6 @@ Animation::Animation(DraciEngine *vm) : _vm(vm) { _z = 0; _playing = false; _looping = false; - _delay = 0; _tick = _vm->_system->getMillis(); _currentFrame = 0; } @@ -52,12 +51,6 @@ void Animation::setLooping(bool looping) { looping, _id); } -void Animation::setDelay(uint delay) { - _delay = delay; - debugC(7, kDraciAnimationDebugLevel, "Setting delay to %u on animation %d", - delay, _id); -} - void Animation::nextFrame(bool force) { // If there's only one or no frames, return @@ -65,8 +58,9 @@ void Animation::nextFrame(bool force) { return; Common::Rect frameRect = _frames[_currentFrame]->getRect(); + Drawable *frame = _frames[_currentFrame]; - if (force || (_tick + _delay <= _vm->_system->getMillis())) { + 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 if ((_currentFrame == getFramesNum() - 1) && !_looping) { @@ -75,13 +69,14 @@ void Animation::nextFrame(bool force) { } else { _vm->_screen->getSurface()->markDirtyRect(frameRect); _currentFrame = nextFrameNum(); - _tick += _delay; + _tick += frame->getDelay(); } } debugC(6, kDraciAnimationDebugLevel, "anim=%d tick=%d delay=%d tick+delay=%d currenttime=%d frame=%d framenum=%d", - _id, _tick, _delay, _tick + _delay, _vm->_system->getMillis(), _currentFrame, _frames.size()); + _id, _tick, frame->getDelay(), _tick + frame->getDelay(), _vm->_system->getMillis(), + _currentFrame, _frames.size()); } uint Animation::nextFrameNum() { diff --git a/engines/draci/animation.h b/engines/draci/animation.h index cef8182f7b..fea7fb3f89 100644 --- a/engines/draci/animation.h +++ b/engines/draci/animation.h @@ -46,8 +46,6 @@ public: void setID(int id); int getID(); - void setDelay(uint delay); - void nextFrame(bool force = false); void drawFrame(Surface *surface); @@ -68,7 +66,6 @@ private: int _id; uint _currentFrame; uint _z; - uint _delay; uint _tick; bool _playing; bool _looping; diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 3832768f23..2fbb65b829 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -217,7 +217,9 @@ int Game::loadAnimation(uint animNum, uint z) { animationReader.readByte(); // Relative field, not used Animation *anim = _vm->_anims->addAnimation(animNum, z, false); - + + anim->setLooping(cyclic); + for (uint i = 0; i < numFrames; ++i) { uint spriteNum = animationReader.readUint16LE() - 1; int x = animationReader.readSint16LE(); @@ -229,8 +231,6 @@ int Game::loadAnimation(uint animNum, uint z) { uint freq = animationReader.readUint16LE(); uint delay = animationReader.readUint16LE(); - anim->setDelay(delay * 10); - BAFile *spriteFile = _vm->_spritesArchive->getFile(spriteNum); Sprite *sp = new Sprite(spriteFile->_data, spriteFile->_length, x, y, true); @@ -238,7 +238,7 @@ int Game::loadAnimation(uint animNum, uint z) { if (mirror) sp->setMirrorOn(); - anim->setLooping(cyclic); + sp->setDelay(delay * 10); anim->addFrame(sp); } diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index aad7753b03..dae7a289a2 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -61,6 +61,7 @@ Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y, _height = height; _x = x; _y = y; + _delay = 0; _mirror = false; @@ -83,6 +84,7 @@ Sprite::Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise) _x = x; _y = y; + _delay = 0; _mirror = false; @@ -180,6 +182,7 @@ Text::Text(const Common::String &str, Font *font, byte fontColour, _x = x; _y = y; + _delay = 0; _text = new byte[len]; memcpy(_text, str.c_str(), len); diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h index 3e881914ca..38ee2736ea 100644 --- a/engines/draci/sprite.h +++ b/engines/draci/sprite.h @@ -49,12 +49,20 @@ public: virtual void setX(int x) { _x = x; } virtual void setY(int y) { _y = y; } + void setDelay(int delay) { _delay = delay; } + int getDelay() { return _delay; } + virtual Common::Rect getRect() const = 0; private: uint16 _width; //!< Width of the sprite uint16 _height; //!< Height of the sprite int _x, _y; //!< Sprite coordinates + + /** The time a drawable should stay on the screen + * before being replaced by another or deleted + */ + int _delay; }; /** |