diff options
| author | Matthew Stewart | 2018-02-21 21:06:57 -0500 | 
|---|---|---|
| committer | Eugene Sandulenko | 2018-08-09 08:37:30 +0200 | 
| commit | b84a3bb4f28eb4b9e0bcfc19d405c79867360032 (patch) | |
| tree | 30197091362461438716a34e729587bacbe6b538 | |
| parent | 60d672db7315f9a131cfb128a3a10b29ece10112 (diff) | |
| download | scummvm-rg350-b84a3bb4f28eb4b9e0bcfc19d405c79867360032.tar.gz scummvm-rg350-b84a3bb4f28eb4b9e0bcfc19d405c79867360032.tar.bz2 scummvm-rg350-b84a3bb4f28eb4b9e0bcfc19d405c79867360032.zip  | |
STARTREK: Make Bitmap, Sprite, FileStream classes
| -rw-r--r-- | engines/startrek/filestream.cpp | 38 | ||||
| -rw-r--r-- | engines/startrek/filestream.h | 52 | ||||
| -rwxr-xr-x | engines/startrek/graphics.cpp | 60 | ||||
| -rwxr-xr-x | engines/startrek/graphics.h | 45 | ||||
| -rwxr-xr-x | engines/startrek/module.mk | 1 | ||||
| -rwxr-xr-x | engines/startrek/startrek.cpp | 37 | ||||
| -rwxr-xr-x | engines/startrek/startrek.h | 2 | 
7 files changed, 183 insertions, 52 deletions
diff --git a/engines/startrek/filestream.cpp b/engines/startrek/filestream.cpp new file mode 100644 index 0000000000..3af5ca8bb7 --- /dev/null +++ b/engines/startrek/filestream.cpp @@ -0,0 +1,38 @@ +#include "startrek/filestream.h" + +namespace StarTrek { + +FileStream::FileStream(Common::SeekableReadStream *stream, bool bigEndian) : Common::SeekableReadStreamEndian(bigEndian) { +	_stream = stream; +	_bigEndian = bigEndian; +} + +FileStream::~FileStream() { +	delete _stream; +} + +// ReadStream functions + +bool FileStream::eos() const { +	return _stream->eos(); +} + +uint32 FileStream::read(void* dataPtr, uint32 dataSize) { +	return _stream->read(dataPtr, dataSize); +} + +// SeekableReadStream functions + +int32 FileStream::pos() const { +	return _stream->pos(); +} + +int32 FileStream::size() const { +	return _stream->size(); +} + +bool FileStream::seek(int32 offset, int whence) { +	return _stream->seek(offset, whence); +} + +} diff --git a/engines/startrek/filestream.h b/engines/startrek/filestream.h new file mode 100644 index 0000000000..899f639ad5 --- /dev/null +++ b/engines/startrek/filestream.h @@ -0,0 +1,52 @@ +/* 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 STARTREK_FILESTREAM_H +#define STARTREK_FILESTREAM_H + +#include "common/stream.h" + +namespace StarTrek { + +class FileStream : public Common::SeekableReadStreamEndian { + +public: +	FileStream(Common::SeekableReadStream *stream, bool bigEndian); +	~FileStream(); + +private: +	Common::SeekableReadStream *_stream; +	bool _bigEndian; + +	// ReadStream functions +	virtual bool eos() const; +	virtual uint32 read(void* dataPtr, uint32 dataSize); + +	// SeekableReadStream functions +	virtual int32 pos() const; +	virtual int32 size() const; +	virtual bool seek(int32 offset, int whence); + +}; + +} + +#endif diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp index 8dcc43686e..5304d40dc0 100755 --- a/engines/startrek/graphics.cpp +++ b/engines/startrek/graphics.cpp @@ -31,6 +31,25 @@  namespace StarTrek { +// Bitmap class + +Bitmap::Bitmap(Common::ReadStreamEndian *stream) { +	xoffset = stream->readUint16(); +	yoffset = stream->readUint16(); +	width = stream->readUint16(); +	height = stream->readUint16(); + +	pixels = (byte*)malloc(width*height); +	stream->read(pixels, width*height); +} + +Bitmap::~Bitmap() { +	free(pixels); +} + + +// Graphics class +  Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {  	_font = 0;  	_egaData = 0; @@ -67,6 +86,19 @@ void Graphics::setPalette(const char *paletteFile) {  	delete palStream;  } +void Graphics::drawBitmap(Bitmap *bitmap) { +	int xoffset = bitmap->xoffset; +	int yoffset = bitmap->yoffset; +	if (xoffset >= 320) +		xoffset = 0; +	if (yoffset >= 200) +		yoffset = 0; + +	_vm->_system->copyRectToScreen(bitmap->pixels, bitmap->width, xoffset, yoffset, bitmap->width, bitmap->height); +	_vm->_system->updateScreen(); +} + +  void Graphics::loadEGAData(const char *filename) {  	// Load EGA palette data  	if (!_egaMode) @@ -80,34 +112,6 @@ void Graphics::loadEGAData(const char *filename) {  	delete egaStream;  } -void Graphics::drawImage(const char *filename) { -	// Draw a regular bitmap - -	Common::SeekableReadStream *imageStream = _vm->openFile(filename); -	uint16 xoffset = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); -	uint16 yoffset = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); -	uint16 width = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE(); -	uint16 height = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE();	 - -	if (xoffset >= 320) -		xoffset = 0; -	if (yoffset >= 200) -		yoffset = 0; - -	byte *pixels = (byte *)malloc(width * height); - -	if (_egaMode && _egaData) { -		// FIXME: This doesn't work right -		for (uint32 i = 0; i < (uint32)(width * height); i++) -			pixels[i] = _egaData[imageStream->readByte()]; -	} else { -		imageStream->read(pixels, width * height); -	} - -	_vm->_system->copyRectToScreen(pixels, width, xoffset, yoffset, width, height); -	_vm->_system->updateScreen(); -} -  void Graphics::drawBackgroundImage(const char *filename) {  	// Draw an stjr BGD image (palette built-in) diff --git a/engines/startrek/graphics.h b/engines/startrek/graphics.h index b796e83491..6637928c3e 100755 --- a/engines/startrek/graphics.h +++ b/engines/startrek/graphics.h @@ -29,19 +29,62 @@  #include "startrek/startrek.h"  #include "startrek/font.h" +#include "common/stream.h" +  namespace StarTrek {  class Font;  class StarTrekEngine; + +class Bitmap { +public: +	uint16 xoffset; +	uint16 yoffset; +	uint16 width; +	uint16 height; +	byte *pixels; + +public: +	Bitmap(Common::ReadStreamEndian *stream); +	~Bitmap(); +}; + +class Rectangle { +	uint16 left; +	uint16 top; +	uint16 right; +	uint16 bottom; +}; + +class Sprite { +	uint16 x,y; +	uint16 drawPriority; +	uint16 field6; +	uint16 field8; +	Bitmap *bitmap; +	uint16 drawMode; +	uint16 fieldE; +	uint16 bitmapChanged; +	uint16 redrawCondition2; +	uint16 redrawCondition3; +	uint16 field16; +	Rectangle rectangle1; +	Rectangle clickRectangle; +	Rectangle rectangle2; +	uint16 drawX,drawY; +}; + +  class Graphics {  public:  	Graphics(StarTrekEngine *vm);  	~Graphics();  	void setPalette(const char *paletteFile); +	void drawBitmap(Bitmap *bitmap); +  	void loadEGAData(const char *egaFile); -	void drawImage(const char *filename);  	void drawBackgroundImage(const char *filename); diff --git a/engines/startrek/module.mk b/engines/startrek/module.mk index 75878e03f0..0b95d7dc14 100755 --- a/engines/startrek/module.mk +++ b/engines/startrek/module.mk @@ -2,6 +2,7 @@ MODULE := engines/startrek  MODULE_OBJS = \  	detection.o \ +	filestream.o \  	font.o \  	lzss.o \  	graphics.o \ diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp index abb838365c..5401e5217b 100755 --- a/engines/startrek/startrek.cpp +++ b/engines/startrek/startrek.cpp @@ -35,6 +35,7 @@  #include "engines/util.h"  #include "video/qt_decoder.h" +#include "startrek/filestream.h"  #include "startrek/lzss.h"  #include "startrek/startrek.h" @@ -87,20 +88,10 @@ Common::Error StarTrekEngine::run() {  // EGA not supported  #if 1  	if (getGameType() == GType_ST25) { -		if (getPlatform() == Common::kPlatformMacintosh) { -			if (getFeatures() & GF_DEMO) { -				_gfx->setPalette("BRIDGE.PAL"); -				_gfx->drawImage("BRIDGE.BMP"); -			} else { -				playMovie("Voice Data/Additional Audio/Intro Movie"); -				_gfx->setPalette("BRIDGES.PAL"); -				_gfx->drawImage("BRIDGE0.BMP"); -			} -		} else { -			_gfx->setPalette("BRIDGE.PAL"); -			//_gfx->loadEGAData("BRIDGE.EGA"); -			_gfx->drawImage("DEMON5.BMP"); -		} +		_gfx->setPalette("PALETTE.PAL"); +		Bitmap *b = new Bitmap(openFile("DEMON5.BMP")); +		_gfx->drawBitmap(b); +		delete b;  		if (getPlatform() == Common::kPlatformAmiga)  			_sound->playSoundEffect("TREK2"); @@ -132,10 +123,12 @@ Common::Error StarTrekEngine::run() {  	return Common::kNoError;  } -Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, int fileIndex) { +Common::SeekableReadStreamEndian *StarTrekEngine::openFile(Common::String filename, int fileIndex) {  	filename.toUppercase();  	Common::String basename, extension; +	bool bigEndian = getPlatform() == Common::kPlatformAmiga; +  	for (int i=filename.size()-1; ; i--) {  		if (filename[i] == '.') {  			basename = filename; @@ -151,7 +144,7 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in  		Common::File *file = new Common::File();  		if (!file->open(filename.c_str()))  			error ("Could not find file \'%s\'", filename.c_str()); -		return file; +		return new FileStream(file, bigEndian);  	}  	Common::SeekableReadStream *indexFile = 0; @@ -210,7 +203,7 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in  		if (filename.matchString(testfile)) {  			foundData = true;  			break; -		}		 +		}  	}  	delete indexFile; @@ -230,7 +223,7 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in  		error("Tried to access file index %d for file '%s' which doesn't exist.", fileIndex, filename.c_str());  	Common::SeekableReadStream *dataFile = 0; -	Common::SeekableReadStream *dataRunFile = 0; // FIXME: Amiga & Mac code don't implement this +	Common::SeekableReadStream *dataRunFile = 0; // FIXME: Amiga & Mac need this implemented  	if (getPlatform() == Common::kPlatformAmiga) {  		dataFile = SearchMan.createReadStreamForMember("data.000"); @@ -254,7 +247,7 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in  		Common::SeekableReadStream *stream = dataFile->readStream(uncompressedSize);  		delete dataFile;  		delete dataRunFile; -		return stream; +		return new FileStream(stream, bigEndian);  	} else {  		if (fileCount != 1) {  			dataRunFile->seek(indexOffset); @@ -276,12 +269,12 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in  		delete dataFile;  		delete dataRunFile; -		return stream; +		return new FileStream(stream, bigEndian);  	} -	 +  	// We should not get to this point...  	error("Could not find data for \'%s\'", filename.c_str()); -		 +  	return NULL;  } diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h index 9f6935d72a..22dec315b5 100755 --- a/engines/startrek/startrek.h +++ b/engines/startrek/startrek.h @@ -74,7 +74,7 @@ public:  	Common::Language getLanguage();  	// Resource related functions -	Common::SeekableReadStream *openFile(Common::String filename, int fileIndex=0); +	Common::SeekableReadStreamEndian *openFile(Common::String filename, int fileIndex=0);  	// Movie related functions  	void playMovie(Common::String filename);  | 
