Skip to content

Commit

Permalink
SHERLOCK: Revised door close fix due to new bug when entering morgue
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 3, 2015
1 parent f97e550 commit 0a2c50d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
31 changes: 17 additions & 14 deletions engines/sherlock/scene.cpp
Expand Up @@ -83,6 +83,17 @@ void SceneSound::synchronize(Common::SeekableReadStream &s) {

/*----------------------------------------------------------------*/

int ObjectArray::indexOf(const Object &obj) const {
for (uint idx = 0; idx < size(); ++idx) {
if (&(*this)[idx] == &obj)
return idx;
}

return -1;
}

/*----------------------------------------------------------------*/

Scene::Scene(SherlockEngine *vm): _vm(vm) {
for (int idx = 0; idx < SCENES_COUNT; ++idx)
Common::fill(&_sceneStats[idx][0], &_sceneStats[idx][65], false);
Expand Down Expand Up @@ -1047,18 +1058,9 @@ int Scene::startCAnim(int cAnimNum, int playRate) {
if (cObj._frameNumber <= 26)
gotoCode = cObj._sequences[cObj._frameNumber + 3];

// Set canim to REMOVE type and free memory
cObj.checkObject();
for (uint idx = 0; idx < _canimShapes.size(); ++idx) {
if (&_canimShapes[idx] == &cObj) {
// Do a final call to doBgAnim to erase the anim shape before it's erased
doBgAnim();

// Remove the completed sprite from the animation shapes array
_canimShapes.remove_at(idx);
break;
}
}
// Unless anim shape has already been freed, set it to REMOVE so doBgAnim can free it
if (_canimShapes.indexOf(cObj) != -1)
cObj.checkObject();

if (gotoCode > 0 && !talk._talkToAbort) {
_goToScene = gotoCode;
Expand Down Expand Up @@ -1377,13 +1379,14 @@ void Scene::doBgAnim() {
}
}

for (uint idx = 0; idx < _canimShapes.size(); ++idx) {
for (int idx = _canimShapes.size() - 1; idx >= 0; --idx) {
Object &o = _canimShapes[idx];
if (o._type == REMOVE) {
if (_goToScene == -1)
screen.slamArea(o._position.x, o._position.y, o._delta.x, o._delta.y);

_canimShapes[idx]._type = INVALID;
// Shape for an animation is no longer needed, so remove it completely
_canimShapes.remove_at(idx);
} else if (o._type == ACTIVE_BG_SHAPE) {
screen.flushImage(o._imageFrame, o._position,
&o._oldPosition.x, &o._oldPosition.y, &o._oldSize.x, &o._oldSize.y);
Expand Down
7 changes: 6 additions & 1 deletion engines/sherlock/scene.h
Expand Up @@ -83,6 +83,11 @@ struct SceneSound {
void synchronize(Common::SeekableReadStream &s);
};

class ObjectArray: public Common::Array<Object> {
public:
int indexOf(const Object &obj) const;
};

class Scene {
private:
SherlockEngine *_vm;
Expand Down Expand Up @@ -127,7 +132,7 @@ class Scene {
Common::Array<Exit> _exits;
SceneEntry _entrance;
Common::Array<SceneSound> _sounds;
Common::Array<Object> _canimShapes;
ObjectArray _canimShapes;
bool _restoreFlag;
int _animating;
bool _doBgAnimDone;
Expand Down

0 comments on commit 0a2c50d

Please sign in to comment.