Reduced huge code duplication by introducing Game::stopObjectAnimations()

svn-id: r44961
This commit is contained in:
Robert Špalek 2009-10-12 00:15:34 +00:00
parent 6aaf99ec67
commit 3ef5145b41
3 changed files with 12 additions and 22 deletions

View file

@ -952,10 +952,7 @@ void Game::walkHero(int x, int y) {
_hero = _currentRoom._walkingMap.findNearestWalkable(x, y, surface->getRect()); _hero = _currentRoom._walkingMap.findNearestWalkable(x, y, surface->getRect());
GameObject *dragon = getObject(kDragonObject); GameObject *dragon = getObject(kDragonObject);
stopObjectAnimations(dragon);
for (uint i = 0; i < dragon->_anim.size(); ++i) {
_vm->_anims->stop(dragon->_anim[i]);
}
debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", _hero.x, _hero.y); debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", _hero.x, _hero.y);
@ -1297,9 +1294,7 @@ void Game::enterNewRoom(bool force_reload) {
// TODO: Make objects capable of stopping their own animations // TODO: Make objects capable of stopping their own animations
const GameObject *dragon = getObject(kDragonObject); const GameObject *dragon = getObject(kDragonObject);
for (uint i = 0; i < dragon->_anim.size(); ++i) { stopObjectAnimations(dragon);
_vm->_anims->stop(dragon->_anim[i]);
}
// Remember the previous room for returning back from the map. // Remember the previous room for returning back from the map.
rememberRoomNumAsPrevious(); rememberRoomNumAsPrevious();
@ -1530,6 +1525,12 @@ void Game::deleteAnimationsAfterIndex(int lastAnimIndex) {
_vm->_anims->deleteAfterIndex(lastAnimIndex); _vm->_anims->deleteAfterIndex(lastAnimIndex);
} }
void Game::stopObjectAnimations(const GameObject *obj) {
for (uint i = 0; i < obj->_anim.size(); ++i) {
_vm->_anims->stop(obj->_anim[i]);
}
}
/** /**
* See Game::getMarkedAnimationIndex(). * See Game::getMarkedAnimationIndex().
*/ */

View file

@ -271,6 +271,7 @@ public:
int getObjectWithAnimation(int animID) const; int getObjectWithAnimation(int animID) const;
void deleteObjectAnimations(); void deleteObjectAnimations();
void deleteAnimationsAfterIndex(int lastAnimIndex); void deleteAnimationsAfterIndex(int lastAnimIndex);
void stopObjectAnimations(const GameObject *obj);
int getVariable(int varNum) const; int getVariable(int varNum) const;
void setVariable(int varNum, int value); void setVariable(int varNum, int value);

View file

@ -411,12 +411,7 @@ void Script::start(Common::Queue<int> &params) {
int animID = params.pop() - 1; int animID = params.pop() - 1;
GameObject *obj = _vm->_game->getObject(objID); GameObject *obj = _vm->_game->getObject(objID);
_vm->_game->stopObjectAnimations(obj);
// Stop all animation that the object owns
for (uint i = 0; i < obj->_anim.size(); ++i) {
_vm->_anims->stop(obj->_anim[i]);
}
Animation *anim = _vm->_anims->getAnimation(animID); Animation *anim = _vm->_anims->getAnimation(animID);
if (!anim) { if (!anim) {
@ -463,12 +458,7 @@ void Script::startPlay(Common::Queue<int> &params) {
int animID = params.pop() - 1; int animID = params.pop() - 1;
GameObject *obj = _vm->_game->getObject(objID); GameObject *obj = _vm->_game->getObject(objID);
_vm->_game->stopObjectAnimations(obj);
// Stop all animation that the object owns
for (uint i = 0; i < obj->_anim.size(); ++i) {
_vm->_anims->stop(obj->_anim[i]);
}
Animation *anim = _vm->_anims->getAnimation(animID); Animation *anim = _vm->_anims->getAnimation(animID);
if (!anim) { if (!anim) {
@ -599,9 +589,7 @@ void Script::objStat(Common::Queue<int> &params) {
obj->_location = -1; obj->_location = -1;
} }
for (uint i = 0; i < obj->_anim.size(); ++i) { _vm->_game->stopObjectAnimations(obj);
_vm->_anims->stop(obj->_anim[i]);
}
} }
void Script::execInit(Common::Queue<int> &params) { void Script::execInit(Common::Queue<int> &params) {