aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/access/access.cpp17
-rw-r--r--engines/access/access.h8
-rw-r--r--engines/access/amazon/amazon_game.cpp15
-rw-r--r--engines/access/amazon/amazon_room.cpp6
-rw-r--r--engines/access/animation.cpp77
-rw-r--r--engines/access/animation.h11
-rw-r--r--engines/access/asurface.cpp29
-rw-r--r--engines/access/asurface.h5
-rw-r--r--engines/access/bubble_box.cpp6
-rw-r--r--engines/access/char.cpp14
-rw-r--r--engines/access/files.cpp154
-rw-r--r--engines/access/files.h57
-rw-r--r--engines/access/martian/martian_game.cpp6
-rw-r--r--engines/access/martian/martian_room.cpp6
-rw-r--r--engines/access/player.cpp6
-rw-r--r--engines/access/room.cpp44
-rw-r--r--engines/access/screen.cpp5
-rw-r--r--engines/access/scripts.cpp23
-rw-r--r--engines/access/scripts.h6
-rw-r--r--engines/access/sound.cpp9
-rw-r--r--engines/access/sound.h12
-rw-r--r--engines/access/video.cpp26
-rw-r--r--engines/access/video.h13
23 files changed, 307 insertions, 248 deletions
diff --git a/engines/access/access.cpp b/engines/access/access.cpp
index 6058800ddb..080cd36032 100644
--- a/engines/access/access.cpp
+++ b/engines/access/access.cpp
@@ -70,6 +70,7 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc)
_scaleMaxY = 0;
_scaleI = 0;
_scaleFlag = false;
+ _eseg = nullptr;
_conversation = 0;
_currentMan = 0;
@@ -124,9 +125,9 @@ AccessEngine::~AccessEngine() {
delete _video;
freeCells();
- delete[] _inactive;
- delete[] _music;
- delete[] _title;
+ delete _inactive;
+ delete _music;
+ delete _title;
}
void AccessEngine::setVGA() {
@@ -211,9 +212,9 @@ int AccessEngine::getRandomNumber(int maxNumber) {
void AccessEngine::loadCells(Common::Array<CellIdent> &cells) {
for (uint i = 0; i < cells.size(); ++i) {
- byte *spriteData = _files->loadFile(cells[i]);
- _objectsTable[cells[i]._cell] = new SpriteResource(this,
- spriteData, _files->_filesize, DisposeAfterUse::YES);
+ Resource *spriteData = _files->loadFile(cells[i]);
+ _objectsTable[cells[i]._cell] = new SpriteResource(this, spriteData);
+ delete spriteData;
}
}
@@ -251,7 +252,7 @@ void AccessEngine::speakText(ASurface *s, Common::Array<Common::String> msgArr)
if ((s->_printOrg.y > _printEnd) && (!lastLine)) {
while (true) {
- _sound->_soundTable[0]._data = _sound->loadSound(_narateFile + 99, _sndSubFile);
+ _sound->_soundTable[0] = _sound->loadSound(_narateFile + 99, _sndSubFile);
_sound->_soundPriority[0] = 1;
_sound->playSound(1);
_scripts->CMDFREESOUND();
@@ -286,7 +287,7 @@ void AccessEngine::speakText(ASurface *s, Common::Array<Common::String> msgArr)
return;
while(true) {
- _sound->_soundTable[0]._data = _sound->loadSound(_narateFile + 99, _sndSubFile);
+ _sound->_soundTable[0] = _sound->loadSound(_narateFile + 99, _sndSubFile);
_sound->_soundPriority[0] = 1;
_sound->playSound(1);
_scripts->CMDFREESOUND();
diff --git a/engines/access/access.h b/engines/access/access.h
index f25effef06..55810e8a16 100644
--- a/engines/access/access.h
+++ b/engines/access/access.h
@@ -148,9 +148,9 @@ public:
int _mouseMode;
int _currentManOld;
- byte *_inactive;
- byte *_music;
- byte *_title;
+ Resource *_inactive;
+ Resource *_music;
+ Resource *_title;
int _converseMode;
int _startAboutBox;
int _startTravelBox;
@@ -164,7 +164,7 @@ public:
int _scaleI;
bool _scaleFlag;
- byte *_eseg;
+ Resource *_eseg;
int _et;
int _printEnd;
int _txtPages;
diff --git a/engines/access/amazon/amazon_game.cpp b/engines/access/amazon/amazon_game.cpp
index 15869a4499..cf383ce45a 100644
--- a/engines/access/amazon/amazon_game.cpp
+++ b/engines/access/amazon/amazon_game.cpp
@@ -134,9 +134,9 @@ void AmazonEngine::doTitle() {
_screen->forceFadeIn();
_sound->playSound(1);
- byte *spriteData = _files->loadFile(0, 2);
- _objectsTable[0] = new SpriteResource(this, spriteData, _files->_filesize,
- DisposeAfterUse::YES);
+ Resource *spriteData = _files->loadFile(0, 2);
+ _objectsTable[0] = new SpriteResource(this, spriteData);
+ delete spriteData;
_sound->playSound(1);
@@ -300,13 +300,13 @@ void AmazonEngine::tileScreen() {
if (!_files->existFile(_tileFiles[idx]))
return;
- byte *data = _files->loadFile(_tileFiles[idx]);
- int x = READ_LE_UINT16(data);
- int y = READ_LE_UINT16(data + 2);
+ Resource *res = _files->loadFile(_tileFiles[idx]);
+ int x = res->_stream->readSint16LE();
+ int y = res->_stream->readSint16LE();
int size = ((x + 2) * y) + 10;
for (int i = 0; i < size; ++i)
- _tileData[i] = data[i + 4];
+ _tileData[i] = res->_stream->readByte();
// CHECKME: Depending on the Vesa mode during initialization, 400 or 480
for (_tilePos.y = 0; _tilePos.y < 480; _tilePos.y += y) {
@@ -314,6 +314,7 @@ void AmazonEngine::tileScreen() {
warning("TODO: DRAWOBJECT");
}
+ delete res;
}
void AmazonEngine::updateSummary(int chap) {
diff --git a/engines/access/amazon/amazon_room.cpp b/engines/access/amazon/amazon_room.cpp
index f64264f7d7..227fc474cf 100644
--- a/engines/access/amazon/amazon_room.cpp
+++ b/engines/access/amazon/amazon_room.cpp
@@ -131,9 +131,9 @@ void AmazonRoom::roomSet() {
}
void AmazonRoom::roomMenu() {
- byte *iconData = _vm->_files->loadFile("ICONS.LZ");
- SpriteResource *spr = new SpriteResource(_vm, iconData, _vm->_files->_filesize);
- delete[] iconData;
+ Resource *iconData = _vm->_files->loadFile("ICONS.LZ");
+ SpriteResource *spr = new SpriteResource(_vm, iconData);
+ delete iconData;
_vm->_screen->saveScreen();
_vm->_screen->setDisplayScan();
diff --git a/engines/access/animation.cpp b/engines/access/animation.cpp
index b286237bfb..03f349e34a 100644
--- a/engines/access/animation.cpp
+++ b/engines/access/animation.cpp
@@ -27,18 +27,17 @@
namespace Access {
-AnimationResource::AnimationResource(AccessEngine *vm, const byte *data, int size) {
- Common::MemoryReadStream stream(data, size);
- int count = stream.readUint16LE();
+AnimationResource::AnimationResource(AccessEngine *vm, Resource *res) {
+ int count = res->_stream->readUint16LE();
Common::Array<int> offsets;
for (int i = 0; i < count; ++i)
- offsets.push_back(stream.readUint32LE());
+ offsets.push_back(res->_stream->readUint32LE());
_animations.reserve(count);
for (int i = 0; i < count; ++i) {
- stream.seek(offsets[i]);
- Animation *anim = new Animation(vm, stream);
+ res->_stream->seek(offsets[i]);
+ Animation *anim = new Animation(vm, res->_stream);
_animations.push_back(anim);
}
}
@@ -50,29 +49,29 @@ AnimationResource::~AnimationResource() {
/*------------------------------------------------------------------------*/
-Animation::Animation(AccessEngine *vm, Common::MemoryReadStream &stream):
+Animation::Animation(AccessEngine *vm, Common::SeekableReadStream *stream) :
Manager(vm) {
- uint32 startOfs = stream.pos();
-
- _type = stream.readByte();
- _scaling = stream.readSByte();
- stream.readByte(); // unk
- _frameNumber = stream.readByte();
- _initialTicks = stream.readUint16LE();
- stream.readUint16LE(); // unk
- stream.readUint16LE(); // unk
- _loopCount = stream.readSint16LE();
- _countdownTicks = stream.readUint16LE();
- _currentLoopCount = stream.readSint16LE();
- stream.readUint16LE(); // unk
+ uint32 startOfs = stream->pos();
+
+ _type = stream->readByte();
+ _scaling = stream->readSByte();
+ stream->readByte(); // unk
+ _frameNumber = stream->readByte();
+ _initialTicks = stream->readUint16LE();
+ stream->readUint16LE(); // unk
+ stream->readUint16LE(); // unk
+ _loopCount = stream->readSint16LE();
+ _countdownTicks = stream->readUint16LE();
+ _currentLoopCount = stream->readSint16LE();
+ stream->readUint16LE(); // unk
Common::Array<uint16> frameOffsets;
uint16 ofs;
- while ((ofs = stream.readUint16LE()) != 0)
+ while ((ofs = stream->readUint16LE()) != 0)
frameOffsets.push_back(ofs);
for (int i = 0; i < (int)frameOffsets.size(); i++) {
- stream.seek(startOfs + frameOffsets[i]);
+ stream->seek(startOfs + frameOffsets[i]);
AnimationFrame *frame = new AnimationFrame(stream, startOfs);
_frames.push_back(frame);
@@ -239,22 +238,22 @@ void Animation::setFrame1(AnimationFrame *frame) {
/*------------------------------------------------------------------------*/
-AnimationFrame::AnimationFrame(Common::MemoryReadStream &stream, int startOffset) {
+AnimationFrame::AnimationFrame(Common::SeekableReadStream *stream, int startOffset) {
uint16 nextOffset;
- stream.readByte(); // unk
- _baseX = stream.readUint16LE();
- _baseY = stream.readUint16LE();
- _frameDelay = stream.readUint16LE();
- nextOffset = stream.readUint16LE();
+ stream->readByte(); // unk
+ _baseX = stream->readUint16LE();
+ _baseY = stream->readUint16LE();
+ _frameDelay = stream->readUint16LE();
+ nextOffset = stream->readUint16LE();
while (nextOffset != 0) {
- stream.seek(startOffset + nextOffset);
+ stream->seek(startOffset + nextOffset);
AnimationFramePart *framePart = new AnimationFramePart(stream);
_parts.push_back(framePart);
- nextOffset = stream.readUint16LE();
+ nextOffset = stream->readUint16LE();
}
}
@@ -265,13 +264,13 @@ AnimationFrame::~AnimationFrame() {
/*------------------------------------------------------------------------*/
-AnimationFramePart::AnimationFramePart(Common::MemoryReadStream &stream) {
- _flags = stream.readByte();
- _spritesIndex = stream.readByte();
- _frameIndex = stream.readByte();
- _position.x = stream.readUint16LE();
- _position.y = stream.readUint16LE();
- _offsetY = stream.readUint16LE();
+AnimationFramePart::AnimationFramePart(Common::SeekableReadStream *stream) {
+ _flags = stream->readByte();
+ _spritesIndex = stream->readByte();
+ _frameIndex = stream->readByte();
+ _position.x = stream->readUint16LE();
+ _position.y = stream->readUint16LE();
+ _offsetY = stream->readUint16LE();
}
/*------------------------------------------------------------------------*/
@@ -296,10 +295,10 @@ void AnimationManager::clearTimers() {
_animationTimers.clear();
}
-void AnimationManager::loadAnimations(const byte *data, int size) {
+void AnimationManager::loadAnimations(Resource *res) {
_animationTimers.clear();
delete _animation;
- _animation = new AnimationResource(_vm, data, size);
+ _animation = new AnimationResource(_vm, res);
}
diff --git a/engines/access/animation.h b/engines/access/animation.h
index 7e94f58cbd..8a39333764 100644
--- a/engines/access/animation.h
+++ b/engines/access/animation.h
@@ -27,6 +27,7 @@
#include "common/array.h"
#include "common/memstream.h"
#include "access/data.h"
+#include "access/files.h"
namespace Access {
@@ -47,7 +48,7 @@ public:
AnimationManager(AccessEngine *vm);
~AnimationManager();
void freeAnimationData();
- void loadAnimations(const byte *data, int size);
+ void loadAnimations(Resource *res);
Animation *findAnimation(int animId);
Animation *setAnimation(int animId);
@@ -74,7 +75,7 @@ class AnimationResource {
private:
Common::Array<Animation *> _animations;
public:
- AnimationResource(AccessEngine *vm, const byte *data, int size);
+ AnimationResource(AccessEngine *vm, Resource *res);
~AnimationResource();
int getCount() { return _animations.size(); }
@@ -107,7 +108,7 @@ public:
int _currentLoopCount;
int _field10;
public:
- Animation(AccessEngine *vm, Common::MemoryReadStream &stream);
+ Animation(AccessEngine *vm, Common::SeekableReadStream *stream);
~Animation();
void animate();
@@ -119,7 +120,7 @@ public:
int _frameDelay;
Common::Array<AnimationFramePart *> _parts;
public:
- AnimationFrame(Common::MemoryReadStream &stream, int startOffset);
+ AnimationFrame(Common::SeekableReadStream *stream, int startOffset);
~AnimationFrame();
};
@@ -131,7 +132,7 @@ public:
Common::Point _position;
int _offsetY;
public:
- AnimationFramePart(Common::MemoryReadStream &stream);
+ AnimationFramePart(Common::SeekableReadStream *stream);
};
} // End of namespace Access
diff --git a/engines/access/asurface.cpp b/engines/access/asurface.cpp
index cdf8b3dd3f..cf8bf0766f 100644
--- a/engines/access/asurface.cpp
+++ b/engines/access/asurface.cpp
@@ -28,27 +28,22 @@
namespace Access {
-SpriteResource::SpriteResource(AccessEngine *vm, const byte *data, uint32 size,
- DisposeAfterUse::Flag disposeMemory) {
- Common::MemoryReadStream stream(data, size);
+SpriteResource::SpriteResource(AccessEngine *vm, Resource *res) {
Common::Array<uint32> offsets;
- int count = stream.readUint16LE();
+ int count = res->_stream->readUint16LE();
for (int i = 0; i < count; i++)
- offsets.push_back(stream.readUint32LE());
- offsets.push_back(size); // For easier calculations of Noctropolis sizes
+ offsets.push_back(res->_stream->readUint32LE());
+ offsets.push_back(res->_size); // For easier calculations of Noctropolis sizes
// Build up the frames
for (int i = 0; i < count; ++i) {
- stream.seek(offsets[i]);
+ res->_stream->seek(offsets[i]);
int frameSize = offsets[i + 1] - offsets[i];
- SpriteFrame *frame = new SpriteFrame(vm, stream, frameSize);
+ SpriteFrame *frame = new SpriteFrame(vm, res->_stream, frameSize);
_frames.push_back(frame);
}
-
- if (disposeMemory == DisposeAfterUse::YES)
- delete[] data;
}
SpriteResource::~SpriteResource() {
@@ -56,9 +51,9 @@ SpriteResource::~SpriteResource() {
delete _frames[i];
}
-SpriteFrame::SpriteFrame(AccessEngine *vm, Common::MemoryReadStream &stream, int frameSize) {
- int xSize = stream.readUint16LE();
- int ySize = stream.readUint16LE();
+SpriteFrame::SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, int frameSize) {
+ int xSize = stream->readUint16LE();
+ int ySize = stream->readUint16LE();
create(xSize, ySize);
// Empty surface
@@ -67,12 +62,12 @@ SpriteFrame::SpriteFrame(AccessEngine *vm, Common::MemoryReadStream &stream, int
// Decode the data
for (int y = 0; y < h; ++y) {
- int offset = stream.readByte();
- int len = stream.readByte();
+ int offset = stream->readByte();
+ int len = stream->readByte();
assert((offset + len) <= w);
byte *destP = (byte *)getBasePtr(offset, y);
- stream.read(destP, len);
+ stream->read(destP, len);
}
}
diff --git a/engines/access/asurface.h b/engines/access/asurface.h
index 5d1f6fd307..5c164f0e59 100644
--- a/engines/access/asurface.h
+++ b/engines/access/asurface.h
@@ -115,7 +115,7 @@ public:
class SpriteFrame : public ASurface {
public:
- SpriteFrame(AccessEngine *vm, Common::MemoryReadStream &stream, int frameSize);
+ SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, int frameSize);
~SpriteFrame();
};
@@ -123,8 +123,7 @@ class SpriteResource {
public:
Common::Array<SpriteFrame *> _frames;
public:
- SpriteResource(AccessEngine *vm, const byte *data, uint32 size,
- DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO);
+ SpriteResource(AccessEngine *vm, Resource *res);
~SpriteResource();
int getCount() { return _frames.size(); }
diff --git a/engines/access/bubble_box.cpp b/engines/access/bubble_box.cpp
index d3782a3125..c4272b607a 100644
--- a/engines/access/bubble_box.cpp
+++ b/engines/access/bubble_box.cpp
@@ -191,9 +191,9 @@ void BubbleBox::doBox(int item, int box) {
}
// Get icons data
- byte *iconData = _vm->_files->loadFile("ICONS.LZ");
- SpriteResource *icons = new SpriteResource(_vm, iconData, _vm->_files->_filesize);
- delete[] iconData;
+ Resource *iconData = _vm->_files->loadFile("ICONS.LZ");
+ SpriteResource *icons = new SpriteResource(_vm, iconData);
+ delete iconData;
// Set the up boundaries and color to use for the box background
_vm->_screen->_orgX1 = _bounds.left - 2;
diff --git a/engines/access/char.cpp b/engines/access/char.cpp
index 09335fc017..767512f43e 100644
--- a/engines/access/char.cpp
+++ b/engines/access/char.cpp
@@ -121,15 +121,15 @@ void CharManager::loadChar(int charId) {
_vm->loadCells(ce._cells);
if (ce._animFile._fileNum != -1) {
- byte *data = _vm->_files->loadFile(ce._animFile);
- _vm->_animation->loadAnimations(data, _vm->_files->_filesize);
+ Resource *data = _vm->_files->loadFile(ce._animFile);
+ _vm->_animation->loadAnimations(data);
}
// Load script data
_vm->_scripts->freeScriptData();
if (ce._scriptFile._fileNum != -1) {
- const byte *data = _vm->_files->loadFile(ce._scriptFile);
- _vm->_scripts->setScript(data, _vm->_files->_filesize);
+ Resource *data = _vm->_files->loadFile(ce._scriptFile);
+ _vm->_scripts->setScript(data);
}
// Load extra cells
@@ -139,9 +139,9 @@ void CharManager::loadChar(int charId) {
}
void CharManager::charMenu() {
- byte *iconData = _vm->_files->loadFile("ICONS.LZ");
- SpriteResource *spr = new SpriteResource(_vm, iconData, _vm->_files->_filesize);
- delete[] iconData;
+ Resource *iconData = _vm->_files->loadFile("ICONS.LZ");
+ SpriteResource *spr = new SpriteResource(_vm, iconData);
+ delete iconData;
Screen &screen = *_vm->_screen;
screen.saveScreen();
diff --git a/engines/access/files.cpp b/engines/access/files.cpp
index b1d6140e3e..78cb3eff51 100644
--- a/engines/access/files.cpp
+++ b/engines/access/files.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "common/substream.h"
#include "access/files.h"
#include "access/amazon/amazon_resources.h"
#include "access/martian/martian_resources.h"
@@ -47,6 +48,27 @@ CellIdent::CellIdent(int cell, int fileNum, int subfile) {
/*------------------------------------------------------------------------*/
+Resource::Resource() {
+ _stream = nullptr;
+ _size = 0;
+}
+
+Resource::~Resource() {
+ delete _stream;
+}
+
+byte *Resource::data() {
+ if (_data == nullptr) {
+ _data = new byte[_size];
+ _stream->seek(0);
+ _stream->read(_data, _size);
+ }
+
+ return _data;
+}
+
+/*------------------------------------------------------------------------*/
+
FileManager::FileManager(AccessEngine *vm): _vm(vm) {
switch (vm->getGameID()) {
case GType_Amazon:
@@ -60,71 +82,70 @@ FileManager::FileManager(AccessEngine *vm): _vm(vm) {
}
_fileNumber = -1;
- _stream = nullptr;
}
FileManager::~FileManager() {
- delete _stream;
- _file.close();
}
-byte *FileManager::loadFile(int fileNum, int subfile) {
- setAppended(fileNum);
- gotoAppended(subfile);
+Resource *FileManager::loadFile(int fileNum, int subfile) {
+ Resource *res = new Resource();
+ setAppended(res, fileNum);
+ gotoAppended(res, subfile);
- return handleFile();
+ handleFile(res);
+ return res;
}
-byte *FileManager::loadFile(FileIdent &fileIdent) {
+Resource *FileManager::loadFile(FileIdent &fileIdent) {
return loadFile(fileIdent._fileNum, fileIdent._subfile);
}
-byte *FileManager::loadFile(const Common::String &filename) {
+Resource *FileManager::loadFile(const Common::String &filename) {
+ Resource *res = new Resource();
+
// Open the file
- openFile(filename);
+ openFile(res, filename);
- // Get a stream for the entire file
- delete _stream;
- _stream = _file.readStream(_file.size());
+ // Set up stream for the entire file
+ res->_size = res->_file.size();
+ res->_stream = res->_file.readStream(res->_size);
- return handleFile();
+ handleFile(res);
+ return res;
}
bool FileManager::existFile(const Common::String &filename) {
- return _file.exists(filename);
+ Common::File f;
+ return f.exists(filename);
}
-void FileManager::openFile(const Common::String &filename) {
+void FileManager::openFile(Resource *res, const Common::String &filename) {
// Open up the file
_fileNumber = -1;
- _file.close();
- if (!_file.open(filename))
+ if (!res->_file.open(filename))
error("Could not open file - %s", filename.c_str());
-
- _filesize = _file.size();
}
void FileManager::loadScreen(Graphics::Surface *dest, int fileNum, int subfile) {
- setAppended(fileNum);
- gotoAppended(subfile);
- _vm->_screen->loadPalette(_stream);
+ Resource *res = loadFile(fileNum, subfile);
+ handleScreen(dest, res);
+ delete res;
+}
- // Get the data for the screen, and copy it over
- byte *pSrc = handleFile();
+void FileManager::handleScreen(Graphics::Surface *dest, Resource *res) {
+ _vm->_screen->loadPalette(res->_stream);
if (dest != _vm->_screen)
dest->w = _vm->_screen->w;
if (dest->w == dest->pitch) {
- Common::copy(pSrc, pSrc + _filesize, (byte *)dest->getPixels());
+ res->_stream->read((byte *)dest->getPixels(), dest->w * dest->h);
} else {
- byte *pCurr = pSrc;
- for (int y = 0; y < dest->h; ++y, pCurr += dest->w) {
+ for (int y = 0; y < dest->h; ++y) {
byte *pDest = (byte *)dest->getBasePtr(0, y);
- Common::copy(pCurr, pCurr + dest->w, pDest);
+ res->_stream->read(pDest, dest->w);
}
}
- delete[] pSrc;
}
void FileManager::loadScreen(int fileNum, int subfile) {
@@ -132,69 +153,62 @@ void FileManager::loadScreen(int fileNum, int subfile) {
}
void FileManager::loadScreen(const Common::String &filename) {
- // Open the file
- openFile(filename);
-
- // Get the palette
- _vm->_screen->loadPalette(&_file);
-
- // Get a stream for the remainder of the file
- delete _stream;
- _stream = _file.readStream(_file.size() - _file.pos());
-
- // Get the data for the screen, and copy it over
- byte *pSrc = handleFile();
- Common::copy(pSrc, pSrc + _filesize, (byte *)_vm->_screen->getPixels());
- delete[] pSrc;
+ Resource *res = loadFile(filename);
+ handleScreen(_vm->_screen, res);
+ delete res;
}
-byte *FileManager::handleFile() {
+void FileManager::handleFile(Resource *res) {
char header[3];
- _stream->read(&header[0], 3);
- _stream->seek(-3, SEEK_CUR);
+ res->_stream->read(&header[0], 3);
+ res->_stream->seek(-3, SEEK_CUR);
bool isCompressed = !strncmp(header, "DBE", 3);
- // Get the data from the file or resource
- _filesize = _stream->size() - _stream->pos();
- byte *data = new byte[_filesize];
- _stream->read(data, _filesize);
-
- // If the data is compressed, uncompress it
+ // If the data is compressed, uncompress it and replace the stream
+ // in the resource with the decompressed one
if (isCompressed) {
- byte *src = data;
- _filesize = decompressDBE(src, &data);
+ // Read in the entire compressed data
+ byte *src = new byte[res->_size];
+ res->_stream->read(src, res->_size);
+
+ // Decompress the data
+ res->_size = decompressDBE(src, &res->_data);
+
+ // Replace the default resource stream with a stream for the decompressed data
+ delete res->_stream;
+ res->_file.close();
+ res->_stream = new Common::MemoryReadStream(res->_data, res->_size);
+
delete[] src;
}
-
- return data;
}
-void FileManager::setAppended(int fileNum) {
+void FileManager::setAppended(Resource *res, int fileNum) {
+ // Open the file for access
+ if (!res->_file.open(_filenames[fileNum]))
+ error("Could not open file %s", _filenames[fileNum]);
+
+ // If a different file has been opened then previously, load it's index
if (_fileNumber != fileNum) {
_fileNumber = fileNum;
-
- _file.close();
- if (!_file.open(_filenames[fileNum]))
- error("Could not open file %s", _filenames[fileNum]);
-
+
// Read in the file index
- int count = _file.readUint16LE();
+ int count = res->_file.readUint16LE();
assert(count <= 100);
_fileIndex.resize(count);
for (int i = 0; i < count; ++i)
- _fileIndex[i] = _file.readUint32LE();
+ _fileIndex[i] = res->_file.readUint32LE();
}
}
-void FileManager::gotoAppended(int subfile) {
+void FileManager::gotoAppended(Resource *res, int subfile) {
uint32 offset = _fileIndex[subfile];
- uint32 size = (subfile == (int)_fileIndex.size() - 1) ? _file.size() - offset :
+ uint32 size = (subfile == (int)_fileIndex.size() - 1) ? res->_file.size() - offset :
_fileIndex[subfile + 1] - offset;
- _file.seek(offset);
- delete _stream;
- _stream = _file.readStream(size);
+ res->_size = size;
+ res->_stream = new Common::SeekableSubReadStream(&res->_file, offset, offset + size);
}
} // End of namespace Access
diff --git a/engines/access/files.h b/engines/access/files.h
index b13a796925..457cb81f86 100644
--- a/engines/access/files.h
+++ b/engines/access/files.h
@@ -49,20 +49,51 @@ struct CellIdent : FileIdent {
CellIdent(int cell, int fileNum, int subfile);
};
+class FileManager;
+
+class Resource {
+ friend class FileManager;
+private:
+ Common::File _file;
+ byte *_data;
+public:
+ Common::SeekableReadStream *_stream;
+ int _size;
+
+ Resource();
+ ~Resource();
+ byte *data();
+};
+
class FileManager {
private:
AccessEngine *_vm;
const char * const *_filenames;
- void openFile(const Common::String &filename);
+ void openFile(Resource *res, const Common::String &filename);
+
+ /**
+ * Handles setting up the resource with a stream for the located resource
+ */
+ void handleFile(Resource *res);
+
+ /**
+ * Handles loading a screen surface and palette with decoded resource
+ */
+ void handleScreen(Graphics::Surface *dest, Resource *res);
+
+ /**
+ * Open up a sub-file container file
+ */
+ void setAppended(Resource *file, int fileNum);
- byte *handleFile();
+ /**
+ * Open up a sub-file resource within an alrady opened container file.
+ */
+ void gotoAppended(Resource *file, int subfile);
public:
int _fileNumber;
- Common::File _file;
- Common::SeekableReadStream *_stream;
Common::Array<uint32> _fileIndex;
- uint32 _filesize;
public:
FileManager(AccessEngine *vm);
~FileManager();
@@ -75,17 +106,17 @@ public:
/**
* Load a given subfile from a container file
*/
- byte *loadFile(int fileNum, int subfile);
+ Resource *loadFile(int fileNum, int subfile);
/**
* Loads a resource specified by a file identifier
*/
- byte *loadFile(FileIdent &fileIdent);
+ Resource *loadFile(FileIdent &fileIdent);
/**
* Load a given file by name
*/
- byte *loadFile(const Common::String &filename);
+ Resource *loadFile(const Common::String &filename);
/**
* Load a given scren from a container file
@@ -101,16 +132,6 @@ public:
* Load a screen resource onto a designated surface
*/
void loadScreen(Graphics::Surface *dest, int fileNum, int subfile);
-
- /**
- * Open up a sub-file container file
- */
- void setAppended(int fileNum);
-
- /**
- * Open up a sub-file resource within an alrady opened container file.
- */
- void gotoAppended(int subfile);
};
} // End of namespace Access
diff --git a/engines/access/martian/martian_game.cpp b/engines/access/martian/martian_game.cpp
index f087b56ac6..969267f719 100644
--- a/engines/access/martian/martian_game.cpp
+++ b/engines/access/martian/martian_game.cpp
@@ -106,9 +106,9 @@ void MartianEngine::doTitle() {
_screen->forceFadeIn();
_sound->playSound(1);
- byte *spriteData = _files->loadFile(0, 2);
- _objectsTable[0] = new SpriteResource(this, spriteData, _files->_filesize,
- DisposeAfterUse::YES);
+ Resource *spriteData = _files->loadFile(0, 2);
+ _objectsTable[0] = new SpriteResource(this, spriteData);
+ delete spriteData;
_sound->playSound(1);
diff --git a/engines/access/martian/martian_room.cpp b/engines/access/martian/martian_room.cpp
index 80eaf59fec..52eead7c0b 100644
--- a/engines/access/martian/martian_room.cpp
+++ b/engines/access/martian/martian_room.cpp
@@ -117,9 +117,9 @@ void MartianRoom::roomSet() {
}
void MartianRoom::roomMenu() {
- byte *iconData = _vm->_files->loadFile("ICONS.LZ");
- SpriteResource *spr = new SpriteResource(_vm, iconData, _vm->_files->_filesize);
- delete[] iconData;
+ Resource *iconData = _vm->_files->loadFile("ICONS.LZ");
+ SpriteResource *spr = new SpriteResource(_vm, iconData);
+ delete iconData;
_vm->_screen->saveScreen();
_vm->_screen->setDisplayScan();
diff --git a/engines/access/player.cpp b/engines/access/player.cpp
index 336be0d462..df2ad67826 100644
--- a/engines/access/player.cpp
+++ b/engines/access/player.cpp
@@ -157,9 +157,9 @@ void Player::load() {
void Player::loadSprites(const Common::String &name) {
freeSprites();
- const byte *data = _vm->_files->loadFile(name);
- _playerSprites1 = new SpriteResource(_vm, data, _vm->_files->_filesize,
- DisposeAfterUse::YES);
+ Resource *data = _vm->_files->loadFile(name);
+ _playerSprites1 = new SpriteResource(_vm, data);
+ delete data;
}
void Player::freeSprites() {
diff --git a/engines/access/room.cpp b/engines/access/room.cpp
index 10146ff6c3..0c60f7b818 100644
--- a/engines/access/room.cpp
+++ b/engines/access/room.cpp
@@ -175,7 +175,6 @@ void Room::loadRoomData(const byte *roomData) {
_vm->_sound->freeMusic();
if (roomInfo._musicFile._fileNum != -1) {
_vm->_sound->_music = _vm->_files->loadFile(roomInfo._musicFile);
- _vm->_sound->_midiSize = _vm->_files->_filesize;
_vm->_sound->midiPlay();
_vm->_sound->_musicRepeat = true;
}
@@ -199,15 +198,15 @@ void Room::loadRoomData(const byte *roomData) {
// Load script data
_vm->_scripts->freeScriptData();
if (roomInfo._scriptFile._fileNum != -1) {
- const byte *data = _vm->_files->loadFile(roomInfo._scriptFile);
- _vm->_scripts->setScript(data, _vm->_files->_filesize);
+ Resource *newScript = _vm->_files->loadFile(roomInfo._scriptFile);
+ _vm->_scripts->setScript(newScript);
}
// Load animation data
_vm->_animation->freeAnimationData();
if (roomInfo._animFile._fileNum != -1) {
- byte *data = _vm->_files->loadFile(roomInfo._animFile);
- _vm->_animation->loadAnimations(data, _vm->_files->_filesize);
+ Resource *anim = _vm->_files->loadFile(roomInfo._animFile);
+ _vm->_animation->loadAnimations(anim);
}
_vm->_scale = _vm->_scaleI = roomInfo._scaleI;
@@ -325,38 +324,39 @@ void Room::buildRow(int playY, int screenY) {
}
void Room::loadPlayField(int fileNum, int subfile) {
- byte *playData = _vm->_files->loadFile(fileNum, subfile);
- Common::MemoryReadStream stream(playData + 0x10, _vm->_files->_filesize - 0x10);
+ Resource *playData = _vm->_files->loadFile(fileNum, subfile);
+ byte header[16];
+ playData->_stream->read(&header[0], 16);
Screen &screen = *_vm->_screen;
// Copy the new palette
- screen.loadRawPalette(&stream);
+ screen.loadRawPalette(playData->_stream);
// Copy off the tile data
- _tileSize = playData[2] << 8;
+ _tileSize = (int)header[2] << 8;
_tile = new byte[_tileSize];
- stream.read(_tile, _tileSize);
+ playData->_stream->read(_tile, _tileSize);
// Copy off the playfield data
- _matrixSize = playData[0] * playData[1];
+ _matrixSize = header[0] * header[1];
_playField = new byte[_matrixSize];
- stream.read(_playField, _matrixSize);
+ playData->_stream->read(_playField, _matrixSize);
// Load the plotter data
int numWalls = READ_LE_UINT16(playData + 6);
- int numBlocks = playData[8];
- _plotter.load(&stream, numWalls, numBlocks);
+ int numBlocks = header[8];
+ _plotter.load(playData->_stream, numWalls, numBlocks);
- _playFieldWidth = playData[0];
- _playFieldHeight = playData[1];
- screen._vWindowWidth = playData[3];
+ _playFieldWidth = header[0];
+ _playFieldHeight = header[1];
+ screen._vWindowWidth = header[3];
screen._vWindowBytesWide = screen._vWindowWidth << 4;
screen._bufferBytesWide = screen._vWindowBytesWide + 16;
- screen._vWindowHeight = playData[4];
+ screen._vWindowHeight = header[4];
screen._vWindowLinesTall = screen._vWindowHeight << 4;
_vm->_screen->setBufferScan();
- delete[] playData;
+ delete playData;
}
/*------------------------------------------------------------------------*/
@@ -502,9 +502,9 @@ void Room::executeCommand(int commandId) {
_vm->_screen->setDisplayScan();
// Get the toolbar icons resource
- byte *iconData = _vm->_files->loadFile("ICONS.LZ");
- SpriteResource *spr = new SpriteResource(_vm, iconData, _vm->_files->_filesize);
- delete[] iconData;
+ Resource *iconData = _vm->_files->loadFile("ICONS.LZ");
+ SpriteResource *spr = new SpriteResource(_vm, iconData);
+ delete iconData;
// Draw the button as selected
_vm->_screen->plotImage(spr, _selectCommand + 2,
diff --git a/engines/access/screen.cpp b/engines/access/screen.cpp
index 4f2ee3e3ac..4b1c6d824d 100644
--- a/engines/access/screen.cpp
+++ b/engines/access/screen.cpp
@@ -104,9 +104,10 @@ void Screen::loadPalette(Common::SeekableReadStream *stream) {
}
void Screen::loadPalette(int fileNum, int subfile) {
- byte *palette = _vm->_files->loadFile(fileNum, subfile);
+ Resource *res = _vm->_files->loadFile(fileNum, subfile);
+ byte *palette = res->data();
Common::copy(palette, palette + (_numColors * 3), &_rawPalette[_startColor * 3]);
- delete[] palette;
+ delete res;
}
void Screen::setPalette() {
diff --git a/engines/access/scripts.cpp b/engines/access/scripts.cpp
index 833aff337a..5e0986e379 100644
--- a/engines/access/scripts.cpp
+++ b/engines/access/scripts.cpp
@@ -30,7 +30,7 @@
namespace Access {
Scripts::Scripts(AccessEngine *vm) : Manager(vm) {
- _rawData = nullptr;
+ _resource = nullptr;
_data = nullptr;
_sequence = 0;
_endFlag = false;
@@ -45,16 +45,15 @@ Scripts::~Scripts() {
freeScriptData();
}
-void Scripts::setScript(const byte *data, int size) {
- _rawData = data;
- _data = new Common::MemoryReadStream(data, size, DisposeAfterUse::NO);
+void Scripts::setScript(Resource *res) {
+ _resource = res;
+ _data = res->_stream;
}
void Scripts::freeScriptData() {
- delete[] _rawData;
- delete _data;
+ delete _resource;
+ _resource = nullptr;
_data = nullptr;
- _rawData = nullptr;
}
void Scripts::searchForSequence() {
@@ -418,13 +417,13 @@ void Scripts::cmdSetTravel() {
}
void Scripts::cmdSetVideo() {
- FileIdent fi;
- fi._fileNum = _data->readSint16LE();
- fi._subfile = _data->readUint16LE();
+ Common::Point pt;
+ pt.x = _data->readSint16LE();
+ pt.y = _data->readSint16LE();
int cellIndex = _data->readUint16LE();
int rate = _data->readUint16LE();
- _vm->_video->setVideo(_vm->_extraCells[cellIndex]._vid, fi, rate);
+ _vm->_video->setVideo(_vm->_screen, pt, _vm->_extraCells[cellIndex]._vid, rate);
}
void Scripts::CMDPLAYVID() { error("TODO CMDPLAYVID"); }
@@ -654,7 +653,7 @@ void Scripts::cmdClearBlock() {
void Scripts::cmdLoadSound() {
int idx = _data->readSint16LE();
- _vm->_sound->_soundTable[0]._data = _vm->_files->loadFile(_vm->_extraCells[idx]._vidSound);
+ _vm->_sound->_soundTable[0] = _vm->_files->loadFile(_vm->_extraCells[idx]._vidSound);
_vm->_sound->_soundPriority[0] = 1;
}
diff --git a/engines/access/scripts.h b/engines/access/scripts.h
index aa5c4063f6..ec386cf35a 100644
--- a/engines/access/scripts.h
+++ b/engines/access/scripts.h
@@ -34,11 +34,11 @@ class Scripts;
class Scripts: public Manager {
private:
- const byte *_rawData;
+ Resource *_resource;
int _specialFunction;
protected:
- Common::MemoryReadStream *_data;
+ Common::SeekableReadStream *_data;
virtual void executeSpecial(int commandIndex, int param1, int param2) = 0;
virtual void executeCommand(int commandIndex);
@@ -134,7 +134,7 @@ public:
virtual ~Scripts();
- void setScript(const byte *data, int size);
+ void setScript(Resource *data);
void freeScriptData();
diff --git a/engines/access/sound.cpp b/engines/access/sound.cpp
index aebd76fe84..c032f6cfd2 100644
--- a/engines/access/sound.cpp
+++ b/engines/access/sound.cpp
@@ -31,10 +31,9 @@ SoundManager::SoundManager(AccessEngine *vm, Audio::Mixer *mixer) :
_vm(vm), _mixer(mixer) {
Common::fill(&_soundPriority[0], &_soundPriority[MAX_SOUNDS], 0);
for (int i = 0; i < MAX_SOUNDS; ++i)
- _soundTable[i]._data = nullptr;
+ _soundTable[i] = nullptr;
_music = nullptr;
- _midiSize = 0;
_musicRepeat = false;
_soundFrame = 0;
_soundFlag = false;
@@ -42,7 +41,7 @@ SoundManager::SoundManager(AccessEngine *vm, Audio::Mixer *mixer) :
SoundManager::~SoundManager() {
for (int i = 0; i < MAX_SOUNDS; ++i)
- delete _soundTable[i]._data;
+ delete _soundTable[i];
}
void SoundManager::queueSound(int idx, int fileNum, int subfile) {
@@ -52,13 +51,13 @@ void SoundManager::queueSound(int idx, int fileNum, int subfile) {
*/
}
-byte *SoundManager::loadSound(int fileNum, int subfile) {
+Resource *SoundManager::loadSound(int fileNum, int subfile) {
return _vm->_files->loadFile(fileNum, subfile);
}
void SoundManager::playSound(int soundIndex) {
int idx = _soundPriority[soundIndex - 1] - 1;
- playSound(_soundTable[idx]._data, _soundTable[idx]._size);
+ playSound(_soundTable[idx]->data(), _soundTable[idx]->_size);
}
void SoundManager::playSound(byte *data, uint32 size) {
diff --git a/engines/access/sound.h b/engines/access/sound.h
index e0992db0e2..284fa845e7 100644
--- a/engines/access/sound.h
+++ b/engines/access/sound.h
@@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "audio/mixer.h"
+#include "access/files.h"
#define MAX_SOUNDS 20
@@ -33,10 +34,6 @@ namespace Access {
class AccessEngine;
class SoundManager {
- struct SoundEntry {
- byte *_data;
- uint32 _size;
- };
private:
AccessEngine *_vm;
Audio::Mixer *_mixer;
@@ -44,10 +41,9 @@ private:
void playSound(byte *data, uint32 size);
public:
- SoundEntry _soundTable[MAX_SOUNDS];
+ Resource *_soundTable[MAX_SOUNDS];
int _soundPriority[MAX_SOUNDS];
- byte *_music;
- int _midiSize;
+ Resource *_music;
bool _musicRepeat;
int _soundFrame;
bool _soundFlag;
@@ -59,7 +55,7 @@ public:
void playSound(int soundIndex);
- byte *loadSound(int fileNum, int subfile);
+ Resource *loadSound(int fileNum, int subfile);
void loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds);
void midiPlay();
diff --git a/engines/access/video.cpp b/engines/access/video.cpp
index a025d31022..4774703a03 100644
--- a/engines/access/video.cpp
+++ b/engines/access/video.cpp
@@ -21,15 +21,37 @@
*/
#include "access/video.h"
+#include "access/access.h"
namespace Access {
VideoPlayer::VideoPlayer(AccessEngine *vm) : Manager(vm) {
+ _vidSurface = nullptr;
+}
+VideoPlayer::~VideoPlayer() {
+ freeVideo();
}
-void VideoPlayer::setVideo(FileIdent &fi1, FileIdent &fi2, int rate) {
- error("TODO: setVideo");
+
+void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, FileIdent &videoFile, int rate) {
+ _vidSurface = vidSurface;
+ vidSurface->_orgX1 = pt.x;
+ vidSurface->_orgY1 = pt.y;
+ _vm->_timers[31]._timer = rate;
+ _vm->_timers[31]._initTm = rate;
+
+ // Open up video stream
+ _videoData = _vm->_files->loadFile(videoFile);
+
+ // Load in header
+
}
+void VideoPlayer::freeVideo() {
+ delete _videoData;
+ _videoData = nullptr;
+}
+
+
} // End of namespace Access
diff --git a/engines/access/video.h b/engines/access/video.h
index b21f006a97..a87c90ccb8 100644
--- a/engines/access/video.h
+++ b/engines/access/video.h
@@ -24,16 +24,27 @@
#define ACCESS_VIDEO_H
#include "common/scummsys.h"
+#include "common/memstream.h"
#include "access/data.h"
+#include "access/asurface.h"
#include "access/files.h"
namespace Access {
class VideoPlayer: public Manager {
+private:
+ ASurface *_vidSurface;
+ Resource *_videoData;
+ int _frameCount;
+ int _width, _height;
+ int _flags;
public:
VideoPlayer(AccessEngine *vm);
+ ~VideoPlayer();
- void setVideo(FileIdent &fi1, FileIdent &fi2, int rate);
+ void setVideo(ASurface *vidSurface, const Common::Point &pt, FileIdent &videoFile, int rate);
+
+ void freeVideo();
};
} // End of namespace Access