aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/illusions/backgroundresource.cpp47
-rw-r--r--engines/illusions/backgroundresource.h53
-rw-r--r--engines/illusions/illusions.cpp18
-rw-r--r--engines/illusions/illusions.h3
-rw-r--r--engines/illusions/module.mk1
-rw-r--r--engines/illusions/resourcesystem.cpp69
-rw-r--r--engines/illusions/resourcesystem.h45
7 files changed, 215 insertions, 21 deletions
diff --git a/engines/illusions/backgroundresource.cpp b/engines/illusions/backgroundresource.cpp
new file mode 100644
index 0000000000..34d1e985cd
--- /dev/null
+++ b/engines/illusions/backgroundresource.cpp
@@ -0,0 +1,47 @@
+/* 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/illusions.h"
+#include "illusions/backgroundresource.h"
+#include "common/str.h"
+
+namespace Illusions {
+
+// BackgroundResourceLoader
+
+void BackgroundResourceLoader::load(Resource *resource) {
+ debug("BackgroundResourceLoader::load() Loading background %08X from %s...", resource->_resId, resource->_filename.c_str());
+}
+
+void BackgroundResourceLoader::unload(Resource *resource) {
+}
+
+void BackgroundResourceLoader::buildFilename(Resource *resource) {
+ resource->_filename = Common::String::format("%08X.bg", resource->_resId);
+}
+
+bool BackgroundResourceLoader::isFlag(int flag) {
+ return
+ flag == kRlfLoadFile;
+}
+
+} // End of namespace Illusions
diff --git a/engines/illusions/backgroundresource.h b/engines/illusions/backgroundresource.h
new file mode 100644
index 0000000000..58eed03f70
--- /dev/null
+++ b/engines/illusions/backgroundresource.h
@@ -0,0 +1,53 @@
+/* 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_BACKGROUNDRESOURCE_H
+#define ILLUSIONS_BACKGROUNDRESOURCE_H
+
+#include "illusions/resourcesystem.h"
+
+#include "common/array.h"
+#include "common/file.h"
+#include "common/memstream.h"
+#include "common/substream.h"
+#include "common/system.h"
+
+namespace Illusions {
+
+class IllusionsEngine;
+
+class BackgroundResourceLoader : public BaseResourceLoader {
+public:
+ BackgroundResourceLoader(IllusionsEngine *vm) : _vm(vm) {}
+ virtual ~BackgroundResourceLoader() {}
+ virtual void load(Resource *resource);
+ virtual void unload(Resource *resource);
+ virtual void buildFilename(Resource *resource);
+ virtual bool isFlag(int flag);
+protected:
+ IllusionsEngine *_vm;
+};
+
+
+} // End of namespace Illusions
+
+#endif // ILLUSIONS_BACKGROUNDRESOURCE_H
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp
index 5cd335e5e9..a2e8ee4a55 100644
--- a/engines/illusions/illusions.cpp
+++ b/engines/illusions/illusions.cpp
@@ -22,6 +22,7 @@
#include "illusions/illusions.h"
#include "illusions/resourcesystem.h"
+#include "illusions/backgroundresource.h"
#include "audio/audiostream.h"
#include "common/config-manager.h"
@@ -55,13 +56,30 @@ IllusionsEngine::~IllusionsEngine() {
Common::Error IllusionsEngine::run() {
+ // Init search paths
+ const Common::FSNode gameDataDir(ConfMan.get("path"));
+ SearchMan.addSubDirectoryMatching(gameDataDir, "music");
+ SearchMan.addSubDirectoryMatching(gameDataDir, "resource");
+ SearchMan.addSubDirectoryMatching(gameDataDir, "resrem");
+ SearchMan.addSubDirectoryMatching(gameDataDir, "savegame");
+ SearchMan.addSubDirectoryMatching(gameDataDir, "sfx");
+ SearchMan.addSubDirectoryMatching(gameDataDir, "video");
+ SearchMan.addSubDirectoryMatching(gameDataDir, "voice");
+
Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0);
initGraphics(640, 480, true, &pixelFormat16);
+
+ _resSys = new ResourceSystem();
+ _resSys->addResourceLoader(0x00110000, new BackgroundResourceLoader(this));
+
+ _resSys->loadResource(0x00110002, 0, 0);
while (!shouldQuit()) {
updateEvents();
}
+ delete _resSys;
+
return Common::kNoError;
}
diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h
index 8027fc7d76..f35f1bb7df 100644
--- a/engines/illusions/illusions.h
+++ b/engines/illusions/illusions.h
@@ -43,6 +43,8 @@ namespace Illusions {
#define ILLUSIONS_SAVEGAME_VERSION 0
+class ResourceSystem;
+
class IllusionsEngine : public Engine {
protected:
Common::Error run();
@@ -56,6 +58,7 @@ private:
Graphics::PixelFormat _pixelFormat;
public:
Common::RandomSource *_random;
+ ResourceSystem *_resSys;
void updateEvents();
diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk
index 17ff3f4072..3cf4e1f6ea 100644
--- a/engines/illusions/module.mk
+++ b/engines/illusions/module.mk
@@ -1,6 +1,7 @@
MODULE := engines/illusions
MODULE_OBJS := \
+ backgroundresource.o \
illusions.o \
detection.o \
resourcesystem.o
diff --git a/engines/illusions/resourcesystem.cpp b/engines/illusions/resourcesystem.cpp
index b5b7f80b97..f30f46b2c1 100644
--- a/engines/illusions/resourcesystem.cpp
+++ b/engines/illusions/resourcesystem.cpp
@@ -22,8 +22,29 @@
#include "illusions/resourcesystem.h"
+#include "common/algorithm.h"
+
namespace Illusions {
+// Resource
+
+void 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);
+}
+
+void Resource::unloadData() {
+ delete _data;
+ _data = 0;
+ _dataSize = 0;
+}
+
+// ResourceSystem
+
ResourceSystem::ResourceSystem() {
}
@@ -41,7 +62,7 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
BaseResourceLoader *resourceLoader = getResourceLoader(resId);
Resource *resource = new Resource();
- resource->_loaded = 0;
+ resource->_loaded = false;
resource->_resId = resId;
resource->_tag = tag;
resource->_threadId = threadId;
@@ -49,24 +70,13 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
resourceLoader->buildFilename(resource);
- if (resourceLoader->isFlag(kRlfLoadFile)) {
- // TODO Move to Resource class?
- Common::File fd;
- if (!fd.open(resource->filename))
- error("ResourceSystem::loadResource() Could not open %s for reading", resource->filename.c_str());
- resource->_dataSize = fd.size();
- resource->_data = (byte*)malloc(resource->_dataSize);
- fd.read(resource->_data, resource->_dataSize);
- }
+ if (resourceLoader->isFlag(kRlfLoadFile))
+ resource->loadData();
resourceLoader->load(resource);
- if (resourceLoader->isFlag(kRlfFreeDataAfterUse)) {
- // TODO Move to Resource class?
- delete resource->_data;
- resource->_data = 0;
- resource->_dataSize = 0;
- }
+ if (resourceLoader->isFlag(kRlfFreeDataAfterUse))
+ resource->unloadData();
resource->_loaded = true;
@@ -75,6 +85,20 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
}
+void ResourceSystem::unloadResourceById(uint32 resId) {
+ Resource *resource = getResource(resId);
+ if (resource)
+ unloadResource(resource);
+}
+
+void ResourceSystem::unloadResourcesByTag(uint32 tag) {
+ ResourcesArrayIterator it = Common::find_if(_resources.begin(), _resources.end(), ResourceEqualByTag(tag));
+ while (it != _resources.end()) {
+ unloadResource(*it);
+ it = Common::find_if(it, _resources.end(), ResourceEqualByTag(tag));
+ }
+}
+
BaseResourceLoader *ResourceSystem::getResourceLoader(uint32 resId) {
ResourceLoadersMapIterator it = _resourceLoaders.find(ResourceTypeId(resId));
if (it != _resourceLoaders.end())
@@ -82,4 +106,17 @@ BaseResourceLoader *ResourceSystem::getResourceLoader(uint32 resId) {
error("ResourceSystem::getResourceLoader() Could not find resource loader for resource id %08X", resId);
}
+Resource *ResourceSystem::getResource(uint32 resId) {
+ ResourcesArrayIterator it = Common::find_if(_resources.begin(), _resources.end(), ResourceEqualById(resId));
+ return it != _resources.end() ? *it : 0;
+}
+
+void ResourceSystem::unloadResource(Resource *resource) {
+ resource->_resourceLoader->unload(resource);
+ ResourcesArrayIterator it = Common::find_if(_resources.begin(), _resources.end(), ResourceEqualByValue(resource));
+ if (it != _resources.end())
+ _resources.remove_at(it - _resources.begin());
+ delete resource;
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/resourcesystem.h b/engines/illusions/resourcesystem.h
index f5e2dfe2dd..18feb511ac 100644
--- a/engines/illusions/resourcesystem.h
+++ b/engines/illusions/resourcesystem.h
@@ -45,9 +45,14 @@ struct Resource {
byte *_data;
uint32 _dataSize;
BaseResourceLoader *_resourceLoader;
- Common::String filename; // TODO Check if this is needed
+ Common::String _filename; // TODO Check if this is needed
Resource() : _loaded(false), _resId(0), _tag(0), _threadId(0), _data(0), _dataSize(0),
_resourceLoader(0) {}
+ ~Resource() {
+ unloadData();
+ }
+ void loadData();
+ void unloadData();
};
struct ResourceLoaderInfo {
@@ -81,18 +86,48 @@ public:
// TODO Handle threadId in caller as well as pausing of timer
void loadResource(uint32 resId, uint32 tag, uint32 threadId);
+ void unloadResourceById(uint32 resId);
+ void unloadResourcesByTag(uint32 tag);
protected:
typedef Common::HashMap<uint32, BaseResourceLoader*> ResourceLoadersMap;
typedef ResourceLoadersMap::iterator ResourceLoadersMapIterator;
ResourceLoadersMap _resourceLoaders;
-
- Common::Array<Resource*> _resources;
-
BaseResourceLoader *getResourceLoader(uint32 resId);
+
+ typedef Common::Array<Resource*> ResourcesArray;
+ typedef ResourcesArray::iterator ResourcesArrayIterator;
+ ResourcesArray _resources;
+
+ struct ResourceEqualById : public Common::UnaryFunction<const Resource*, bool> {
+ uint32 _resId;
+ ResourceEqualById(uint32 resId) : _resId(resId) {}
+ bool operator()(const Resource *resource) const {
+ return resource->_resId == _resId;
+ }
+ };
+
+ struct ResourceEqualByValue : public Common::UnaryFunction<const Resource*, bool> {
+ const Resource *_resource;
+ ResourceEqualByValue(const Resource *resource) : _resource(resource) {}
+ bool operator()(const Resource *resource) const {
+ return resource == _resource;
+ }
+ };
+
+ struct ResourceEqualByTag : public Common::UnaryFunction<const Resource*, bool> {
+ uint32 _tag;
+ ResourceEqualByTag(uint32 tag) : _tag(tag) {}
+ bool operator()(const Resource *resource) const {
+ return resource->_tag == _tag;
+ }
+ };
+
+ Resource *getResource(uint32 resId);
+ void unloadResource(Resource *resource);
};
} // End of namespace Illusions
-#endif // ILLUSIONS_ILLUSIONS_H
+#endif // ILLUSIONS_RESOURCESYSTEM_H