Skip to content

Commit

Permalink
COMPOSER: Saving/loading code deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
upthorn authored and angstsmurf committed Oct 18, 2016
1 parent c4c6cce commit d91368a
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 318 deletions.
5 changes: 5 additions & 0 deletions engines/composer/composer.h
Expand Up @@ -29,6 +29,8 @@
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/error.h"
=======
#include "common/serializer.h"
#include "common/textconsole.h"
#include "common/rect.h"

Expand Down Expand Up @@ -148,6 +150,8 @@ struct OldScript {
};

class ComposerEngine : public Engine {
template <typename T>
friend void sync(Common::Serializer &ser, T &data, Common::Serializer::Version minVersion, Common::Serializer::Version maxVersion);
protected:
Common::Error run();

Expand Down Expand Up @@ -238,6 +242,7 @@ class ComposerEngine : public Engine {
void tickOldScripts();
bool tickOldScript(OldScript *script);

void loadAnimation(Animation *&anim, uint16 animId, int16 x, int16 y, int16 eventParam, int32 size = 0);
void playAnimation(uint16 animId, int16 param1, int16 param2, int16 param3);
void stopAnimation(Animation *anim, bool localOnly = false, bool pipesOnly = false);
void playWaveForAnim(uint16 id, uint16 priority, bool bufferingOnly);
Expand Down
54 changes: 32 additions & 22 deletions engines/composer/graphics.cpp
Expand Up @@ -83,17 +83,7 @@ void Animation::seekToCurrPos() {
_stream->seek(_offset, SEEK_SET);
}

void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventParam) {
// First, we check if this animation is already playing,
// and if it is, we sabotage that running one first.
for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
Animation *anim = *i;
if (anim->_id != animId)
continue;

stopAnimation(*i);
}

void ComposerEngine::loadAnimation(Animation *&anim, uint16 animId, int16 x, int16 y, int16 eventParam, int32 size) {
Common::SeekableReadStream *stream = NULL;
Pipe *newPipe = NULL;

Expand All @@ -103,7 +93,10 @@ void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventP
if (!pipe->hasResource(ID_ANIM, animId))
continue;
stream = pipe->getResource(ID_ANIM, animId, false);
break;

// When loading from savegame, make sure we have the correct stream
if ((!size) || (stream->size() >= size)) break;
stream = NULL;
}

// If we didn't find it, try the libraries.
Expand All @@ -112,14 +105,16 @@ void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventP
warning("ignoring attempt to play invalid anim %d", animId);
return;
}
stream = getResource(ID_ANIM, animId);
Common::List<Library>::iterator j;
for (j = _libraries.begin(); j != _libraries.end(); j++) {
stream = j->_archive->getResource(ID_ANIM, animId);

uint32 type = 0;
for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++)
if (i->_archive->hasResource(ID_ANIM, animId)) {
type = i->_archive->getResourceFlags(ID_ANIM, animId);
break;
}
// When loading from savegame, make sure we have the correct stream
if ((!size) || (stream->size() >= size)) break;
stream = NULL;
}

uint32 type = j->_archive->getResourceFlags(ID_ANIM, animId);

// If the resource is a pipe itself, then load the pipe
// and then fish the requested animation out of it.
Expand All @@ -132,13 +127,28 @@ void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventP
}
}

Animation *anim = new Animation(stream, animId, Common::Point(x, y), eventParam);
_anims.push_back(anim);
runEvent(kEventAnimStarted, animId, eventParam, 0);
anim = new Animation(stream, animId, Common::Point(x, y), eventParam);
if (newPipe)
newPipe->_anim = anim;
}

void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventParam) {
// First, we check if this animation is already playing,
// and if it is, we sabotage that running one first.
for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
Animation *anim = *i;
if (anim->_id != animId)
continue;

stopAnimation(*i);
}

Animation *anim = NULL;
loadAnimation(anim, animId, x, y, eventParam);
_anims.push_back(anim);
runEvent(kEventAnimStarted, animId, eventParam, 0);
}

void ComposerEngine::stopAnimation(Animation *anim, bool localOnly, bool pipesOnly) {
// disable the animation
anim->_state = 0;
Expand Down

0 comments on commit d91368a

Please sign in to comment.