aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohndoe1232015-11-18 16:25:42 +0100
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commit41978f466d423e9b5f3c3980666c1beb4219b937 (patch)
treede8cf82e097961a85458f785bee247f0fc05e66f
parenta5ad1bc1062f37dc383db6c6cecc4dcbf0081bcf (diff)
downloadscummvm-rg350-41978f466d423e9b5f3c3980666c1beb4219b937.tar.gz
scummvm-rg350-41978f466d423e9b5f3c3980666c1beb4219b937.tar.bz2
scummvm-rg350-41978f466d423e9b5f3c3980666c1beb4219b937.zip
ILLUSIONS: Add GAM archive reader for Duckman and adjust the resource reader/system
-rw-r--r--engines/illusions/actor.cpp4
-rw-r--r--engines/illusions/bbdou/illusions_bbdou.cpp4
-rw-r--r--engines/illusions/duckman/illusions_duckman.cpp15
-rw-r--r--engines/illusions/duckman/scriptopcodes_duckman.cpp4
-rw-r--r--engines/illusions/fileresourcereader.cpp79
-rw-r--r--engines/illusions/fileresourcereader.h41
-rw-r--r--engines/illusions/gamarchive.cpp101
-rw-r--r--engines/illusions/gamarchive.h65
-rw-r--r--engines/illusions/gamresourcereader.cpp44
-rw-r--r--engines/illusions/gamresourcereader.h44
-rw-r--r--engines/illusions/illusions.h2
-rw-r--r--engines/illusions/module.mk3
-rw-r--r--engines/illusions/resourcereader.cpp28
-rw-r--r--engines/illusions/resourcereader.h38
-rw-r--r--engines/illusions/resources/actorresource.cpp6
-rw-r--r--engines/illusions/resources/actorresource.h1
-rw-r--r--engines/illusions/resources/backgroundresource.cpp18
-rw-r--r--engines/illusions/resources/backgroundresource.h1
-rw-r--r--engines/illusions/resources/fontresource.cpp4
-rw-r--r--engines/illusions/resources/fontresource.h1
-rw-r--r--engines/illusions/resources/midiresource.cpp6
-rw-r--r--engines/illusions/resources/midiresource.h1
-rw-r--r--engines/illusions/resources/scriptresource.cpp4
-rw-r--r--engines/illusions/resources/scriptresource.h1
-rw-r--r--engines/illusions/resources/soundresource.cpp8
-rw-r--r--engines/illusions/resources/soundresource.h1
-rw-r--r--engines/illusions/resources/talkresource.cpp4
-rw-r--r--engines/illusions/resources/talkresource.h1
-rw-r--r--engines/illusions/resourcesystem.cpp28
-rw-r--r--engines/illusions/resourcesystem.h4
30 files changed, 482 insertions, 79 deletions
diff --git a/engines/illusions/actor.cpp b/engines/illusions/actor.cpp
index 0e4bae7495..cf3416a572 100644
--- a/engines/illusions/actor.cpp
+++ b/engines/illusions/actor.cpp
@@ -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;
diff --git a/engines/illusions/bbdou/illusions_bbdou.cpp b/engines/illusions/bbdou/illusions_bbdou.cpp
index b2e5098085..98a4a24175 100644
--- a/engines/illusions/bbdou/illusions_bbdou.cpp
+++ b/engines/illusions/bbdou/illusions_bbdou.cpp
@@ -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");
diff --git a/engines/illusions/duckman/illusions_duckman.cpp b/engines/illusions/duckman/illusions_duckman.cpp
index d30f17bd69..041e4372b9 100644
--- a/engines/illusions/duckman/illusions_duckman.cpp
+++ b/engines/illusions/duckman/illusions_duckman.cpp
@@ -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);
diff --git a/engines/illusions/duckman/scriptopcodes_duckman.cpp b/engines/illusions/duckman/scriptopcodes_duckman.cpp
index 3f12209a84..107d8983e7 100644
--- a/engines/illusions/duckman/scriptopcodes_duckman.cpp
+++ b/engines/illusions/duckman/scriptopcodes_duckman.cpp
@@ -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) {
diff --git a/engines/illusions/fileresourcereader.cpp b/engines/illusions/fileresourcereader.cpp
new file mode 100644
index 0000000000..c707c6535a
--- /dev/null
+++ b/engines/illusions/fileresourcereader.cpp
@@ -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
diff --git a/engines/illusions/fileresourcereader.h b/engines/illusions/fileresourcereader.h
new file mode 100644
index 0000000000..70c2e5bc0f
--- /dev/null
+++ b/engines/illusions/fileresourcereader.h
@@ -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
diff --git a/engines/illusions/gamarchive.cpp b/engines/illusions/gamarchive.cpp
new file mode 100644
index 0000000000..517882c501
--- /dev/null
+++ b/engines/illusions/gamarchive.cpp
@@ -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
diff --git a/engines/illusions/gamarchive.h b/engines/illusions/gamarchive.h
new file mode 100644
index 0000000000..3e43c530e2
--- /dev/null
+++ b/engines/illusions/gamarchive.h
@@ -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
diff --git a/engines/illusions/gamresourcereader.cpp b/engines/illusions/gamresourcereader.cpp
new file mode 100644
index 0000000000..4b4f3e0ff0
--- /dev/null
+++ b/engines/illusions/gamresourcereader.cpp
@@ -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
diff --git a/engines/illusions/gamresourcereader.h b/engines/illusions/gamresourcereader.h
new file mode 100644
index 0000000000..ed8227e806
--- /dev/null
+++ b/engines/illusions/gamresourcereader.h
@@ -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
diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h
index 9980698a67..023a45f565 100644
--- a/engines/illusions/illusions.h
+++ b/engines/illusions/illusions.h
@@ -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();
diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk
index 083e2f5980..ee40fb37bc 100644
--- a/engines/illusions/module.mk
+++ b/engines/illusions/module.mk
@@ -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 \
diff --git a/engines/illusions/resourcereader.cpp b/engines/illusions/resourcereader.cpp
new file mode 100644
index 0000000000..e665bfb3e3
--- /dev/null
+++ b/engines/illusions/resourcereader.cpp
@@ -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
diff --git a/engines/illusions/resourcereader.h b/engines/illusions/resourcereader.h
new file mode 100644
index 0000000000..39ddbafda7
--- /dev/null
+++ b/engines/illusions/resourcereader.h
@@ -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
diff --git a/engines/illusions/resources/actorresource.cpp b/engines/illusions/resources/actorresource.cpp
index a8d62e5001..b93cf0f83d 100644
--- a/engines/illusions/resources/actorresource.cpp
+++ b/engines/illusions/resources/actorresource.cpp
@@ -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) {
diff --git a/engines/illusions/resources/actorresource.h b/engines/illusions/resources/actorresource.h
index 2ccb9efd58..b78e515f3f 100644
--- a/engines/illusions/resources/actorresource.h
+++ b/engines/illusions/resources/actorresource.h
@@ -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;
diff --git a/engines/illusions/resources/backgroundresource.cpp b/engines/illusions/resources/backgroundresource.cpp
index bc87311186..e50f46b240 100644
--- a/engines/illusions/resources/backgroundresource.cpp
+++ b/engines/illusions/resources/backgroundresource.cpp
@@ -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;
diff --git a/engines/illusions/resources/backgroundresource.h b/engines/illusions/resources/backgroundresource.h
index 9438501916..d118c3d6d0 100644
--- a/engines/illusions/resources/backgroundresource.h
+++ b/engines/illusions/resources/backgroundresource.h
@@ -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;
diff --git a/engines/illusions/resources/fontresource.cpp b/engines/illusions/resources/fontresource.cpp
index 678e555686..29aaf9bf65 100644
--- a/engines/illusions/resources/fontresource.cpp
+++ b/engines/illusions/resources/fontresource.cpp
@@ -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;
diff --git a/engines/illusions/resources/fontresource.h b/engines/illusions/resources/fontresource.h
index 579277c5f9..e0291452df 100644
--- a/engines/illusions/resources/fontresource.h
+++ b/engines/illusions/resources/fontresource.h
@@ -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;
diff --git a/engines/illusions/resources/midiresource.cpp b/engines/illusions/resources/midiresource.cpp
index a3aeef7798..203ed12ad0 100644
--- a/engines/illusions/resources/midiresource.cpp
+++ b/engines/illusions/resources/midiresource.cpp
@@ -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;
}
diff --git a/engines/illusions/resources/midiresource.h b/engines/illusions/resources/midiresource.h
index 9032e99396..1cd3f806ef 100644
--- a/engines/illusions/resources/midiresource.h
+++ b/engines/illusions/resources/midiresource.h
@@ -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;
diff --git a/engines/illusions/resources/scriptresource.cpp b/engines/illusions/resources/scriptresource.cpp
index a29fd78253..5ce7154439 100644
--- a/engines/illusions/resources/scriptresource.cpp
+++ b/engines/illusions/resources/scriptresource.cpp
@@ -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;
diff --git a/engines/illusions/resources/scriptresource.h b/engines/illusions/resources/scriptresource.h
index c2119b03c8..eb58c66cb9 100644
--- a/engines/illusions/resources/scriptresource.h
+++ b/engines/illusions/resources/scriptresource.h
@@ -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;
diff --git a/engines/illusions/resources/soundresource.cpp b/engines/illusions/resources/soundresource.cpp
index 73ec163363..5cfa240db6 100644
--- a/engines/illusions/resources/soundresource.cpp
+++ b/engines/illusions/resources/soundresource.cpp
@@ -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)
diff --git a/engines/illusions/resources/soundresource.h b/engines/illusions/resources/soundresource.h
index 638e8df810..97e6f89773 100644
--- a/engines/illusions/resources/soundresource.h
+++ b/engines/illusions/resources/soundresource.h
@@ -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;
diff --git a/engines/illusions/resources/talkresource.cpp b/engines/illusions/resources/talkresource.cpp
index 57392c7f97..9b03b37cc2 100644
--- a/engines/illusions/resources/talkresource.cpp
+++ b/engines/illusions/resources/talkresource.cpp
@@ -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;
diff --git a/engines/illusions/resources/talkresource.h b/engines/illusions/resources/talkresource.h
index 5e3797e592..a29e58ceb5 100644
--- a/engines/illusions/resources/talkresource.h
+++ b/engines/illusions/resources/talkresource.h
@@ -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;
diff --git a/engines/illusions/resourcesystem.cpp b/engines/illusions/resourcesystem.cpp
index 9e81f1f9df..13e4da6aec 100644
--- a/engines/illusions/resourcesystem.cpp
+++ b/engines/illusions/resourcesystem.cpp
@@ -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());
diff --git a/engines/illusions/resourcesystem.h b/engines/illusions/resourcesystem.h
index edf1cdd08c..a0c2c06f99 100644
--- a/engines/illusions/resourcesystem.h
+++ b/engines/illusions/resourcesystem.h
@@ -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;
};