From 2457905ed42820d27264a4beccc9ae45da746c18 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 Apr 2014 21:24:35 -0400 Subject: MADS: Fixes for switching between scenes --- engines/mads/game.cpp | 5 ++++- engines/mads/player.cpp | 3 +++ engines/mads/scene.cpp | 7 ++++++- engines/mads/scene.h | 6 ++++++ engines/mads/sprites.cpp | 19 +++++++++++++++---- 5 files changed, 34 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index d964c14451..90ea105bd1 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -143,6 +143,8 @@ void Game::gameLoop() { } _player.releasePlayerSprites(); + assert(_scene._sprites.size() == 0); + _vm->_palette->unlock(); _vm->_events->waitCursor(); _vm->_events->freeCursors(); @@ -271,7 +273,8 @@ void Game::sectionLoop() { _scene._reloadSceneFlag = false; - warning("TODO: sub_1DD8C, sub_1DD7E"); + _scene._userInterface.noInventoryAnim(); + _scene.removeSprites(); if (!_player._loadedFirst) { _player._spritesLoaded = false; diff --git a/engines/mads/player.cpp b/engines/mads/player.cpp index b337f8ada0..10d8b3e327 100644 --- a/engines/mads/player.cpp +++ b/engines/mads/player.cpp @@ -675,6 +675,9 @@ void Player::releasePlayerSprites() { scene._sprites.remove(spriteEnd); } while (--spriteEnd >= _spritesStart); } + + _spritesLoaded = false; + _spritesChanged = true; } } // End of namespace MADS diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 9ef7d0b245..d297cb79ec 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -389,7 +389,7 @@ void Scene::doFrame() { _animFlag = true; _vm->_game->_fx = kTransitionNone; - if (_freeAnimationFlag) { + if (_freeAnimationFlag && _activeAnimation) { _activeAnimation->free(); _activeAnimation = nullptr; } @@ -570,6 +570,11 @@ void Scene::free() { _sceneInfo = nullptr; } +void Scene::removeSprites() { + for (int idx = _sprites.size() - 1; idx >= _spritesCount; --idx) + _sprites.remove(idx); +} + void Scene::changeVariant(int variant) { _variant = variant; _sceneInfo->loadCodes(_depthSurface, variant); diff --git a/engines/mads/scene.h b/engines/mads/scene.h index dbb218842b..b0ecf111e6 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -214,6 +214,12 @@ public: void resetScene(); void backgroundAnimation(); + + /** + * Removes all the scene specific sprites fromt the sprites list, + * leaving any player sprites list in place at the start of the list. + */ + void removeSprites(); }; } // End of namespace MADS diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 442125e929..0dd640bca0 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -372,14 +372,18 @@ int SpriteSets::add(SpriteAsset *asset, int idx) { if (idx >= (int)size()) resize(idx + 1); - delete (*this)[idx]; - (*this)[idx] = asset; + if ((*this)[idx]) { + delete (*this)[idx]; + } else { + ++_assetCount; + } + + (*this)[idx] = asset; return idx; } int SpriteSets::addSprites(const Common::String &resName, int flags) { - ++_assetCount; return add(new SpriteAsset(_vm, resName, flags)); } @@ -394,7 +398,14 @@ void SpriteSets::clear() { void SpriteSets::remove(int idx) { if (idx >= 0) { delete (*this)[idx]; - (*this)[idx] = nullptr; + + if (idx < ((int)size() - 1)) + (*this)[idx] = nullptr; + else { + do { + remove_at(size() - 1); + } while (size() > 0 && (*this)[size() - 1] == nullptr); + } --_assetCount; } -- cgit v1.2.3