mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 13:50:13 +00:00
- Implemented the SAGA2 resource loader
- Some cleanup svn-id: r35536
This commit is contained in:
parent
e27110d3cc
commit
c8ca4d59bc
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -118,33 +118,32 @@ SagaEngine::~SagaEngine() {
|
||||
}
|
||||
}
|
||||
|
||||
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 _scene;
|
||||
|
||||
if (getGameId() == GID_ITE) {
|
||||
delete _isoMap;
|
||||
delete _puzzle;
|
||||
}
|
||||
|
||||
delete _sndRes;
|
||||
delete _events;
|
||||
|
||||
if (!isSaga2()) {
|
||||
delete _font;
|
||||
delete _sprite;
|
||||
}
|
||||
|
||||
delete _anim;
|
||||
delete _script;
|
||||
if (!isSaga2())
|
||||
delete _interface;
|
||||
delete _actor;
|
||||
delete _palanim;
|
||||
delete _scene;
|
||||
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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user