[Scummvm-cvs-logs] scummvm master -> 77705752efa00ab7f6c65ff8d99e4d9c3fdc4929

bluegr bluegr at gmail.com
Tue Dec 16 01:00:35 CET 2014


This automated email contains information about 10 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
409ce79a35 ZVISION: Rename RlfAnimation -> RLFDecoder
3315522ba1 ZVISION: Move the RLF decoder
3d1a9e3442 ZVISION: Simplify the working window code
67bd78a95f ZVISION: Prefix class member variables with an underscore
7f61a09478 ZVISION: Make the RLF decoder a subclass of the common video decoder
4b2b5e686b ZVISION: Move the mouse cursor handling code into the graphics code
2463b45804 ZVISION: Move the MIDI code together with the rest of the sound code
d8a961244d ZVISION: Move all the file-related classes together
7630e3204e ZVISION: Move all the remaining utility classes into the core
77705752ef ZVISION: Move trimCommentsAndWhiteSpace() into the script manager


Commit: 409ce79a35131d8538e3100e499366e43ae15d02
    https://github.com/scummvm/scummvm/commit/409ce79a35131d8538e3100e499366e43ae15d02
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:53+02:00

Commit Message:
ZVISION: Rename RlfAnimation -> RLFDecoder

Changed paths:
    engines/zvision/animation/meta_animation.cpp
    engines/zvision/animation/meta_animation.h
    engines/zvision/animation/rlf_animation.cpp
    engines/zvision/animation/rlf_animation.h
    engines/zvision/zvision.h



diff --git a/engines/zvision/animation/meta_animation.cpp b/engines/zvision/animation/meta_animation.cpp
index 857a0dd..5a8dba6 100644
--- a/engines/zvision/animation/meta_animation.cpp
+++ b/engines/zvision/animation/meta_animation.cpp
@@ -44,7 +44,7 @@ MetaAnimation::MetaAnimation(const Common::String &fileName, ZVision *engine)
 	if (tmpFileName.hasSuffix(".rlf")) {
 		_fileType = RLF;
 		Common::File *_file = engine->getSearchManager()->openFile(tmpFileName);
-		_animation.rlf = new RlfAnimation(_file, false);
+		_animation.rlf = new RLFDecoder(_file, false);
 		_frmDelay = _animation.rlf->frameTime();
 	} else if (tmpFileName.hasSuffix(".avi")) {
 		_fileType = AVI;
diff --git a/engines/zvision/animation/meta_animation.h b/engines/zvision/animation/meta_animation.h
index 93b6958..6d2025b 100644
--- a/engines/zvision/animation/meta_animation.h
+++ b/engines/zvision/animation/meta_animation.h
@@ -43,7 +43,7 @@ struct Surface;
 namespace ZVision {
 
 class ZVision;
-class RlfAnimation;
+class RLFDecoder;
 
 class MetaAnimation {
 public:
@@ -69,7 +69,7 @@ private:
 
 private:
 	union {
-		RlfAnimation *rlf;
+		RLFDecoder *rlf;
 		Video::VideoDecoder *avi;
 	} _animation;
 
diff --git a/engines/zvision/animation/rlf_animation.cpp b/engines/zvision/animation/rlf_animation.cpp
index d9b8fa3..eaf08a7 100644
--- a/engines/zvision/animation/rlf_animation.cpp
+++ b/engines/zvision/animation/rlf_animation.cpp
@@ -34,7 +34,7 @@
 
 namespace ZVision {
 
-RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream)
+RLFDecoder::RLFDecoder(const Common::String &fileName, bool stream)
 	: _stream(stream),
 	  _readStream(NULL),
 	  _lastFrameRead(0),
@@ -72,7 +72,7 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream)
 	}
 }
 
-RlfAnimation::RlfAnimation(Common::SeekableReadStream *rstream, bool stream)
+RLFDecoder::RLFDecoder(Common::SeekableReadStream *rstream, bool stream)
 	: _stream(stream),
 	  _readStream(rstream),
 	  _lastFrameRead(0),
@@ -102,7 +102,7 @@ RlfAnimation::RlfAnimation(Common::SeekableReadStream *rstream, bool stream)
 	}
 }
 
