ILLUSIONS: Add GAM archive reader for Duckman and adjust the resource reader/system

This commit is contained in:
johndoe123 2015-11-18 16:25:42 +01:00 committed by Eugene Sandulenko
parent a5ad1bc106
commit 41978f466d
30 changed files with 482 additions and 79 deletions

View File

@ -947,7 +947,7 @@ void Control::startSequenceActorIntern(uint32 sequenceId, int value, byte *entry
Sequence *sequence = _vm->_dict->findSequence(sequenceId);
if (!sequence && _vm->getGameId() == kGameIdDuckman) {
debug("Load external sequence...");
debug(1, "Load external sequence...");
_vm->_resSys->loadResource(0x00060000 | (sequenceId & 0xFFFF), _vm->getCurrentScene(), 0);
sequence = _vm->_dict->findSequence(sequenceId);
_actor->_flags |= 0x800;
@ -1378,7 +1378,7 @@ void Controls::actorControlRoutine(Control *control, uint32 deltaTime) {
int savedSeqCodeValue1 = actor->_seqCodeValue1;
int savedSeqCodeValue3 = actor->_seqCodeValue3;
uint32 regionSequenceId = actor->_regionLayer->getRegionSequenceId(regionIndex);
debug("Running transition sequence %08X", regionSequenceId);
debug(1, "Running transition sequence %08X", regionSequenceId);
Sequence *sequence = _vm->_dict->findSequence(regionSequenceId);
actor->_sequenceId = regionSequenceId;
actor->_seqCodeIp = sequence->_sequenceCode;

View File

@ -25,6 +25,7 @@
#include "illusions/camera.h"
#include "illusions/cursor.h"
#include "illusions/dictionary.h"
#include "illusions/fileresourcereader.h"
#include "illusions/graphics.h"
#include "illusions/input.h"
#include "illusions/resources/actorresource.h"
@ -138,6 +139,8 @@ Common::Error IllusionsEngine_BBDOU::run() {
_dict = new Dictionary();
_resReader = new ResourceReaderFileReader();
_resSys = new ResourceSystem(this);
_resSys->addResourceLoader(0x00060000, new ActorResourceLoader(this));
_resSys->addResourceLoader(0x00080000, new SoundGroupResourceLoader(this));
@ -216,6 +219,7 @@ Common::Error IllusionsEngine_BBDOU::run() {
delete _screenText;
delete _screen;
delete _resSys;
delete _resReader;
delete _dict;
debug("Ok");

View File

@ -28,11 +28,12 @@
#include "illusions/camera.h"
#include "illusions/cursor.h"
#include "illusions/dictionary.h"
#include "illusions/resources/fontresource.h"
#include "illusions/gamresourcereader.h"
#include "illusions/graphics.h"
#include "illusions/input.h"
#include "illusions/resources/actorresource.h"
#include "illusions/resources/backgroundresource.h"
#include "illusions/resources/fontresource.h"
#include "illusions/resources/midiresource.h"
#include "illusions/resources/scriptresource.h"
#include "illusions/resources/soundresource.h"
@ -83,9 +84,10 @@ Common::Error IllusionsEngine_Duckman::run() {
SearchMan.addSubDirectoryMatching(gameDataDir, "sfx", 0, 2);
SearchMan.addSubDirectoryMatching(gameDataDir, "video");
SearchMan.addSubDirectoryMatching(gameDataDir, "voice");
SearchMan.addSubDirectoryMatching(gameDataDir, "x");// DEBUG until gam reader is done
_dict = new Dictionary();
_resReader = new ResourceReaderGamArchive("duckman.gam");
_resSys = new ResourceSystem(this);
_resSys->addResourceLoader(0x00060000, new ActorResourceLoader(this));
@ -115,7 +117,7 @@ Common::Error IllusionsEngine_Duckman::run() {
_screen->setColorKey1(0);
initInput();
initInput();
initUpdateFunctions();
@ -190,6 +192,7 @@ Common::Error IllusionsEngine_Duckman::run() {
delete _screenText;
delete _screen;
delete _resSys;
delete _resReader;
delete _dict;
debug("Ok");
@ -388,7 +391,7 @@ Common::Point IllusionsEngine_Duckman::getNamedPointPosition(uint32 namedPointId
}
} else {
// TODO
debug("getNamedPointPosition(%08X) UNKNOWN", namedPointId);
debug(1, "getNamedPointPosition(%08X) UNKNOWN", namedPointId);
return Common::Point(0, 0);
}
}
@ -1005,7 +1008,7 @@ bool IllusionsEngine_Duckman::getTriggerCause(uint32 verbId, uint32 objectId2, u
uint32 IllusionsEngine_Duckman::runTriggerCause(uint32 verbId, uint32 objectId2, uint32 objectId) {
// TODO
debug("runTriggerCause(%08X, %08X, %08X)", verbId, objectId2, objectId);
debug(1, "runTriggerCause(%08X, %08X, %08X)", verbId, objectId2, objectId);
uint32 triggerThreadId;
if (!getTriggerCause(verbId, objectId2, objectId, triggerThreadId))
@ -1048,7 +1051,7 @@ uint32 IllusionsEngine_Duckman::runTriggerCause(uint32 verbId, uint32 objectId2,
}
uint32 tempThreadId = newTempThreadId();
debug("Starting cause thread %08X with triggerThreadId %08X", tempThreadId, triggerThreadId);
debug(1, "Starting cause thread %08X with triggerThreadId %08X", tempThreadId, triggerThreadId);
CauseThread_Duckman *causeThread = new CauseThread_Duckman(this, tempThreadId, 0, 0,
triggerThreadId);
_threads->startThread(causeThread);

View File

@ -272,7 +272,7 @@ void ScriptOpcodes_Duckman::opChangeScene(ScriptThread *scriptThread, OpCall &op
ARG_UINT32(threadId);
_vm->_input->discardAllEvents();
debug("changeScene(%08X, %08X)", sceneId, threadId);
debug(1, "changeScene(%08X, %08X)", sceneId, threadId);
//DEBUG
if (dsceneId) {
@ -555,9 +555,7 @@ void ScriptOpcodes_Duckman::opPlayVideo(ScriptThread *scriptThread, OpCall &opCa
void ScriptOpcodes_Duckman::opRunSpecialCode(ScriptThread *scriptThread, OpCall &opCall) {
ARG_SKIP(2);
ARG_UINT32(specialCodeId);
debug("run(%08X)", specialCodeId);
_vm->_specialCode->run(specialCodeId, opCall);
debug("run(%08X) OK", specialCodeId);
}
void ScriptOpcodes_Duckman::opStartSound(ScriptThread *scriptThread, OpCall &opCall) {

View File

@ -0,0 +1,79 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "illusions/resourcesystem.h"
#include "illusions/fileresourcereader.h"
#include "illusions/illusions.h"
#include "common/file.h"
#include "common/str.h"
namespace Illusions {
byte *ResourceReaderFileReader::readResource(uint32 sceneId, uint32 resId, uint32 &dataSize) {
debug("ResourceReaderFileReader::readResource(%08X, %08X)", sceneId, resId);
Common::String filename = buildResourceFilename(resId);
Common::File fd;
if (!fd.open(filename))
error("Resource::loadData() Could not open %s for reading", filename.c_str());
dataSize = fd.size();
byte *data = (byte*)malloc(dataSize);
fd.read(data, dataSize);
return data;
}
Common::String ResourceReaderFileReader::buildResourceFilename(uint32 resId) {
const char *ext = getResourceExtension(resId);
return Common::String::format("%08X%s", resId, ext);
}
const char *ResourceReaderFileReader::getResourceExtension(uint32 resId) {
// TODO Make constants
switch (ResourceTypeId(resId)) {
case 0x00060000:
case 0x00100000:
// ActorResource
return ".act";
case 0x00080000:
// SoundGroupResource
return ".sg";
case 0x000D0000:
// ScriptResource
return ".scr";
case 0x000F0000:
// TalkResource
return ".tlk";
case 0x00110000:
// BackgroundResource
return ".bg";
case 0x00120000:
// FontResource
return ".fnt";
case 0x00170000:
// SpecialCode
return "";
default:
return "";
}
}
} // End of namespace Illusions

View File

@ -0,0 +1,41 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ILLUSIONS_FILERESOURCEREADER_H
#define ILLUSIONS_FILERESOURCEREADER_H
#include "illusions/illusions.h"
#include "illusions/resourcereader.h"
namespace Illusions {
class ResourceReaderFileReader : public BaseResourceReader {
public:
byte *readResource(uint32 sceneId, uint32 resId, uint32 &dataSize);
protected:
Common::String buildResourceFilename(uint32 resId);
const char *getResourceExtension(uint32 resId);
};
} // End of namespace Illusions
#endif // ILLUSIONS_FILERESOURCEREADER_H

View File

@ -0,0 +1,101 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "illusions/gamarchive.h"
namespace Illusions {
GamArchive::GamArchive(const char *filename)
: _fd(0), _groupCount(0), _groups(0) {
_fd = new Common::File();
if (!_fd->open(filename))
error("GamArchive::GamArchive() Could not open %s", filename);
loadDictionary();
}
GamArchive::~GamArchive() {
delete[] _groups;
}
byte *GamArchive::readResource(uint32 sceneId, uint32 resId, uint32 &dataSize) {
const GamFileEntry *fileEntry = getGroupFileEntry(sceneId, resId);
_fd->seek(fileEntry->_fileOffset);
dataSize = fileEntry->_fileSize;
byte *data = (byte*)malloc(dataSize);
_fd->read(data, dataSize);
return data;
}
void GamArchive::loadDictionary() {
_groupCount = _fd->readUint32LE();
_groups = new GamGroupEntry[_groupCount];
uint32 *groupOffsets = new uint32[_groupCount];
for (uint i = 0; i < _groupCount; ++i) {
_groups[i]._id = _fd->readUint32LE();
groupOffsets[i] = _fd->readUint32LE();
}
for (uint i = 0; i < _groupCount; ++i) {
_fd->seek(groupOffsets[i]);
uint32 fileCount = _fd->readUint32LE();
_groups[i]._fileCount = fileCount;
_groups[i]._files = new GamFileEntry[fileCount];
debug("Group %08X, fileCount: %d", _groups[i]._id, _groups[i]._fileCount);
for (uint j = 0; j < fileCount; ++j) {
_groups[i]._files[j]._id = _fd->readUint32LE();
_groups[i]._files[j]._fileOffset = _fd->readUint32LE();
_groups[i]._files[j]._fileSize = _fd->readUint32LE();
debug(" %08X, %08X, %d", _groups[i]._files[j]._id, _groups[i]._files[j]._fileOffset, _groups[i]._files[j]._fileSize);
}
}
delete[] groupOffsets;
}
const GamGroupEntry *GamArchive::getGroupEntry(uint32 sceneId) {
for (uint i = 0; i < _groupCount; ++i)
if (_groups[i]._id == sceneId)
return &_groups[i];
return 0;
}
const GamFileEntry *GamArchive::getFileEntry(const GamGroupEntry *groupEntry, uint32 resId) {
for (uint i = 0; i < groupEntry->_fileCount; ++i)
if (groupEntry->_files[i]._id == resId)
return &groupEntry->_files[i];
return 0;
}
const GamFileEntry *GamArchive::getGroupFileEntry(uint32 sceneId, uint32 resId) {
const GamGroupEntry *groupEntry = getGroupEntry(sceneId);
if (!groupEntry)
error("GamArchive::getFileEntry() Group %08X not found", sceneId);
const GamFileEntry *fileEntry = getFileEntry(groupEntry, resId);
if (!fileEntry)
error("GamArchive::getFileEntry() File %08X in group %08X not found", resId, sceneId);
return fileEntry;
}
} // End of namespace Illusions

View File

@ -0,0 +1,65 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ILLUSIONS_GAMARCHIVE_H
#define ILLUSIONS_GAMARCHIVE_H
#include "illusions/illusions.h"
#include "common/file.h"
namespace Illusions {
struct GamFileEntry {
uint32 _id;
uint32 _fileOffset;
uint32 _fileSize;
};
struct GamGroupEntry {
uint32 _id;
uint _fileCount;
GamFileEntry *_files;
GamGroupEntry() : _fileCount(0), _files(0) {
}
~GamGroupEntry() {
delete[] _files;
}
};
class GamArchive {
public:
GamArchive(const char *filename);
~GamArchive();
byte *readResource(uint32 sceneId, uint32 resId, uint32 &dataSize);
protected:
Common::File *_fd;
uint _groupCount;
GamGroupEntry *_groups;
void loadDictionary();
const GamGroupEntry *getGroupEntry(uint32 sceneId);
const GamFileEntry *getFileEntry(const GamGroupEntry *groupEntry, uint32 resId);
const GamFileEntry *getGroupFileEntry(uint32 sceneId, uint32 resId);
};
} // End of namespace Illusions
#endif // ILLUSIONS_GAMARCHIVE_H

View File

@ -0,0 +1,44 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "illusions/resourcesystem.h"
#include "illusions/resourcereader_gamarchive.h"
#include "illusions/gamarchive.h"
#include "illusions/illusions.h"
#include "common/file.h"
#include "common/str.h"
namespace Illusions {
ResourceReaderGamArchive::ResourceReaderGamArchive(const char *filename) {
_gamArchive = new GamArchive(filename);
}
ResourceReaderGamArchive::~ResourceReaderGamArchive() {
delete _gamArchive;
}
byte *ResourceReaderGamArchive::readResource(uint32 sceneId, uint32 resId, uint32 &dataSize) {
return _gamArchive->readResource(sceneId, resId, dataSize);
}
} // End of namespace Illusions

View File

@ -0,0 +1,44 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ILLUSIONS_RESOURCEREADER_GAMARCHIVE_H
#define ILLUSIONS_RESOURCEREADER_GAMARCHIVE_H
#include "illusions/illusions.h"
#include "illusions/resourcereader.h"
namespace Illusions {
class GamArchive;
class ResourceReaderGamArchive : public BaseResourceReader {
public:
ResourceReaderGamArchive(const char *filename);
~ResourceReaderGamArchive();
byte *readResource(uint32 sceneId, uint32 resId, uint32 &dataSize);
protected:
GamArchive *_gamArchive;
};
} // End of namespace Illusions
#endif // ILLUSIONS_RESOURCEREADER_GAMARCHIVE_H

View File

@ -47,6 +47,7 @@ namespace Illusions {
#define ILLUSIONS_SAVEGAME_VERSION 0
class ResourceSystem;
class BaseResourceReader;
struct SurfInfo;
@ -99,6 +100,7 @@ public:
Common::RandomSource *_random;
Dictionary *_dict;
ResourceSystem *_resSys;
BaseResourceReader *_resReader;
UpdateFunctions *_updateFunctions;
void updateEvents();

View File

@ -20,7 +20,10 @@ MODULE_OBJS := \
duckman/illusions_duckman.o \
duckman/propertytimers.o \
duckman/scriptopcodes_duckman.o \
fileresourcereader.o \
fixedpoint.o \
gamarchive.o \
gamresourcereader.o \
graphics.o \
illusions.o \
input.o \

View File

@ -0,0 +1,28 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "illusions/resourcereader.h"
#include "illusions/illusions.h"
namespace Illusions {
} // End of namespace Illusions

View File

@ -0,0 +1,38 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ILLUSIONS_RESOURCEREADER_H
#define ILLUSIONS_RESOURCEREADER_H
#include "illusions/illusions.h"
namespace Illusions {
class BaseResourceReader {
public:
virtual ~BaseResourceReader() {}
virtual byte *readResource(uint32 sceneId, uint32 resId, uint32 &dataSize) = 0;
};
} // End of namespace Illusions
#endif // ILLUSIONS_RESOURCEREADER_H

View File

@ -32,10 +32,6 @@ void ActorResourceLoader::load(Resource *resource) {
resource->_instance = _vm->_actorInstances->createActorInstance(resource);
}
void ActorResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.act", resource->_resId);
}
bool ActorResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile;
@ -161,7 +157,7 @@ void ActorResource::load(Resource *resource) {
_namedPoints.load(namedPointsCount, stream);
}
debug("ActorResource(%08X) framesCount: %d", resource->_resId, framesCount);
debug(1, "ActorResource(%08X) framesCount: %d", resource->_resId, framesCount);
}
bool ActorResource::containsSequence(Sequence *sequence) {

View File

@ -36,7 +36,6 @@ public:
ActorResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~ActorResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -37,10 +37,6 @@ void BackgroundResourceLoader::load(Resource *resource) {
resource->_instance = _vm->_backgroundInstances->createBackgroundInstance(resource);
}
void BackgroundResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.bg", resource->_resId);
}
bool BackgroundResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile;
@ -131,7 +127,7 @@ void RegionLayer::load(byte *dataStart, Common::SeekableReadStream &stream) {
_mapWidth = READ_LE_UINT16(_map + 0);
_mapHeight = READ_LE_UINT16(_map + 2);
_map += 8;
debug("RegionLayer::load() %d; regionSequenceIdsOffs: %08X; _width: %d; _height: %d; mapOffs: %08X; valuesOffs: %08X",
debug(1, "RegionLayer::load() %d; regionSequenceIdsOffs: %08X; _width: %d; _height: %d; mapOffs: %08X; valuesOffs: %08X",
_unk, regionSequenceIdsOffs, _width, _height, mapOffs, valuesOffs);
}
@ -248,7 +244,7 @@ void BackgroundResource::load(byte *data, uint32 dataSize) {
_priorityLayers = new PriorityLayer[_priorityLayersCount];
stream.seek(0x34);
uint32 priorityLayersOffs = stream.readUint32LE();
debug("_priorityLayersCount: %d", _priorityLayersCount);
debug(1, "_priorityLayersCount: %d", _priorityLayersCount);
for (uint i = 0; i < _priorityLayersCount; ++i) {
stream.seek(priorityLayersOffs + i * 12);
_priorityLayers[i].load(data, stream);
@ -260,7 +256,7 @@ void BackgroundResource::load(byte *data, uint32 dataSize) {
_regionLayers = new RegionLayer[_regionLayersCount];
stream.seek(0x38);
uint32 regionLayersOffs = stream.readUint32LE();
debug("_regionLayersCount: %d", _regionLayersCount);
debug(1, "_regionLayersCount: %d", _regionLayersCount);
for (uint i = 0; i < _regionLayersCount; ++i) {
stream.seek(regionLayersOffs + i * 20);
_regionLayers[i].load(data, stream);
@ -291,7 +287,7 @@ void BackgroundResource::load(byte *data, uint32 dataSize) {
// Load path walk points
stream.seek(0x0E);
_pathWalkPointsCount = stream.readUint16LE();
debug("_pathWalkPointsCount: %d", _pathWalkPointsCount);
debug(1, "_pathWalkPointsCount: %d", _pathWalkPointsCount);
_pathWalkPoints = new PathWalkPoints[_pathWalkPointsCount];
stream.seek(0x28);
uint32 pathWalkPointsOffs = stream.readUint32LE();
@ -303,7 +299,7 @@ void BackgroundResource::load(byte *data, uint32 dataSize) {
// Load path walk rects
stream.seek(0x12);
_pathWalkRectsCount = stream.readUint16LE();
debug("_pathWalkRectsCount: %d", _pathWalkRectsCount);
debug(1, "_pathWalkRectsCount: %d", _pathWalkRectsCount);
_pathWalkRects = new PathWalkRects[_pathWalkRectsCount];
stream.seek(0x30);
uint32 pathWalkRectsOffs = stream.readUint32LE();
@ -376,7 +372,7 @@ BackgroundInstance::BackgroundInstance(IllusionsEngine *vm)
}
void BackgroundInstance::load(Resource *resource) {
debug("BackgroundResourceLoader::load() Loading background %08X from %s...", resource->_resId, resource->_filename.c_str());
debug(1, "BackgroundResourceLoader::load() Loading background %08X from %s...", resource->_resId, resource->_filename.c_str());
BackgroundResource *backgroundResource = new BackgroundResource();
backgroundResource->load(resource->_data, resource->_dataSize);
@ -403,7 +399,7 @@ void BackgroundInstance::load(Resource *resource) {
}
void BackgroundInstance::unload() {
debug("BackgroundInstance::unload()");
debug(1, "BackgroundInstance::unload()");
freeSurface();
unregisterResources();
delete _bgRes;

View File

@ -47,7 +47,6 @@ public:
BackgroundResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~BackgroundResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -34,10 +34,6 @@ void FontResourceLoader::load(Resource *resource) {
resource->_instance = fontInstance;
}
void FontResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.fnt", resource->_resId);
}
bool FontResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile;

View File

@ -35,7 +35,6 @@ public:
FontResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~FontResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -28,16 +28,12 @@ namespace Illusions {
// MidiGroupResourceLoader
void MidiGroupResourceLoader::load(Resource *resource) {
debug("MidiGroupResourceLoader::load() Loading midi group %08X...", resource->_resId);
debug(1, "MidiGroupResourceLoader::load() Loading midi group %08X...", resource->_resId);
// TODO
}
void MidiGroupResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.fnt", resource->_resId);
}
bool MidiGroupResourceLoader::isFlag(int flag) {
return false;
}

View File

@ -35,7 +35,6 @@ public:
MidiGroupResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~MidiGroupResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -33,10 +33,6 @@ void ScriptResourceLoader::load(Resource *resource) {
resource->_instance = scriptInstance;
}
void ScriptResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.scr", resource->_resId);
}
bool ScriptResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile;

View File

@ -34,7 +34,6 @@ public:
ScriptResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~ScriptResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -34,10 +34,6 @@ void SoundGroupResourceLoader::load(Resource *resource) {
resource->_instance = soundGroupInstance;
}
void SoundGroupResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.sg", resource->_resId);
}
bool SoundGroupResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile/* ||
@ -53,7 +49,7 @@ void SoundEffect::load(Common::SeekableReadStream &stream) {
_volume = stream.readUint16LE();
_frequency = stream.readUint16LE();
stream.skip(32 + 4); // Skip name
debug("SoundEffect::load() _soundEffectId: %08X, _looping: %d, _field6: %d, _volume: %d, _frequency: %d",
debug(1, "SoundEffect::load() _soundEffectId: %08X, _looping: %d, _field6: %d, _volume: %d, _frequency: %d",
_soundEffectId, _looping, _field6, _volume, _frequency);
}
@ -74,7 +70,7 @@ void SoundGroupResource::load(byte *data, uint32 dataSize) {
_soundEffectsCount = stream.readUint16LE();
stream.skip(2);
uint32 soundEffectsOffs = stream.readUint32LE();
debug("_soundEffectsCount: %d; soundEffectsOffs: %08X", _soundEffectsCount, soundEffectsOffs);
debug(1, "_soundEffectsCount: %d; soundEffectsOffs: %08X", _soundEffectsCount, soundEffectsOffs);
_soundEffects = new SoundEffect[_soundEffectsCount];
stream.seek(soundEffectsOffs);
for (uint i = 0; i < _soundEffectsCount; ++i)

View File

@ -35,7 +35,6 @@ public:
SoundGroupResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~SoundGroupResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -32,10 +32,6 @@ void TalkResourceLoader::load(Resource *resource) {
resource->_instance = _vm->_talkItems->createTalkInstance(resource);
}
void TalkResourceLoader::buildFilename(Resource *resource) {
resource->_filename = Common::String::format("%08X.tlk", resource->_resId);
}
bool TalkResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile;

View File

@ -35,7 +35,6 @@ public:
TalkResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
virtual ~TalkResourceLoader() {}
virtual void load(Resource *resource);
virtual void buildFilename(Resource *resource);
virtual bool isFlag(int flag);
protected:
IllusionsEngine *_vm;

View File

@ -21,6 +21,7 @@
*/
#include "illusions/resourcesystem.h"
#include "illusions/resourcereader.h"
#include "illusions/illusions.h"
#include "common/algorithm.h"
@ -47,21 +48,11 @@ ResourceInstance::~ResourceInstance() {
// Resource
void Resource::loadData() {
debug("Resource::loadData()");
Common::File fd;
if (!fd.open(_filename))
error("Resource::loadData() Could not open %s for reading", _filename.c_str());
_dataSize = fd.size();
_data = (byte*)malloc(_dataSize);
fd.read(_data, _dataSize);
debug("Resource::loadData() OK");
void Resource::loadData(BaseResourceReader *resReader) {
_data = resReader->readResource(_tag, _resId, _dataSize);
}
void Resource::unloadData() {
debug("Resource::unloadData()");
free(_data);
_data = 0;
_dataSize = 0;
@ -84,7 +75,7 @@ void ResourceSystem::addResourceLoader(uint32 resTypeId, BaseResourceLoader *res
}
void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
debug("ResourceSystem::loadResource(%08X, %08X, %08X)", resId, tag, threadId);
debug(1, "ResourceSystem::loadResource(%08X, %08X, %08X)", resId, tag, threadId);
BaseResourceLoader *resourceLoader = getResourceLoader(resId);
Resource *resource = new Resource();
@ -94,24 +85,21 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
resource->_threadId = threadId;
resource->_gameId = _vm->getGameId();
resourceLoader->buildFilename(resource);
if (resourceLoader->isFlag(kRlfLoadFile)) {
debug("ResourceSystem::loadResource() kRlfLoadFile");
resource->loadData();
debug(1, "ResourceSystem::loadResource() kRlfLoadFile");
resource->loadData(_vm->_resReader);
}
resourceLoader->load(resource);
if (resourceLoader->isFlag(kRlfFreeDataAfterLoad)) {
debug("ResourceSystem::loadResource() kRlfFreeDataAfterLoad");
debug(1, "ResourceSystem::loadResource() kRlfFreeDataAfterLoad");
resource->unloadData();
}
resource->_loaded = true;
_resources.push_back(resource);
// TODO? Not sure if this is needed krnfileAdd(filenameb, taga);
}
@ -150,7 +138,7 @@ Resource *ResourceSystem::getResource(uint32 resId) {
}
void ResourceSystem::unloadResource(Resource *resource) {
debug("Unloading %08X... (tag: %08X)", resource->_resId, resource->_tag);
debug(1, "Unloading %08X... (tag: %08X)", resource->_resId, resource->_tag);
ResourcesArrayIterator it = Common::find_if(_resources.begin(), _resources.end(), ResourceEqualByValue(resource));
if (it != _resources.end())
_resources.remove_at(it - _resources.begin());

View File

@ -36,6 +36,7 @@ namespace Illusions {
#define ResourceTypeId(x) ((x) & 0xFFFF0000)
class BaseResourceLoader;
class BaseResourceReader;
class IllusionsEngine;
struct Resource;
@ -66,7 +67,7 @@ struct Resource {
delete _instance;
unloadData();
}
void loadData();
void loadData(BaseResourceReader *resReader);
void unloadData();
};
@ -79,7 +80,6 @@ class BaseResourceLoader {
public:
virtual ~BaseResourceLoader() {}
virtual void load(Resource *resource) = 0;
virtual void buildFilename(Resource *resource) = 0;
virtual bool isFlag(int flag) = 0;
};