Skip to content

Commit

Permalink
ACCESS: Refactor the file manager to return resource structures
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 28, 2014
1 parent 455011c commit c0a7852
Show file tree
Hide file tree
Showing 23 changed files with 307 additions and 248 deletions.
17 changes: 9 additions & 8 deletions engines/access/access.cpp
Expand Up @@ -70,6 +70,7 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc)
_scaleMaxY = 0;
_scaleI = 0;
_scaleFlag = false;
_eseg = nullptr;

_conversation = 0;
_currentMan = 0;
Expand Down Expand Up @@ -124,9 +125,9 @@ AccessEngine::~AccessEngine() {
delete _video;

freeCells();
delete[] _inactive;
delete[] _music;
delete[] _title;
delete _inactive;
delete _music;
delete _title;
}

void AccessEngine::setVGA() {
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions engines/access/access.h
Expand Up @@ -148,9 +148,9 @@ class AccessEngine : public Engine {
int _mouseMode;

int _currentManOld;
byte *_inactive;
byte *_music;
byte *_title;
Resource *_inactive;
Resource *_music;
Resource *_title;
int _converseMode;
int _startAboutBox;
int _startTravelBox;
Expand All @@ -164,7 +164,7 @@ class AccessEngine : public Engine {
int _scaleI;
bool _scaleFlag;

byte *_eseg;
Resource *_eseg;
int _et;
int _printEnd;
int _txtPages;
Expand Down
15 changes: 8 additions & 7 deletions engines/access/amazon/amazon_game.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -300,20 +300,21 @@ 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) {
for (_tilePos.x = 0; _tilePos.x < 640; _tilePos.x += x)
warning("TODO: DRAWOBJECT");
}

delete res;
}

void AmazonEngine::updateSummary(int chap) {
Expand Down
6 changes: 3 additions & 3 deletions engines/access/amazon/amazon_room.cpp
Expand Up @@ -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();
Expand Down
77 changes: 38 additions & 39 deletions engines/access/animation.cpp
Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}

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

/*------------------------------------------------------------------------*/
Expand All @@ -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);
}


Expand Down
11 changes: 6 additions & 5 deletions engines/access/animation.h
Expand Up @@ -27,6 +27,7 @@
#include "common/array.h"
#include "common/memstream.h"
#include "access/data.h"
#include "access/files.h"

namespace Access {

Expand All @@ -47,7 +48,7 @@ class AnimationManager : public Manager {
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);
Expand All @@ -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(); }
Expand Down Expand Up @@ -107,7 +108,7 @@ class Animation: public Manager {
int _currentLoopCount;
int _field10;
public:
Animation(AccessEngine *vm, Common::MemoryReadStream &stream);
Animation(AccessEngine *vm, Common::SeekableReadStream *stream);
~Animation();

void animate();
Expand All @@ -119,7 +120,7 @@ class AnimationFrame {
int _frameDelay;
Common::Array<AnimationFramePart *> _parts;
public:
AnimationFrame(Common::MemoryReadStream &stream, int startOffset);
AnimationFrame(Common::SeekableReadStream *stream, int startOffset);
~AnimationFrame();
};

Expand All @@ -131,7 +132,7 @@ class AnimationFramePart {
Common::Point _position;
int _offsetY;
public:
AnimationFramePart(Common::MemoryReadStream &stream);
AnimationFramePart(Common::SeekableReadStream *stream);
};

} // End of namespace Access
Expand Down
29 changes: 12 additions & 17 deletions engines/access/asurface.cpp
Expand Up @@ -28,37 +28,32 @@

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() {
for (uint i = 0; i < _frames.size(); ++i)
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
Expand All @@ -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);
}
}

Expand Down
5 changes: 2 additions & 3 deletions engines/access/asurface.h
Expand Up @@ -115,16 +115,15 @@ class ASurface : public Graphics::Surface {

class SpriteFrame : public ASurface {
public:
SpriteFrame(AccessEngine *vm, Common::MemoryReadStream &stream, int frameSize);
SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, int frameSize);
~SpriteFrame();
};

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

0 comments on commit c0a7852

Please sign in to comment.