aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Špalek2009-11-22 20:44:37 +0000
committerRobert Špalek2009-11-22 20:44:37 +0000
commitd3d16422e0177942fcf5045cc65585c10d0da9b0 (patch)
tree5f7723ab50b3eb95ddc0915bc492b9265392fe51
parent772b89682d7ae314d1b776f6c47ab10ac6d865cb (diff)
downloadscummvm-rg350-d3d16422e0177942fcf5045cc65585c10d0da9b0.tar.gz
scummvm-rg350-d3d16422e0177942fcf5045cc65585c10d0da9b0.tar.bz2
scummvm-rg350-d3d16422e0177942fcf5045cc65585c10d0da9b0.zip
Further cleaned up the hack with removing old animations.
Now only a long-term (complete rewrite) TODO is left in the code, but nothing urgent to solve. svn-id: r46097
-rw-r--r--engines/draci/game.cpp37
-rw-r--r--engines/draci/game.h1
2 files changed, 21 insertions, 17 deletions
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index d34b43645a..3ea717c2d9 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -1161,6 +1161,7 @@ void Game::deleteObjectAnimations() {
// survive clearing the sound sample cache when changing the location.
// It's OK to unload them even if they are still in the inventory,
// because we only need their icons which survive.
+ // Start from 1, because 0==kDragonObject.
for (uint i = 1; i < _info._numObjects; ++i) {
GameObject *obj = &_objects[i];
obj->deleteAnims();
@@ -1197,29 +1198,25 @@ void Game::deleteObjectAnimations() {
// be re-loaded next time assuming that they are already correctly
// loaded.
//
- // mini-TODO: integrate this deletion into deleteAnim() an optional
- // parameter with starting index for deletion.
- //
- // Why this only occurs for sound samples and not sprites? This bug is
+ // Why this only occurred for sound samples and not sprites? This bug is
// concealed by a complete coincidence, that all sprites are stored
// column-wise and our class Sprite detects this and creates a local
// copy. If this wasn't the case, each animation (not just with sound
// samples) would fail and preserving the ~20 hero animations wouldn't
// work either.
//
- // TODO: maybe simply deallocate everything except for those ~20 hero
- // animations instead of listing what to deallocate. maybe simply
- // deallocate everything; reloading isn't that expensive.
- //
// TODO: completely rewrite the resource management. maybe implement
// usage counters? maybe completely ignore the GPL2 hints and manage
// memory completely on my own?
+
+ // We don't want to deallocate the first ~20 resident dragon
+ // animations, because they are loaded exactly once in dragon's init
+ // script and we rely upon their existence.
GameObject *dragon = &_objects[kDragonObject];
- for (uint i = dragon->_anim.size() - 1; i >= kFirstTemporaryAnimation; --i) {
- dragon->_anim.back()->del();
- dragon->_anim.pop_back();
- }
- if (dragon->_playingAnim >= kFirstTemporaryAnimation) {
+ dragon->deleteAnimsFrom(kFirstTemporaryAnimation);
+ if (dragon->_playingAnim < 0) {
+ // For the hero, we always need to have exactly 1 playing
+ // animation, otherwise we index an array with -1.
dragon->_playingAnim = 0;
}
}
@@ -1549,11 +1546,17 @@ void GameObject::stopAnim() {
}
void GameObject::deleteAnims() {
- for (uint j = 0; j < _anim.size(); ++j) {
- _anim[j]->del();
+ deleteAnimsFrom(0);
+}
+
+void GameObject::deleteAnimsFrom(int index) {
+ for (int j = _anim.size() - 1; j >= index; --j) {
+ _anim.back()->del();
+ _anim.pop_back();
+ }
+ if (_playingAnim >= index) {
+ _playingAnim = -1;
}
- _anim.clear();
- _playingAnim = -1;
}
void GameObject::load(uint objNum, BArchive *archive) {
diff --git a/engines/draci/game.h b/engines/draci/game.h
index 747bfa07c0..63ad10a814 100644
--- a/engines/draci/game.h
+++ b/engines/draci/game.h
@@ -99,6 +99,7 @@ public:
void playAnim(int i);
void stopAnim();
void deleteAnims();
+ void deleteAnimsFrom(int index);
void load(uint objNum, BArchive *archive);
};