-RlfAnimation::~RlfAnimation() {
+RLFDecoder::~RLFDecoder() {
 	for (uint i = 0; i < _frameCount; ++i) {
 		delete[] _frames[i].encodedData;
 	}
@@ -111,7 +111,7 @@ RlfAnimation::~RlfAnimation() {
 	_currentFrameBuffer.free();
 }
 
-bool RlfAnimation::readHeader() {
+bool RLFDecoder::readHeader() {
 	if (_readStream->readUint32BE() != MKTAG('F', 'E', 'L', 'R')) {
 		return false;
 	}
@@ -160,8 +160,8 @@ bool RlfAnimation::readHeader() {
 	return true;
 }
 
-RlfAnimation::Frame RlfAnimation::readNextFrame() {
-	RlfAnimation::Frame frame;
+RLFDecoder::Frame RLFDecoder::readNextFrame() {
+	RLFDecoder::Frame frame;
 
 	_readStream->readUint32BE();                        // Magic number MARF
 	uint32 size = _readStream->readUint32LE();          // Size
@@ -188,7 +188,7 @@ RlfAnimation::Frame RlfAnimation::readNextFrame() {
 	return frame;
 }
 
-void RlfAnimation::seekToFrame(int frameNumber) {
+void RLFDecoder::seekToFrame(int frameNumber) {
 	assert(!_stream);
 	assert(frameNumber < (int)_frameCount || frameNumber >= -1);
 
@@ -228,7 +228,7 @@ void RlfAnimation::seekToFrame(int frameNumber) {
 	_nextFrame = frameNumber;
 }
 
-const Graphics::Surface *RlfAnimation::getFrameData(uint frameNumber) {
+const Graphics::Surface *RLFDecoder::getFrameData(uint frameNumber) {
 	assert(!_stream);
 	assert(frameNumber < _frameCount);
 
@@ -244,7 +244,7 @@ const Graphics::Surface *RlfAnimation::getFrameData(uint frameNumber) {
 	return decodeNextFrame();
 }
 
-const Graphics::Surface *RlfAnimation::decodeNextFrame() {
+const Graphics::Surface *RLFDecoder::decodeNextFrame() {
 	assert(_nextFrame < (int)_frameCount);
 
 	if (_stream) {
@@ -257,7 +257,7 @@ const Graphics::Surface *RlfAnimation::decodeNextFrame() {
 	return &_currentFrameBuffer;
 }
 
-void RlfAnimation::applyFrameToCurrent(uint frameNumber) {
+void RLFDecoder::applyFrameToCurrent(uint frameNumber) {
 	if (_frames[frameNumber].type == Masked) {
 		decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize);
 	} else if (_frames[frameNumber].type == Simple) {
@@ -265,7 +265,7 @@ void RlfAnimation::applyFrameToCurrent(uint frameNumber) {
 	}
 }
 
-void RlfAnimation::applyFrameToCurrent(const RlfAnimation::Frame &frame) {
+void RLFDecoder::applyFrameToCurrent(const RLFDecoder::Frame &frame) {
 	if (frame.type == Masked) {
 		decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
 	} else if (frame.type == Simple) {
@@ -273,7 +273,7 @@ void RlfAnimation::applyFrameToCurrent(const RlfAnimation::Frame &frame) {
 	}
 }
 
-void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
+void RLFDecoder::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
 	uint32 sourceOffset = 0;
 	uint32 destOffset = 0;
 	int16 numberOfCopy = 0;
@@ -320,7 +320,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3
 	}
 }
 
-void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
+void RLFDecoder::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
 	uint32 sourceOffset = 0;
 	uint32 destOffset = 0;
 	int16 numberOfCopy = 0;
diff --git a/engines/zvision/animation/rlf_animation.h b/engines/zvision/animation/rlf_animation.h
index c8b2930..62fa609 100644
--- a/engines/zvision/animation/rlf_animation.h
+++ b/engines/zvision/animation/rlf_animation.h
@@ -33,11 +33,11 @@ class String;
 
 namespace ZVision {
 
-class RlfAnimation {
+class RLFDecoder {
 public:
-	RlfAnimation(const Common::String &fileName, bool stream = true);
-	RlfAnimation(Common::SeekableReadStream *rstream, bool stream);
-	~RlfAnimation();
+	RLFDecoder(const Common::String &fileName, bool stream = true);
+	RLFDecoder(Common::SeekableReadStream *rstream, bool stream);
+	~RLFDecoder();
 
 private:
 	enum EncodingType {
@@ -143,7 +143,7 @@ private:
 	 *
 	 * @param frame    A Frame object to apply to _currentFrameBuffer
 	 */
-	void applyFrameToCurrent(const RlfAnimation::Frame &frame);
+	void applyFrameToCurrent(const RLFDecoder::Frame &frame);
 
 	/**
 	 * Decode frame data that uses masked run length encoding. This is the encoding
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index 5850bf6..891f9a9 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -50,7 +50,7 @@ class RenderManager;
 class CursorManager;
 class StringManager;
 class SaveManager;
-class RlfAnimation;
+class RLFDecoder;
 class MenuHandler;
 class TextRenderer;
 class Subtitle;


Commit: 3315522ba1607d68c3402f3d1c8b51b7dc38a7dd
    https://github.com/scummvm/scummvm/commit/3315522ba1607d68c3402f3d1c8b51b7dc38a7dd
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:53+02:00

Commit Message:
ZVISION: Move the RLF decoder

Changed paths:
  A engines/zvision/video/rlf_decoder.cpp
  A engines/zvision/video/rlf_decoder.h
  R engines/zvision/animation/rlf_animation.cpp
  R engines/zvision/animation/rlf_animation.h
    engines/zvision/animation/meta_animation.cpp
    engines/zvision/core/events.cpp
    engines/zvision/module.mk



diff --git a/engines/zvision/animation/meta_animation.cpp b/engines/zvision/animation/meta_animation.cpp
index 5a8dba6..85b2e0f 100644
--- a/engines/zvision/animation/meta_animation.cpp
+++ b/engines/zvision/animation/meta_animation.cpp
@@ -27,7 +27,7 @@
 #include "zvision/zvision.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/scripting/script_manager.h"
-#include "zvision/animation/rlf_animation.h"
+#include "zvision/video/rlf_decoder.h"
 #include "zvision/video/zork_avi_decoder.h"
 
 #include "video/video_decoder.h"
diff --git a/engines/zvision/animation/rlf_animation.cpp b/engines/zvision/animation/rlf_animation.cpp
deleted file mode 100644
index eaf08a7..0000000
--- a/engines/zvision/animation/rlf_animation.cpp
+++ /dev/null
@@ -1,382 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-*/
-
-#include "common/scummsys.h"
-
-#include "zvision/animation/rlf_animation.h"
-
-#include "common/str.h"
-#include "common/file.h"
-#include "common/textconsole.h"
-#include "common/debug.h"
-#include "common/endian.h"
-
-#include "graphics/colormasks.h"
-
-namespace ZVision {
-
-RLFDecoder::RLFDecoder(const Common::String &fileName, bool stream)
-	: _stream(stream),
-	  _readStream(NULL),
-	  _lastFrameRead(0),
-	  _frameCount(0),
-	  _width(0),
-	  _height(0),
-	  _frameTime(0),
-	  _frames(0),
-	  _nextFrame(0),
-	  _frameBufferByteSize(0) {
-
-	Common::File *_file = new Common::File;
-	if (!_file->open(fileName)) {
-		warning("RLF animation file %s could not be opened", fileName.c_str());
-		return;
-	}
-
-	_readStream = _file;
-
-	if (!readHeader()) {
-		warning("%s is not a RLF animation file. Wrong magic number", fileName.c_str());
-		return;
-	}
-
-	_currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>());
-	_frameBufferByteSize = _width * _height * sizeof(uint16);
-
-	if (!stream) {
-		_frames = new Frame[_frameCount];
-
-		// Read in each frame
-		for (uint i = 0; i < _frameCount; ++i) {
-			_frames[i] = readNextFrame();
-		}
-	}
-}
-
-RLFDecoder::RLFDecoder(Common::SeekableReadStream *rstream, bool stream)
-	: _stream(stream),
-	  _readStream(rstream),
-	  _lastFrameRead(0),
-	  _frameCount(0),
-	  _width(0),
-	  _height(0),
-	  _frameTime(0),
-	  _frames(0),
-	  _nextFrame(0),
-	  _frameBufferByteSize(0) {
-
-	if (!readHeader()) {
-		warning("Stream is not a RLF animation. Wrong magic number");
-		return;
-	}
-
-	_currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>());
-	_frameBufferByteSize = _width * _height * sizeof(uint16);
-
-	if (!stream) {
-		_frames = new Frame[_frameCount];
-
-		// Read in each frame
-		for (uint i = 0; i < _frameCount; ++i) {
-			_frames[i] = readNextFrame();
-		}
-	}
-}
-
-RLFDecoder::~RLFDecoder() {
-	for (uint i = 0; i < _frameCount; ++i) {
-		delete[] _frames[i].encodedData;
-	}
-	delete[] _frames;
-	delete _readStream;
-	_currentFrameBuffer.free();
-}
-
-bool RLFDecoder::readHeader() {
-	if (_readStream->readUint32BE() != MKTAG('F', 'E', 'L', 'R')) {
-		return false;
-	}
-
-	// Read the header
-	_readStream->readUint32LE();                // Size1
-	_readStream->readUint32LE();                // Unknown1
-	_readStream->readUint32LE();                // Unknown2
-	_frameCount = _readStream->readUint32LE();  // Frame count
-
-	// Since we don't need any of the data, we can just seek right to the
-	// entries we need rather than read in all the individual entries.
-	_readStream->seek(136, SEEK_CUR);
-
-	//// Read CIN header
-	//_readStream->readUint32BE();          // Magic number FNIC
-	//_readStream->readUint32LE();          // Size2
-	//_readStream->readUint32LE();          // Unknown3
-	//_readStream->readUint32LE();          // Unknown4
-	//_readStream->readUint32LE();          // Unknown5
-	//_readStream->seek(0x18, SEEK_CUR);    // VRLE
-	//_readStream->readUint32LE();          // LRVD
-	//_readStream->readUint32LE();          // Unknown6
-	//_readStream->seek(0x18, SEEK_CUR);    // HRLE
-	//_readStream->readUint32LE();          // ELHD
-	//_readStream->readUint32LE();          // Unknown7
-	//_readStream->seek(0x18, SEEK_CUR);    // HKEY
-	//_readStream->readUint32LE();          // ELRH
-
-	//// Read MIN info header
-	//_readStream->readUint32BE();          // Magic number FNIM
-	//_readStream->readUint32LE();          // Size3
-	//_readStream->readUint32LE();          // OEDV
-	//_readStream->readUint32LE();          // Unknown8
-	//_readStream->readUint32LE();          // Unknown9
-	//_readStream->readUint32LE();          // Unknown10
-	_width = _readStream->readUint32LE();   // Width
-	_height = _readStream->readUint32LE();  // Height
-
-	// Read time header
-	_readStream->readUint32BE();                    // Magic number EMIT
-	_readStream->readUint32LE();                    // Size4
-	_readStream->readUint32LE();                    // Unknown11
-	_frameTime = _readStream->readUint32LE() / 10;  // Frame time in microseconds
-
-	return true;
-}
-
-RLFDecoder::Frame RLFDecoder::readNextFrame() {
-	RLFDecoder::Frame frame;
-
-	_readStream->readUint32BE();                        // Magic number MARF
-	uint32 size = _readStream->readUint32LE();          // Size
-	_readStream->readUint32LE();                        // Unknown1
-	_readStream->readUint32LE();                        // Unknown2
-	uint32 type = _readStream->readUint32BE();          // Either ELHD or ELRH
-	uint32 headerSize = _readStream->readUint32LE();    // Offset from the beginning of this frame to the frame data. Should always be 28
-	_readStream->readUint32LE();                        // Unknown3
-
-	frame.encodedSize = size - headerSize;
-	frame.encodedData = new int8[frame.encodedSize];
-	_readStream->read(frame.encodedData, frame.encodedSize);
-
-	if (type == MKTAG('E', 'L', 'H', 'D')) {
-		frame.type = Masked;
-	} else if (type == MKTAG('E', 'L', 'R', 'H')) {
-		frame.type = Simple;
-		_completeFrames.push_back(_lastFrameRead);
-	} else {
-		warning("Frame %u doesn't have type that can be decoded", _lastFrameRead);
-	}
-
-	_lastFrameRead++;
-	return frame;
-}
-
-void RLFDecoder::seekToFrame(int frameNumber) {
-	assert(!_stream);
-	assert(frameNumber < (int)_frameCount || frameNumber >= -1);
-
-	if (_nextFrame == frameNumber)
-		return;
-
-	if (frameNumber < 0) {
-		_nextFrame = 0;
-		return;
-	}
-
-	int closestFrame = _nextFrame;
-	int distance = (int)frameNumber - _nextFrame;
-
-	if (distance < 0) {
-		for (uint i = 0; i < _completeFrames.size(); ++i) {
-			if ((int)_completeFrames[i] > frameNumber)
-				break;
-			closestFrame = _completeFrames[i];
-		}
-	} else {
-		for (uint i = 0; i < _completeFrames.size(); ++i) {
-			int newDistance = (int)frameNumber - (int)(_completeFrames[i]);
-			if (newDistance < 0)
-				break;
-			if (newDistance < distance) {
-				closestFrame = _completeFrames[i];
-				distance = newDistance;
-			}
-		}
-	}
-
-	for (int i = closestFrame; i < frameNumber; ++i) {
-		applyFrameToCurrent(i);
-	}
-
-	_nextFrame = frameNumber;
-}
-
-const Graphics::Surface *RLFDecoder::getFrameData(uint frameNumber) {
-	assert(!_stream);
-	assert(frameNumber < _frameCount);
-
-	// Since this method is so expensive, first check to see if we can use
-	// decodeNextFrame() it's cheap.
-	if ((int)frameNumber == _nextFrame - 1) {
-		return &_currentFrameBuffer;
-	} else if (_nextFrame == (int)frameNumber) {
-		return decodeNextFrame();
-	}
-
-	seekToFrame(frameNumber);
-	return decodeNextFrame();
-}
-
-const Graphics::Surface *RLFDecoder::decodeNextFrame() {
-	assert(_nextFrame < (int)_frameCount);
-
-	if (_stream) {
-		applyFrameToCurrent(readNextFrame());
-	} else {
-		applyFrameToCurrent(_nextFrame);
-	}
-
-	_nextFrame++;
-	return &_currentFrameBuffer;
-}
-
-void RLFDecoder::applyFrameToCurrent(uint frameNumber) {
-	if (_frames[frameNumber].type == Masked) {
-		decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize);
-	} else if (_frames[frameNumber].type == Simple) {
-		decodeSimpleRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize);
-	}
-}
-
-void RLFDecoder::applyFrameToCurrent(const RLFDecoder::Frame &frame) {
-	if (frame.type == Masked) {
-		decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
-	} else if (frame.type == Simple) {
-		decodeSimpleRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
-	}
-}
-
-void RLFDecoder::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
-	uint32 sourceOffset = 0;
-	uint32 destOffset = 0;
-	int16 numberOfCopy = 0;
-
-	while (sourceOffset < sourceSize) {
-		int8 numberOfSamples = source[sourceOffset];
-		sourceOffset++;
-
-		// If numberOfSamples is negative, the next abs(numberOfSamples) samples should
-		// be copied directly from source to dest
-		if (numberOfSamples < 0) {
-			numberOfCopy = -numberOfSamples;
-
-			while (numberOfCopy > 0) {
-				if (sourceOffset + 1 >= sourceSize) {
-					return;
-				} else if (destOffset + 1 >= destSize) {
-					debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
-					return;
-				}
-
-				byte r, g, b;
-				Graphics::colorToRGB<Graphics::ColorMasks<555> >(READ_LE_UINT16(source + sourceOffset), r, g, b);
-				uint16 destColor = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
-				WRITE_UINT16(dest + destOffset, destColor);
-
-				sourceOffset += 2;
-				destOffset += 2;
-				numberOfCopy--;
-			}
-
-			// If numberOfSamples is >= 0, move destOffset forward ((numberOfSamples * 2) + 2)
-			// This function assumes the dest buffer has been memset with 0's.
-		} else {
-			if (sourceOffset + 1 >= sourceSize) {
-				return;
-			} else if (destOffset + 1 >= destSize) {
-				debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
-				return;
-			}
-
-			destOffset += (numberOfSamples * 2) + 2;
-		}
-	}
-}
-
-void RLFDecoder::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
-	uint32 sourceOffset = 0;
-	uint32 destOffset = 0;
-	int16 numberOfCopy = 0;
-
-	while (sourceOffset < sourceSize) {
-		int8 numberOfSamples = source[sourceOffset];
-		sourceOffset++;
-
-		// If numberOfSamples is negative, the next abs(numberOfSamples) samples should
-		// be copied directly from source to dest
-		if (numberOfSamples < 0) {
-			numberOfCopy = -numberOfSamples;
-
-			while (numberOfCopy > 0) {
-				if (sourceOffset + 1 >= sourceSize) {
-					return;
-				} else if (destOffset + 1 >= destSize) {
-					debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
-					return;
-				}
-
-				byte r, g, b;
-				Graphics::colorToRGB<Graphics::ColorMasks<555> >(READ_LE_UINT16(source + sourceOffset), r, g, b);
-				uint16 destColor = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
-				WRITE_UINT16(dest + destOffset, destColor);
-
-				sourceOffset += 2;
-				destOffset += 2;
-				numberOfCopy--;
-			}
-
-			// If numberOfSamples is >= 0, copy one sample from source to the
-			// next (numberOfSamples + 2) dest spots
-		} else {
-			if (sourceOffset + 1 >= sourceSize) {
-				return;
-			}
-
-			byte r, g, b;
-			Graphics::colorToRGB<Graphics::ColorMasks<555> >(READ_LE_UINT16(source + sourceOffset), r, g, b);
-			uint16 sampleColor = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
-			sourceOffset += 2;
-
-			numberOfCopy = numberOfSamples + 2;
-			while (numberOfCopy > 0) {
-				if (destOffset + 1 >= destSize) {
-					debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
-					return;
-				}
-
-				WRITE_UINT16(dest + destOffset, sampleColor);
-				destOffset += 2;
-				numberOfCopy--;
-			}
-		}
-	}
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/animation/rlf_animation.h b/engines/zvision/animation/rlf_animation.h
deleted file mode 100644
index 62fa609..0000000
--- a/engines/zvision/animation/rlf_animation.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_RLF_ANIMATION_H
-#define ZVISION_RLF_ANIMATION_H
-
-#include "common/file.h"
-
-#include "graphics/surface.h"
-
-namespace Common {
-class String;
-}
-
-namespace ZVision {
-
-class RLFDecoder {
-public:
-	RLFDecoder(const Common::String &fileName, bool stream = true);
-	RLFDecoder(Common::SeekableReadStream *rstream, bool stream);
-	~RLFDecoder();
-
-private:
-	enum EncodingType {
-		Masked,
-		Simple
-	};
-
-	struct Frame {
-		EncodingType type;
-		int8 *encodedData;
-		uint32 encodedSize;
-	};
-
-private:
-	Common::SeekableReadStream *_readStream;
-	bool _stream;
-	uint _lastFrameRead;
-
-	uint _frameCount;
-	uint _width;
-	uint _height;
-	uint32 _frameTime; // In milliseconds
-	Frame *_frames;
-	Common::Array<uint> _completeFrames;
-
-	int _nextFrame;
-	Graphics::Surface _currentFrameBuffer;
-	uint32 _frameBufferByteSize;
-
-public:
-	uint frameCount() {
-		return _frameCount;
-	}
-	uint width() {
-		return _width;
-	}
-	uint height() {
-		return _height;
-	}
-	uint32 frameTime() {
-		return _frameTime;
-	}
-
-	/**
-	 * Seeks to the frameNumber and updates the internal Surface with
-	 * the new frame data. If frameNumber == -1, it only sets _currentFrame,
-	 * the internal Surface is unchanged. This function requires _stream = false
-	 *
-	 * @param frameNumber    The frame number to seek to
-	 */
-	void seekToFrame(int frameNumber);
-
-	/**
-	 * Returns the pixel data of the frame specified. It will try to use
-	 * decodeNextFrame() if possible. If not, it uses seekToFrame() to
-	 * update the internal Surface and then returns a pointer to it.
-	 * This function requires _stream = false
-	 *
-	 * @param frameNumber    The frame number to get data for
-	 * @return               A pointer to the pixel data. Do NOT delete this.
-	 */
-	const Graphics::Surface *getFrameData(uint frameNumber);
-	/**
-	 * Returns the pixel data of current frame and go to next. It is up to the user to
-	 * check if the current frame is valid before calling this.
-	 * IE. Use endOfAnimation()
-	 *
-	 * @return    A pointer to the pixel data. Do NOT delete this.
-	 */
-	const Graphics::Surface *decodeNextFrame();
-	/**
-	 * @return Is the currentFrame is the last frame in the animation?
-	 */
-	bool endOfAnimation() {
-		return _nextFrame == (int)_frameCount;
-	}
-
-private:
-	/**
-	 * Reads in the header of the RLF file
-	 *
-	 * @return    Will return false if the header magic number is wrong
-	 */
-	bool readHeader();
-	/**
-	 * Reads the next frame from the RLF file, stores the data in
-	 * a Frame object, then returns the object
-	 *
-	 * @return    A Frame object representing the frame data
-	 */
-	Frame readNextFrame();
-
-	/**
-	 * Applies the frame corresponding to frameNumber on top of _currentFrameBuffer.
-	 * This function requires _stream = false so it can look up the Frame object
-	 * referenced by frameNumber.
-	 *
-	 * @param frameNumber    The frame number to apply to _currentFrameBuffer
-	 */
-	void applyFrameToCurrent(uint frameNumber);
-	/**
-	 * Applies the data from a Frame object on top of a _currentFrameBuffer.
-	 *
-	 * @param frame    A Frame object to apply to _currentFrameBuffer
-	 */
-	void applyFrameToCurrent(const RLFDecoder::Frame &frame);
-
-	/**
-	 * Decode frame data that uses masked run length encoding. This is the encoding
-	 * used by P-frames.
-	 *
-	 * @param source        The source pixel data
-	 * @param dest          The destination buffer
-	 * @param sourceSize    The size of the source pixel data
-	 * @param destSize      The size of the destination buffer
-	 */
-	void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
-	/**
-	 * Decode frame data that uses simple run length encoding. This is the encoding
-	 * used by I-frames.
-	 *
-	 * @param source        The source pixel data
-	 * @param dest          The destination buffer
-	 * @param sourceSize    The size of the source pixel data
-	 * @param destSize      The size of the destination buffer
-	 */
-	void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp
index 52d71c9..839f919 100644
--- a/engines/zvision/core/events.cpp
+++ b/engines/zvision/core/events.cpp
@@ -28,7 +28,6 @@
 #include "zvision/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/scripting/script_manager.h"
-#include "zvision/animation/rlf_animation.h"
 #include "zvision/core/menu.h"
 #include "zvision/sound/zork_raw.h"
 
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 045eb52..5c2fd20 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -2,7 +2,6 @@ MODULE := engines/zvision
 
 MODULE_OBJS := \
 	animation/meta_animation.o \
-	animation/rlf_animation.o \
 	core/console.o \
 	core/events.o \
 	core/menu.o \
@@ -48,6 +47,7 @@ MODULE_OBJS := \
 	utility/lzss_read_stream.o \
 	utility/utility.o \
 	utility/zfs_archive.o \
+	video/rlf_decoder.o \
 	video/video.o \
 	video/zork_avi_decoder.o \
 	zvision.o
diff --git a/engines/zvision/video/rlf_decoder.cpp b/engines/zvision/video/rlf_decoder.cpp
new file mode 100644
index 0000000..a4f16af
--- /dev/null
+++ b/engines/zvision/video/rlf_decoder.cpp
@@ -0,0 +1,382 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "common/scummsys.h"
+
+#include "zvision/video/rlf_decoder.h"
+
+#include "common/str.h"
+#include "common/file.h"
+#include "common/textconsole.h"
+#include "common/debug.h"
+#include "common/endian.h"
+
+#include "graphics/colormasks.h"
+
+namespace ZVision {
+
+RLFDecoder::RLFDecoder(const Common::String &fileName, bool stream)
+	: _stream(stream),
+	  _readStream(NULL),
+	  _lastFrameRead(0),
+	  _frameCount(0),
+	  _width(0),
+	  _height(0),
+	  _frameTime(0),
+	  _frames(0),
+	  _nextFrame(0),
+	  _frameBufferByteSize(0) {
+
+	Common::File *_file = new Common::File;
+	if (!_file->open(fileName)) {
+		warning("RLF animation file %s could not be opened", fileName.c_str());
+		return;
+	}
+
+	_readStream = _file;
+
+	if (!readHeader()) {
+		warning("%s is not a RLF animation file. Wrong magic number", fileName.c_str());
+		return;
+	}
+
+	_currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>());
+	_frameBufferByteSize = _width * _height * sizeof(uint16);
+
+	if (!stream) {
+		_frames = new Frame[_frameCount];
+
+		// Read in each frame
+		for (uint i = 0; i < _frameCount; ++i) {
+			_frames[i] = readNextFrame();
+		}
+	}
+}
+
+RLFDecoder::RLFDecoder(Common::SeekableReadStream *rstream, bool stream)
+	: _stream(stream),
+	  _readStream(rstream),
+	  _lastFrameRead(0),
+	  _frameCount(0),
+	  _width(0),
+	  _height(0),
+	  _frameTime(0),
+	  _frames(0),
+	  _nextFrame(0),
+	  _frameBufferByteSize(0) {
+
+	if (!readHeader()) {
+		warning("Stream is not a RLF animation. Wrong magic number");
+		return;
+	}
+
+	_currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>());
+	_frameBufferByteSize = _width * _height * sizeof(uint16);
+
+	if (!stream) {
+		_frames = new Frame[_frameCount];
+
+		// Read in each frame
+		for (uint i = 0; i < _frameCount; ++i) {
+			_frames[i] = readNextFrame();
+		}
+	}
+}
+
+RLFDecoder::~RLFDecoder() {
+	for (uint i = 0; i < _frameCount; ++i) {
+		delete[] _frames[i].encodedData;
+	}
+	delete[] _frames;
+	delete _readStream;
+	_currentFrameBuffer.free();
+}
+
+bool RLFDecoder::readHeader() {
+	if (_readStream->readUint32BE() != MKTAG('F', 'E', 'L', 'R')) {
+		return false;
+	}
+
+	// Read the header
+	_readStream->readUint32LE();                // Size1
+	_readStream->readUint32LE();                // Unknown1
+	_readStream->readUint32LE();                // Unknown2
+	_frameCount = _readStream->readUint32LE();  // Frame count
+
+	// Since we don't need any of the data, we can just seek right to the
+	// entries we need rather than read in all the individual entries.
+	_readStream->seek(136, SEEK_CUR);
+
+	//// Read CIN header
+	//_readStream->readUint32BE();          // Magic number FNIC
+	//_readStream->readUint32LE();          // Size2
+	//_readStream->readUint32LE();          // Unknown3
+	//_readStream->readUint32LE();          // Unknown4
+	//_readStream->readUint32LE();          // Unknown5
+	//_readStream->seek(0x18, SEEK_CUR);    // VRLE
+	//_readStream->readUint32LE();          // LRVD
+	//_readStream->readUint32LE();          // Unknown6
+	//_readStream->seek(0x18, SEEK_CUR);    // HRLE
+	//_readStream->readUint32LE();          // ELHD
+	//_readStream->readUint32LE();          // Unknown7
+	//_readStream->seek(0x18, SEEK_CUR);    // HKEY
+	//_readStream->readUint32LE();          // ELRH
+
+	//// Read MIN info header
+	//_readStream->readUint32BE();          // Magic number FNIM
+	//_readStream->readUint32LE();          // Size3
+	//_readStream->readUint32LE();          // OEDV
+	//_readStream->readUint32LE();          // Unknown8
+	//_readStream->readUint32LE();          // Unknown9
+	//_readStream->readUint32LE();          // Unknown10
+	_width = _readStream->readUint32LE();   // Width
+	_height = _readStream->readUint32LE();  // Height
+
+	// Read time header
+	_readStream->readUint32BE();                    // Magic number EMIT
+	_readStream->readUint32LE();                    // Size4
+	_readStream->readUint32LE();                    // Unknown11
+	_frameTime = _readStream->readUint32LE() / 10;  // Frame time in microseconds
+
+	return true;
+}
+
+RLFDecoder::Frame RLFDecoder::readNextFrame() {
+	RLFDecoder::Frame frame;
+
+	_readStream->readUint32BE();                        // Magic number MARF
+	uint32 size = _readStream->readUint32LE();          // Size
+	_readStream->readUint32LE();                        // Unknown1
+	_readStream->readUint32LE();                        // Unknown2
+	uint32 type = _readStream->readUint32BE();          // Either ELHD or ELRH
+	uint32 headerSize = _readStream->readUint32LE();    // Offset from the beginning of this frame to the frame data. Should always be 28
+	_readStream->readUint32LE();                        // Unknown3
+
+	frame.encodedSize = size - headerSize;
+	frame.encodedData = new int8[frame.encodedSize];
+	_readStream->read(frame.encodedData, frame.encodedSize);
+
+	if (type == MKTAG('E', 'L', 'H', 'D')) {
+		frame.type = Masked;
+	} else if (type == MKTAG('E', 'L', 'R', 'H')) {
+		frame.type = Simple;
+		_completeFrames.push_back(_lastFrameRead);
+	} else {
+		warning("Frame %u doesn't have type that can be decoded", _lastFrameRead);
+	}
+
+	_lastFrameRead++;
+	return frame;
+}
+
+void RLFDecoder::seekToFrame(int frameNumber) {
+	assert(!_stream);
+	assert(frameNumber < (int)_frameCount || frameNumber >= -1);
+
+	if (_nextFrame == frameNumber)
+		return;
+
+	if (frameNumber < 0) {
+		_nextFrame = 0;
+		return;
+	}
+
+	int closestFrame = _nextFrame;
+	int distance = (int)frameNumber - _nextFrame;
+
+	if (distance < 0) {
+		for (uint i = 0; i < _completeFrames.size(); ++i) {
+			if ((int)_completeFrames[i] > frameNumber)
+				break;
+			closestFrame = _completeFrames[i];
+		}
+	} else {
+		for (uint i = 0; i < _completeFrames.size(); ++i) {
+			int newDistance = (int)frameNumber - (int)(_completeFrames[i]);
+			if (newDistance < 0)
+				break;
+			if (newDistance < distance) {
+				closestFrame = _completeFrames[i];
+				distance = newDistance;
+			}
+		}
+	}
+
+	for (int i = closestFrame; i < frameNumber; ++i) {
+		applyFrameToCurrent(i);
+	}
+
+	_nextFrame = frameNumber;
+}
+
+const Graphics::Surface *RLFDecoder::getFrameData(uint frameNumber) {
+	assert(!_stream);
+	assert(frameNumber < _frameCount);
+
+	// Since this method is so expensive, first check to see if we can use
+	// decodeNextFrame() it's cheap.
+	if ((int)frameNumber == _nextFrame - 1) {
+		return &_currentFrameBuffer;
+	} else if (_nextFrame == (int)frameNumber) {
+		return decodeNextFrame();
+	}
+
+	seekToFrame(frameNumber);
+	return decodeNextFrame();
+}
+
+const Graphics::Surface *RLFDecoder::decodeNextFrame() {
+	assert(_nextFrame < (int)_frameCount);
+
+	if (_stream) {
+		applyFrameToCurrent(readNextFrame());
+	} else {
+		applyFrameToCurrent(_nextFrame);
+	}
+
+	_nextFrame++;
+	return &_currentFrameBuffer;
+}
+
+void RLFDecoder::applyFrameToCurrent(uint frameNumber) {
+	if (_frames[frameNumber].type == Masked) {
+		decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize);
+	} else if (_frames[frameNumber].type == Simple) {
+		decodeSimpleRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize);
+	}
+}
+
+void RLFDecoder::applyFrameToCurrent(const RLFDecoder::Frame &frame) {
+	if (frame.type == Masked) {
+		decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
+	} else if (frame.type == Simple) {
+		decodeSimpleRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
+	}
+}
+
+void RLFDecoder::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
+	uint32 sourceOffset = 0;
+	uint32 destOffset = 0;
+	int16 numberOfCopy = 0;
+
+	while (sourceOffset < sourceSize) {
+		int8 numberOfSamples = source[sourceOffset];
+		sourceOffset++;
+
+		// If numberOfSamples is negative, the next abs(numberOfSamples) samples should
+		// be copied directly from source to dest
+		if (numberOfSamples < 0) {
+			numberOfCopy = -numberOfSamples;
+
+			while (numberOfCopy > 0) {
+				if (sourceOffset + 1 >= sourceSize) {
+					return;
+				} else if (destOffset + 1 >= destSize) {
+					debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
+					return;
+				}
+
+				byte r, g, b;
+				Graphics::colorToRGB<Graphics::ColorMasks<555> >(READ_LE_UINT16(source + sourceOffset), r, g, b);
+				uint16 destColor = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
+				WRITE_UINT16(dest + destOffset, destColor);
+
+				sourceOffset += 2;
+				destOffset += 2;
+				numberOfCopy--;
+			}
+
+			// If numberOfSamples is >= 0, move destOffset forward ((numberOfSamples * 2) + 2)
+			// This function assumes the dest buffer has been memset with 0's.
+		} else {
+			if (sourceOffset + 1 >= sourceSize) {
+				return;
+			} else if (destOffset + 1 >= destSize) {
+				debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
+				return;
+			}
+
+			destOffset += (numberOfSamples * 2) + 2;
+		}
+	}
+}
+
+void RLFDecoder::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
+	uint32 sourceOffset = 0;
+	uint32 destOffset = 0;
+	int16 numberOfCopy = 0;
+
+	while (sourceOffset < sourceSize) {
+		int8 numberOfSamples = source[sourceOffset];
+		sourceOffset++;
+
+		// If numberOfSamples is negative, the next abs(numberOfSamples) samples should
+		// be copied directly from source to dest
+		if (numberOfSamples < 0) {
+			numberOfCopy = -numberOfSamples;
+
+			while (numberOfCopy > 0) {
+				if (sourceOffset + 1 >= sourceSize) {
+					return;
+				} else if (destOffset + 1 >= destSize) {
+					debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
+					return;
+				}
+
+				byte r, g, b;
+				Graphics::colorToRGB<Graphics::ColorMasks<555> >(READ_LE_UINT16(source + sourceOffset), r, g, b);
+				uint16 destColor = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
+				WRITE_UINT16(dest + destOffset, destColor);
+
+				sourceOffset += 2;
+				destOffset += 2;
+				numberOfCopy--;
+			}
+
+			// If numberOfSamples is >= 0, copy one sample from source to the
+			// next (numberOfSamples + 2) dest spots
+		} else {
+			if (sourceOffset + 1 >= sourceSize) {
+				return;
+			}
+
+			byte r, g, b;
+			Graphics::colorToRGB<Graphics::ColorMasks<555> >(READ_LE_UINT16(source + sourceOffset), r, g, b);
+			uint16 sampleColor = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b);
+			sourceOffset += 2;
+
+			numberOfCopy = numberOfSamples + 2;
+			while (numberOfCopy > 0) {
+				if (destOffset + 1 >= destSize) {
+					debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize);
+					return;
+				}
+
+				WRITE_UINT16(dest + destOffset, sampleColor);
+				destOffset += 2;
+				numberOfCopy--;
+			}
+		}
+	}
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/video/rlf_decoder.h b/engines/zvision/video/rlf_decoder.h
new file mode 100644
index 0000000..dcfd860
--- /dev/null
+++ b/engines/zvision/video/rlf_decoder.h
@@ -0,0 +1,172 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_RLF_DECODER_H
+#define ZVISION_RLF_DECODER_H
+
+#include "common/file.h"
+
+#include "graphics/surface.h"
+
+namespace Common {
+class String;
+}
+
+namespace ZVision {
+
+class RLFDecoder {
+public:
+	RLFDecoder(const Common::String &fileName, bool stream = true);
+	RLFDecoder(Common::SeekableReadStream *rstream, bool stream);
+	~RLFDecoder();
+
+private:
+	enum EncodingType {
+		Masked,
+		Simple
+	};
+
+	struct Frame {
+		EncodingType type;
+		int8 *encodedData;
+		uint32 encodedSize;
+	};
+
+private:
+	Common::SeekableReadStream *_readStream;
+	bool _stream;
+	uint _lastFrameRead;
+
+	uint _frameCount;
+	uint _width;
+	uint _height;
+	uint32 _frameTime; // In milliseconds
+	Frame *_frames;
+	Common::Array<uint> _completeFrames;
+
+	int _nextFrame;
+	Graphics::Surface _currentFrameBuffer;
+	uint32 _frameBufferByteSize;
+
+public:
+	uint frameCount() {
+		return _frameCount;
+	}
+	uint width() {
+		return _width;
+	}
+	uint height() {
+		return _height;
+	}
+	uint32 frameTime() {
+		return _frameTime;
+	}
+
+	/**
+	 * Seeks to the frameNumber and updates the internal Surface with
+	 * the new frame data. If frameNumber == -1, it only sets _currentFrame,
+	 * the internal Surface is unchanged. This function requires _stream = false
+	 *
+	 * @param frameNumber    The frame number to seek to
+	 */
+	void seekToFrame(int frameNumber);
+
+	/**
+	 * Returns the pixel data of the frame specified. It will try to use
+	 * decodeNextFrame() if possible. If not, it uses seekToFrame() to
+	 * update the internal Surface and then returns a pointer to it.
+	 * This function requires _stream = false
+	 *
+	 * @param frameNumber    The frame number to get data for
+	 * @return               A pointer to the pixel data. Do NOT delete this.
+	 */
+	const Graphics::Surface *getFrameData(uint frameNumber);
+	/**
+	 * Returns the pixel data of current frame and go to next. It is up to the user to
+	 * check if the current frame is valid before calling this.
+	 * IE. Use endOfAnimation()
+	 *
+	 * @return    A pointer to the pixel data. Do NOT delete this.
+	 */
+	const Graphics::Surface *decodeNextFrame();
+	/**
+	 * @return Is the currentFrame is the last frame in the animation?
+	 */
+	bool endOfAnimation() {
+		return _nextFrame == (int)_frameCount;
+	}
+
+private:
+	/**
+	 * Reads in the header of the RLF file
+	 *
+	 * @return    Will return false if the header magic number is wrong
+	 */
+	bool readHeader();
+	/**
+	 * Reads the next frame from the RLF file, stores the data in
+	 * a Frame object, then returns the object
+	 *
+	 * @return    A Frame object representing the frame data
+	 */
+	Frame readNextFrame();
+
+	/**
+	 * Applies the frame corresponding to frameNumber on top of _currentFrameBuffer.
+	 * This function requires _stream = false so it can look up the Frame object
+	 * referenced by frameNumber.
+	 *
+	 * @param frameNumber    The frame number to apply to _currentFrameBuffer
+	 */
+	void applyFrameToCurrent(uint frameNumber);
+	/**
+	 * Applies the data from a Frame object on top of a _currentFrameBuffer.
+	 *
+	 * @param frame    A Frame object to apply to _currentFrameBuffer
+	 */
+	void applyFrameToCurrent(const RLFDecoder::Frame &frame);
+
+	/**
+	 * Decode frame data that uses masked run length encoding. This is the encoding
+	 * used by P-frames.
+	 *
+	 * @param source        The source pixel data
+	 * @param dest          The destination buffer
+	 * @param sourceSize    The size of the source pixel data
+	 * @param destSize      The size of the destination buffer
+	 */
+	void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
+	/**
+	 * Decode frame data that uses simple run length encoding. This is the encoding
+	 * used by I-frames.
+	 *
+	 * @param source        The source pixel data
+	 * @param dest          The destination buffer
+	 * @param sourceSize    The size of the source pixel data
+	 * @param destSize      The size of the destination buffer
+	 */
+	void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
+};
+
+} // End of namespace ZVision
+
+#endif


Commit: 3d1a9e34422f3bb9d86149c18695cc5a9e4ebac8
    https://github.com/scummvm/scummvm/commit/3d1a9e34422f3bb9d86149c18695cc5a9e4ebac8
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:54+02:00

Commit Message:
ZVISION: Simplify the working window code

Changed paths:
    engines/zvision/zvision.cpp
    engines/zvision/zvision.h



diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index 8a44cce..ec1fb94 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -81,9 +81,6 @@ struct zvisionIniSettings {
 ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
 	: Engine(syst),
 	  _gameDescription(gameDesc),
-	  _workingWindow_ZGI((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2, (WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2, ((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2) + WORKING_WINDOW_WIDTH, ((WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2) + WORKING_WINDOW_HEIGHT),
-	  _workingWindow_ZNM((WINDOW_WIDTH - ZNM_WORKING_WINDOW_WIDTH) / 2, (WINDOW_HEIGHT - ZNM_WORKING_WINDOW_HEIGHT) / 2, ((WINDOW_WIDTH - ZNM_WORKING_WINDOW_WIDTH) / 2) + ZNM_WORKING_WINDOW_WIDTH, ((WINDOW_HEIGHT - ZNM_WORKING_WINDOW_HEIGHT) / 2) + ZNM_WORKING_WINDOW_HEIGHT),
-	  _workingWindow(gameDesc->gameId == GID_NEMESIS ? _workingWindow_ZNM : _workingWindow_ZGI),
 	  _pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), /*RGB 565*/
 	  _desiredFrameTime(33), /* ~30 fps */
 	  _clock(_system),
@@ -101,6 +98,15 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
 
 	debug(1, "ZVision::ZVision");
 
+	uint16 workingWindowWidth  = (gameDesc->gameId == GID_NEMESIS) ? ZNM_WORKING_WINDOW_WIDTH  : ZGI_WORKING_WINDOW_WIDTH;
+	uint16 workingWindowHeight = (gameDesc->gameId == GID_NEMESIS) ? ZNM_WORKING_WINDOW_HEIGHT : ZGI_WORKING_WINDOW_HEIGHT;
+	_workingWindow = Common::Rect(
+						 (WINDOW_WIDTH  -  workingWindowWidth) / 2,
+						 (WINDOW_HEIGHT - workingWindowHeight) / 2,
+						((WINDOW_WIDTH  -  workingWindowWidth) / 2) + workingWindowWidth,
+						((WINDOW_HEIGHT - workingWindowHeight) / 2) + workingWindowHeight
+					 );
+
 	memset(_cheatBuff, 0, sizeof(_cheatBuff));
 }
 
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index 891f9a9..f8763f9 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -67,7 +67,7 @@ public:
 	 * are given in this coordinate space. Also, all images are clipped to the
 	 * edges of this Rectangle
 	 */
-	const Common::Rect &_workingWindow;
+	Common::Rect _workingWindow;
 	const Graphics::PixelFormat _pixelFormat;
 
 private:
@@ -75,13 +75,13 @@ private:
 		WINDOW_WIDTH = 640,
 		WINDOW_HEIGHT = 480,
 
-		//Zork nemesis working window sizes
+		// Zork nemesis working window sizes
 		ZNM_WORKING_WINDOW_WIDTH  = 512,
 		ZNM_WORKING_WINDOW_HEIGHT = 320,
 
-		//ZGI(and default) working window sizes
-		WORKING_WINDOW_WIDTH  = 640,
-		WORKING_WINDOW_HEIGHT = 344,
+		// ZGI working window sizes
+		ZGI_WORKING_WINDOW_WIDTH  = 640,
+		ZGI_WORKING_WINDOW_HEIGHT = 344,
 
 		ROTATION_SCREEN_EDGE_OFFSET = 60,
 		MAX_ROTATION_SPEED = 400, // Pixels per second
@@ -117,9 +117,6 @@ private:
 	// To prevent allocation every time we process events
 	Common::Event _event;
 
-	const Common::Rect _workingWindow_ZGI;
-	const Common::Rect _workingWindow_ZNM;
-
 	int _rendDelay;
 	int16 _mouseVelocity;
 	int16 _kbdVelocity;


Commit: 67bd78a95f6efab6d0da4b3bef1b0cebc79c537c
    https://github.com/scummvm/scummvm/commit/67bd78a95f6efab6d0da4b3bef1b0cebc79c537c
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:54+02:00

Commit Message:
ZVISION: Prefix class member variables with an underscore

This makes the code adhere to our code formatting conventions

Changed paths:
    engines/zvision/core/search_manager.cpp
    engines/zvision/core/search_manager.h



diff --git a/engines/zvision/core/search_manager.cpp b/engines/zvision/core/search_manager.cpp
index 9c5d8fb..1523319 100644
--- a/engines/zvision/core/search_manager.cpp
+++ b/engines/zvision/core/search_manager.cpp
@@ -36,11 +36,11 @@ SearchManager::SearchManager(const Common::String &rootPath, int depth) {
 
 	Common::FSNode fsNode(_root);
 
-	listDirRecursive(dirList, fsNode, depth);
+	listDirRecursive(_dirList, fsNode, depth);
 
-	for (Common::List<Common::String>::iterator it = dirList.begin(); it != dirList.end();)
+	for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end();)
 		if (it->size() == _root.size())
-			it = dirList.erase(it);
+			it = _dirList.erase(it);
 		else if (it->size() > _root.size()) {
 			*it = Common::String(it->c_str() + _root.size() + 1);
 			it++;
@@ -49,32 +49,32 @@ SearchManager::SearchManager(const Common::String &rootPath, int depth) {
 }
 
 SearchManager::~SearchManager() {
-	Common::List<Common::Archive *>::iterator it = archList.begin();
-	while (it != archList.end()) {
+	Common::List<Common::Archive *>::iterator it = _archList.begin();
+	while (it != _archList.end()) {
 		delete *it;
 		it++;
 	}
 
-	archList.clear();
+	_archList.clear();
 }
 
 void SearchManager::addPatch(const Common::String &src, const Common::String &dst) {
 	Common::String lowerCaseName = dst;
 	lowerCaseName.toLowercase();
 
-	SearchManager::MatchList::iterator it = files.find(lowerCaseName);
+	SearchManager::MatchList::iterator it = _files.find(lowerCaseName);
 
-	if (it != files.end()) {
+	if (it != _files.end()) {
 		lowerCaseName = src;
 		lowerCaseName.toLowercase();
-		files[lowerCaseName] = it->_value;
+		_files[lowerCaseName] = it->_value;
 	}
 }
 
 void SearchManager::addFile(const Common::String &name, Common::Archive *arch) {
 	bool addArch = true;
-	Common::List<Common::Archive *>::iterator it = archList.begin();
-	while (it != archList.end()) {
+	Common::List<Common::Archive *>::iterator it = _archList.begin();
+	while (it != _archList.end()) {
 		if (*it == arch) {
 			addArch = false;
 			break;
@@ -82,7 +82,7 @@ void SearchManager::addFile(const Common::String &name, Common::Archive *arch) {
 		it++;
 	}
 	if (addArch)
-		archList.push_back(arch);
+		_archList.push_back(arch);
 
 	Common::String lowerCaseName = name;
 	lowerCaseName.toLowercase();
@@ -91,10 +91,10 @@ void SearchManager::addFile(const Common::String &name, Common::Archive *arch) {
 	nod.name = lowerCaseName;
 	nod.arch = arch;
 
-	SearchManager::MatchList::iterator fit = files.find(lowerCaseName);
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
 
-	if (fit == files.end()) {
-		files[lowerCaseName] = nod;
+	if (fit == _files.end()) {
+		_files[lowerCaseName] = nod;
 	} else {
 		Common::SeekableReadStream *stream = fit->_value.arch->createReadStreamForMember(fit->_value.name);
 		if (stream) {
@@ -102,7 +102,7 @@ void SearchManager::addFile(const Common::String &name, Common::Archive *arch) {
 				fit->_value.arch = arch;
 			delete stream;
 		} else {
-			files[lowerCaseName] = nod;
+			_files[lowerCaseName] = nod;
 		}
 	}
 }
@@ -111,9 +111,9 @@ Common::File *SearchManager::openFile(const Common::String &name) {
 	Common::String lowerCaseName = name;
 	lowerCaseName.toLowercase();
 
-	SearchManager::MatchList::iterator fit = files.find(lowerCaseName);
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
 
-	if (fit != files.end()) {
+	if (fit != _files.end()) {
 		Common::File *tmp = new Common::File();
 		tmp->open(fit->_value.name, *fit->_value.arch);
 		return tmp;
@@ -125,9 +125,9 @@ bool SearchManager::openFile(Common::File &file, const Common::String &name) {
 	Common::String lowerCaseName = name;
 	lowerCaseName.toLowercase();
 
-	SearchManager::MatchList::iterator fit = files.find(lowerCaseName);
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
 
-	if (fit != files.end())
+	if (fit != _files.end())
 		return file.open(fit->_value.name, *fit->_value.arch);
 	return false;
 }
@@ -136,9 +136,9 @@ bool SearchManager::hasFile(const Common::String &name) {
 	Common::String lowerCaseName = name;
 	lowerCaseName.toLowercase();
 
-	SearchManager::MatchList::iterator fit = files.find(lowerCaseName);
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
 
-	if (fit != files.end())
+	if (fit != _files.end())
 		return true;
 	return false;
 }
@@ -187,7 +187,7 @@ void SearchManager::loadZix(const Common::String &name) {
 					if (path[path.size() - 1] == '\\' || path[path.size() - 1] == '/')
 						path.deleteLastChar();
 					if (path.size())
-						for (Common::List<Common::String>::iterator it = dirList.begin(); it != dirList.end(); ++it)
+						for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end(); ++it)
 							if (path.equalsIgnoreCase(*it)) {
 								path = *it;
 								break;
@@ -220,7 +220,7 @@ void SearchManager::loadZix(const Common::String &name) {
 
 void SearchManager::addDir(const Common::String &name) {
 	Common::String path;
-	for (Common::List<Common::String>::iterator it = dirList.begin(); it != dirList.end(); ++it)
+	for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end(); ++it)
 		if (name.equalsIgnoreCase(*it)) {
 			path = *it;
 			break;
diff --git a/engines/zvision/core/search_manager.h b/engines/zvision/core/search_manager.h
index 180102e..fdd70fd 100644
--- a/engines/zvision/core/search_manager.h
+++ b/engines/zvision/core/search_manager.h
@@ -56,12 +56,12 @@ private:
 		Common::Archive *arch;
 	};
 
-	Common::List<Common::String> dirList;
+	Common::List<Common::String> _dirList;
 
 	typedef Common::HashMap<Common::String, Node, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> MatchList;
 
-	Common::List<Common::Archive *> archList;
-	MatchList files;
+	Common::List<Common::Archive *> _archList;
+	MatchList _files;
 
 	Common::String _root;
 


Commit: 7f61a094781256f7c2734aa08637494c1dfac6bf
    https://github.com/scummvm/scummvm/commit/7f61a094781256f7c2734aa08637494c1dfac6bf
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:55+02:00

Commit Message:
ZVISION: Make the RLF decoder a subclass of the common video decoder

This way, the redundant MetaAnimation class can now be removed

Changed paths:
  R engines/zvision/animation/meta_animation.cpp
  R engines/zvision/animation/meta_animation.h
    engines/zvision/module.mk
    engines/zvision/scripting/controls/fist_control.cpp
    engines/zvision/scripting/controls/fist_control.h
    engines/zvision/scripting/controls/hotmov_control.cpp
    engines/zvision/scripting/controls/hotmov_control.h
    engines/zvision/scripting/controls/input_control.cpp
    engines/zvision/scripting/controls/input_control.h
    engines/zvision/scripting/controls/lever_control.cpp
    engines/zvision/scripting/controls/lever_control.h
    engines/zvision/scripting/controls/safe_control.cpp
    engines/zvision/scripting/controls/safe_control.h
    engines/zvision/scripting/sidefx/animation_node.cpp
    engines/zvision/scripting/sidefx/animation_node.h
    engines/zvision/video/rlf_decoder.cpp
    engines/zvision/video/rlf_decoder.h
    engines/zvision/video/video.cpp
    engines/zvision/zvision.h



diff --git a/engines/zvision/animation/meta_animation.cpp b/engines/zvision/animation/meta_animation.cpp
deleted file mode 100644
index 85b2e0f..0000000
--- a/engines/zvision/animation/meta_animation.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "zvision/animation/meta_animation.h"
-
-#include "zvision/zvision.h"
-#include "zvision/graphics/render_manager.h"
-#include "zvision/scripting/script_manager.h"
-#include "zvision/video/rlf_decoder.h"
-#include "zvision/video/zork_avi_decoder.h"
-
-#include "video/video_decoder.h"
-
-#include "graphics/surface.h"
-
-namespace ZVision {
-
-MetaAnimation::MetaAnimation(const Common::String &fileName, ZVision *engine)
-	: _fileType(RLF),
-	  _curFrame(NULL) {
-	Common::String tmpFileName = fileName;
-	tmpFileName.toLowercase();
-	if (tmpFileName.hasSuffix(".rlf")) {
-		_fileType = RLF;
-		Common::File *_file = engine->getSearchManager()->openFile(tmpFileName);
-		_animation.rlf = new RLFDecoder(_file, false);
-		_frmDelay = _animation.rlf->frameTime();
-	} else if (tmpFileName.hasSuffix(".avi")) {
-		_fileType = AVI;
-		Common::File *_file = engine->getSearchManager()->openFile(tmpFileName);
-		_animation.avi = new ZorkAVIDecoder();
-		_animation.avi->loadStream(_file);
-		_frmDelay = 1000.0 / _animation.avi->getDuration().framerate();
-	} else {
-		warning("Unrecognized animation file type: %s", fileName.c_str());
-	}
-}
-
-MetaAnimation::~MetaAnimation() {
-	if (_fileType == RLF) {
-		delete _animation.rlf;
-	} else if (_fileType == AVI) {
-		delete _animation.avi;
-	}
-}
-
-uint MetaAnimation::frameCount() {
-	if (_fileType == RLF) {
-		return _animation.rlf->frameCount();
-	} else
-		return _animation.avi->getFrameCount();
-
-}
-
-uint MetaAnimation::width() {
-	if (_fileType == RLF) {
-		return _animation.rlf->width();
-	} else
-		return _animation.avi->getWidth();
-}
-uint MetaAnimation::height() {
-	if (_fileType == RLF) {
-		return _animation.rlf->height();
-	} else
-		return _animation.avi->getHeight();
-}
-uint32 MetaAnimation::frameTime() {
-	return _frmDelay;
-}
-
-void MetaAnimation::seekToFrame(int frameNumber) {
-	if (frameNumber >= (int)frameCount())
-		frameNumber = frameCount() - 1;
-
-	if (_fileType == RLF) {
-		_animation.rlf->seekToFrame(frameNumber);
-	} else
-		_animation.avi->seekToFrame(frameNumber);
-}
-
-const Graphics::Surface *MetaAnimation::decodeNextFrame() {
-	if (_fileType == RLF)
-		_curFrame = _animation.rlf->decodeNextFrame();
-	else
-		_curFrame = _animation.avi->decodeNextFrame();
-
-	return _curFrame;
-}
-
-const Graphics::Surface *MetaAnimation::getFrameData(uint frameNumber) {
-	if (frameNumber >= frameCount())
-		frameNumber = frameCount() - 1;
-
-	if (_fileType == RLF) {
-		_curFrame = _animation.rlf->getFrameData(frameNumber);
-		return _curFrame;
-	} else {
-		_animation.avi->seekToFrame(frameNumber);
-		_curFrame = _animation.avi->decodeNextFrame();
-		return _curFrame;
-	}
-}
-
-bool MetaAnimation::endOfAnimation() {
-	if (_fileType == RLF) {
-		return _animation.rlf->endOfAnimation();
-	} else
-		return _animation.avi->endOfVideo();
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/animation/meta_animation.h b/engines/zvision/animation/meta_animation.h
deleted file mode 100644
index 6d2025b..0000000
--- a/engines/zvision/animation/meta_animation.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_METAANIM_NODE_H
-#define ZVISION_METAANIM_NODE_H
-
-#include "zvision/scripting/sidefx.h"
-#include "zvision/zvision.h"
-#include "common/rect.h"
-#include "common/list.h"
-
-namespace Common {
-class String;
-}
-
-namespace Video {
-class VideoDecoder;
-}
-
-namespace Graphics {
-struct Surface;
-}
-
-namespace ZVision {
-
-class ZVision;
-class RLFDecoder;
-
-class MetaAnimation {
-public:
-	MetaAnimation(const Common::String &fileName, ZVision *engine);
-	~MetaAnimation();
-
-	struct playnode {
-		Common::Rect pos;
-		int32 slot;
-		int32 start;
-		int32 stop;
-		int32 loop;
-		int32 _curFrame;
-		int32 _delay;
-		Graphics::Surface *_scaled;
-	};
-
-private:
-	enum FileType {
-		RLF = 1,
-		AVI = 2
-	};
-
-private:
-	union {
-		RLFDecoder *rlf;
-		Video::VideoDecoder *avi;
-	} _animation;
-
-	FileType _fileType;
-	int32 _frmDelay;
-
-	const Graphics::Surface *_curFrame;
-
-public:
-
-	uint frameCount();
-	uint width();
-	uint height();
-	uint32 frameTime();
-
-	void seekToFrame(int frameNumber);
-
-	const Graphics::Surface *decodeNextFrame();
-	const Graphics::Surface *getFrameData(uint frameNumber);
-
-	bool endOfAnimation();
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 5c2fd20..6ed3eee 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -1,7 +1,6 @@
 MODULE := engines/zvision
 
 MODULE_OBJS := \
-	animation/meta_animation.o \
 	core/console.o \
 	core/events.o \
 	core/menu.o \
diff --git a/engines/zvision/scripting/controls/fist_control.cpp b/engines/zvision/scripting/controls/fist_control.cpp
index dd6a7f1..c3a6908 100644
--- a/engines/zvision/scripting/controls/fist_control.cpp
+++ b/engines/zvision/scripting/controls/fist_control.cpp
@@ -22,20 +22,19 @@
 
 #include "common/scummsys.h"
 
-#include "zvision/scripting/controls/fist_control.h"
-
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
+#include "zvision/scripting/controls/fist_control.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/cursors/cursor_manager.h"
-#include "zvision/animation/meta_animation.h"
 #include "zvision/utility/utility.h"
+#include "zvision/video/rlf_decoder.h"
 
 #include "common/stream.h"
 #include "common/file.h"
 #include "common/system.h"
-
 #include "graphics/surface.h"
+#include "video/video_decoder.h"
 
 namespace ZVision {
 
@@ -106,7 +105,8 @@ void FistControl::renderFrame(uint frameNumber) {
 	const Graphics::Surface *frameData;
 
 	if (_animation) {
-		frameData = _animation->getFrameData(frameNumber);
+		_animation->seekToFrame(frameNumber);
+		frameData = _animation->decodeNextFrame();
 		if (frameData)
 			_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _anmRect);
 	}
@@ -121,7 +121,7 @@ bool FistControl::process(uint32 deltaTimeInMillis) {
 			_frameTime -= deltaTimeInMillis;
 
 			if (_frameTime <= 0) {
-				_frameTime = _animation->frameTime();
+				_frameTime = 1000.0 / _animation->getDuration().framerate();
 
 				renderFrame(_frameCur);
 
@@ -194,7 +194,7 @@ void FistControl::readDescFile(const Common::String &fileName) {
 		if (param.matchString("animation_id", true)) {
 			// Not used
 		} else if (param.matchString("animation", true)) {
-			_animation = new MetaAnimation(values, _engine);
+			_animation = _engine->loadAnimation(values);
 		} else if (param.matchString("anim_rect", true)) {
 			int left, top, right, bottom;
 			sscanf(values.c_str(), "%d %d %d %d", &left, &top, &right, &bottom);
diff --git a/engines/zvision/scripting/controls/fist_control.h b/engines/zvision/scripting/controls/fist_control.h
index cb765c4..0a6b977 100644
--- a/engines/zvision/scripting/controls/fist_control.h
+++ b/engines/zvision/scripting/controls/fist_control.h
@@ -28,9 +28,11 @@
 #include "common/array.h"
 #include "common/rect.h"
 
-namespace ZVision {
+namespace Video {
+	class VideoDecoder;
+}
 
-class MetaAnimation;
+namespace ZVision {
 
 class FistControl : public Control {
 public:
@@ -58,7 +60,7 @@ private:
 
 	Common::Array<entries> _entries;
 
-	MetaAnimation *_animation;
+	Video::VideoDecoder *_animation;
 	Common::Rect _anmRect;
 	int32   _soundKey;
 	int32   _frameCur;
diff --git a/engines/zvision/scripting/controls/hotmov_control.cpp b/engines/zvision/scripting/controls/hotmov_control.cpp
index 68861dc..dfa0200 100644
--- a/engines/zvision/scripting/controls/hotmov_control.cpp
+++ b/engines/zvision/scripting/controls/hotmov_control.cpp
@@ -28,14 +28,13 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/cursors/cursor_manager.h"
-#include "zvision/animation/meta_animation.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
 #include "common/system.h"
-
 #include "graphics/surface.h"
+#include "video/video_decoder.h"
 
 namespace ZVision {
 
@@ -79,7 +78,7 @@ HotMovControl::HotMovControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 			char filename[64];
 			sscanf(values.c_str(), "%s", filename);
 			values = Common::String(filename);
-			_animation = new MetaAnimation(values, _engine);
+			_animation = _engine->loadAnimation(values);
 		} else if (param.matchString("venus_id", true)) {
 			_venusId = atoi(values.c_str());
 		}
@@ -106,7 +105,8 @@ void HotMovControl::renderFrame(uint frameNumber) {
 	const Graphics::Surface *frameData;
 
 	if (_animation) {
-		frameData = _animation->getFrameData(frameNumber);
+		_animation->seekToFrame(frameNumber);
+		frameData = _animation->decodeNextFrame();
 		if (frameData)
 			_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _rectangle);
 	}
@@ -130,7 +130,7 @@ bool HotMovControl::process(uint32 deltaTimeInMillis) {
 			else
 				_engine->getScriptManager()->setStateValue(_key, 2);
 
-			_frameTime = _animation->frameTime();
+			_frameTime = 1000.0 / _animation->getDuration().framerate();
 		}
 	}
 
diff --git a/engines/zvision/scripting/controls/hotmov_control.h b/engines/zvision/scripting/controls/hotmov_control.h
index 86600d65..b18d44c 100644
--- a/engines/zvision/scripting/controls/hotmov_control.h
+++ b/engines/zvision/scripting/controls/hotmov_control.h
@@ -28,9 +28,11 @@
 #include "common/array.h"
 #include "common/rect.h"
 
-namespace ZVision {
+namespace Video {
+	class VideoDecoder;
+}
 
-class MetaAnimation;
+namespace ZVision {
 
 class HotMovControl : public Control {
 public:
@@ -44,7 +46,7 @@ private:
 	int32  _lastRenderedFrame;
 	int32  _cycle;
 	int32  _cyclesCount;
-	MetaAnimation *_animation;
+	Video::VideoDecoder *_animation;
 	Common::Rect _rectangle;
 	Common::Array<Common::Rect> _frames;
 public:
diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp
index c541693..60dcd37 100644
--- a/engines/zvision/scripting/controls/input_control.cpp
+++ b/engines/zvision/scripting/controls/input_control.cpp
@@ -34,6 +34,7 @@
 #include "common/str.h"
 #include "common/stream.h"
 #include "common/rect.h"
+#include "video/video_decoder.h"
 
 namespace ZVision {
 
@@ -96,7 +97,7 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 
 			sscanf(values.c_str(), "%25s %*u", fileName);
 
-			_animation = new MetaAnimation(fileName, _engine);
+			_animation = _engine->loadAnimation(fileName);
 			_frame = -1;
 			_frameDelay = 0;
 		} else if (param.matchString("focus", true)) {
@@ -213,16 +214,17 @@ bool InputControl::process(uint32 deltaTimeInMillis) {
 		bool needDraw = true;// = _textChanged;
 		_frameDelay -= deltaTimeInMillis;
 		if (_frameDelay <= 0) {
-			_frame = (_frame + 1) % _animation->frameCount();
-			_frameDelay = _animation->frameTime();
+			_frame = (_frame + 1) % _animation->getFrameCount();
+			_frameDelay = 1000.0 / _animation->getDuration().framerate();
 			needDraw = true;
 		}
 
 		if (needDraw) {
-			const Graphics::Surface *srf = _animation->getFrameData(_frame);
+			_animation->seekToFrame(_frame);
+			const Graphics::Surface *srf = _animation->decodeNextFrame();
 			uint32 xx = _textRectangle.left + _txtWidth;
-			if (xx >= _textRectangle.left + (_textRectangle.width() - _animation->width()))
-				xx = _textRectangle.left + _textRectangle.width() - _animation->width();
+			if (xx >= _textRectangle.left + (_textRectangle.width() - (int16)_animation->getWidth()))
+				xx = _textRectangle.left + _textRectangle.width() - (int16)_animation->getWidth();
 			_engine->getRenderManager()->blitSurfaceToBkg(*srf, xx, _textRectangle.top);
 		}
 	}
diff --git a/engines/zvision/scripting/controls/input_control.h b/engines/zvision/scripting/controls/input_control.h
index 410caf6..99f7f52 100644
--- a/engines/zvision/scripting/controls/input_control.h
+++ b/engines/zvision/scripting/controls/input_control.h
@@ -24,12 +24,15 @@
 #define ZVISION_INPUT_CONTROL_H
 
 #include "zvision/scripting/control.h"
-#include "zvision/animation/meta_animation.h"
 #include "zvision/text/text.h"
 #include "zvision/text/string_manager.h"
 
 #include "common/rect.h"
 
+namespace Video {
+	class VideoDecoder;
+}
+
 namespace ZVision {
 
 class InputControl : public Control {
@@ -51,7 +54,7 @@ private:
 	bool _readOnly;
 
 	int16 _txtWidth;
-	MetaAnimation *_animation;
+	Video::VideoDecoder *_animation;
 	int32 _frameDelay;
 	int16 _frame;
 
diff --git a/engines/zvision/scripting/controls/lever_control.cpp b/engines/zvision/scripting/controls/lever_control.cpp
index 1e40879..9566e4e 100644
--- a/engines/zvision/scripting/controls/lever_control.cpp
+++ b/engines/zvision/scripting/controls/lever_control.cpp
@@ -28,15 +28,14 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/cursors/cursor_manager.h"
-#include "zvision/animation/meta_animation.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
 #include "common/tokenizer.h"
 #include "common/system.h"
-
 #include "graphics/surface.h"
+#include "video/video_decoder.h"
 
 namespace ZVision {
 
@@ -106,7 +105,7 @@ void LeverControl::parseLevFile(const Common::String &fileName) {
 		if (param.matchString("animation_id", true)) {
 			// Not used
 		} else if (param.matchString("filename", true)) {
-			_animation = new MetaAnimation(values, _engine);
+			_animation = _engine->loadAnimation(values);
 		} else if (param.matchString("skipcolor", true)) {
 			// Not used
 		} else if (param.matchString("anim_coords", true)) {
@@ -374,7 +373,8 @@ void LeverControl::renderFrame(uint frameNumber) {
 
 	const Graphics::Surface *frameData;
 
-	frameData = _animation->getFrameData(frameNumber);
+	_animation->seekToFrame(frameNumber);
+	frameData = _animation->decodeNextFrame();
 	if (frameData)
 		_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _animationCoords);
 }
diff --git a/engines/zvision/scripting/controls/lever_control.h b/engines/zvision/scripting/controls/lever_control.h
index 37d4d3b..fdf4a64 100644
--- a/engines/zvision/scripting/controls/lever_control.h
+++ b/engines/zvision/scripting/controls/lever_control.h
@@ -28,10 +28,11 @@
 #include "common/list.h"
 #include "common/rect.h"
 
-namespace ZVision {
+namespace Video {
+	class VideoDecoder;
+}
 
-class ZorkAVIDecoder;
-class MetaAnimation;
+namespace ZVision {
 
 class LeverControl : public Control {
 public:
@@ -59,7 +60,7 @@ private:
 	};
 
 private:
-	MetaAnimation *_animation;
+	Video::VideoDecoder *_animation;
 
 	int _cursor;
 	Common::Rect _animationCoords;
diff --git a/engines/zvision/scripting/controls/safe_control.cpp b/engines/zvision/scripting/controls/safe_control.cpp
index 3ad5d3a..9f4e29a 100644
--- a/engines/zvision/scripting/controls/safe_control.cpp
+++ b/engines/zvision/scripting/controls/safe_control.cpp
@@ -28,15 +28,14 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/cursors/cursor_manager.h"
-#include "zvision/animation/meta_animation.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
 #include "common/tokenizer.h"
 #include "common/system.h"
-
 #include "graphics/surface.h"
+#include "video/video_decoder.h"
 
 namespace ZVision {
 
@@ -65,7 +64,7 @@ SafeControl::SafeControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 
 	while (!stream.eos() && !line.contains('}')) {
 		if (param.matchString("animation", true)) {
-			_animation = new MetaAnimation(values, _engine);
+			_animation = _engine->loadAnimation(values);
 		} else if (param.matchString("rectangle", true)) {
 			int x;
 			int y;
@@ -129,7 +128,8 @@ void SafeControl::renderFrame(uint frameNumber) {
 	int x = _rectangle.left;
 	int y = _rectangle.top;
 
-	frameData = _animation->getFrameData(frameNumber);
+	_animation->seekToFrame(frameNumber);
+	frameData = _animation->decodeNextFrame();
 	if (frameData)
 		_engine->getRenderManager()->blitSurfaceToBkg(*frameData, x, y);
 }
@@ -149,7 +149,7 @@ bool SafeControl::process(uint32 deltaTimeInMillis) {
 				_curFrame--;
 				renderFrame(_curFrame);
 			}
-			_frameTime = _animation->frameTime();
+			_frameTime = 1000.0 / _animation->getDuration().framerate();
 		}
 	}
 	return false;
diff --git a/engines/zvision/scripting/controls/safe_control.h b/engines/zvision/scripting/controls/safe_control.h
index e32ca97..6e1095e 100644
--- a/engines/zvision/scripting/controls/safe_control.h
+++ b/engines/zvision/scripting/controls/safe_control.h
@@ -28,10 +28,11 @@
 #include "common/list.h"
 #include "common/rect.h"
 
-namespace ZVision {
+namespace Video {
+	class VideoDecoder;
+}
 
-class ZorkAVIDecoder;
-class MetaAnimation;
+namespace ZVision {
 
 class SafeControl : public Control {
 public:
@@ -41,7 +42,7 @@ public:
 private:
 	int16  _statesCount;
 	int16  _curState;
-	MetaAnimation *_animation;
+	Video::VideoDecoder *_animation;
 	Common::Point _center;
 	Common::Rect _rectangle;
 	int16  _innerRaduis;
diff --git a/engines/zvision/scripting/sidefx/animation_node.cpp b/engines/zvision/scripting/sidefx/animation_node.cpp
index 74e4cad..e15f8ec 100644
--- a/engines/zvision/scripting/sidefx/animation_node.cpp
+++ b/engines/zvision/scripting/sidefx/animation_node.cpp
@@ -27,9 +27,9 @@
 #include "zvision/zvision.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/scripting/script_manager.h"
-#include "zvision/animation/meta_animation.h"
 
 #include "graphics/surface.h"
+#include "video/video_decoder.h"
 
 namespace ZVision {
 
@@ -39,8 +39,8 @@ AnimationNode::AnimationNode(ZVision *engine, uint32 controlKey, const Common::S
 	  _mask(mask),
 	  _animation(NULL) {
 
-	_animation = new MetaAnimation(fileName, engine);
-	_frmDelay = _animation->frameTime();
+	_animation = engine->loadAnimation(fileName);
+	_frmDelay = 1000.0 / _animation->getDuration().framerate();
 
 	if (frate > 0)
 		_frmDelay = 1000.0 / frate;
@@ -164,8 +164,8 @@ void AnimationNode::addPlayNode(int32 slot, int x, int y, int x2, int y2, int st
 	nod.start = startFrame;
 	nod.stop = endFrame;
 
-	if (nod.stop >= (int)_animation->frameCount())
-		nod.stop = _animation->frameCount() - 1;
+	if (nod.stop >= (int)_animation->getFrameCount())
+		nod.stop = _animation->getFrameCount() - 1;
 
 	nod.slot = slot;
 	nod._curFrame = -1;
diff --git a/engines/zvision/scripting/sidefx/animation_node.h b/engines/zvision/scripting/sidefx/animation_node.h
index 94428d2..3adfd91 100644
--- a/engines/zvision/scripting/sidefx/animation_node.h
+++ b/engines/zvision/scripting/sidefx/animation_node.h
@@ -27,18 +27,17 @@
 #include "common/rect.h"
 #include "common/list.h"
 
-namespace Common {
-class String;
-}
-
 namespace Graphics {
 struct Surface;
 }
 
+namespace Video {
+	class VideoDecoder;
+}
+
 namespace ZVision {
 
 class ZVision;
-class MetaAnimation;
 
 class AnimationNode : public SideFX {
 public:
@@ -64,7 +63,7 @@ private:
 	int32 _mask;
 	bool _DisposeAfterUse;
 
-	MetaAnimation *_animation;
+	Video::VideoDecoder *_animation;
 	int32 _frmDelay;
 
 public:
diff --git a/engines/zvision/video/rlf_decoder.cpp b/engines/zvision/video/rlf_decoder.cpp
index a4f16af..bdb5dc1 100644
--- a/engines/zvision/video/rlf_decoder.cpp
+++ b/engines/zvision/video/rlf_decoder.cpp
@@ -34,75 +34,46 @@
 
 namespace ZVision {
 
-RLFDecoder::RLFDecoder(const Common::String &fileName, bool stream)
-	: _stream(stream),
-	  _readStream(NULL),
-	  _lastFrameRead(0),
-	  _frameCount(0),
-	  _width(0),
-	  _height(0),
-	  _frameTime(0),
-	  _frames(0),
-	  _nextFrame(0),
-	  _frameBufferByteSize(0) {
-
-	Common::File *_file = new Common::File;
-	if (!_file->open(fileName)) {
-		warning("RLF animation file %s could not be opened", fileName.c_str());
-		return;
-	}
-
-	_readStream = _file;
-
-	if (!readHeader()) {
-		warning("%s is not a RLF animation file. Wrong magic number", fileName.c_str());
-		return;
-	}
+RLFDecoder::~RLFDecoder() {
+	close();
+}
 
-	_currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>());
-	_frameBufferByteSize = _width * _height * sizeof(uint16);
+bool RLFDecoder::loadStream(Common::SeekableReadStream *stream) {
+	close();
 
-	if (!stream) {
-		_frames = new Frame[_frameCount];
+	addTrack(new RLFVideoTrack(stream));
 
-		// Read in each frame
-		for (uint i = 0; i < _frameCount; ++i) {
-			_frames[i] = readNextFrame();
-		}
-	}
+	return true;
 }
 
-RLFDecoder::RLFDecoder(Common::SeekableReadStream *rstream, bool stream)
-	: _stream(stream),
-	  _readStream(rstream),
+RLFDecoder::RLFVideoTrack::RLFVideoTrack(Common::SeekableReadStream *stream)
+	: _readStream(stream),
 	  _lastFrameRead(0),
 	  _frameCount(0),
 	  _width(0),
 	  _height(0),
 	  _frameTime(0),
 	  _frames(0),
-	  _nextFrame(0),
+	  _curFrame(0),
 	  _frameBufferByteSize(0) {
 
 	if (!readHeader()) {
-		warning("Stream is not a RLF animation. Wrong magic number");
+		warning("Not a RLF animation file. Wrong magic number");
 		return;
 	}
 
 	_currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>());
 	_frameBufferByteSize = _width * _height * sizeof(uint16);
 
-	if (!stream) {
-		_frames = new Frame[_frameCount];
+	_frames = new Frame[_frameCount];
 
-		// Read in each frame
-		for (uint i = 0; i < _frameCount; ++i) {
-			_frames[i] = readNextFrame();
-		}
+	// Read in each frame
+	for (uint i = 0; i < _frameCount; ++i) {
+		_frames[i] = readNextFrame();
 	}
 }
 
-RLFDecoder::~RLFDecoder() {
+RLFDecoder::RLFVideoTrack::~RLFVideoTrack() {
 	for (uint i = 0; i < _frameCount; ++i) {
 		delete[] _frames[i].encodedData;
 	}
@@ -111,7 +82,7 @@ RLFDecoder::~RLFDecoder() {
 	_currentFrameBuffer.free();
 }
 
-bool RLFDecoder::readHeader() {
+bool RLFDecoder::RLFVideoTrack::readHeader() {
 	if (_readStream->readUint32BE() != MKTAG('F', 'E', 'L', 'R')) {
 		return false;
 	}
@@ -160,8 +131,8 @@ bool RLFDecoder::readHeader() {
 	return true;
 }
 
-RLFDecoder::Frame RLFDecoder::readNextFrame() {
-	RLFDecoder::Frame frame;
+RLFDecoder::RLFVideoTrack::Frame RLFDecoder::RLFVideoTrack::readNextFrame() {
+	RLFDecoder::RLFVideoTrack::Frame frame;
 
 	_readStream->readUint32BE();                        // Magic number MARF
 	uint32 size = _readStream->readUint32LE();          // Size
@@ -188,30 +159,30 @@ RLFDecoder::Frame RLFDecoder::readNextFrame() {
 	return frame;
 }
 
-void RLFDecoder::seekToFrame(int frameNumber) {
-	assert(!_stream);
-	assert(frameNumber < (int)_frameCount || frameNumber >= -1);
+bool RLFDecoder::RLFVideoTrack::seek(const Audio::Timestamp &time) {
+	uint frame = getFrameAtTime(time);
+	assert(frame < (int)_frameCount);
 
-	if (_nextFrame == frameNumber)
-		return;
+	if ((uint)_curFrame == frame)
+		return true;
 
-	if (frameNumber < 0) {
-		_nextFrame = 0;
-		return;
+	if (frame < 0) {
+		_curFrame = 0;
+		return false;
 	}
 
-	int closestFrame = _nextFrame;
-	int distance = (int)frameNumber - _nextFrame;
+	int closestFrame = _curFrame;
+	int distance = (int)frame - _curFrame;
 
 	if (distance < 0) {
 		for (uint i = 0; i < _completeFrames.size(); ++i) {
-			if ((int)_completeFrames[i] > frameNumber)
+			if ((int)_completeFrames[i] > frame)
 				break;
 			closestFrame = _completeFrames[i];
 		}
 	} else {
 		for (uint i = 0; i < _completeFrames.size(); ++i) {
-			int newDistance = (int)frameNumber - (int)(_completeFrames[i]);
+			int newDistance = (int)frame - (int)(_completeFrames[i]);
 			if (newDistance < 0)
 				break;
 			if (newDistance < distance) {
@@ -221,43 +192,27 @@ void RLFDecoder::seekToFrame(int frameNumber) {
 		}
 	}
 
-	for (int i = closestFrame; i < frameNumber; ++i) {
+	for (uint i = closestFrame; i < frame; ++i) {
 		applyFrameToCurrent(i);
 	}
 
-	_nextFrame = frameNumber;
-}
-
-const Graphics::Surface *RLFDecoder::getFrameData(uint frameNumber) {
-	assert(!_stream);
-	assert(frameNumber < _frameCount);
+	_curFrame = frame;
 
-	// Since this method is so expensive, first check to see if we can use
-	// decodeNextFrame() it's cheap.
-	if ((int)frameNumber == _nextFrame - 1) {
-		return &_currentFrameBuffer;
-	} else if (_nextFrame == (int)frameNumber) {
-		return decodeNextFrame();
-	}
-
-	seekToFrame(frameNumber);
-	return decodeNextFrame();
+	return true;
 }
 
-const Graphics::Surface *RLFDecoder::decodeNextFrame() {
-	assert(_nextFrame < (int)_frameCount);
+const Graphics::Surface *RLFDecoder::RLFVideoTrack::decodeNextFrame() {
+	// When an animation ends, rewind
+	if (_curFrame == (int)_frameCount)
+		seek(Audio::Timestamp(0, getFrameRate().toInt()));
+	
+	applyFrameToCurrent(_curFrame);
 
-	if (_stream) {
-		applyFrameToCurrent(readNextFrame());
-	} else {
-		applyFrameToCurrent(_nextFrame);
-	}
-
-	_nextFrame++;
+	_curFrame++;
 	return &_currentFrameBuffer;
 }
 
-void RLFDecoder::applyFrameToCurrent(uint frameNumber) {
+void RLFDecoder::RLFVideoTrack::applyFrameToCurrent(uint frameNumber) {
 	if (_frames[frameNumber].type == Masked) {
 		decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize);
 	} else if (_frames[frameNumber].type == Simple) {
@@ -265,15 +220,7 @@ void RLFDecoder::applyFrameToCurrent(uint frameNumber) {
 	}
 }
 
-void RLFDecoder::applyFrameToCurrent(const RLFDecoder::Frame &frame) {
-	if (frame.type == Masked) {
-		decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
-	} else if (frame.type == Simple) {
-		decodeSimpleRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize);
-	}
-}
-
-void RLFDecoder::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
+void RLFDecoder::RLFVideoTrack::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
 	uint32 sourceOffset = 0;
 	uint32 destOffset = 0;
 	int16 numberOfCopy = 0;
@@ -320,7 +267,7 @@ void RLFDecoder::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32
 	}
 }
 
-void RLFDecoder::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
+void RLFDecoder::RLFVideoTrack::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const {
 	uint32 sourceOffset = 0;
 	uint32 destOffset = 0;
 	int16 numberOfCopy = 0;
diff --git a/engines/zvision/video/rlf_decoder.h b/engines/zvision/video/rlf_decoder.h
index dcfd860..f0f31c2 100644
--- a/engines/zvision/video/rlf_decoder.h
+++ b/engines/zvision/video/rlf_decoder.h
@@ -24,147 +24,109 @@
 #define ZVISION_RLF_DECODER_H
 
 #include "common/file.h"
+#include "video/video_decoder.h"
 
 #include "graphics/surface.h"
 
-namespace Common {
-class String;
-}
-
 namespace ZVision {
 
-class RLFDecoder {
+class RLFDecoder : public Video::VideoDecoder {
 public:
-	RLFDecoder(const Common::String &fileName, bool stream = true);
-	RLFDecoder(Common::SeekableReadStream *rstream, bool stream);
+	RLFDecoder() {}
 	~RLFDecoder();
 
-private:
-	enum EncodingType {
-		Masked,
-		Simple
-	};
-
-	struct Frame {
-		EncodingType type;
-		int8 *encodedData;
-		uint32 encodedSize;
-	};
-
-private:
-	Common::SeekableReadStream *_readStream;
-	bool _stream;
-	uint _lastFrameRead;
-
-	uint _frameCount;
-	uint _width;
-	uint _height;
-	uint32 _frameTime; // In milliseconds
-	Frame *_frames;
-	Common::Array<uint> _completeFrames;
-
-	int _nextFrame;
-	Graphics::Surface _currentFrameBuffer;
-	uint32 _frameBufferByteSize;
-
-public:
-	uint frameCount() {
-		return _frameCount;
-	}
-	uint width() {
-		return _width;
-	}
-	uint height() {
-		return _height;
-	}
-	uint32 frameTime() {
-		return _frameTime;
-	}
-
-	/**
-	 * Seeks to the frameNumber and updates the internal Surface with
-	 * the new frame data. If frameNumber == -1, it only sets _currentFrame,
-	 * the internal Surface is unchanged. This function requires _stream = false
-	 *
-	 * @param frameNumber    The frame number to seek to
-	 */
-	void seekToFrame(int frameNumber);
-
-	/**
-	 * Returns the pixel data of the frame specified. It will try to use
-	 * decodeNextFrame() if possible. If not, it uses seekToFrame() to
-	 * update the internal Surface and then returns a pointer to it.
-	 * This function requires _stream = false
-	 *
-	 * @param frameNumber    The frame number to get data for
-	 * @return               A pointer to the pixel data. Do NOT delete this.
-	 */
-	const Graphics::Surface *getFrameData(uint frameNumber);
-	/**
-	 * Returns the pixel data of current frame and go to next. It is up to the user to
-	 * check if the current frame is valid before calling this.
-	 * IE. Use endOfAnimation()
-	 *
-	 * @return    A pointer to the pixel data. Do NOT delete this.
-	 */
-	const Graphics::Surface *decodeNextFrame();
-	/**
-	 * @return Is the currentFrame is the last frame in the animation?
-	 */
-	bool endOfAnimation() {
-		return _nextFrame == (int)_frameCount;
-	}
+	bool loadStream(Common::SeekableReadStream *stream);
 
 private:
-	/**
-	 * Reads in the header of the RLF file
-	 *
-	 * @return    Will return false if the header magic number is wrong
-	 */
-	bool readHeader();
-	/**
-	 * Reads the next frame from the RLF file, stores the data in
-	 * a Frame object, then returns the object
-	 *
-	 * @return    A Frame object representing the frame data
-	 */
-	Frame readNextFrame();
-
-	/**
-	 * Applies the frame corresponding to frameNumber on top of _currentFrameBuffer.
-	 * This function requires _stream = false so it can look up the Frame object
-	 * referenced by frameNumber.
-	 *
-	 * @param frameNumber    The frame number to apply to _currentFrameBuffer
-	 */
-	void applyFrameToCurrent(uint frameNumber);
-	/**
-	 * Applies the data from a Frame object on top of a _currentFrameBuffer.
-	 *
-	 * @param frame    A Frame object to apply to _currentFrameBuffer
-	 */
-	void applyFrameToCurrent(const RLFDecoder::Frame &frame);
-
-	/**
-	 * Decode frame data that uses masked run length encoding. This is the encoding
-	 * used by P-frames.
-	 *
-	 * @param source        The source pixel data
-	 * @param dest          The destination buffer
-	 * @param sourceSize    The size of the source pixel data
-	 * @param destSize      The size of the destination buffer
-	 */
-	void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
-	/**
-	 * Decode frame data that uses simple run length encoding. This is the encoding
-	 * used by I-frames.
-	 *
-	 * @param source        The source pixel data
-	 * @param dest          The destination buffer
-	 * @param sourceSize    The size of the source pixel data
-	 * @param destSize      The size of the destination buffer
-	 */
-	void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
+	class RLFVideoTrack : public FixedRateVideoTrack {
+	public:
+		RLFVideoTrack(Common::SeekableReadStream *stream);
+		~RLFVideoTrack();
+
+		uint16 getWidth() const { return _width; }
+		uint16 getHeight() const { return _height; }
+		Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); /*RGB 565*/ }
+		int getCurFrame() const { return _curFrame; }
+		int getFrameCount() const { return _frameCount; }
+		const Graphics::Surface *decodeNextFrame();
+		bool isSeekable() const { return true; }
+		bool seek(const Audio::Timestamp &time);
+
+	protected:
+		Common::Rational getFrameRate() const { return Common::Rational(60, _frameTime); }
+
+	private:
+		enum EncodingType {
+			Masked,
+			Simple
+		};
+
+		struct Frame {
+			EncodingType type;
+			int8 *encodedData;
+			uint32 encodedSize;
+		};
+
+		/**
+		 * Reads in the header of the RLF file
+		 *
+		 * @return    Will return false if the header magic number is wrong
+		 */
+		bool readHeader();
+
+		/**
+		 * Reads the next frame from the RLF file, stores the data in
+		 * a Frame object, then returns the object
+		 *
+		 * @return    A Frame object representing the frame data
+		 */
+		Frame readNextFrame();
+
+		/**
+		 * Applies the frame corresponding to frameNumber on top of _currentFrameBuffer.
+		 * This function requires _stream = false so it can look up the Frame object
+		 * referenced by frameNumber.
+		 *
+		 * @param frameNumber    The frame number to apply to _currentFrameBuffer
+		 */
+		void applyFrameToCurrent(uint frameNumber);
+
+		/**
+		 * Decode frame data that uses masked run length encoding. This is the encoding
+		 * used by P-frames.
+		 *
+		 * @param source        The source pixel data
+		 * @param dest          The destination buffer
+		 * @param sourceSize    The size of the source pixel data
+		 * @param destSize      The size of the destination buffer
+		 */
+		void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
+		/**
+		 * Decode frame data that uses simple run length encoding. This is the encoding
+		 * used by I-frames.
+		 *
+		 * @param source        The source pixel data
+		 * @param dest          The destination buffer
+		 * @param sourceSize    The size of the source pixel data
+		 * @param destSize      The size of the destination buffer
+		 */
+		void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const;
+
+		uint _lastFrameRead;
+
+		uint _frameCount;
+		uint _width;
+		uint _height;
+		uint32 _frameTime; // In milliseconds
+		Frame *_frames;
+		Common::Array<uint> _completeFrames;
+
+		int _curFrame;
+		Graphics::Surface _currentFrameBuffer;
+		uint32 _frameBufferByteSize;
+
+		Common::SeekableReadStream *_readStream;
+	};	// RLFVideoTrack
 };
 
 } // End of namespace ZVision
diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp
index db6161b..c8f968d 100644
--- a/engines/zvision/video/video.cpp
+++ b/engines/zvision/video/video.cpp
@@ -30,9 +30,29 @@
 #include "zvision/utility/clock.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/subtitles.h"
+#include "zvision/video/rlf_decoder.h"
+#include "zvision/video/zork_avi_decoder.h"
 
 namespace ZVision {
 
+Video::VideoDecoder *ZVision::loadAnimation(const Common::String &fileName) {
+	Common::String tmpFileName = fileName;
+	tmpFileName.toLowercase();
+	Video::VideoDecoder *animation = NULL;
+
+	if (tmpFileName.hasSuffix(".rlf"))
+		animation = new RLFDecoder();
+	else if (tmpFileName.hasSuffix(".avi"))
+		animation = new ZorkAVIDecoder();
+	else
+		error("Unknown suffix for animation %s", fileName.c_str());
+
+	Common::File *_file = getSearchManager()->openFile(tmpFileName);
+	animation->loadStream(_file);
+	
+	return animation;
+}
+
 void ZVision::playVideo(Video::VideoDecoder &vid, const Common::Rect &destRect, bool skippable, Subtitle *sub) {
 	Common::Rect dst = destRect;
 	// If destRect is empty, no specific scaling was requested. However, we may choose to do scaling anyway
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index f8763f9..82030e6 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -173,6 +173,7 @@ public:
 	 * @param skippable       If true, the video can be skipped at any time using [Spacebar]
 	 */
 	void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true, Subtitle *sub = NULL);
+	Video::VideoDecoder *loadAnimation(const Common::String &fileName);
 
 	void rotateTo(int16 to, int16 time);
 


Commit: 4b2b5e686b6ac2105f11983b2072037358d9ad7f
    https://github.com/scummvm/scummvm/commit/4b2b5e686b6ac2105f11983b2072037358d9ad7f
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:55+02:00

Commit Message:
ZVISION: Move the mouse cursor handling code into the graphics code

Changed paths:
  A engines/zvision/graphics/cursors/cursor.cpp
  A engines/zvision/graphics/cursors/cursor.h
  A engines/zvision/graphics/cursors/cursor_manager.cpp
  A engines/zvision/graphics/cursors/cursor_manager.h
  R engines/zvision/cursors/cursor.cpp
  R engines/zvision/cursors/cursor.h
  R engines/zvision/cursors/cursor_manager.cpp
  R engines/zvision/cursors/cursor_manager.h
    engines/zvision/core/console.cpp
    engines/zvision/core/events.cpp
    engines/zvision/module.mk
    engines/zvision/scripting/actions.cpp
    engines/zvision/scripting/controls/fist_control.cpp
    engines/zvision/scripting/controls/hotmov_control.cpp
    engines/zvision/scripting/controls/input_control.cpp
    engines/zvision/scripting/controls/lever_control.cpp
    engines/zvision/scripting/controls/paint_control.cpp
    engines/zvision/scripting/controls/push_toggle_control.cpp
    engines/zvision/scripting/controls/safe_control.cpp
    engines/zvision/scripting/controls/slot_control.cpp
    engines/zvision/scripting/script_manager.cpp
    engines/zvision/zvision.cpp



diff --git a/engines/zvision/core/console.cpp b/engines/zvision/core/console.cpp
index 0f6cbfc..76481a3 100644
--- a/engines/zvision/core/console.cpp
+++ b/engines/zvision/core/console.cpp
@@ -31,7 +31,7 @@
 #include "zvision/video/zork_avi_decoder.h"
 #include "zvision/sound/zork_raw.h"
 #include "zvision/utility/utility.h"
-#include "zvision/cursors/cursor.h"
+#include "zvision/graphics/cursors/cursor.h"
 
 #include "common/system.h"
 #include "common/file.h"
diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp
index 839f919..c66e61a 100644
--- a/engines/zvision/core/events.cpp
+++ b/engines/zvision/core/events.cpp
@@ -25,7 +25,7 @@
 #include "zvision/zvision.h"
 
 #include "zvision/core/console.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/core/menu.h"
diff --git a/engines/zvision/cursors/cursor.cpp b/engines/zvision/cursors/cursor.cpp
deleted file mode 100644
index b07220d..0000000
--- a/engines/zvision/cursors/cursor.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-*/
-
-#include "common/scummsys.h"
-
-#include "zvision/cursors/cursor.h"
-
-#include "common/str.h"
-#include "common/file.h"
-
-namespace ZVision {
-
-ZorkCursor::ZorkCursor()
-	: _width(0),
-	  _height(0),
-	  _hotspotX(0),
-	  _hotspotY(0) {
-}
-
-ZorkCursor::ZorkCursor(const Common::String &fileName)
-	: _width(0),
-	  _height(0),
-	  _hotspotX(0),
-	  _hotspotY(0) {
-	Common::File file;
-	if (!file.open(fileName))
-		return;
-
-	uint32 magic = file.readUint32BE();
-	if (magic != MKTAG('Z', 'C', 'R', '1')) {
-		warning("%s is not a Zork Cursor file", fileName.c_str());
-		return;
-	}
-
-	_hotspotX = file.readUint16LE();
-	_hotspotY = file.readUint16LE();
-	_width = file.readUint16LE();
-	_height = file.readUint16LE();
-
-	uint dataSize = _width * _height * sizeof(uint16);
-	_surface.create(_width, _height, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
-	uint32 bytesRead = file.read(_surface.getPixels(), dataSize);
-	assert(bytesRead == dataSize);
-
-	// Convert to RGB 565
-	_surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
-}
-
-ZorkCursor::ZorkCursor(ZVision *engine, const Common::String &fileName)
-	: _width(0),
-	  _height(0),
-	  _hotspotX(0),
-	  _hotspotY(0) {
-	Common::File file;
-	if (!engine->getSearchManager()->openFile(file, fileName))
-		return;
-
-	uint32 magic = file.readUint32BE();
-	if (magic != MKTAG('Z', 'C', 'R', '1')) {
-		warning("%s is not a Zork Cursor file", fileName.c_str());
-		return;
-	}
-
-	_hotspotX = file.readUint16LE();
-	_hotspotY = file.readUint16LE();
-	_width = file.readUint16LE();
-	_height = file.readUint16LE();
-
-	uint dataSize = _width * _height * sizeof(uint16);
-	_surface.create(_width, _height, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
-	uint32 bytesRead = file.read(_surface.getPixels(), dataSize);
-	assert(bytesRead == dataSize);
-
-	// Convert to RGB 565
-	_surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
-}
-
-ZorkCursor::ZorkCursor(const ZorkCursor &other) {
-	_width = other._width;
-	_height = other._height;
-	_hotspotX = other._hotspotX;
-	_hotspotY = other._hotspotY;
-
-	_surface.copyFrom(other._surface);
-}
-
-ZorkCursor &ZorkCursor::operator=(const ZorkCursor &other) {
-	_width = other._width;
-	_height = other._height;
-	_hotspotX = other._hotspotX;
-	_hotspotY = other._hotspotY;
-
-	_surface.free();
-	_surface.copyFrom(other._surface);
-
-	return *this;
-}
-
-ZorkCursor::~ZorkCursor() {
-	_surface.free();
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/cursors/cursor.h b/engines/zvision/cursors/cursor.h
deleted file mode 100644
index 0c1e994..0000000
--- a/engines/zvision/cursors/cursor.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_CURSOR_H
-#define ZVISION_CURSOR_H
-
-#include "graphics/surface.h"
-#include "zvision/zvision.h"
-
-namespace Common {
-class String;
-}
-
-namespace ZVision {
-
-/**
- * Utility class to parse and hold cursor data
- * Modeled off Graphics::Cursor
- */
-class ZorkCursor {
-public:
-	ZorkCursor();
-	ZorkCursor(const Common::String &fileName);
-	ZorkCursor(ZVision *engine, const Common::String &fileName);
-	ZorkCursor(const ZorkCursor &other);
-	~ZorkCursor();
-
-private:
-	uint16 _width;
-	uint16 _height;
-	uint16 _hotspotX;
-	uint16 _hotspotY;
-	Graphics::Surface _surface;
-
-public:
-	ZorkCursor &operator=(const ZorkCursor &other);
-
-	uint16 getWidth() const {
-		return _width;
-	}
-	uint16 getHeight() const {
-		return _height;
-	}
-	uint16 getHotspotX() const {
-		return _hotspotX;
-	}
-	uint16 getHotspotY() const {
-		return _hotspotY;
-	}
-	byte getKeyColor() const {
-		return 0;
-	}
-	const byte *getSurface() const {
-		return (const byte *)_surface.getPixels();
-	}
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/cursors/cursor_manager.cpp b/engines/zvision/cursors/cursor_manager.cpp
deleted file mode 100644
index 33fb555..0000000
--- a/engines/zvision/cursors/cursor_manager.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-*/
-
-#include "common/scummsys.h"
-
-#include "zvision/cursors/cursor_manager.h"
-
-#include "zvision/zvision.h"
-
-#include "common/system.h"
-
-#include "graphics/pixelformat.h"
-#include "graphics/cursorman.h"
-
-namespace ZVision {
-
-const char *CursorManager::_cursorNames[NUM_CURSORS] = { "active", "arrow", "backward", "downarrow", "forward", "handpt", "handpu", "hdown", "hleft",
-                                                         "hright", "hup", "idle", "leftarrow", "rightarrow", "suggest_surround", "suggest_tilt", "turnaround", "zuparrow"
-                                                       };
-
-const char *CursorManager::_zgiCursorFileNames[NUM_CURSORS] = { "g0gbc011.zcr", "g0gac001.zcr", "g0gac021.zcr", "g0gac031.zcr", "g0gac041.zcr", "g0gac051.zcr", "g0gac061.zcr", "g0gac071.zcr", "g0gac081.zcr",
-                                                                "g0gac091.zcr", "g0gac101.zcr", "g0gac011.zcr", "g0gac111.zcr", "g0gac121.zcr", "g0gac131.zcr", "g0gac141.zcr", "g0gac151.zcr", "g0gac161.zcr"
-                                                              };
-
-const char *CursorManager::_zNemCursorFileNames[NUM_CURSORS] = { "00act", "arrow", "back", "down", "forw", "handpt", "handpu", "hdown", "hleft",
-                                                                 "hright", "hup", "00idle", "left", "right", "ssurr", "stilt", "turn", "up"
-                                                               };
-
-CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat)
-	: _engine(engine),
-	  _pixelFormat(pixelFormat),
-	  _cursorIsPushed(false),
-	  _item(0),
-	  _lastitem(0) {
-	for (int i = 0; i < NUM_CURSORS; i++) {
-		if (_engine->getGameId() == GID_NEMESIS) {
-			Common::String name;
-			name = Common::String::format("%sa.zcr", _zNemCursorFileNames[i]);
-			_cursors[i][0] = ZorkCursor(_engine, name); // Up cursor
-			name = Common::String::format("%sb.zcr", _zNemCursorFileNames[i]);
-			_cursors[i][1] = ZorkCursor(_engine, name); // Down cursor
-		} else if (_engine->getGameId() == GID_GRANDINQUISITOR) {
-			_cursors[i][0] = ZorkCursor(_engine, _zgiCursorFileNames[i]); // Up cursor
-			char buffer[25];
-			strcpy(buffer, _zgiCursorFileNames[i]);
-			buffer[3] += 2;
-			_cursors[i][1] = ZorkCursor(_engine, buffer); // Down cursor
-		}
-	}
-}
-
-void CursorManager::setItemID(int id) {
-	if (id != _item) {
-		if (id) {
-			Common::String file;
-			if (_engine->getGameId() == GID_NEMESIS) {
-				file = Common::String::format("%2.2d%s%c.zcr", id, "idle", 'a');
-				_cursors[NUM_CURSORS][0] = ZorkCursor(_engine, file);
-				file = Common::String::format("%2.2d%s%c.zcr", id, "idle", 'b');
-				_cursors[NUM_CURSORS][1] = ZorkCursor(_engine, file);
-				file = Common::String::format("%2.2d%s%c.zcr", id, "act", 'a');
-				_cursors[NUM_CURSORS + 1][0] = ZorkCursor(_engine, file);
-				file = Common::String::format("%2.2d%s%c.zcr", id, "act", 'b');
-				_cursors[NUM_CURSORS + 1][0] = ZorkCursor(_engine, file);
-			} else if (_engine->getGameId() == GID_GRANDINQUISITOR) {
-				file = Common::String::format("g0b%cc%2.2x1.zcr", 'a' , id);
-				_cursors[NUM_CURSORS][0] = ZorkCursor(_engine, file);
-				file = Common::String::format("g0b%cc%2.2x1.zcr", 'c' , id);
-				_cursors[NUM_CURSORS][1] = ZorkCursor(_engine, file);
-				file = Common::String::format("g0b%cc%2.2x1.zcr", 'b' , id);
-				_cursors[NUM_CURSORS + 1][0] = ZorkCursor(_engine, file);
-				file = Common::String::format("g0b%cc%2.2x1.zcr", 'd' , id);
-				_cursors[NUM_CURSORS + 1][1] = ZorkCursor(_engine, file);
-			} else
-				return;
-		}
-		_item = id;
-		changeCursor(CursorIndex_Idle);
-	}
-}
-
-void CursorManager::initialize() {
-	changeCursor(_cursors[CursorIndex_Idle][_cursorIsPushed]);
-	showMouse(true);
-}
-
-void CursorManager::changeCursor(const ZorkCursor &cursor) {
-	CursorMan.replaceCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat);
-}
-
-void CursorManager::cursorDown(bool pushed) {
-	if (_cursorIsPushed == pushed)
-		return;
-
-	_cursorIsPushed = pushed;
-
-	changeCursor(_cursors[_currentCursor][_cursorIsPushed]);
-}
-
-void CursorManager::changeCursor(int id) {
-	int _id = id;
-
-	if (_item &&
-	        (_id == CursorIndex_Active ||
-	         _id == CursorIndex_Idle ||
-	         _id == CursorIndex_HandPu)) {
-
-		if (_id == CursorIndex_Idle)
-			_id = CursorIndex_ItemIdle;
-		else
-			_id = CursorIndex_ItemAct;
-	}
-
-	if (_currentCursor != _id ||
-	        ((_id == CursorIndex_ItemAct || _id == CursorIndex_ItemIdle) && _lastitem != _item)) {
-		_currentCursor = _id;
-		_lastitem = _item;
-		changeCursor(_cursors[_currentCursor][_cursorIsPushed]);
-	}
-}
-
-int CursorManager::getCursorId(const Common::String &name) {
-	for (int i = 0; i < NUM_CURSORS; i++)
-		if (name.equals(_cursorNames[i]))
-			return i;
-	return CursorIndex_Idle;
-}
-
-void CursorManager::showMouse(bool vis) {
-	CursorMan.showMouse(vis);
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/cursors/cursor_manager.h b/engines/zvision/cursors/cursor_manager.h
deleted file mode 100644
index 460f6fa..0000000
--- a/engines/zvision/cursors/cursor_manager.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_CURSOR_MANAGER_H
-#define ZVISION_CURSOR_MANAGER_H
-
-#include "zvision/cursors/cursor.h"
-
-#include "common/str.h"
-
-namespace Graphics {
-struct PixelFormat;
-}
-
-namespace ZVision {
-
-class ZVision;
-
-/**
- * Mostly usable cursors
- */
-enum CursorIndex {
-	CursorIndex_Active = 0,
-	CursorIndex_DownArr = 3,
-	CursorIndex_HandPu = 6,
-	CursorIndex_Idle = 11,
-	CursorIndex_Left = 12,
-	CursorIndex_Right = 13,
-	CursorIndex_UpArr = 17,
-	CursorIndex_ItemIdle = 18,
-	CursorIndex_ItemAct = 19
-};
-
-/**
- * Class to manage cursor changes. The actual changes have to be done
- * through CursorMan. Otherwise the cursor will disappear after GMM
- * or debug console.
- * TODO: Figure out a way to get rid of the extraneous data copying due to having to use CursorMan
- */
-class CursorManager {
-public:
-	CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat);
-
-private:
-	static const int NUM_CURSORS = 18;
-
-	// 18 default cursors in up/down states, +2 for items idle/act cursors
-	ZorkCursor _cursors[NUM_CURSORS + 2][2];
-
-	ZVision *_engine;
-	const Graphics::PixelFormat *_pixelFormat;
-	bool _cursorIsPushed;
-	int _item;
-	int _lastitem;
-	int _currentCursor;
-
-	static const char *_cursorNames[];
-	static const char *_zgiCursorFileNames[];
-	static const char *_zNemCursorFileNames[];
-
-public:
-	/** Creates the idle cursor and shows it */
-	void initialize();
-
-	/**
-	 * Change cursor to specified cursor ID. If item setted to not 0 and cursor id idle/acrive/handpu change cursor to item.
-	 *
-	 * @param id    Wanted cursor id.
-	 */
-
-	void changeCursor(int id);
-
-	/**
-	 * Return founded id for string contains cursor name
-	 *
-	 * @param name    Cursor name
-	 * @return        Id of cursor or idle cursor id if not found
-	 */
-
-	int getCursorId(const Common::String &name);
-
-	/**
-	 * Load cursor for item by id, and try to change cursor to item cursor if it's not 0
-	 *
-	 * @param id    Item id or 0 for no item cursor
-	 */
-
-	void setItemID(int id);
-
-	/**
-	 * Change the cursor to a certain push state. If the cursor is already in the specified push state, nothing will happen.
-	 *
-	 * @param pushed    Should the cursor be pushed (true) or not pushed (false) (Another way to say it: down or up)
-	 */
-	void cursorDown(bool pushed);
-
-	/**
-	 * Show or hide mouse cursor.
-	 *
-	 * @param vis    Should the cursor be showed (true) or hide (false)
-	 */
-	void showMouse(bool vis);
-
-private:
-	/**
-	 * Calls CursorMan.replaceCursor() using the data in cursor
-	 *
-	 * @param cursor    The cursor to show
-	 */
-	void changeCursor(const ZorkCursor &cursor);
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/graphics/cursors/cursor.cpp b/engines/zvision/graphics/cursors/cursor.cpp
new file mode 100644
index 0000000..07323b4
--- /dev/null
+++ b/engines/zvision/graphics/cursors/cursor.cpp
@@ -0,0 +1,122 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "common/scummsys.h"
+
+#include "zvision/graphics/cursors/cursor.h"
+
+#include "common/str.h"
+#include "common/file.h"
+
+namespace ZVision {
+
+ZorkCursor::ZorkCursor()
+	: _width(0),
+	  _height(0),
+	  _hotspotX(0),
+	  _hotspotY(0) {
+}
+
+ZorkCursor::ZorkCursor(const Common::String &fileName)
+	: _width(0),
+	  _height(0),
+	  _hotspotX(0),
+	  _hotspotY(0) {
+	Common::File file;
+	if (!file.open(fileName))
+		return;
+
+	uint32 magic = file.readUint32BE();
+	if (magic != MKTAG('Z', 'C', 'R', '1')) {
+		warning("%s is not a Zork Cursor file", fileName.c_str());
+		return;
+	}
+
+	_hotspotX = file.readUint16LE();
+	_hotspotY = file.readUint16LE();
+	_width = file.readUint16LE();
+	_height = file.readUint16LE();
+
+	uint dataSize = _width * _height * sizeof(uint16);
+	_surface.create(_width, _height, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
+	uint32 bytesRead = file.read(_surface.getPixels(), dataSize);
+	assert(bytesRead == dataSize);
+
+	// Convert to RGB 565
+	_surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
+}
+
+ZorkCursor::ZorkCursor(ZVision *engine, const Common::String &fileName)
+	: _width(0),
+	  _height(0),
+	  _hotspotX(0),
+	  _hotspotY(0) {
+	Common::File file;
+	if (!engine->getSearchManager()->openFile(file, fileName))
+		return;
+
+	uint32 magic = file.readUint32BE();
+	if (magic != MKTAG('Z', 'C', 'R', '1')) {
+		warning("%s is not a Zork Cursor file", fileName.c_str());
+		return;
+	}
+
+	_hotspotX = file.readUint16LE();
+	_hotspotY = file.readUint16LE();
+	_width = file.readUint16LE();
+	_height = file.readUint16LE();
+
+	uint dataSize = _width * _height * sizeof(uint16);
+	_surface.create(_width, _height, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
+	uint32 bytesRead = file.read(_surface.getPixels(), dataSize);
+	assert(bytesRead == dataSize);
+
+	// Convert to RGB 565
+	_surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
+}
+
+ZorkCursor::ZorkCursor(const ZorkCursor &other) {
+	_width = other._width;
+	_height = other._height;
+	_hotspotX = other._hotspotX;
+	_hotspotY = other._hotspotY;
+
+	_surface.copyFrom(other._surface);
+}
+
+ZorkCursor &ZorkCursor::operator=(const ZorkCursor &other) {
+	_width = other._width;
+	_height = other._height;
+	_hotspotX = other._hotspotX;
+	_hotspotY = other._hotspotY;
+
+	_surface.free();
+	_surface.copyFrom(other._surface);
+
+	return *this;
+}
+
+ZorkCursor::~ZorkCursor() {
+	_surface.free();
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/graphics/cursors/cursor.h b/engines/zvision/graphics/cursors/cursor.h
new file mode 100644
index 0000000..0c1e994
--- /dev/null
+++ b/engines/zvision/graphics/cursors/cursor.h
@@ -0,0 +1,79 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_CURSOR_H
+#define ZVISION_CURSOR_H
+
+#include "graphics/surface.h"
+#include "zvision/zvision.h"
+
+namespace Common {
+class String;
+}
+
+namespace ZVision {
+
+/**
+ * Utility class to parse and hold cursor data
+ * Modeled off Graphics::Cursor
+ */
+class ZorkCursor {
+public:
+	ZorkCursor();
+	ZorkCursor(const Common::String &fileName);
+	ZorkCursor(ZVision *engine, const Common::String &fileName);
+	ZorkCursor(const ZorkCursor &other);
+	~ZorkCursor();
+
+private:
+	uint16 _width;
+	uint16 _height;
+	uint16 _hotspotX;
+	uint16 _hotspotY;
+	Graphics::Surface _surface;
+
+public:
+	ZorkCursor &operator=(const ZorkCursor &other);
+
+	uint16 getWidth() const {
+		return _width;
+	}
+	uint16 getHeight() const {
+		return _height;
+	}
+	uint16 getHotspotX() const {
+		return _hotspotX;
+	}
+	uint16 getHotspotY() const {
+		return _hotspotY;
+	}
+	byte getKeyColor() const {
+		return 0;
+	}
+	const byte *getSurface() const {
+		return (const byte *)_surface.getPixels();
+	}
+};
+
+} // End of namespace ZVision
+
+#endif
diff --git a/engines/zvision/graphics/cursors/cursor_manager.cpp b/engines/zvision/graphics/cursors/cursor_manager.cpp
new file mode 100644
index 0000000..a20deb2
--- /dev/null
+++ b/engines/zvision/graphics/cursors/cursor_manager.cpp
@@ -0,0 +1,152 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "common/scummsys.h"
+
+#include "zvision/graphics/cursors/cursor_manager.h"
+
+#include "zvision/zvision.h"
+
+#include "common/system.h"
+
+#include "graphics/pixelformat.h"
+#include "graphics/cursorman.h"
+
+namespace ZVision {
+
+const char *CursorManager::_cursorNames[NUM_CURSORS] = { "active", "arrow", "backward", "downarrow", "forward", "handpt", "handpu", "hdown", "hleft",
+                                                         "hright", "hup", "idle", "leftarrow", "rightarrow", "suggest_surround", "suggest_tilt", "turnaround", "zuparrow"
+                                                       };
+
+const char *CursorManager::_zgiCursorFileNames[NUM_CURSORS] = { "g0gbc011.zcr", "g0gac001.zcr", "g0gac021.zcr", "g0gac031.zcr", "g0gac041.zcr", "g0gac051.zcr", "g0gac061.zcr", "g0gac071.zcr", "g0gac081.zcr",
+                                                                "g0gac091.zcr", "g0gac101.zcr", "g0gac011.zcr", "g0gac111.zcr", "g0gac121.zcr", "g0gac131.zcr", "g0gac141.zcr", "g0gac151.zcr", "g0gac161.zcr"
+                                                              };
+
+const char *CursorManager::_zNemCursorFileNames[NUM_CURSORS] = { "00act", "arrow", "back", "down", "forw", "handpt", "handpu", "hdown", "hleft",
+                                                                 "hright", "hup", "00idle", "left", "right", "ssurr", "stilt", "turn", "up"
+                                                               };
+
+CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat)
+	: _engine(engine),
+	  _pixelFormat(pixelFormat),
+	  _cursorIsPushed(false),
+	  _item(0),
+	  _lastitem(0) {
+	for (int i = 0; i < NUM_CURSORS; i++) {
+		if (_engine->getGameId() == GID_NEMESIS) {
+			Common::String name;
+			name = Common::String::format("%sa.zcr", _zNemCursorFileNames[i]);
+			_cursors[i][0] = ZorkCursor(_engine, name); // Up cursor
+			name = Common::String::format("%sb.zcr", _zNemCursorFileNames[i]);
+			_cursors[i][1] = ZorkCursor(_engine, name); // Down cursor
+		} else if (_engine->getGameId() == GID_GRANDINQUISITOR) {
+			_cursors[i][0] = ZorkCursor(_engine, _zgiCursorFileNames[i]); // Up cursor
+			char buffer[25];
+			strcpy(buffer, _zgiCursorFileNames[i]);
+			buffer[3] += 2;
+			_cursors[i][1] = ZorkCursor(_engine, buffer); // Down cursor
+		}
+	}
+}
+
+void CursorManager::setItemID(int id) {
+	if (id != _item) {
+		if (id) {
+			Common::String file;
+			if (_engine->getGameId() == GID_NEMESIS) {
+				file = Common::String::format("%2.2d%s%c.zcr", id, "idle", 'a');
+				_cursors[NUM_CURSORS][0] = ZorkCursor(_engine, file);
+				file = Common::String::format("%2.2d%s%c.zcr", id, "idle", 'b');
+				_cursors[NUM_CURSORS][1] = ZorkCursor(_engine, file);
+				file = Common::String::format("%2.2d%s%c.zcr", id, "act", 'a');
+				_cursors[NUM_CURSORS + 1][0] = ZorkCursor(_engine, file);
+				file = Common::String::format("%2.2d%s%c.zcr", id, "act", 'b');
+				_cursors[NUM_CURSORS + 1][0] = ZorkCursor(_engine, file);
+			} else if (_engine->getGameId() == GID_GRANDINQUISITOR) {
+				file = Common::String::format("g0b%cc%2.2x1.zcr", 'a' , id);
+				_cursors[NUM_CURSORS][0] = ZorkCursor(_engine, file);
+				file = Common::String::format("g0b%cc%2.2x1.zcr", 'c' , id);
+				_cursors[NUM_CURSORS][1] = ZorkCursor(_engine, file);
+				file = Common::String::format("g0b%cc%2.2x1.zcr", 'b' , id);
+				_cursors[NUM_CURSORS + 1][0] = ZorkCursor(_engine, file);
+				file = Common::String::format("g0b%cc%2.2x1.zcr", 'd' , id);
+				_cursors[NUM_CURSORS + 1][1] = ZorkCursor(_engine, file);
+			} else
+				return;
+		}
+		_item = id;
+		changeCursor(CursorIndex_Idle);
+	}
+}
+
+void CursorManager::initialize() {
+	changeCursor(_cursors[CursorIndex_Idle][_cursorIsPushed]);
+	showMouse(true);
+}
+
+void CursorManager::changeCursor(const ZorkCursor &cursor) {
+	CursorMan.replaceCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat);
+}
+
+void CursorManager::cursorDown(bool pushed) {
+	if (_cursorIsPushed == pushed)
+		return;
+
+	_cursorIsPushed = pushed;
+
+	changeCursor(_cursors[_currentCursor][_cursorIsPushed]);
+}
+
+void CursorManager::changeCursor(int id) {
+	int _id = id;
+
+	if (_item &&
+	        (_id == CursorIndex_Active ||
+	         _id == CursorIndex_Idle ||
+	         _id == CursorIndex_HandPu)) {
+
+		if (_id == CursorIndex_Idle)
+			_id = CursorIndex_ItemIdle;
+		else
+			_id = CursorIndex_ItemAct;
+	}
+
+	if (_currentCursor != _id ||
+	        ((_id == CursorIndex_ItemAct || _id == CursorIndex_ItemIdle) && _lastitem != _item)) {
+		_currentCursor = _id;
+		_lastitem = _item;
+		changeCursor(_cursors[_currentCursor][_cursorIsPushed]);
+	}
+}
+
+int CursorManager::getCursorId(const Common::String &name) {
+	for (int i = 0; i < NUM_CURSORS; i++)
+		if (name.equals(_cursorNames[i]))
+			return i;
+	return CursorIndex_Idle;
+}
+
+void CursorManager::showMouse(bool vis) {
+	CursorMan.showMouse(vis);
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/graphics/cursors/cursor_manager.h b/engines/zvision/graphics/cursors/cursor_manager.h
new file mode 100644
index 0000000..bbfa085
--- /dev/null
+++ b/engines/zvision/graphics/cursors/cursor_manager.h
@@ -0,0 +1,134 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_CURSOR_MANAGER_H
+#define ZVISION_CURSOR_MANAGER_H
+
+#include "zvision/graphics/cursors/cursor.h"
+
+#include "common/str.h"
+
+namespace Graphics {
+struct PixelFormat;
+}
+
+namespace ZVision {
+
+class ZVision;
+
+/**
+ * Mostly usable cursors
+ */
+enum CursorIndex {
+	CursorIndex_Active = 0,
+	CursorIndex_DownArr = 3,
+	CursorIndex_HandPu = 6,
+	CursorIndex_Idle = 11,
+	CursorIndex_Left = 12,
+	CursorIndex_Right = 13,
+	CursorIndex_UpArr = 17,
+	CursorIndex_ItemIdle = 18,
+	CursorIndex_ItemAct = 19
+};
+
+/**
+ * Class to manage cursor changes. The actual changes have to be done
+ * through CursorMan. Otherwise the cursor will disappear after GMM
+ * or debug console.
+ * TODO: Figure out a way to get rid of the extraneous data copying due to having to use CursorMan
+ */
+class CursorManager {
+public:
+	CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat);
+
+private:
+	static const int NUM_CURSORS = 18;
+
+	// 18 default cursors in up/down states, +2 for items idle/act cursors
+	ZorkCursor _cursors[NUM_CURSORS + 2][2];
+
+	ZVision *_engine;
+	const Graphics::PixelFormat *_pixelFormat;
+	bool _cursorIsPushed;
+	int _item;
+	int _lastitem;
+	int _currentCursor;
+
+	static const char *_cursorNames[];
+	static const char *_zgiCursorFileNames[];
+	static const char *_zNemCursorFileNames[];
+
+public:
+	/** Creates the idle cursor and shows it */
+	void initialize();
+
+	/**
+	 * Change cursor to specified cursor ID. If item setted to not 0 and cursor id idle/acrive/handpu change cursor to item.
+	 *
+	 * @param id    Wanted cursor id.
+	 */
+
+	void changeCursor(int id);
+
+	/**
+	 * Return founded id for string contains cursor name
+	 *
+	 * @param name    Cursor name
+	 * @return        Id of cursor or idle cursor id if not found
+	 */
+
+	int getCursorId(const Common::String &name);
+
+	/**
+	 * Load cursor for item by id, and try to change cursor to item cursor if it's not 0
+	 *
+	 * @param id    Item id or 0 for no item cursor
+	 */
+
+	void setItemID(int id);
+
+	/**
+	 * Change the cursor to a certain push state. If the cursor is already in the specified push state, nothing will happen.
+	 *
+	 * @param pushed    Should the cursor be pushed (true) or not pushed (false) (Another way to say it: down or up)
+	 */
+	void cursorDown(bool pushed);
+
+	/**
+	 * Show or hide mouse cursor.
+	 *
+	 * @param vis    Should the cursor be showed (true) or hide (false)
+	 */
+	void showMouse(bool vis);
+
+private:
+	/**
+	 * Calls CursorMan.replaceCursor() using the data in cursor
+	 *
+	 * @param cursor    The cursor to show
+	 */
+	void changeCursor(const ZorkCursor &cursor);
+};
+
+} // End of namespace ZVision
+
+#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 6ed3eee..604b697 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -7,9 +7,9 @@ MODULE_OBJS := \
 	core/midi.o \
 	core/save_manager.o \
 	core/search_manager.o \
-	cursors/cursor_manager.o \
-	cursors/cursor.o \
 	detection.o \
+	graphics/cursors/cursor_manager.o \
+	graphics/cursors/cursor.o \
 	graphics/effects/fog.o \
 	graphics/effects/light.o \
 	graphics/effects/wave.o \
diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp
index c8c8206..d6883ed 100644
--- a/engines/zvision/scripting/actions.cpp
+++ b/engines/zvision/scripting/actions.cpp
@@ -43,7 +43,7 @@
 #include "zvision/graphics/effects/light.h"
 #include "zvision/graphics/effects/wave.h"
 #include "zvision/core/save_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 
 #include "common/file.h"
 
diff --git a/engines/zvision/scripting/controls/fist_control.cpp b/engines/zvision/scripting/controls/fist_control.cpp
index c3a6908..887ad79 100644
--- a/engines/zvision/scripting/controls/fist_control.cpp
+++ b/engines/zvision/scripting/controls/fist_control.cpp
@@ -26,7 +26,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/scripting/controls/fist_control.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/utility/utility.h"
 #include "zvision/video/rlf_decoder.h"
 
diff --git a/engines/zvision/scripting/controls/hotmov_control.cpp b/engines/zvision/scripting/controls/hotmov_control.cpp
index dfa0200..b2c9cdd 100644
--- a/engines/zvision/scripting/controls/hotmov_control.cpp
+++ b/engines/zvision/scripting/controls/hotmov_control.cpp
@@ -27,7 +27,7 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp
index 60dcd37..1b15eac 100644
--- a/engines/zvision/scripting/controls/input_control.cpp
+++ b/engines/zvision/scripting/controls/input_control.cpp
@@ -23,7 +23,7 @@
 #include "common/scummsys.h"
 
 #include "zvision/scripting/controls/input_control.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
diff --git a/engines/zvision/scripting/controls/lever_control.cpp b/engines/zvision/scripting/controls/lever_control.cpp
index 9566e4e..07eec1f 100644
--- a/engines/zvision/scripting/controls/lever_control.cpp
+++ b/engines/zvision/scripting/controls/lever_control.cpp
@@ -27,7 +27,7 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
diff --git a/engines/zvision/scripting/controls/paint_control.cpp b/engines/zvision/scripting/controls/paint_control.cpp
index 9bad6f2..0ef7618 100644
--- a/engines/zvision/scripting/controls/paint_control.cpp
+++ b/engines/zvision/scripting/controls/paint_control.cpp
@@ -26,7 +26,7 @@
 
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/utility/utility.h"
 
diff --git a/engines/zvision/scripting/controls/push_toggle_control.cpp b/engines/zvision/scripting/controls/push_toggle_control.cpp
index c5ec070..fcd8cd0 100644
--- a/engines/zvision/scripting/controls/push_toggle_control.cpp
+++ b/engines/zvision/scripting/controls/push_toggle_control.cpp
@@ -26,7 +26,7 @@
 
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
diff --git a/engines/zvision/scripting/controls/safe_control.cpp b/engines/zvision/scripting/controls/safe_control.cpp
index 9f4e29a..8135eb3 100644
--- a/engines/zvision/scripting/controls/safe_control.cpp
+++ b/engines/zvision/scripting/controls/safe_control.cpp
@@ -27,7 +27,7 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/utility/utility.h"
 
 #include "common/stream.h"
diff --git a/engines/zvision/scripting/controls/slot_control.cpp b/engines/zvision/scripting/controls/slot_control.cpp
index 1d83b44..7f04c2d 100644
--- a/engines/zvision/scripting/controls/slot_control.cpp
+++ b/engines/zvision/scripting/controls/slot_control.cpp
@@ -26,7 +26,7 @@
 
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/utility/utility.h"
 
diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp
index c532a2b..c735fe6 100644
--- a/engines/zvision/scripting/script_manager.cpp
+++ b/engines/zvision/scripting/script_manager.cpp
@@ -26,7 +26,7 @@
 
 #include "zvision/zvision.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/core/save_manager.h"
 #include "zvision/scripting/actions.h"
 #include "zvision/utility/utility.h"
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index ec1fb94..34fe079 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -26,7 +26,7 @@
 #include "zvision/core/console.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/cursors/cursor_manager.h"
+#include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/core/save_manager.h"
 #include "zvision/text/string_manager.h"
 #include "zvision/detection.h"


Commit: 2463b4580436b41a46500e53b4868789c9c7b21e
    https://github.com/scummvm/scummvm/commit/2463b4580436b41a46500e53b4868789c9c7b21e
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:55+02:00

Commit Message:
ZVISION: Move the MIDI code together with the rest of the sound code

Changed paths:
  A engines/zvision/sound/midi.cpp
  A engines/zvision/sound/midi.h
  R engines/zvision/core/midi.cpp
  R engines/zvision/core/midi.h
    engines/zvision/module.mk
    engines/zvision/scripting/sidefx/music_node.cpp
    engines/zvision/zvision.cpp



diff --git a/engines/zvision/core/midi.cpp b/engines/zvision/core/midi.cpp
deleted file mode 100644
index 736be13..0000000
--- a/engines/zvision/core/midi.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "zvision/core/midi.h"
-
-namespace ZVision {
-
-MidiManager::MidiManager() {
-	MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB);
-	_driver = MidiDriver::createMidi(dev);
-	_driver->open();
-}
-
-MidiManager::~MidiManager() {
-	stop();
-	_driver->close();
-	delete _driver;
-}
-
-void MidiManager::stop() {
-	for (int8 i = 0; i < 16; i++)
-		if (_playChannels[i].playing)
-			noteOff(i);
-}
-
-void MidiManager::noteOn(int8 channel, int8 note, int8 velocity) {
-	assert(channel <= 15);
-
-	_playChannels[channel].playing = true;
-	_playChannels[channel].note = note;
-	_driver->send(channel | (velocity << 16) | (note << 8) | 0x90);
-}
-
-void MidiManager::noteOff(int8 channel) {
-	assert(channel <= 15);
-
-	if (_playChannels[channel].playing) {
-		_playChannels[channel].playing = false;
-		_driver->send(channel | (_playChannels[channel].note << 8) | 0x80);
-	}
-}
-
-int8 MidiManager::getFreeChannel() {
-	for (int8 i = 0; i < 16; i++)
-		if (!_playChannels[i].playing)
-			return i;
-	return -1;
-}
-
-void MidiManager::setPan(int8 channel, int8 pan) {
-	assert(channel <= 15);
-
-	_driver->send(channel | (pan << 16) | 0xAB0);
-}
-
-void MidiManager::setVolume(int8 channel, int8 volume) {
-	assert(channel <= 15);
-
-	_driver->send(channel | (volume << 16) | 0x7B0);
-}
-
-void MidiManager::setProgram(int8 channel, int8 prog) {
-	assert(channel <= 15);
-
-	_driver->send(channel | (prog << 8) | 0xC0);
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/core/midi.h b/engines/zvision/core/midi.h
deleted file mode 100644
index a3bac19..0000000
--- a/engines/zvision/core/midi.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_MIDI_H
-#define ZVISION_MIDI_H
-
-#include "audio/mididrv.h"
-
-namespace ZVision {
-
-class MidiManager {
-public:
-	MidiManager();
-	~MidiManager();
-
-	void stop();
-	void noteOn(int8 channel, int8 noteNumber, int8 velocity);
-	void noteOff(int8 channel);
-	void setPan(int8 channel, int8 pan);
-	void setVolume(int8 channel, int8 volume);
-	void setProgram(int8 channel, int8 prog);
-
-	int8 getFreeChannel();
-
-protected:
-
-	struct chan {
-		bool playing;
-		int8 note;
-
-		chan() : playing(false), note(0) {};
-	};
-
-	MidiDriver *_driver;
-	chan _playChannels[16];
-};
-
-}
-
-#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 604b697..c9a1cb7 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -4,7 +4,6 @@ MODULE_OBJS := \
 	core/console.o \
 	core/events.o \
 	core/menu.o \
-	core/midi.o \
 	core/save_manager.o \
 	core/search_manager.o \
 	detection.o \
@@ -39,6 +38,7 @@ MODULE_OBJS := \
 	scripting/sidefx/syncsound_node.o \
 	scripting/sidefx/timer_node.o \
 	scripting/sidefx/ttytext_node.o \
+	sound/midi.o \
 	sound/zork_raw.o \
 	text/string_manager.o \
 	text/text.o \
diff --git a/engines/zvision/scripting/sidefx/music_node.cpp b/engines/zvision/scripting/sidefx/music_node.cpp
index 8316c1a..c79dd02 100644
--- a/engines/zvision/scripting/sidefx/music_node.cpp
+++ b/engines/zvision/scripting/sidefx/music_node.cpp
@@ -25,9 +25,9 @@
 #include "zvision/scripting/sidefx/music_node.h"
 
 #include "zvision/zvision.h"
-#include "zvision/core/midi.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
+#include "zvision/sound/midi.h"
 #include "zvision/sound/zork_raw.h"
 
 #include "common/stream.h"
diff --git a/engines/zvision/sound/midi.cpp b/engines/zvision/sound/midi.cpp
new file mode 100644
index 0000000..920002c
--- /dev/null
+++ b/engines/zvision/sound/midi.cpp
@@ -0,0 +1,89 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+#include "zvision/sound/midi.h"
+
+namespace ZVision {
+
+MidiManager::MidiManager() {
+	MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB);
+	_driver = MidiDriver::createMidi(dev);
+	_driver->open();
+}
+
+MidiManager::~MidiManager() {
+	stop();
+	_driver->close();
+	delete _driver;
+}
+
+void MidiManager::stop() {
+	for (int8 i = 0; i < 16; i++)
+		if (_playChannels[i].playing)
+			noteOff(i);
+}
+
+void MidiManager::noteOn(int8 channel, int8 note, int8 velocity) {
+	assert(channel <= 15);
+
+	_playChannels[channel].playing = true;
+	_playChannels[channel].note = note;
+	_driver->send(channel | (velocity << 16) | (note << 8) | 0x90);
+}
+
+void MidiManager::noteOff(int8 channel) {
+	assert(channel <= 15);
+
+	if (_playChannels[channel].playing) {
+		_playChannels[channel].playing = false;
+		_driver->send(channel | (_playChannels[channel].note << 8) | 0x80);
+	}
+}
+
+int8 MidiManager::getFreeChannel() {
+	for (int8 i = 0; i < 16; i++)
+		if (!_playChannels[i].playing)
+			return i;
+	return -1;
+}
+
+void MidiManager::setPan(int8 channel, int8 pan) {
+	assert(channel <= 15);
+
+	_driver->send(channel | (pan << 16) | 0xAB0);
+}
+
+void MidiManager::setVolume(int8 channel, int8 volume) {
+	assert(channel <= 15);
+
+	_driver->send(channel | (volume << 16) | 0x7B0);
+}
+
+void MidiManager::setProgram(int8 channel, int8 prog) {
+	assert(channel <= 15);
+
+	_driver->send(channel | (prog << 8) | 0xC0);
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/sound/midi.h b/engines/zvision/sound/midi.h
new file mode 100644
index 0000000..a3bac19
--- /dev/null
+++ b/engines/zvision/sound/midi.h
@@ -0,0 +1,59 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_MIDI_H
+#define ZVISION_MIDI_H
+
+#include "audio/mididrv.h"
+
+namespace ZVision {
+
+class MidiManager {
+public:
+	MidiManager();
+	~MidiManager();
+
+	void stop();
+	void noteOn(int8 channel, int8 noteNumber, int8 velocity);
+	void noteOff(int8 channel);
+	void setPan(int8 channel, int8 pan);
+	void setVolume(int8 channel, int8 volume);
+	void setProgram(int8 channel, int8 prog);
+
+	int8 getFreeChannel();
+
+protected:
+
+	struct chan {
+		bool playing;
+		int8 note;
+
+		chan() : playing(false), note(0) {};
+	};
+
+	MidiDriver *_driver;
+	chan _playChannels[16];
+};
+
+}
+
+#endif
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index 34fe079..45dc124 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -34,7 +34,7 @@
 #include "zvision/core/search_manager.h"
 #include "zvision/text/text.h"
 #include "zvision/graphics/truetype_font.h"
-#include "zvision/core/midi.h"
+#include "zvision/sound/midi.h"
 #include "zvision/utility/zfs_archive.h"
 
 #include "common/config-manager.h"


Commit: d8a961244d99a87c1a01613a971173cc135c246a
    https://github.com/scummvm/scummvm/commit/d8a961244d99a87c1a01613a971173cc135c246a
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:56+02:00

Commit Message:
ZVISION: Move all the file-related classes together

Changed paths:
  A engines/zvision/file/lzss_read_stream.cpp
  A engines/zvision/file/lzss_read_stream.h
  A engines/zvision/file/search_manager.cpp
  A engines/zvision/file/search_manager.h
  A engines/zvision/file/zfs_archive.cpp
  A engines/zvision/file/zfs_archive.h
  R engines/zvision/core/search_manager.cpp
  R engines/zvision/core/search_manager.h
  R engines/zvision/utility/lzss_read_stream.cpp
  R engines/zvision/utility/lzss_read_stream.h
  R engines/zvision/utility/zfs_archive.cpp
  R engines/zvision/utility/zfs_archive.h
    engines/zvision/graphics/render_manager.cpp
    engines/zvision/graphics/subtitles.cpp
    engines/zvision/module.mk
    engines/zvision/text/string_manager.cpp
    engines/zvision/zvision.cpp
    engines/zvision/zvision.h



diff --git a/engines/zvision/core/search_manager.cpp b/engines/zvision/core/search_manager.cpp
deleted file mode 100644
index 1523319..0000000
--- a/engines/zvision/core/search_manager.cpp
+++ /dev/null
@@ -1,273 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-*/
-
-#include "common/debug.h"
-#include "common/fs.h"
-#include "common/stream.h"
-
-#include "zvision/core/search_manager.h"
-#include "zvision/utility/zfs_archive.h"
-
-namespace ZVision {
-
-SearchManager::SearchManager(const Common::String &rootPath, int depth) {
-	_root = rootPath;
-	if (_root[_root.size() - 1] == '\\' || _root[_root.size() - 1] == '/')
-		_root.deleteLastChar();
-
-	Common::FSNode fsNode(_root);
-
-	listDirRecursive(_dirList, fsNode, depth);
-
-	for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end();)
-		if (it->size() == _root.size())
-			it = _dirList.erase(it);
-		else if (it->size() > _root.size()) {
-			*it = Common::String(it->c_str() + _root.size() + 1);
-			it++;
-		} else
-			it++;
-}
-
-SearchManager::~SearchManager() {
-	Common::List<Common::Archive *>::iterator it = _archList.begin();
-	while (it != _archList.end()) {
-		delete *it;
-		it++;
-	}
-
-	_archList.clear();
-}
-
-void SearchManager::addPatch(const Common::String &src, const Common::String &dst) {
-	Common::String lowerCaseName = dst;
-	lowerCaseName.toLowercase();
-
-	SearchManager::MatchList::iterator it = _files.find(lowerCaseName);
-
-	if (it != _files.end()) {
-		lowerCaseName = src;
-		lowerCaseName.toLowercase();
-		_files[lowerCaseName] = it->_value;
-	}
-}
-
-void SearchManager::addFile(const Common::String &name, Common::Archive *arch) {
-	bool addArch = true;
-	Common::List<Common::Archive *>::iterator it = _archList.begin();
-	while (it != _archList.end()) {
-		if (*it == arch) {
-			addArch = false;
-			break;
-		}
-		it++;
-	}
-	if (addArch)
-		_archList.push_back(arch);
-
-	Common::String lowerCaseName = name;
-	lowerCaseName.toLowercase();
-
-	SearchManager::Node nod;
-	nod.name = lowerCaseName;
-	nod.arch = arch;
-
-	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
-
-	if (fit == _files.end()) {
-		_files[lowerCaseName] = nod;
-	} else {
-		Common::SeekableReadStream *stream = fit->_value.arch->createReadStreamForMember(fit->_value.name);
-		if (stream) {
-			if (stream->size() < 10)
-				fit->_value.arch = arch;
-			delete stream;
-		} else {
-			_files[lowerCaseName] = nod;
-		}
-	}
-}
-
-Common::File *SearchManager::openFile(const Common::String &name) {
-	Common::String lowerCaseName = name;
-	lowerCaseName.toLowercase();
-
-	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
-
-	if (fit != _files.end()) {
-		Common::File *tmp = new Common::File();
-		tmp->open(fit->_value.name, *fit->_value.arch);
-		return tmp;
-	}
-	return NULL;
-}
-
-bool SearchManager::openFile(Common::File &file, const Common::String &name) {
-	Common::String lowerCaseName = name;
-	lowerCaseName.toLowercase();
-
-	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
-
-	if (fit != _files.end())
-		return file.open(fit->_value.name, *fit->_value.arch);
-	return false;
-}
-
-bool SearchManager::hasFile(const Common::String &name) {
-	Common::String lowerCaseName = name;
-	lowerCaseName.toLowercase();
-
-	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
-
-	if (fit != _files.end())
-		return true;
-	return false;
-}
-
-void SearchManager::loadZix(const Common::String &name) {
-	Common::File file;
-	file.open(name);
-
-	Common::String line;
-
-	while (!file.eos()) {
-		line = file.readLine();
-		if (line.matchString("----------*", true))
-			break;
-	}
-
-	if (file.eos())
-		return;
-
-	Common::Array<Common::Archive *> archives;
-
-	while (!file.eos()) {
-		line = file.readLine();
-		line.trim();
-		if (line.matchString("----------*", true))
-			break;
-		else if (line.matchString("DIR:*", true)) {
-			Common::String path(line.c_str() + 5);
-			Common::Archive *arc;
-			char tempPath[128];
-			strcpy(tempPath, path.c_str());
-			for (uint i = 0; i < path.size(); i++)
-				if (tempPath[i] == '\\')
-					tempPath[i] = '/';
-
-			path = Common::String(tempPath);
-			if (path.size() && path[0] == '.')
-				path.deleteChar(0);
-			if (path.size() && path[0] == '/')
-				path.deleteChar(0);
-
-			if (path.matchString("*.zfs", true))
-				arc = new ZfsArchive(path);
-			else {
-				if (path.size()) {
-					if (path[path.size() - 1] == '\\' || path[path.size() - 1] == '/')
-						path.deleteLastChar();
-					if (path.size())
-						for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end(); ++it)
-							if (path.equalsIgnoreCase(*it)) {
-								path = *it;
-								break;
-							}
-				}
-
-				path = Common::String::format("%s/%s", _root.c_str(), path.c_str());
-
-				arc = new Common::FSDirectory(path);
-			}
-			archives.push_back(arc);
-		}
-	}
-
-	if (file.eos())
-		return;
-
-	while (!file.eos()) {
-		line = file.readLine();
-		line.trim();
-		uint dr = 0;
-		char buf[32];
-		if (sscanf(line.c_str(), "%u %s", &dr, buf) == 2) {
-			if (dr <= archives.size() && dr > 0) {
-				addFile(Common::String(buf), archives[dr - 1]);
-			}
-		}
-	}
-}
-
-void SearchManager::addDir(const Common::String &name) {
-	Common::String path;
-	for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end(); ++it)
-		if (name.equalsIgnoreCase(*it)) {
-			path = *it;
-			break;
-		}
-
-	if (path.size() == 0)
-		return;
-
-	path = Common::String::format("%s/%s", _root.c_str(), path.c_str());
-
-	Common::FSDirectory *dir = new Common::FSDirectory(path);
-
-	Common::ArchiveMemberList list;
-	dir->listMatchingMembers(list, "*.zfs");
-
-	for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) {
-		Common::String flname = (*iter)->getName();
-
-		ZfsArchive *zfs = new ZfsArchive(Common::String::format("%s/%s", name.c_str(), flname.c_str()));
-
-		Common::ArchiveMemberList zfslist;
-		zfs->listMembers(zfslist);
-
-		for (Common::ArchiveMemberList::iterator ziter = zfslist.begin(); ziter != zfslist.end(); ++ziter) {
-			Common::String zfsFileName = (*ziter)->getName();
-			addFile(zfsFileName, zfs);
-		}
-	}
-
-	list.clear();
-	dir->listMembers(list);
-
-	for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) {
-		Common::String flname = (*iter)->getName();
-		addFile(flname, dir);
-	}
-}
-
-void SearchManager::listDirRecursive(Common::List<Common::String> &_list, const Common::FSNode &fsNode, int depth) {
-	Common::FSList fsList;
-	fsNode.getChildren(fsList);
-
-	_list.push_back(fsNode.getPath());
-
-	if (depth > 1)
-		for (Common::FSList::const_iterator it = fsList.begin(); it != fsList.end(); ++it)
-			listDirRecursive(_list, *it, depth - 1);
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/core/search_manager.h b/engines/zvision/core/search_manager.h
deleted file mode 100644
index fdd70fd..0000000
--- a/engines/zvision/core/search_manager.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_SEARCH_MANAGER_H
-#define ZVISION_SEARCH_MANAGER_H
-
-#include "common/str.h"
-#include "common/hash-str.h"
-#include "common/hashmap.h"
-#include "common/archive.h"
-#include "common/file.h"
-#include "common/list.h"
-
-namespace ZVision {
-
-class SearchManager {
-public:
-	SearchManager(const Common::String &rootPath, int depth);
-	~SearchManager();
-
-	void addFile(const Common::String &name, Common::Archive *arch);
-	void addDir(const Common::String &name);
-	void addPatch(const Common::String &src, const Common::String &dst);
-
-	Common::File *openFile(const Common::String &name);
-	bool openFile(Common::File &file, const Common::String &name);
-	bool hasFile(const Common::String &name);
-
-	void loadZix(const Common::String &name);
-
-private:
-
-	void listDirRecursive(Common::List<Common::String> &dirList, const Common::FSNode &fsNode, int depth);
-
-	struct Node {
-		Common::String name;
-		Common::Archive *arch;
-	};
-
-	Common::List<Common::String> _dirList;
-
-	typedef Common::HashMap<Common::String, Node, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> MatchList;
-
-	Common::List<Common::Archive *> _archList;
-	MatchList _files;
-
-	Common::String _root;
-
-private:
-};
-
-}
-
-#endif // ZVISION_SEARCH_MANAGER_H
diff --git a/engines/zvision/file/lzss_read_stream.cpp b/engines/zvision/file/lzss_read_stream.cpp
new file mode 100644
index 0000000..6f27eaa
--- /dev/null
+++ b/engines/zvision/file/lzss_read_stream.cpp
@@ -0,0 +1,102 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+#include "zvision/file/lzss_read_stream.h"
+
+namespace ZVision {
+
+LzssReadStream::LzssReadStream(Common::SeekableReadStream *source)
+	: _source(source),
+	  // It's convention to set the starting cursor position to blockSize - 16
+	  _windowCursor(0x0FEE),
+	  _eosFlag(false) {
+	// Clear the window to null
+	memset(_window, 0, BLOCK_SIZE);
+}
+
+uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) {
+	uint32 destinationCursor = 0;
+
+	while (destinationCursor < numberOfBytes) {
+		byte flagbyte = _source->readByte();
+		if (_source->eos())
+			break;
+		uint mask = 1;
+
+		for (int i = 0; i < 8; ++i) {
+			if ((flagbyte & mask) == mask) {
+				byte data = _source->readByte();
+				if (_source->eos()) {
+					return destinationCursor;
+				}
+
+				_window[_windowCursor] = data;
+				destination[destinationCursor++] = data;
+
+				// Increment and wrap the window cursor
+				_windowCursor = (_windowCursor + 1) & 0xFFF;
+			} else {
+				byte low = _source->readByte();
+				if (_source->eos()) {
+					return destinationCursor;
+				}
+
+				byte high = _source->readByte();
+				if (_source->eos()) {
+					return destinationCursor;
+				}
+
+				uint16 length = (high & 0xF) + 2;
+				uint16 offset = low | ((high & 0xF0) << 4);
+
+				for (int j = 0; j <= length; ++j) {
+					byte temp = _window[(offset + j) & 0xFFF];
+					_window[_windowCursor] = temp;
+					destination[destinationCursor++] = temp;
+					_windowCursor = (_windowCursor + 1) & 0xFFF;
+				}
+			}
+
+			mask = mask << 1;
+		}
+	}
+
+	return destinationCursor;
+}
+
+bool LzssReadStream::eos() const {
+	return _eosFlag;
+}
+
+uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) {
+	uint32 bytesRead = decompressBytes(static_cast<byte *>(dataPtr), dataSize);
+	if (bytesRead < dataSize) {
+		// Flag that we're at EOS
+		_eosFlag = true;
+	}
+
+	return dataSize;
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/file/lzss_read_stream.h b/engines/zvision/file/lzss_read_stream.h
new file mode 100644
index 0000000..1420621
--- /dev/null
+++ b/engines/zvision/file/lzss_read_stream.h
@@ -0,0 +1,71 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_LZSS_STREAM_H
+#define ZVISION_LZSS_STREAM_H
+
+#include "common/stream.h"
+#include "common/array.h"
+
+namespace Common {
+class SeekableReadStream;
+}
+
+namespace ZVision {
+
+class LzssReadStream : public Common::ReadStream {
+public:
+	/**
+	 * A class that decompresses LZSS data and implements ReadStream for easy access
+	 * to the decompiled data.
+	 *
+	 * @param source              The source data
+	 */
+	LzssReadStream(Common::SeekableReadStream *source);
+
+private:
+	enum {
+		BLOCK_SIZE = 0x1000
+	};
+
+private:
+	Common::SeekableReadStream *_source;
+	byte _window[BLOCK_SIZE];
+	uint _windowCursor;
+	bool _eosFlag;
+
+public:
+	bool eos() const;
+	uint32 read(void *dataPtr, uint32 dataSize);
+
+private:
+	/**
+	 * Decompress the next <numberOfBytes> from the source stream. Or until EOS
+	 *
+	 * @param numberOfBytes    How many bytes to decompress. This is a count of source bytes, not destination bytes
+	 */
+	uint32 decompressBytes(byte *destination, uint32 numberOfBytes);
+};
+
+}
+
+#endif
diff --git a/engines/zvision/file/search_manager.cpp b/engines/zvision/file/search_manager.cpp
new file mode 100644
index 0000000..752b52b
--- /dev/null
+++ b/engines/zvision/file/search_manager.cpp
@@ -0,0 +1,273 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "common/debug.h"
+#include "common/fs.h"
+#include "common/stream.h"
+
+#include "zvision/file/search_manager.h"
+#include "zvision/file/zfs_archive.h"
+
+namespace ZVision {
+
+SearchManager::SearchManager(const Common::String &rootPath, int depth) {
+	_root = rootPath;
+	if (_root[_root.size() - 1] == '\\' || _root[_root.size() - 1] == '/')
+		_root.deleteLastChar();
+
+	Common::FSNode fsNode(_root);
+
+	listDirRecursive(_dirList, fsNode, depth);
+
+	for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end();)
+		if (it->size() == _root.size())
+			it = _dirList.erase(it);
+		else if (it->size() > _root.size()) {
+			*it = Common::String(it->c_str() + _root.size() + 1);
+			it++;
+		} else
+			it++;
+}
+
+SearchManager::~SearchManager() {
+	Common::List<Common::Archive *>::iterator it = _archList.begin();
+	while (it != _archList.end()) {
+		delete *it;
+		it++;
+	}
+
+	_archList.clear();
+}
+
+void SearchManager::addPatch(const Common::String &src, const Common::String &dst) {
+	Common::String lowerCaseName = dst;
+	lowerCaseName.toLowercase();
+
+	SearchManager::MatchList::iterator it = _files.find(lowerCaseName);
+
+	if (it != _files.end()) {
+		lowerCaseName = src;
+		lowerCaseName.toLowercase();
+		_files[lowerCaseName] = it->_value;
+	}
+}
+
+void SearchManager::addFile(const Common::String &name, Common::Archive *arch) {
+	bool addArch = true;
+	Common::List<Common::Archive *>::iterator it = _archList.begin();
+	while (it != _archList.end()) {
+		if (*it == arch) {
+			addArch = false;
+			break;
+		}
+		it++;
+	}
+	if (addArch)
+		_archList.push_back(arch);
+
+	Common::String lowerCaseName = name;
+	lowerCaseName.toLowercase();
+
+	SearchManager::Node nod;
+	nod.name = lowerCaseName;
+	nod.arch = arch;
+
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
+
+	if (fit == _files.end()) {
+		_files[lowerCaseName] = nod;
+	} else {
+		Common::SeekableReadStream *stream = fit->_value.arch->createReadStreamForMember(fit->_value.name);
+		if (stream) {
+			if (stream->size() < 10)
+				fit->_value.arch = arch;
+			delete stream;
+		} else {
+			_files[lowerCaseName] = nod;
+		}
+	}
+}
+
+Common::File *SearchManager::openFile(const Common::String &name) {
+	Common::String lowerCaseName = name;
+	lowerCaseName.toLowercase();
+
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
+
+	if (fit != _files.end()) {
+		Common::File *tmp = new Common::File();
+		tmp->open(fit->_value.name, *fit->_value.arch);
+		return tmp;
+	}
+	return NULL;
+}
+
+bool SearchManager::openFile(Common::File &file, const Common::String &name) {
+	Common::String lowerCaseName = name;
+	lowerCaseName.toLowercase();
+
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
+
+	if (fit != _files.end())
+		return file.open(fit->_value.name, *fit->_value.arch);
+	return false;
+}
+
+bool SearchManager::hasFile(const Common::String &name) {
+	Common::String lowerCaseName = name;
+	lowerCaseName.toLowercase();
+
+	SearchManager::MatchList::iterator fit = _files.find(lowerCaseName);
+
+	if (fit != _files.end())
+		return true;
+	return false;
+}
+
+void SearchManager::loadZix(const Common::String &name) {
+	Common::File file;
+	file.open(name);
+
+	Common::String line;
+
+	while (!file.eos()) {
+		line = file.readLine();
+		if (line.matchString("----------*", true))
+			break;
+	}
+
+	if (file.eos())
+		return;
+
+	Common::Array<Common::Archive *> archives;
+
+	while (!file.eos()) {
+		line = file.readLine();
+		line.trim();
+		if (line.matchString("----------*", true))
+			break;
+		else if (line.matchString("DIR:*", true)) {
+			Common::String path(line.c_str() + 5);
+			Common::Archive *arc;
+			char tempPath[128];
+			strcpy(tempPath, path.c_str());
+			for (uint i = 0; i < path.size(); i++)
+				if (tempPath[i] == '\\')
+					tempPath[i] = '/';
+
+			path = Common::String(tempPath);
+			if (path.size() && path[0] == '.')
+				path.deleteChar(0);
+			if (path.size() && path[0] == '/')
+				path.deleteChar(0);
+
+			if (path.matchString("*.zfs", true))
+				arc = new ZfsArchive(path);
+			else {
+				if (path.size()) {
+					if (path[path.size() - 1] == '\\' || path[path.size() - 1] == '/')
+						path.deleteLastChar();
+					if (path.size())
+						for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end(); ++it)
+							if (path.equalsIgnoreCase(*it)) {
+								path = *it;
+								break;
+							}
+				}
+
+				path = Common::String::format("%s/%s", _root.c_str(), path.c_str());
+
+				arc = new Common::FSDirectory(path);
+			}
+			archives.push_back(arc);
+		}
+	}
+
+	if (file.eos())
+		return;
+
+	while (!file.eos()) {
+		line = file.readLine();
+		line.trim();
+		uint dr = 0;
+		char buf[32];
+		if (sscanf(line.c_str(), "%u %s", &dr, buf) == 2) {
+			if (dr <= archives.size() && dr > 0) {
+				addFile(Common::String(buf), archives[dr - 1]);
+			}
+		}
+	}
+}
+
+void SearchManager::addDir(const Common::String &name) {
+	Common::String path;
+	for (Common::List<Common::String>::iterator it = _dirList.begin(); it != _dirList.end(); ++it)
+		if (name.equalsIgnoreCase(*it)) {
+			path = *it;
+			break;
+		}
+
+	if (path.size() == 0)
+		return;
+
+	path = Common::String::format("%s/%s", _root.c_str(), path.c_str());
+
+	Common::FSDirectory *dir = new Common::FSDirectory(path);
+
+	Common::ArchiveMemberList list;
+	dir->listMatchingMembers(list, "*.zfs");
+
+	for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) {
+		Common::String flname = (*iter)->getName();
+
+		ZfsArchive *zfs = new ZfsArchive(Common::String::format("%s/%s", name.c_str(), flname.c_str()));
+
+		Common::ArchiveMemberList zfslist;
+		zfs->listMembers(zfslist);
+
+		for (Common::ArchiveMemberList::iterator ziter = zfslist.begin(); ziter != zfslist.end(); ++ziter) {
+			Common::String zfsFileName = (*ziter)->getName();
+			addFile(zfsFileName, zfs);
+		}
+	}
+
+	list.clear();
+	dir->listMembers(list);
+
+	for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) {
+		Common::String flname = (*iter)->getName();
+		addFile(flname, dir);
+	}
+}
+
+void SearchManager::listDirRecursive(Common::List<Common::String> &_list, const Common::FSNode &fsNode, int depth) {
+	Common::FSList fsList;
+	fsNode.getChildren(fsList);
+
+	_list.push_back(fsNode.getPath());
+
+	if (depth > 1)
+		for (Common::FSList::const_iterator it = fsList.begin(); it != fsList.end(); ++it)
+			listDirRecursive(_list, *it, depth - 1);
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/file/search_manager.h b/engines/zvision/file/search_manager.h
new file mode 100644
index 0000000..fdd70fd
--- /dev/null
+++ b/engines/zvision/file/search_manager.h
@@ -0,0 +1,73 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_SEARCH_MANAGER_H
+#define ZVISION_SEARCH_MANAGER_H
+
+#include "common/str.h"
+#include "common/hash-str.h"
+#include "common/hashmap.h"
+#include "common/archive.h"
+#include "common/file.h"
+#include "common/list.h"
+
+namespace ZVision {
+
+class SearchManager {
+public:
+	SearchManager(const Common::String &rootPath, int depth);
+	~SearchManager();
+
+	void addFile(const Common::String &name, Common::Archive *arch);
+	void addDir(const Common::String &name);
+	void addPatch(const Common::String &src, const Common::String &dst);
+
+	Common::File *openFile(const Common::String &name);
+	bool openFile(Common::File &file, const Common::String &name);
+	bool hasFile(const Common::String &name);
+
+	void loadZix(const Common::String &name);
+
+private:
+
+	void listDirRecursive(Common::List<Common::String> &dirList, const Common::FSNode &fsNode, int depth);
+
+	struct Node {
+		Common::String name;
+		Common::Archive *arch;
+	};
+
+	Common::List<Common::String> _dirList;
+
+	typedef Common::HashMap<Common::String, Node, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> MatchList;
+
+	Common::List<Common::Archive *> _archList;
+	MatchList _files;
+
+	Common::String _root;
+
+private:
+};
+
+}
+
+#endif // ZVISION_SEARCH_MANAGER_H
diff --git a/engines/zvision/file/zfs_archive.cpp b/engines/zvision/file/zfs_archive.cpp
new file mode 100644
index 0000000..9b55a36
--- /dev/null
+++ b/engines/zvision/file/zfs_archive.cpp
@@ -0,0 +1,154 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+#include "common/memstream.h"
+#include "common/debug.h"
+#include "common/file.h"
+
+#include "zvision/file/zfs_archive.h"
+
+namespace ZVision {
+
+ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) {
+	Common::File zfsFile;
+
+	if (!zfsFile.open(_fileName)) {
+		warning("ZFSArchive::ZFSArchive(): Could not find the archive file");
+		return;
+	}
+
+	readHeaders(&zfsFile);
+
+	debug(1, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size());
+}
+
+ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) {
+	readHeaders(stream);
+
+	debug(1, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size());
+}
+
+ZfsArchive::~ZfsArchive() {
+	debug(1, "ZfsArchive Destructor Called");
+	ZfsEntryHeaderMap::iterator it = _entryHeaders.begin();
+	for (; it != _entryHeaders.end(); ++it) {
+		delete it->_value;
+	}
+}
+
+void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) {
+	// Don't do a straight struct cast since we can't guarantee endianness
+	_header.magic = stream->readUint32LE();
+	_header.unknown1 = stream->readUint32LE();
+	_header.maxNameLength = stream->readUint32LE();
+	_header.filesPerBlock = stream->readUint32LE();
+	_header.fileCount = stream->readUint32LE();
+	_header.xorKey[0] = stream->readByte();
+	_header.xorKey[1] = stream->readByte();
+	_header.xorKey[2] = stream->readByte();
+	_header.xorKey[3] = stream->readByte();
+	_header.fileSectionOffset = stream->readUint32LE();
+
+	uint32 nextOffset;
+
+	do {
+		// Read the offset to the next block
+		nextOffset = stream->readUint32LE();
+
+		// Read in each entry header
+		for (uint32 i = 0; i < _header.filesPerBlock; ++i) {
+			ZfsEntryHeader entryHeader;
+
+			entryHeader.name = readEntryName(stream);
+			entryHeader.offset = stream->readUint32LE();
+			entryHeader.id = stream->readUint32LE();
+			entryHeader.size = stream->readUint32LE();
+			entryHeader.time = stream->readUint32LE();
+			entryHeader.unknown = stream->readUint32LE();
+
+			if (entryHeader.size != 0)
+				_entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader);
+		}
+
+		// Seek to the next block of headers
+		stream->seek(nextOffset);
+	} while (nextOffset != 0);
+}
+
+Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const {
+	// Entry Names are at most 16 bytes and are null padded
+	char buffer[16];
+	stream->read(buffer, 16);
+
+	return Common::String(buffer);
+}
+
+bool ZfsArchive::hasFile(const Common::String &name) const {
+	return _entryHeaders.contains(name);
+}
+
+int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const {
+	int matches = 0;
+
+	for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) {
+		list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this)));
+		matches++;
+	}
+
+	return matches;
+}
+
+const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const {
+	if (!_entryHeaders.contains(name))
+		return Common::ArchiveMemberPtr();
+
+	return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
+}
+
+Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const {
+	if (!_entryHeaders.contains(name)) {
+		return 0;
+	}
+
+	ZfsEntryHeader *entryHeader = _entryHeaders[name];
+
+	Common::File zfsArchive;
+	zfsArchive.open(_fileName);
+	zfsArchive.seek(entryHeader->offset);
+
+	// This *HAS* to be malloc (not new[]) because MemoryReadStream uses free() to free the memory
+	byte *buffer = (byte *)malloc(entryHeader->size);
+	zfsArchive.read(buffer, entryHeader->size);
+	// Decrypt the data in place
+	if (_header.xorKey != 0)
+		unXor(buffer, entryHeader->size, _header.xorKey);
+
+	return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES);
+}
+
+void ZfsArchive::unXor(byte *buffer, uint32 length, const byte *xorKey) const {
+	for (uint32 i = 0; i < length; ++i)
+		buffer[i] ^= xorKey[i % 4];
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/file/zfs_archive.h b/engines/zvision/file/zfs_archive.h
new file mode 100644
index 0000000..571591a
--- /dev/null
+++ b/engines/zvision/file/zfs_archive.h
@@ -0,0 +1,125 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_ZFS_ARCHIVE_H
+#define ZVISION_ZFS_ARCHIVE_H
+
+#include "common/archive.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+
+namespace Common {
+class String;
+}
+
+namespace ZVision {
+
+struct ZfsHeader {
+	uint32 magic;
+	uint32 unknown1;
+	uint32 maxNameLength;
+	uint32 filesPerBlock;
+	uint32 fileCount;
+	byte xorKey[4];
+	uint32 fileSectionOffset;
+};
+
+struct ZfsEntryHeader {
+	Common::String name;
+	uint32 offset;
+	uint32 id;
+	uint32 size;
+	uint32 time;
+	uint32 unknown;
+};
+
+typedef Common::HashMap<Common::String, ZfsEntryHeader *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ZfsEntryHeaderMap;
+
+class ZfsArchive : public Common::Archive {
+public:
+	ZfsArchive(const Common::String &fileName);
+	ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream);
+	~ZfsArchive();
+
+	/**
+	 * Check if a member with the given name is present in the Archive.
+	 * Patterns are not allowed, as this is meant to be a quick File::exists()
+	 * replacement.
+	 */
+	bool hasFile(const Common::String &fileName) const;
+
+	/**
+	 * Add all members of the Archive to list.
+	 * Must only append to list, and not remove elements from it.
+	 *
+	 * @return    The number of names added to list
+	 */
+	int listMembers(Common::ArchiveMemberList &list) const;
+
+	/**
+	 * Returns a ArchiveMember representation of the given file.
+	 */
+	const Common::ArchiveMemberPtr getMember(const Common::String &name) const;
+
+	/**
+	 * Create a stream bound to a member with the specified name in the
+	 * archive. If no member with this name exists, 0 is returned.
+	 *
+	 * @return    The newly created input stream
+	 */
+	Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const;
+
+private:
+	const Common::String _fileName;
+	ZfsHeader _header;
+	ZfsEntryHeaderMap _entryHeaders;
+
+	/**
+	 * Parses the zfs file into file entry headers that can be used later
+	 * to get the entry data.
+	 *
+	 * @param stream    The contents of the zfs file
+	 */
+	void readHeaders(Common::SeekableReadStream *stream);
+
+	/**
+	 * Entry names are contained within a 16 byte block. This reads the block
+	 * and converts it the name to a Common::String
+	 *
+	 * @param stream    The zfs file stream
+	 * @return          The entry file name
+	 */
+	Common::String readEntryName(Common::SeekableReadStream *stream) const;
+
+	/**
+	 * ZFS file entries can be encrypted using XOR encoding. This method
+	 * decodes the buffer in place using the supplied xorKey.
+	 *
+	 * @param buffer    The data to decode
+	 * @param length    Length of buffer
+	 */
+	void unXor(byte *buffer, uint32 length, const byte *xorKey) const;
+};
+
+} // End of namespace ZVision
+
+#endif
diff --git a/engines/zvision/graphics/render_manager.cpp b/engines/zvision/graphics/render_manager.cpp
index 97d47e3..e2ad13a 100644
--- a/engines/zvision/graphics/render_manager.cpp
+++ b/engines/zvision/graphics/render_manager.cpp
@@ -27,7 +27,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/text/text.h"
 
-#include "zvision/utility/lzss_read_stream.h"
+#include "zvision/file/lzss_read_stream.h"
 
 #include "common/file.h"
 #include "common/system.h"
diff --git a/engines/zvision/graphics/subtitles.cpp b/engines/zvision/graphics/subtitles.cpp
index 7847215..d2c56f0 100644
--- a/engines/zvision/graphics/subtitles.cpp
+++ b/engines/zvision/graphics/subtitles.cpp
@@ -22,7 +22,7 @@
 
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/subtitles.h"
-#include "zvision/core/search_manager.h"
+#include "zvision/file/search_manager.h"
 #include "zvision/text/text.h"
 
 namespace ZVision {
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index c9a1cb7..1d89e22 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -5,8 +5,10 @@ MODULE_OBJS := \
 	core/events.o \
 	core/menu.o \
 	core/save_manager.o \
-	core/search_manager.o \
 	detection.o \
+	file/lzss_read_stream.o \
+	file/search_manager.o \
+	file/zfs_archive.o \
 	graphics/cursors/cursor_manager.o \
 	graphics/cursors/cursor.o \
 	graphics/effects/fog.o \
@@ -43,9 +45,7 @@ MODULE_OBJS := \
 	text/string_manager.o \
 	text/text.o \
 	utility/clock.o \
-	utility/lzss_read_stream.o \
 	utility/utility.o \
-	utility/zfs_archive.o \
 	video/rlf_decoder.o \
 	video/video.o \
 	video/zork_avi_decoder.o \
diff --git a/engines/zvision/text/string_manager.cpp b/engines/zvision/text/string_manager.cpp
index 1a04c67..d275bc8 100644
--- a/engines/zvision/text/string_manager.cpp
+++ b/engines/zvision/text/string_manager.cpp
@@ -28,7 +28,7 @@
 #include "graphics/colormasks.h"
 
 #include "zvision/zvision.h"
-#include "zvision/core/search_manager.h"
+#include "zvision/file/search_manager.h"
 #include "zvision/text/string_manager.h"
 #include "zvision/graphics/truetype_font.h"
 
diff --git a/engines/zvision/utility/lzss_read_stream.cpp b/engines/zvision/utility/lzss_read_stream.cpp
deleted file mode 100644
index bbe6e35..0000000
--- a/engines/zvision/utility/lzss_read_stream.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "zvision/utility/lzss_read_stream.h"
-
-namespace ZVision {
-
-LzssReadStream::LzssReadStream(Common::SeekableReadStream *source)
-	: _source(source),
-	  // It's convention to set the starting cursor position to blockSize - 16
-	  _windowCursor(0x0FEE),
-	  _eosFlag(false) {
-	// Clear the window to null
-	memset(_window, 0, BLOCK_SIZE);
-}
-
-uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) {
-	uint32 destinationCursor = 0;
-
-	while (destinationCursor < numberOfBytes) {
-		byte flagbyte = _source->readByte();
-		if (_source->eos())
-			break;
-		uint mask = 1;
-
-		for (int i = 0; i < 8; ++i) {
-			if ((flagbyte & mask) == mask) {
-				byte data = _source->readByte();
-				if (_source->eos()) {
-					return destinationCursor;
-				}
-
-				_window[_windowCursor] = data;
-				destination[destinationCursor++] = data;
-
-				// Increment and wrap the window cursor
-				_windowCursor = (_windowCursor + 1) & 0xFFF;
-			} else {
-				byte low = _source->readByte();
-				if (_source->eos()) {
-					return destinationCursor;
-				}
-
-				byte high = _source->readByte();
-				if (_source->eos()) {
-					return destinationCursor;
-				}
-
-				uint16 length = (high & 0xF) + 2;
-				uint16 offset = low | ((high & 0xF0) << 4);
-
-				for (int j = 0; j <= length; ++j) {
-					byte temp = _window[(offset + j) & 0xFFF];
-					_window[_windowCursor] = temp;
-					destination[destinationCursor++] = temp;
-					_windowCursor = (_windowCursor + 1) & 0xFFF;
-				}
-			}
-
-			mask = mask << 1;
-		}
-	}
-
-	return destinationCursor;
-}
-
-bool LzssReadStream::eos() const {
-	return _eosFlag;
-}
-
-uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) {
-	uint32 bytesRead = decompressBytes(static_cast<byte *>(dataPtr), dataSize);
-	if (bytesRead < dataSize) {
-		// Flag that we're at EOS
-		_eosFlag = true;
-	}
-
-	return dataSize;
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/utility/lzss_read_stream.h b/engines/zvision/utility/lzss_read_stream.h
deleted file mode 100644
index 1420621..0000000
--- a/engines/zvision/utility/lzss_read_stream.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_LZSS_STREAM_H
-#define ZVISION_LZSS_STREAM_H
-
-#include "common/stream.h"
-#include "common/array.h"
-
-namespace Common {
-class SeekableReadStream;
-}
-
-namespace ZVision {
-
-class LzssReadStream : public Common::ReadStream {
-public:
-	/**
-	 * A class that decompresses LZSS data and implements ReadStream for easy access
-	 * to the decompiled data.
-	 *
-	 * @param source              The source data
-	 */
-	LzssReadStream(Common::SeekableReadStream *source);
-
-private:
-	enum {
-		BLOCK_SIZE = 0x1000
-	};
-
-private:
-	Common::SeekableReadStream *_source;
-	byte _window[BLOCK_SIZE];
-	uint _windowCursor;
-	bool _eosFlag;
-
-public:
-	bool eos() const;
-	uint32 read(void *dataPtr, uint32 dataSize);
-
-private:
-	/**
-	 * Decompress the next <numberOfBytes> from the source stream. Or until EOS
-	 *
-	 * @param numberOfBytes    How many bytes to decompress. This is a count of source bytes, not destination bytes
-	 */
-	uint32 decompressBytes(byte *destination, uint32 numberOfBytes);
-};
-
-}
-
-#endif
diff --git a/engines/zvision/utility/zfs_archive.cpp b/engines/zvision/utility/zfs_archive.cpp
deleted file mode 100644
index 13b0168..0000000
--- a/engines/zvision/utility/zfs_archive.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-#include "common/memstream.h"
-#include "common/debug.h"
-#include "common/file.h"
-
-#include "zvision/utility/zfs_archive.h"
-
-namespace ZVision {
-
-ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) {
-	Common::File zfsFile;
-
-	if (!zfsFile.open(_fileName)) {
-		warning("ZFSArchive::ZFSArchive(): Could not find the archive file");
-		return;
-	}
-
-	readHeaders(&zfsFile);
-
-	debug(1, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size());
-}
-
-ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) {
-	readHeaders(stream);
-
-	debug(1, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size());
-}
-
-ZfsArchive::~ZfsArchive() {
-	debug(1, "ZfsArchive Destructor Called");
-	ZfsEntryHeaderMap::iterator it = _entryHeaders.begin();
-	for (; it != _entryHeaders.end(); ++it) {
-		delete it->_value;
-	}
-}
-
-void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) {
-	// Don't do a straight struct cast since we can't guarantee endianness
-	_header.magic = stream->readUint32LE();
-	_header.unknown1 = stream->readUint32LE();
-	_header.maxNameLength = stream->readUint32LE();
-	_header.filesPerBlock = stream->readUint32LE();
-	_header.fileCount = stream->readUint32LE();
-	_header.xorKey[0] = stream->readByte();
-	_header.xorKey[1] = stream->readByte();
-	_header.xorKey[2] = stream->readByte();
-	_header.xorKey[3] = stream->readByte();
-	_header.fileSectionOffset = stream->readUint32LE();
-
-	uint32 nextOffset;
-
-	do {
-		// Read the offset to the next block
-		nextOffset = stream->readUint32LE();
-
-		// Read in each entry header
-		for (uint32 i = 0; i < _header.filesPerBlock; ++i) {
-			ZfsEntryHeader entryHeader;
-
-			entryHeader.name = readEntryName(stream);
-			entryHeader.offset = stream->readUint32LE();
-			entryHeader.id = stream->readUint32LE();
-			entryHeader.size = stream->readUint32LE();
-			entryHeader.time = stream->readUint32LE();
-			entryHeader.unknown = stream->readUint32LE();
-
-			if (entryHeader.size != 0)
-				_entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader);
-		}
-
-		// Seek to the next block of headers
-		stream->seek(nextOffset);
-	} while (nextOffset != 0);
-}
-
-Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const {
-	// Entry Names are at most 16 bytes and are null padded
-	char buffer[16];
-	stream->read(buffer, 16);
-
-	return Common::String(buffer);
-}
-
-bool ZfsArchive::hasFile(const Common::String &name) const {
-	return _entryHeaders.contains(name);
-}
-
-int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const {
-	int matches = 0;
-
-	for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) {
-		list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this)));
-		matches++;
-	}
-
-	return matches;
-}
-
-const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const {
-	if (!_entryHeaders.contains(name))
-		return Common::ArchiveMemberPtr();
-
-	return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
-}
-
-Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const {
-	if (!_entryHeaders.contains(name)) {
-		return 0;
-	}
-
-	ZfsEntryHeader *entryHeader = _entryHeaders[name];
-
-	Common::File zfsArchive;
-	zfsArchive.open(_fileName);
-	zfsArchive.seek(entryHeader->offset);
-
-	// This *HAS* to be malloc (not new[]) because MemoryReadStream uses free() to free the memory
-	byte *buffer = (byte *)malloc(entryHeader->size);
-	zfsArchive.read(buffer, entryHeader->size);
-	// Decrypt the data in place
-	if (_header.xorKey != 0)
-		unXor(buffer, entryHeader->size, _header.xorKey);
-
-	return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES);
-}
-
-void ZfsArchive::unXor(byte *buffer, uint32 length, const byte *xorKey) const {
-	for (uint32 i = 0; i < length; ++i)
-		buffer[i] ^= xorKey[i % 4];
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/utility/zfs_archive.h b/engines/zvision/utility/zfs_archive.h
deleted file mode 100644
index 571591a..0000000
--- a/engines/zvision/utility/zfs_archive.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_ZFS_ARCHIVE_H
-#define ZVISION_ZFS_ARCHIVE_H
-
-#include "common/archive.h"
-#include "common/hashmap.h"
-#include "common/hash-str.h"
-
-namespace Common {
-class String;
-}
-
-namespace ZVision {
-
-struct ZfsHeader {
-	uint32 magic;
-	uint32 unknown1;
-	uint32 maxNameLength;
-	uint32 filesPerBlock;
-	uint32 fileCount;
-	byte xorKey[4];
-	uint32 fileSectionOffset;
-};
-
-struct ZfsEntryHeader {
-	Common::String name;
-	uint32 offset;
-	uint32 id;
-	uint32 size;
-	uint32 time;
-	uint32 unknown;
-};
-
-typedef Common::HashMap<Common::String, ZfsEntryHeader *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ZfsEntryHeaderMap;
-
-class ZfsArchive : public Common::Archive {
-public:
-	ZfsArchive(const Common::String &fileName);
-	ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream);
-	~ZfsArchive();
-
-	/**
-	 * Check if a member with the given name is present in the Archive.
-	 * Patterns are not allowed, as this is meant to be a quick File::exists()
-	 * replacement.
-	 */
-	bool hasFile(const Common::String &fileName) const;
-
-	/**
-	 * Add all members of the Archive to list.
-	 * Must only append to list, and not remove elements from it.
-	 *
-	 * @return    The number of names added to list
-	 */
-	int listMembers(Common::ArchiveMemberList &list) const;
-
-	/**
-	 * Returns a ArchiveMember representation of the given file.
-	 */
-	const Common::ArchiveMemberPtr getMember(const Common::String &name) const;
-
-	/**
-	 * Create a stream bound to a member with the specified name in the
-	 * archive. If no member with this name exists, 0 is returned.
-	 *
-	 * @return    The newly created input stream
-	 */
-	Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const;
-
-private:
-	const Common::String _fileName;
-	ZfsHeader _header;
-	ZfsEntryHeaderMap _entryHeaders;
-
-	/**
-	 * Parses the zfs file into file entry headers that can be used later
-	 * to get the entry data.
-	 *
-	 * @param stream    The contents of the zfs file
-	 */
-	void readHeaders(Common::SeekableReadStream *stream);
-
-	/**
-	 * Entry names are contained within a 16 byte block. This reads the block
-	 * and converts it the name to a Common::String
-	 *
-	 * @param stream    The zfs file stream
-	 * @return          The entry file name
-	 */
-	Common::String readEntryName(Common::SeekableReadStream *stream) const;
-
-	/**
-	 * ZFS file entries can be encrypted using XOR encoding. This method
-	 * decodes the buffer in place using the supplied xorKey.
-	 *
-	 * @param buffer    The data to decode
-	 * @param length    Length of buffer
-	 */
-	void unXor(byte *buffer, uint32 length, const byte *xorKey) const;
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index 45dc124..f9d6bb3 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -31,11 +31,11 @@
 #include "zvision/text/string_manager.h"
 #include "zvision/detection.h"
 #include "zvision/core/menu.h"
-#include "zvision/core/search_manager.h"
+#include "zvision/file/search_manager.h"
 #include "zvision/text/text.h"
 #include "zvision/graphics/truetype_font.h"
 #include "zvision/sound/midi.h"
-#include "zvision/utility/zfs_archive.h"
+#include "zvision/file/zfs_archive.h"
 
 #include "common/config-manager.h"
 #include "common/str.h"
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index 82030e6..55dddd4 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -26,7 +26,7 @@
 
 #include "zvision/detection.h"
 #include "zvision/utility/clock.h"
-#include "zvision/core/search_manager.h"
+#include "zvision/file/search_manager.h"
 
 #include "common/random.h"
 #include "common/events.h"


Commit: 7630e3204e3b932d9b43bda7dc4b658405fabf33
    https://github.com/scummvm/scummvm/commit/7630e3204e3b932d9b43bda7dc4b658405fabf33
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:56+02:00

Commit Message:
ZVISION: Move all the remaining utility classes into the core

Changed paths:
  A engines/zvision/core/clock.cpp
  A engines/zvision/core/clock.h
  A engines/zvision/core/utility.cpp
  A engines/zvision/core/utility.h
  R engines/zvision/utility/clock.cpp
  R engines/zvision/utility/clock.h
  R engines/zvision/utility/utility.cpp
  R engines/zvision/utility/utility.h
    engines/zvision/core/console.cpp
    engines/zvision/module.mk
    engines/zvision/scripting/control.cpp
    engines/zvision/scripting/controls/fist_control.cpp
    engines/zvision/scripting/controls/hotmov_control.cpp
    engines/zvision/scripting/controls/input_control.cpp
    engines/zvision/scripting/controls/lever_control.cpp
    engines/zvision/scripting/controls/paint_control.cpp
    engines/zvision/scripting/controls/push_toggle_control.cpp
    engines/zvision/scripting/controls/safe_control.cpp
    engines/zvision/scripting/controls/save_control.cpp
    engines/zvision/scripting/controls/slot_control.cpp
    engines/zvision/scripting/controls/titler_control.cpp
    engines/zvision/scripting/scr_file_handling.cpp
    engines/zvision/scripting/script_manager.cpp
    engines/zvision/sound/zork_raw.cpp
    engines/zvision/video/video.cpp
    engines/zvision/zvision.h



diff --git a/engines/zvision/core/clock.cpp b/engines/zvision/core/clock.cpp
new file mode 100644
index 0000000..1425d55
--- /dev/null
+++ b/engines/zvision/core/clock.cpp
@@ -0,0 +1,68 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+#include "zvision/core/clock.h"
+
+#include "common/system.h"
+
+namespace ZVision {
+
+Clock::Clock(OSystem *system)
+	: _system(system),
+	  _lastTime(0),
+	  _deltaTime(0),
+	  _pausedTime(0),
+	  _paused(false) {
+}
+
+void Clock::update() {
+	uint32 currentTime = _system->getMillis();
+
+	_deltaTime = (currentTime - _lastTime);
+	if (_paused) {
+		_deltaTime -= (currentTime - _pausedTime);
+	}
+
+	if (_deltaTime < 0) {
+		_deltaTime = 0;
+	}
+
+	_lastTime = currentTime;
+}
+
+void Clock::start() {
+	if (_paused) {
+		_lastTime = _system->getMillis();
+		_paused = false;
+	}
+}
+
+void Clock::stop() {
+	if (!_paused) {
+		_pausedTime = _system->getMillis();
+		_paused = true;
+	}
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/core/clock.h b/engines/zvision/core/clock.h
new file mode 100644
index 0000000..cbf52be
--- /dev/null
+++ b/engines/zvision/core/clock.h
@@ -0,0 +1,84 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_CLOCK_H
+#define ZVISION_CLOCK_H
+
+#include "common/types.h"
+
+class OSystem;
+
+namespace ZVision {
+
+/* Class for handling frame to frame deltaTime while keeping track of time pauses/un-pauses */
+class Clock {
+public:
+	Clock(OSystem *system);
+
+private:
+	OSystem *_system;
+	uint32 _lastTime;
+	int32 _deltaTime;
+	uint32 _pausedTime;
+	bool _paused;
+
+public:
+	/**
+	 * Updates _deltaTime with the difference between the current time and
+	 * when the last update() was called.
+	 */
+	void update();
+
+	/**
+	 * Get the delta time since the last frame. (The time between update() calls)
+	 *
+	 * @return    Delta time since the last frame (in milliseconds)
+	 */
+	uint32 getDeltaTime() const {
+		return _deltaTime;
+	}
+
+	/**
+	 * Get the time from the program starting to the last update() call
+	 *
+	 * @return Time from program start to last update() call (in milliseconds)
+	 */
+	uint32 getLastMeasuredTime() {
+		return _lastTime;
+	}
+
+	/**
+	 * Pause the clock. Any future delta times will take this pause into account.
+	 * Has no effect if the clock is already paused.
+	 */
+	void start();
+
+	/**
+	 * Un-pause the clock.
+	 * Has no effect if the clock is already un-paused.
+	 */
+	void stop();
+};
+
+} // End of namespace ZVision
+
+#endif
diff --git a/engines/zvision/core/console.cpp b/engines/zvision/core/console.cpp
index 76481a3..eb4d281 100644
--- a/engines/zvision/core/console.cpp
+++ b/engines/zvision/core/console.cpp
@@ -30,7 +30,7 @@
 #include "zvision/text/string_manager.h"
 #include "zvision/video/zork_avi_decoder.h"
 #include "zvision/sound/zork_raw.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 #include "zvision/graphics/cursors/cursor.h"
 
 #include "common/system.h"
diff --git a/engines/zvision/core/utility.cpp b/engines/zvision/core/utility.cpp
new file mode 100644
index 0000000..dcbb411
--- /dev/null
+++ b/engines/zvision/core/utility.cpp
@@ -0,0 +1,45 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+#include "zvision/core/utility.h"
+
+#include "zvision/zvision.h"
+#include "zvision/sound/zork_raw.h"
+
+#include "common/tokenizer.h"
+#include "common/file.h"
+
+namespace ZVision {
+
+void trimCommentsAndWhiteSpace(Common::String *string) {
+	for (int i = string->size() - 1; i >= 0; i--) {
+		if ((*string)[i] == '#') {
+			string->erase(i);
+		}
+	}
+
+	string->trim();
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/core/utility.h b/engines/zvision/core/utility.h
new file mode 100644
index 0000000..0ca26b9
--- /dev/null
+++ b/engines/zvision/core/utility.h
@@ -0,0 +1,47 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_UTILITY_H
+#define ZVISION_UTILITY_H
+
+#include "common/array.h"
+
+namespace Common {
+class String;
+}
+
+namespace ZVision {
+
+class ZVision;
+
+/**
+ * Removes any line comments using '#' as a sequence start.
+ * Then removes any trailing and leading 'whitespace' using String::trim()
+ * Note: String::trim uses isspace() to determine what is whitespace and what is not.
+ *
+ * @param string    The string to modify. It is modified in place
+ */
+void trimCommentsAndWhiteSpace(Common::String *string);
+
+} // End of namespace ZVision
+
+#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 1d89e22..18923ee 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -2,9 +2,11 @@ MODULE := engines/zvision
 
 MODULE_OBJS := \
 	core/console.o \
+	core/clock.o \
 	core/events.o \
 	core/menu.o \
 	core/save_manager.o \
+	core/utility.o \
 	detection.o \
 	file/lzss_read_stream.o \
 	file/search_manager.o \
@@ -44,8 +46,6 @@ MODULE_OBJS := \
 	sound/zork_raw.o \
 	text/string_manager.o \
 	text/text.o \
-	utility/clock.o \
-	utility/utility.o \
 	video/rlf_decoder.o \
 	video/video.o \
 	video/zork_avi_decoder.o \
diff --git a/engines/zvision/scripting/control.cpp b/engines/zvision/scripting/control.cpp
index 5469106..86f6a30 100644
--- a/engines/zvision/scripting/control.cpp
+++ b/engines/zvision/scripting/control.cpp
@@ -27,7 +27,7 @@
 
 #include "zvision/zvision.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
diff --git a/engines/zvision/scripting/controls/fist_control.cpp b/engines/zvision/scripting/controls/fist_control.cpp
index 887ad79..40d016f 100644
--- a/engines/zvision/scripting/controls/fist_control.cpp
+++ b/engines/zvision/scripting/controls/fist_control.cpp
@@ -27,7 +27,7 @@
 #include "zvision/scripting/controls/fist_control.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 #include "zvision/video/rlf_decoder.h"
 
 #include "common/stream.h"
diff --git a/engines/zvision/scripting/controls/hotmov_control.cpp b/engines/zvision/scripting/controls/hotmov_control.cpp
index b2c9cdd..4a6d270 100644
--- a/engines/zvision/scripting/controls/hotmov_control.cpp
+++ b/engines/zvision/scripting/controls/hotmov_control.cpp
@@ -28,7 +28,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp
index 1b15eac..e17a5f6 100644
--- a/engines/zvision/scripting/controls/input_control.cpp
+++ b/engines/zvision/scripting/controls/input_control.cpp
@@ -29,7 +29,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/text/string_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/str.h"
 #include "common/stream.h"
diff --git a/engines/zvision/scripting/controls/lever_control.cpp b/engines/zvision/scripting/controls/lever_control.cpp
index 07eec1f..632554e 100644
--- a/engines/zvision/scripting/controls/lever_control.cpp
+++ b/engines/zvision/scripting/controls/lever_control.cpp
@@ -28,7 +28,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
diff --git a/engines/zvision/scripting/controls/paint_control.cpp b/engines/zvision/scripting/controls/paint_control.cpp
index 0ef7618..24306bf 100644
--- a/engines/zvision/scripting/controls/paint_control.cpp
+++ b/engines/zvision/scripting/controls/paint_control.cpp
@@ -28,7 +28,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 namespace ZVision {
 
diff --git a/engines/zvision/scripting/controls/push_toggle_control.cpp b/engines/zvision/scripting/controls/push_toggle_control.cpp
index fcd8cd0..28c7911 100644
--- a/engines/zvision/scripting/controls/push_toggle_control.cpp
+++ b/engines/zvision/scripting/controls/push_toggle_control.cpp
@@ -27,7 +27,7 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
diff --git a/engines/zvision/scripting/controls/safe_control.cpp b/engines/zvision/scripting/controls/safe_control.cpp
index 8135eb3..cb754ec 100644
--- a/engines/zvision/scripting/controls/safe_control.cpp
+++ b/engines/zvision/scripting/controls/safe_control.cpp
@@ -28,7 +28,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
diff --git a/engines/zvision/scripting/controls/save_control.cpp b/engines/zvision/scripting/controls/save_control.cpp
index d773b5f..7de138d 100644
--- a/engines/zvision/scripting/controls/save_control.cpp
+++ b/engines/zvision/scripting/controls/save_control.cpp
@@ -24,7 +24,7 @@
 
 #include "zvision/scripting/controls/input_control.h"
 #include "zvision/scripting/controls/save_control.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
diff --git a/engines/zvision/scripting/controls/slot_control.cpp b/engines/zvision/scripting/controls/slot_control.cpp
index 7f04c2d..63578d5 100644
--- a/engines/zvision/scripting/controls/slot_control.cpp
+++ b/engines/zvision/scripting/controls/slot_control.cpp
@@ -28,7 +28,7 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
diff --git a/engines/zvision/scripting/controls/titler_control.cpp b/engines/zvision/scripting/controls/titler_control.cpp
index f0126be..af26aed 100644
--- a/engines/zvision/scripting/controls/titler_control.cpp
+++ b/engines/zvision/scripting/controls/titler_control.cpp
@@ -28,7 +28,7 @@
 #include "zvision/text/text.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
diff --git a/engines/zvision/scripting/scr_file_handling.cpp b/engines/zvision/scripting/scr_file_handling.cpp
index f97eed6..631cb61 100644
--- a/engines/zvision/scripting/scr_file_handling.cpp
+++ b/engines/zvision/scripting/scr_file_handling.cpp
@@ -25,7 +25,7 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 #include "zvision/scripting/puzzle.h"
 #include "zvision/scripting/actions.h"
 #include "zvision/scripting/controls/push_toggle_control.h"
diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp
index c735fe6..605d272 100644
--- a/engines/zvision/scripting/script_manager.cpp
+++ b/engines/zvision/scripting/script_manager.cpp
@@ -29,7 +29,7 @@
 #include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/core/save_manager.h"
 #include "zvision/scripting/actions.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 #include "zvision/scripting/sidefx/timer_node.h"
 
 #include "common/algorithm.h"
diff --git a/engines/zvision/sound/zork_raw.cpp b/engines/zvision/sound/zork_raw.cpp
index c26c33a..d8fabc4 100644
--- a/engines/zvision/sound/zork_raw.cpp
+++ b/engines/zvision/sound/zork_raw.cpp
@@ -34,7 +34,7 @@
 #include "zvision/sound/zork_raw.h"
 #include "zvision/zvision.h"
 #include "zvision/detection.h"
-#include "zvision/utility/utility.h"
+#include "zvision/core/utility.h"
 
 namespace ZVision {
 
diff --git a/engines/zvision/utility/clock.cpp b/engines/zvision/utility/clock.cpp
deleted file mode 100644
index 0e800a2..0000000
--- a/engines/zvision/utility/clock.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "zvision/utility/clock.h"
-
-#include "common/system.h"
-
-namespace ZVision {
-
-Clock::Clock(OSystem *system)
-	: _system(system),
-	  _lastTime(0),
-	  _deltaTime(0),
-	  _pausedTime(0),
-	  _paused(false) {
-}
-
-void Clock::update() {
-	uint32 currentTime = _system->getMillis();
-
-	_deltaTime = (currentTime - _lastTime);
-	if (_paused) {
-		_deltaTime -= (currentTime - _pausedTime);
-	}
-
-	if (_deltaTime < 0) {
-		_deltaTime = 0;
-	}
-
-	_lastTime = currentTime;
-}
-
-void Clock::start() {
-	if (_paused) {
-		_lastTime = _system->getMillis();
-		_paused = false;
-	}
-}
-
-void Clock::stop() {
-	if (!_paused) {
-		_pausedTime = _system->getMillis();
-		_paused = true;
-	}
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/utility/clock.h b/engines/zvision/utility/clock.h
deleted file mode 100644
index cbf52be..0000000
--- a/engines/zvision/utility/clock.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_CLOCK_H
-#define ZVISION_CLOCK_H
-
-#include "common/types.h"
-
-class OSystem;
-
-namespace ZVision {
-
-/* Class for handling frame to frame deltaTime while keeping track of time pauses/un-pauses */
-class Clock {
-public:
-	Clock(OSystem *system);
-
-private:
-	OSystem *_system;
-	uint32 _lastTime;
-	int32 _deltaTime;
-	uint32 _pausedTime;
-	bool _paused;
-
-public:
-	/**
-	 * Updates _deltaTime with the difference between the current time and
-	 * when the last update() was called.
-	 */
-	void update();
-
-	/**
-	 * Get the delta time since the last frame. (The time between update() calls)
-	 *
-	 * @return    Delta time since the last frame (in milliseconds)
-	 */
-	uint32 getDeltaTime() const {
-		return _deltaTime;
-	}
-
-	/**
-	 * Get the time from the program starting to the last update() call
-	 *
-	 * @return Time from program start to last update() call (in milliseconds)
-	 */
-	uint32 getLastMeasuredTime() {
-		return _lastTime;
-	}
-
-	/**
-	 * Pause the clock. Any future delta times will take this pause into account.
-	 * Has no effect if the clock is already paused.
-	 */
-	void start();
-
-	/**
-	 * Un-pause the clock.
-	 * Has no effect if the clock is already un-paused.
-	 */
-	void stop();
-};
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/utility/utility.cpp b/engines/zvision/utility/utility.cpp
deleted file mode 100644
index e09545a..0000000
--- a/engines/zvision/utility/utility.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "zvision/utility/utility.h"
-
-#include "zvision/zvision.h"
-#include "zvision/sound/zork_raw.h"
-
-#include "common/tokenizer.h"
-#include "common/file.h"
-
-namespace ZVision {
-
-void trimCommentsAndWhiteSpace(Common::String *string) {
-	for (int i = string->size() - 1; i >= 0; i--) {
-		if ((*string)[i] == '#') {
-			string->erase(i);
-		}
-	}
-
-	string->trim();
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/utility/utility.h b/engines/zvision/utility/utility.h
deleted file mode 100644
index 0ca26b9..0000000
--- a/engines/zvision/utility/utility.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_UTILITY_H
-#define ZVISION_UTILITY_H
-
-#include "common/array.h"
-
-namespace Common {
-class String;
-}
-
-namespace ZVision {
-
-class ZVision;
-
-/**
- * Removes any line comments using '#' as a sequence start.
- * Then removes any trailing and leading 'whitespace' using String::trim()
- * Note: String::trim uses isspace() to determine what is whitespace and what is not.
- *
- * @param string    The string to modify. It is modified in place
- */
-void trimCommentsAndWhiteSpace(Common::String *string);
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp
index c8f968d..189fb22 100644
--- a/engines/zvision/video/video.cpp
+++ b/engines/zvision/video/video.cpp
@@ -27,7 +27,7 @@
 #include "graphics/surface.h"
 
 #include "zvision/zvision.h"
-#include "zvision/utility/clock.h"
+#include "zvision/core/clock.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/subtitles.h"
 #include "zvision/video/rlf_decoder.h"
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index 55dddd4..78c1c82 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -25,7 +25,7 @@
 #define ZVISION_ZVISION_H
 
 #include "zvision/detection.h"
-#include "zvision/utility/clock.h"
+#include "zvision/core/clock.h"
 #include "zvision/file/search_manager.h"
 
 #include "common/random.h"


Commit: 77705752efa00ab7f6c65ff8d99e4d9c3fdc4929
    https://github.com/scummvm/scummvm/commit/77705752efa00ab7f6c65ff8d99e4d9c3fdc4929
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2014-12-16T01:58:57+02:00

Commit Message:
ZVISION: Move trimCommentsAndWhiteSpace() into the script manager

This allows us to remove the last remnants of utility.*

Changed paths:
  R engines/zvision/core/utility.cpp
  R engines/zvision/core/utility.h
    engines/zvision/core/console.cpp
    engines/zvision/module.mk
    engines/zvision/scripting/control.cpp
    engines/zvision/scripting/controls/fist_control.cpp
    engines/zvision/scripting/controls/hotmov_control.cpp
    engines/zvision/scripting/controls/input_control.cpp
    engines/zvision/scripting/controls/lever_control.cpp
    engines/zvision/scripting/controls/paint_control.cpp
    engines/zvision/scripting/controls/push_toggle_control.cpp
    engines/zvision/scripting/controls/safe_control.cpp
    engines/zvision/scripting/controls/save_control.cpp
    engines/zvision/scripting/controls/slot_control.cpp
    engines/zvision/scripting/controls/titler_control.cpp
    engines/zvision/scripting/scr_file_handling.cpp
    engines/zvision/scripting/script_manager.cpp
    engines/zvision/scripting/script_manager.h
    engines/zvision/sound/zork_raw.cpp



diff --git a/engines/zvision/core/console.cpp b/engines/zvision/core/console.cpp
index eb4d281..4dd10d6 100644
--- a/engines/zvision/core/console.cpp
+++ b/engines/zvision/core/console.cpp
@@ -30,7 +30,6 @@
 #include "zvision/text/string_manager.h"
 #include "zvision/video/zork_avi_decoder.h"
 #include "zvision/sound/zork_raw.h"
-#include "zvision/core/utility.h"
 #include "zvision/graphics/cursors/cursor.h"
 
 #include "common/system.h"
diff --git a/engines/zvision/core/utility.cpp b/engines/zvision/core/utility.cpp
deleted file mode 100644
index dcbb411..0000000
--- a/engines/zvision/core/utility.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/scummsys.h"
-
-#include "zvision/core/utility.h"
-
-#include "zvision/zvision.h"
-#include "zvision/sound/zork_raw.h"
-
-#include "common/tokenizer.h"
-#include "common/file.h"
-
-namespace ZVision {
-
-void trimCommentsAndWhiteSpace(Common::String *string) {
-	for (int i = string->size() - 1; i >= 0; i--) {
-		if ((*string)[i] == '#') {
-			string->erase(i);
-		}
-	}
-
-	string->trim();
-}
-
-} // End of namespace ZVision
diff --git a/engines/zvision/core/utility.h b/engines/zvision/core/utility.h
deleted file mode 100644
index 0ca26b9..0000000
--- a/engines/zvision/core/utility.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ZVISION_UTILITY_H
-#define ZVISION_UTILITY_H
-
-#include "common/array.h"
-
-namespace Common {
-class String;
-}
-
-namespace ZVision {
-
-class ZVision;
-
-/**
- * Removes any line comments using '#' as a sequence start.
- * Then removes any trailing and leading 'whitespace' using String::trim()
- * Note: String::trim uses isspace() to determine what is whitespace and what is not.
- *
- * @param string    The string to modify. It is modified in place
- */
-void trimCommentsAndWhiteSpace(Common::String *string);
-
-} // End of namespace ZVision
-
-#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 18923ee..00652f0 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -6,7 +6,6 @@ MODULE_OBJS := \
 	core/events.o \
 	core/menu.o \
 	core/save_manager.o \
-	core/utility.o \
 	detection.o \
 	file/lzss_read_stream.o \
 	file/search_manager.o \
diff --git a/engines/zvision/scripting/control.cpp b/engines/zvision/scripting/control.cpp
index 86f6a30..127f35e 100644
--- a/engines/zvision/scripting/control.cpp
+++ b/engines/zvision/scripting/control.cpp
@@ -27,7 +27,6 @@
 
 #include "zvision/zvision.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
@@ -43,7 +42,7 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 
 	while (!stream.eos() && !line.contains('}')) {
 		if (line.matchString("angle*", true)) {
@@ -67,7 +66,7 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	}
 
 	renderTable->generateRenderTable();
@@ -79,7 +78,7 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 
 	while (!stream.eos() && !line.contains('}')) {
 		if (line.matchString("angle*", true)) {
@@ -99,7 +98,7 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	}
 
 	renderTable->generateRenderTable();
diff --git a/engines/zvision/scripting/controls/fist_control.cpp b/engines/zvision/scripting/controls/fist_control.cpp
index 40d016f..34a64b4 100644
--- a/engines/zvision/scripting/controls/fist_control.cpp
+++ b/engines/zvision/scripting/controls/fist_control.cpp
@@ -27,7 +27,6 @@
 #include "zvision/scripting/controls/fist_control.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/core/utility.h"
 #include "zvision/video/rlf_decoder.h"
 
 #include "common/stream.h"
@@ -63,7 +62,7 @@ FistControl::FistControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -82,7 +81,7 @@ FistControl::FistControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 }
diff --git a/engines/zvision/scripting/controls/hotmov_control.cpp b/engines/zvision/scripting/controls/hotmov_control.cpp
index 4a6d270..e77272e 100644
--- a/engines/zvision/scripting/controls/hotmov_control.cpp
+++ b/engines/zvision/scripting/controls/hotmov_control.cpp
@@ -28,7 +28,6 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
@@ -53,7 +52,7 @@ HotMovControl::HotMovControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -84,7 +83,7 @@ HotMovControl::HotMovControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 }
diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp
index e17a5f6..6959f9e 100644
--- a/engines/zvision/scripting/controls/input_control.cpp
+++ b/engines/zvision/scripting/controls/input_control.cpp
@@ -29,7 +29,6 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/text/string_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/str.h"
 #include "common/stream.h"
@@ -50,7 +49,7 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 	  _animation(NULL) {
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -108,7 +107,7 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 }
diff --git a/engines/zvision/scripting/controls/lever_control.cpp b/engines/zvision/scripting/controls/lever_control.cpp
index 632554e..71dd52f 100644
--- a/engines/zvision/scripting/controls/lever_control.cpp
+++ b/engines/zvision/scripting/controls/lever_control.cpp
@@ -28,7 +28,6 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
@@ -53,7 +52,7 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 
 	Common::String param;
 	Common::String values;
@@ -73,7 +72,7 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 
diff --git a/engines/zvision/scripting/controls/paint_control.cpp b/engines/zvision/scripting/controls/paint_control.cpp
index 24306bf..f06dee2 100644
--- a/engines/zvision/scripting/controls/paint_control.cpp
+++ b/engines/zvision/scripting/controls/paint_control.cpp
@@ -28,7 +28,6 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/core/utility.h"
 
 namespace ZVision {
 
@@ -44,7 +43,7 @@ PaintControl::PaintControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -93,7 +92,7 @@ PaintControl::PaintControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 
diff --git a/engines/zvision/scripting/controls/push_toggle_control.cpp b/engines/zvision/scripting/controls/push_toggle_control.cpp
index 28c7911..3811498 100644
--- a/engines/zvision/scripting/controls/push_toggle_control.cpp
+++ b/engines/zvision/scripting/controls/push_toggle_control.cpp
@@ -27,7 +27,6 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
@@ -42,7 +41,7 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -78,7 +77,7 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 
diff --git a/engines/zvision/scripting/controls/safe_control.cpp b/engines/zvision/scripting/controls/safe_control.cpp
index cb754ec..71be692 100644
--- a/engines/zvision/scripting/controls/safe_control.cpp
+++ b/engines/zvision/scripting/controls/safe_control.cpp
@@ -28,7 +28,6 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 #include "common/file.h"
@@ -57,7 +56,7 @@ SafeControl::SafeControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -102,7 +101,7 @@ SafeControl::SafeControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 	renderFrame(_curState);
diff --git a/engines/zvision/scripting/controls/save_control.cpp b/engines/zvision/scripting/controls/save_control.cpp
index 7de138d..e27faa5 100644
--- a/engines/zvision/scripting/controls/save_control.cpp
+++ b/engines/zvision/scripting/controls/save_control.cpp
@@ -24,7 +24,6 @@
 
 #include "zvision/scripting/controls/input_control.h"
 #include "zvision/scripting/controls/save_control.h"
-#include "zvision/core/utility.h"
 
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
@@ -42,7 +41,7 @@ SaveControl::SaveControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 	  _saveControl(false) {
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -66,7 +65,7 @@ SaveControl::SaveControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 
diff --git a/engines/zvision/scripting/controls/slot_control.cpp b/engines/zvision/scripting/controls/slot_control.cpp
index 63578d5..292a2b4 100644
--- a/engines/zvision/scripting/controls/slot_control.cpp
+++ b/engines/zvision/scripting/controls/slot_control.cpp
@@ -28,7 +28,6 @@
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
@@ -42,7 +41,7 @@ SlotControl::SlotControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -98,7 +97,7 @@ SlotControl::SlotControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 
diff --git a/engines/zvision/scripting/controls/titler_control.cpp b/engines/zvision/scripting/controls/titler_control.cpp
index af26aed..10ba0af 100644
--- a/engines/zvision/scripting/controls/titler_control.cpp
+++ b/engines/zvision/scripting/controls/titler_control.cpp
@@ -28,7 +28,6 @@
 #include "zvision/text/text.h"
 #include "zvision/scripting/script_manager.h"
 #include "zvision/graphics/render_manager.h"
-#include "zvision/core/utility.h"
 
 #include "common/stream.h"
 
@@ -42,7 +41,7 @@ TitlerControl::TitlerControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
-	trimCommentsAndWhiteSpace(&line);
+	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 	Common::String param;
 	Common::String values;
 	getParams(line, param, values);
@@ -62,7 +61,7 @@ TitlerControl::TitlerControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 		}
 
 		line = stream.readLine();
-		trimCommentsAndWhiteSpace(&line);
+		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
 
diff --git a/engines/zvision/scripting/scr_file_handling.cpp b/engines/zvision/scripting/scr_file_handling.cpp
index 631cb61..56d0c3b 100644
--- a/engines/zvision/scripting/scr_file_handling.cpp
+++ b/engines/zvision/scripting/scr_file_handling.cpp
@@ -25,7 +25,6 @@
 #include "zvision/zvision.h"
 #include "zvision/scripting/script_manager.h"
 
-#include "zvision/core/utility.h"
 #include "zvision/scripting/puzzle.h"
 #include "zvision/scripting/actions.h"
 #include "zvision/scripting/controls/push_toggle_control.h"
diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp
index 605d272..65077df 100644
--- a/engines/zvision/scripting/script_manager.cpp
+++ b/engines/zvision/scripting/script_manager.cpp
@@ -29,7 +29,6 @@
 #include "zvision/graphics/cursors/cursor_manager.h"
 #include "zvision/core/save_manager.h"
 #include "zvision/scripting/actions.h"
-#include "zvision/core/utility.h"
 #include "zvision/scripting/sidefx/timer_node.h"
 
 #include "common/algorithm.h"
@@ -812,6 +811,16 @@ void ScriptManager::flushEvent(Common::EventType type) {
 	}
 }
 
+void ScriptManager::trimCommentsAndWhiteSpace(Common::String *string) const {
+	for (int i = string->size() - 1; i >= 0; i--) {
+		if ((*string)[i] == '#') {
+			string->erase(i);
+		}
+	}
+
+	string->trim();
+}
+
 ValueSlot::ValueSlot(ScriptManager *scriptManager, const char *slotValue):
 	_scriptManager(scriptManager) {
 	value = 0;
diff --git a/engines/zvision/scripting/script_manager.h b/engines/zvision/scripting/script_manager.h
index 89b9616..1e308fa 100644
--- a/engines/zvision/scripting/script_manager.h
+++ b/engines/zvision/scripting/script_manager.h
@@ -247,6 +247,15 @@ public:
 	Location getLastLocation();
 	Location getLastMenuLocation();
 
+	/**
+	 * Removes any line comments using '#' as a sequence start.
+	 * Then removes any trailing and leading 'whitespace' using String::trim()
+	 * Note: String::trim uses isspace() to determine what is whitespace and what is not.
+	 *
+	 * @param string    The string to modify. It is modified in place
+	 */
+	void trimCommentsAndWhiteSpace(Common::String *string) const;
+
 private:
 	void referenceTableAddPuzzle(uint32 key, PuzzleRef ref);
 	void addPuzzlesToReferenceTable(ScriptScope &scope);
diff --git a/engines/zvision/sound/zork_raw.cpp b/engines/zvision/sound/zork_raw.cpp
index d8fabc4..78c851e 100644
--- a/engines/zvision/sound/zork_raw.cpp
+++ b/engines/zvision/sound/zork_raw.cpp
@@ -34,7 +34,6 @@
 #include "zvision/sound/zork_raw.h"
 #include "zvision/zvision.h"
 #include "zvision/detection.h"
-#include "zvision/core/utility.h"
 
 namespace ZVision {
 






More information about the Scummvm-git-logs mailing list