Skip to content

Commit

Permalink
ZVISION: Move lever code to use MetaAnimation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Jan 17, 2014
1 parent ff2a208 commit 9c9f59d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
34 changes: 9 additions & 25 deletions engines/zvision/lever_control.cpp
Expand Up @@ -28,8 +28,7 @@
#include "zvision/script_manager.h"
#include "zvision/render_manager.h"
#include "zvision/cursor_manager.h"
#include "zvision/rlf_animation.h"
#include "zvision/zork_avi_decoder.h"
#include "zvision/meta_animation.h"
#include "zvision/utility.h"

#include "common/stream.h"
Expand Down Expand Up @@ -79,11 +78,8 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre
}

LeverControl::~LeverControl() {
if (_fileType == AVI) {
delete _animation.avi;
} else if (_fileType == RLF) {
delete _animation.rlf;
}
if (_animation)
delete _animation;

delete[] _frameInfo;
}
Expand All @@ -106,14 +102,9 @@ void LeverControl::parseLevFile(const Common::String &fileName) {

Common::String animationFileName(fileNameBuffer);

if (animationFileName.hasSuffix(".avi")) {
_animation.avi = new ZorkAVIDecoder();
_animation.avi->loadFile(animationFileName);
_fileType = AVI;
} else if (animationFileName.hasSuffix(".rlf")) {
_animation.rlf = new RlfAnimation(animationFileName, false);
_fileType = RLF;
}
if (animationFileName.hasSuffix(".avi") || animationFileName.hasSuffix(".rlf"))
_animation = new MetaAnimation(animationFileName);

} else if (line.matchString("*skipcolor*", true)) {
// Not used
} else if (line.matchString("*anim_coords*", true)) {
Expand Down Expand Up @@ -379,16 +370,9 @@ void LeverControl::renderFrame(uint frameNumber) {
int x = _animationCoords.left;
int y = _animationCoords.top;

if (_fileType == RLF) {
// getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can
frameData = _animation.rlf->getFrameData(frameNumber);
} else if (_fileType == AVI) {
_animation.avi->seekToFrame(frameNumber);
const Graphics::Surface *surface = _animation.avi->decodeNextFrame();
frameData = surface;
}

_engine->getRenderManager()->blitSurfaceToBkg(*frameData, x, y);
frameData = _animation->getFrameData(frameNumber);
if (frameData)
_engine->getRenderManager()->blitSurfaceToBkg(*frameData, x, y);
}

} // End of namespace ZVision
12 changes: 2 additions & 10 deletions engines/zvision/lever_control.h
Expand Up @@ -32,18 +32,14 @@
namespace ZVision {

class ZorkAVIDecoder;
class RlfAnimation;
class MetaAnimation;

class LeverControl : public Control {
public:
LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
~LeverControl();

private:
enum FileType {
RLF = 1,
AVI = 2
};

struct Direction {
Direction(uint a, uint t) : angle(a), toFrame(t) {}
Expand All @@ -64,11 +60,7 @@ class LeverControl : public Control {
};

private:
union {
RlfAnimation *rlf;
ZorkAVIDecoder *avi;
} _animation;
FileType _fileType;
MetaAnimation *_animation;

Common::String _cursorName;
Common::Rect _animationCoords;
Expand Down

0 comments on commit 9c9f59d

Please sign in to comment.