ACCESS: Refactor the file manager to return resource structures

This commit is contained in:
Paul Gilbert 2014-08-27 22:13:43 -04:00
parent 455011c37e
commit c0a7852662
23 changed files with 307 additions and 248 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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) {

View File

@ -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();

View File

@ -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();
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
_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);
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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(); }

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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);
byte *handleFile();
/**
* 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);
/**
* 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

View File

@ -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);

View File

@ -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();

View File

@ -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() {

View File

@ -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,

View File

@ -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() {

View File

@ -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;
}

View File

@ -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();

View File

@ -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) {

View File

@ -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();

View File

@ -21,15 +21,37 @@
*/
#include "access/video.h"
#include "access/access.h"
namespace Access {
VideoPlayer::VideoPlayer(AccessEngine *vm) : Manager(vm) {
_vidSurface = nullptr;
}
void VideoPlayer::setVideo(FileIdent &fi1, FileIdent &fi2, int rate) {
error("TODO: setVideo");
VideoPlayer::~VideoPlayer() {
freeVideo();
}
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

View File

@ -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