diff options
author | Filippos Karapetis | 2008-12-25 12:09:24 +0000 |
---|---|---|
committer | Filippos Karapetis | 2008-12-25 12:09:24 +0000 |
commit | c8ca4d59bc5caedbef9e1a869940028e2459fa83 (patch) | |
tree | e973e977a927032a71dd4bf84590d6646a71d2a8 | |
parent | e27110d3cc17af704d54274c1d504edbc7cc6090 (diff) | |
download | scummvm-rg350-c8ca4d59bc5caedbef9e1a869940028e2459fa83.tar.gz scummvm-rg350-c8ca4d59bc5caedbef9e1a869940028e2459fa83.tar.bz2 scummvm-rg350-c8ca4d59bc5caedbef9e1a869940028e2459fa83.zip |
- Implemented the SAGA2 resource loader
- Some cleanup
svn-id: r35536
-rw-r--r-- | engines/saga/resource.cpp | 4 | ||||
-rw-r--r-- | engines/saga/resource.h | 1 | ||||
-rw-r--r-- | engines/saga/resource_hrs.cpp | 48 | ||||
-rw-r--r-- | engines/saga/saga.cpp | 46 | ||||
-rw-r--r-- | engines/saga/script.cpp | 3 |
5 files changed, 65 insertions, 37 deletions
diff --git a/engines/saga/resource.cpp b/engines/saga/resource.cpp index 4176488117..ef5fa19ec1 100644 --- a/engines/saga/resource.cpp +++ b/engines/saga/resource.cpp @@ -483,6 +483,10 @@ void Resource::clearContexts() { delete context->table[j].patchData; } } + if (_vm->isSaga2()) { + free(context->base); + free(context->groups); + } free(context->table); } free(_contexts); diff --git a/engines/saga/resource.h b/engines/saga/resource.h index 943bbd95ef..6067e0bd74 100644 --- a/engines/saga/resource.h +++ b/engines/saga/resource.h @@ -85,6 +85,7 @@ struct ResourceContext { ResourceData *table; size_t count; uint32 firstGroupOffset; // SAGA2 + ResourceData *base; // SAGA2 ResourceData *groups; // SAGA2 Common::File *getFile(ResourceData *resourceData) const { diff --git a/engines/saga/resource_hrs.cpp b/engines/saga/resource_hrs.cpp index f1b7e6c4fe..c1e6e6e6ba 100644 --- a/engines/saga/resource_hrs.cpp +++ b/engines/saga/resource_hrs.cpp @@ -41,31 +41,59 @@ namespace Saga { bool Resource_HRS::loadResContext_v2(ResourceContext *context, uint32 contextSize) { - ResourceData *resourceData = new ResourceData(); + ResourceData *origin = new ResourceData(); uint32 firstGroupOffset; - //const int resDataSize = 4 + 4 + 4; + uint32 size; + int i, count; context->file->seek(0, SEEK_SET); // Read head element (origin) - resourceData->id = context->file->readUint32BE(); - resourceData->offset = context->file->readUint32LE(); - resourceData->size = context->file->readUint32LE(); + origin->id = context->file->readUint32BE(); // this is BE on purpose + origin->offset = context->file->readUint32LE(); + origin->size = context->file->readUint32LE(); // Check if the file is valid - if (resourceData->id != MKID_BE('HRES')) { // header - free(resourceData); + if (origin->id != MKID_BE('HRES')) { // header + free(origin); return false; } // Read first group offset - context->file->seek(resourceData->offset - 4, SEEK_SET); + context->file->seek(origin->offset - sizeof(uint32), SEEK_SET); firstGroupOffset = context->file->readUint32LE(); // Allocate buffers for root/base node, groups and data - // TODO + context->base = (ResourceData *) calloc(origin->size, sizeof(*context->base)); + size = origin->offset - firstGroupOffset - sizeof(uint32); + context->groups = (ResourceData *) calloc(size / sizeof(*context->groups), sizeof(*context->groups)); - free(resourceData); + if (context->base == NULL || context->groups == NULL) { + free(origin); + return false; + } + + // Read base + count = origin->size / sizeof(*context->base); + for (i = 0; i < count; i++) { + context->base[i].id = context->file->readUint32LE(); + context->base[i].offset = context->file->readUint32LE(); + context->base[i].size = context->file->readUint32LE(); + } + + context->file->seek(firstGroupOffset, SEEK_SET); + + // Read groups + count = size / sizeof(*context->groups); + for (i = 0; i < count; i++) { + context->groups[i].id = context->file->readUint32LE(); + context->groups[i].offset = context->file->readUint32LE(); + context->groups[i].size = context->file->readUint32LE(); + } + + context->count = origin->size / sizeof(*origin); + + free(origin); return true; } diff --git a/engines/saga/saga.cpp b/engines/saga/saga.cpp index 083bb348da..ae708fd2cf 100644 --- a/engines/saga/saga.cpp +++ b/engines/saga/saga.cpp @@ -118,33 +118,32 @@ SagaEngine::~SagaEngine() { } } + if (getGameId() == GID_ITE) { + delete _isoMap; + delete _puzzle; + } + + delete _sndRes; + delete _events; + if (!isSaga2()) { - if (getGameId() == GID_ITE) - delete _puzzle; - delete _sndRes; - delete _events; delete _font; delete _sprite; - delete _anim; - delete _script; - delete _interface; - delete _actor; - delete _palanim; } + delete _anim; + delete _script; + if (!isSaga2()) + delete _interface; + delete _actor; + delete _palanim; delete _scene; - - if (getGameId() == GID_ITE) { - delete _isoMap; - } - delete _render; delete _music; delete _sound; delete _driver; delete _gfx; delete _console; - delete _resource; } @@ -185,29 +184,24 @@ Common::Error SagaEngine::init() { // Initialize engine modules // TODO: implement differences for SAGA2 - if (!isSaga2()) { - _sndRes = new SndRes(this); - } - + _sndRes = new SndRes(this); _events = new Events(this); if (!isSaga2()) { _font = new Font(this); _sprite = new Sprite(this); - _anim = new Anim(this); } + _anim = new Anim(this); _script = new Script(this); _interface = new Interface(this); // requires script module _scene = new Scene(this); _actor = new Actor(this); + _palanim = new PalAnim(this); - if (!isSaga2()) { - _palanim = new PalAnim(this); - if (getGameId() == GID_ITE) { - _isoMap = new IsoMap(this); - _puzzle = new Puzzle(this); - } + if (getGameId() == GID_ITE) { + _isoMap = new IsoMap(this); + _puzzle = new Puzzle(this); } // System initialization diff --git a/engines/saga/script.cpp b/engines/saga/script.cpp index bf2ddb905a..f53aa3d663 100644 --- a/engines/saga/script.cpp +++ b/engines/saga/script.cpp @@ -158,7 +158,8 @@ Script::~Script() { _globalVoiceLUT.freeMem(); freeModules(); - free(_modules); + if (!_vm->isSaga2()) // TODO: remove this once the script module is working for SAGA2 + free(_modules); free(_commonBuffer); } |