2009-07-01 16:20:47 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
#include "draci/draci.h"
|
|
|
|
#include "draci/animation.h"
|
|
|
|
|
2009-07-01 16:20:47 +00:00
|
|
|
namespace Draci {
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
AnimObj::AnimObj(DraciEngine *vm) : _vm(vm) {
|
|
|
|
_id = kUnused;
|
|
|
|
_z = 0;
|
|
|
|
_playing = false;
|
|
|
|
_looping = false;
|
|
|
|
_delay = 0;
|
|
|
|
_tick = _vm->_system->getMillis();
|
|
|
|
_currentFrame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimObj::~AnimObj() {
|
|
|
|
deleteFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimObj::isLooping() {
|
|
|
|
return _looping;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimObj::setLooping(bool looping) {
|
|
|
|
_looping = looping;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimObj::setDelay(uint delay) {
|
|
|
|
_delay = delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimObj::nextFrame(bool force) {
|
|
|
|
|
|
|
|
// If there's only one or no frames, return
|
|
|
|
if (getFramesNum() < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Common::Rect frameRect = _frames[_currentFrame]->getRect();
|
|
|
|
|
|
|
|
// If we are at the last frame and not looping, stop the animation
|
|
|
|
// The animation is also restarted to frame zero
|
|
|
|
if ((_currentFrame == nextFrameNum() - 1) && !_looping) {
|
|
|
|
_currentFrame = 0;
|
|
|
|
_playing = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (force || (_tick + _delay <= _vm->_system->getMillis())) {
|
|
|
|
_vm->_screen->getSurface()->markDirtyRect(frameRect);
|
|
|
|
_currentFrame = nextFrameNum();
|
|
|
|
_tick = _vm->_system->getMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(6, kDraciAnimationDebugLevel,
|
|
|
|
"tick=%d delay=%d tick+delay=%d currenttime=%d frame=%d framenum=%d",
|
|
|
|
_tick, _delay, _tick + _delay, _vm->_system->getMillis(), _currentFrame, _frames.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint AnimObj::nextFrameNum() {
|
|
|
|
|
|
|
|
if ((_currentFrame == getFramesNum() - 1) && _looping)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return _currentFrame + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimObj::drawFrame(Surface *surface) {
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
if (_frames.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_id == kOverlayImage) {
|
|
|
|
_frames[_currentFrame]->draw(surface, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_frames[_currentFrame]->draw(surface, true);
|
|
|
|
}
|
|
|
|
}
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void AnimObj::setID(int id) {
|
|
|
|
|
|
|
|
_id = id;
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
int AnimObj::getID() {
|
|
|
|
|
|
|
|
return _id;
|
|
|
|
}
|
2009-07-03 19:05:58 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void AnimObj::setZ(uint z) {
|
2009-07-03 19:05:58 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
_z = z;
|
2009-07-03 19:05:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
uint AnimObj::getZ() {
|
|
|
|
|
|
|
|
return _z;
|
|
|
|
}
|
2009-07-03 19:05:58 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
bool AnimObj::isPlaying() {
|
2009-07-03 19:05:58 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
return _playing;
|
2009-07-03 19:05:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void AnimObj::setPlaying(bool playing) {
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
_playing = playing;
|
|
|
|
}
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void AnimObj::addFrame(Drawable *frame) {
|
|
|
|
|
|
|
|
_frames.push_back(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint AnimObj::getFramesNum() {
|
|
|
|
|
|
|
|
return _frames.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimObj::deleteFrames() {
|
|
|
|
|
|
|
|
for (uint i = 0; i < getFramesNum(); ++i) {
|
|
|
|
delete _frames[i];
|
|
|
|
_frames.pop_back();
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
2009-07-05 03:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimObj *Animation::addAnimation(int id, uint z, bool playing) {
|
|
|
|
|
|
|
|
AnimObj *obj = new AnimObj(_vm);
|
|
|
|
obj->setID(id);
|
|
|
|
obj->setZ(z);
|
|
|
|
obj->setPlaying(playing);
|
|
|
|
obj->setLooping(false);
|
|
|
|
|
|
|
|
insertAnimation(obj);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::play(int id) {
|
|
|
|
|
|
|
|
AnimObj *obj = getAnimation(id);
|
|
|
|
|
|
|
|
obj->setPlaying(true);
|
|
|
|
}
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void Animation::stop(int id) {
|
|
|
|
|
|
|
|
AnimObj *obj = getAnimation(id);
|
|
|
|
|
|
|
|
obj->setPlaying(false);
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
AnimObj *Animation::getAnimation(int id) {
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
Common::List<AnimObj *>::iterator it;
|
2009-07-03 17:50:22 +00:00
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
2009-07-05 03:24:46 +00:00
|
|
|
if ((*it)->getID() == id) {
|
|
|
|
return *it;
|
|
|
|
}
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
return *_animObjects.end();
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void Animation::insertAnimation(AnimObj *animObj) {
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
Common::List<AnimObj *>::iterator it;
|
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
|
|
|
if (animObj->getZ() < (*it)->getZ())
|
|
|
|
break;
|
|
|
|
}
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
_animObjects.insert(it, animObj);
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::addOverlay(Drawable *overlay, uint z) {
|
2009-07-05 03:24:46 +00:00
|
|
|
AnimObj *obj = new AnimObj(_vm);
|
|
|
|
obj->setID(kOverlayImage);
|
|
|
|
obj->setZ(z);
|
|
|
|
obj->setPlaying(true);
|
|
|
|
obj->addFrame(overlay);
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
insertAnimation(obj);
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::drawScene(Surface *surf) {
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
Common::List<AnimObj *>::iterator it;
|
2009-07-03 17:50:22 +00:00
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
2009-07-05 03:24:46 +00:00
|
|
|
if (! ((*it)->isPlaying()) ) {
|
2009-07-03 19:05:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
(*it)->nextFrame();
|
|
|
|
(*it)->drawFrame(surf);
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
void Animation::deleteAnimation(int id) {
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
Common::List<AnimObj *>::iterator it;
|
2009-07-03 17:50:22 +00:00
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
|
|
|
if ((*it)->getID() == id)
|
|
|
|
break;
|
2009-07-03 18:19:51 +00:00
|
|
|
}
|
2009-07-05 03:24:46 +00:00
|
|
|
|
|
|
|
(*it)->deleteFrames();
|
2009-07-03 18:19:51 +00:00
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
_animObjects.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::deleteAll() {
|
|
|
|
|
2009-07-05 03:24:46 +00:00
|
|
|
Common::List<AnimObj *>::iterator it;
|
2009-07-03 18:19:51 +00:00
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
2009-07-05 03:24:46 +00:00
|
|
|
(*it)->deleteFrames();
|
2009-07-03 18:19:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
_animObjects.clear();
|
2009-07-01 16:20:47 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|