aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2015-03-14 10:11:19 -0400
committerPaul Gilbert2015-03-14 10:11:19 -0400
commit0f02cdb4aa0a0e29bea414583a6db8a5ae389f49 (patch)
tree2cb0bbd477458f9b65804ace4819ba5a542da932 /engines
parent1f8845e9f433365c3586240b4e395cf888ec770b (diff)
downloadscummvm-rg350-0f02cdb4aa0a0e29bea414583a6db8a5ae389f49.tar.gz
scummvm-rg350-0f02cdb4aa0a0e29bea414583a6db8a5ae389f49.tar.bz2
scummvm-rg350-0f02cdb4aa0a0e29bea414583a6db8a5ae389f49.zip
MADS: Fix crash in stream crossing death, simplify SpriteSets class
Diffstat (limited to 'engines')
-rw-r--r--engines/mads/game.cpp2
-rw-r--r--engines/mads/player.cpp2
-rw-r--r--engines/mads/scene.cpp2
-rw-r--r--engines/mads/sprites.cpp52
-rw-r--r--engines/mads/sprites.h8
5 files changed, 35 insertions, 31 deletions
diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp
index 74c2a3f416..b601a12c82 100644
--- a/engines/mads/game.cpp
+++ b/engines/mads/game.cpp
@@ -160,7 +160,7 @@ void Game::gameLoop() {
sectionLoop();
_player.releasePlayerSprites();
- assert(_scene._sprites._assetCount == 0);
+ assert(_scene._sprites.size() == 0);
_vm->_palette->unlock();
_vm->_events->waitCursor();
diff --git a/engines/mads/player.cpp b/engines/mads/player.cpp
index 38e8638415..f61a5a1592 100644
--- a/engines/mads/player.cpp
+++ b/engines/mads/player.cpp
@@ -709,7 +709,7 @@ void Player::releasePlayerSprites() {
_spritesLoaded = false;
_spritesChanged = true;
- if (scene._sprites._assetCount > 0) {
+ if (scene._sprites.size() > 0) {
warning("Player::releasePlayerSprites(): leftover sprites remain, clearing list");
scene._sprites.clear();
}
diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp
index bbc83a791b..463d4a62fd 100644
--- a/engines/mads/scene.cpp
+++ b/engines/mads/scene.cpp
@@ -676,7 +676,7 @@ void Scene::freeCurrentScene() {
}
void Scene::removeSprites() {
- for (int idx = _sprites._assetCount - 1; idx >= _spritesCount; --idx)
+ for (int idx = _sprites.size() - 1; idx >= _spritesCount; --idx)
_sprites.remove(idx);
}
diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp
index 19742e22b0..6488add86c 100644
--- a/engines/mads/sprites.cpp
+++ b/engines/mads/sprites.cpp
@@ -368,19 +368,18 @@ SpriteSets::~SpriteSets() {
}
int SpriteSets::add(SpriteAsset *asset, int idx) {
- if (idx)
- idx = idx + 49;
- else
- idx = _assetCount++;
+ if (idx) {
+ assert(idx == 1);
+ delete _uiSprites;
+ _uiSprites = asset;
- if (idx >= (int)size())
- resize(idx + 1);
+ return SPRITE_SLOTS_MAX_SIZE;
+ } else {
+ assert(size() < SPRITE_SLOTS_MAX_SIZE);
+ push_back(asset);
- if ((*this)[idx])
- delete (*this)[idx];
-
- (*this)[idx] = asset;
- return idx;
+ return (int)size() - 1;
+ }
}
int SpriteSets::addSprites(const Common::String &resName, int flags) {
@@ -390,26 +389,29 @@ int SpriteSets::addSprites(const Common::String &resName, int flags) {
void SpriteSets::clear() {
for (uint i = 0; i < size(); ++i)
delete (*this)[i];
-
- _assetCount = 0;
Common::Array<SpriteAsset *>::clear();
+
+ delete _uiSprites;
+ _uiSprites = nullptr;
}
void SpriteSets::remove(int idx) {
- if (idx >= 0) {
- if (idx < ((int)size() - 1)) {
- delete (*this)[idx];
- (*this)[idx] = nullptr;
- } else {
- do {
- delete (*this)[size() - 1];
- remove_at(size() - 1);
- } while (size() > 0 && (*this)[size() - 1] == nullptr);
- }
+ if (idx == SPRITE_SLOTS_MAX_SIZE) {
+ delete _uiSprites;
+ _uiSprites = nullptr;
+ } else if (idx >= 0) {
+ delete (*this)[idx];
- if (idx < 50 && _assetCount > 0)
- --_assetCount;
+ if (idx == ((int)size() - 1))
+ remove_at(size() - 1);
+ else
+ (*this)[idx] = nullptr;
}
}
+SpriteAsset *&SpriteSets::operator[](int idx) {
+ return (idx == SPRITE_SLOTS_MAX_SIZE) ? _uiSprites :
+ Common::Array<SpriteAsset *>::operator[](idx);
+}
+
} // End of namespace MADS
diff --git a/engines/mads/sprites.h b/engines/mads/sprites.h
index 6ea3c9e52e..bb5fdbe964 100644
--- a/engines/mads/sprites.h
+++ b/engines/mads/sprites.h
@@ -202,12 +202,12 @@ class SpriteSets : public Common::Array<SpriteAsset *> {
private:
MADSEngine *_vm;
public:
- int _assetCount;
-
+ SpriteAsset *_uiSprites;
+public:
/**
* Constructor
*/
- SpriteSets(MADSEngine *vm) : _vm(vm), _assetCount(0) {}
+ SpriteSets(MADSEngine *vm) : _vm(vm), _uiSprites(nullptr) {}
/**
* Destructor
@@ -233,6 +233,8 @@ public:
* Remove an asset from the list
*/
void remove(int idx);
+
+ SpriteAsset *&operator[](int idx);
};
} // End of namespace MADS