diff options
author | johndoe123 | 2014-03-10 11:50:35 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | 7300dd09cd5d2b70e87d3a29faa562801b0767c5 (patch) | |
tree | 4cb9fe559a370510162c971c469f3213aff411ae | |
parent | 9a58385088ccf89393f71909eb3c87f3111006fa (diff) | |
download | scummvm-rg350-7300dd09cd5d2b70e87d3a29faa562801b0767c5.tar.gz scummvm-rg350-7300dd09cd5d2b70e87d3a29faa562801b0767c5.tar.bz2 scummvm-rg350-7300dd09cd5d2b70e87d3a29faa562801b0767c5.zip |
ILLUSIONS: Resource loader skeleton
-rw-r--r-- | engines/illusions/illusions.cpp | 1 | ||||
-rw-r--r-- | engines/illusions/module.mk | 3 | ||||
-rw-r--r-- | engines/illusions/resourcesystem.cpp | 85 | ||||
-rw-r--r-- | engines/illusions/resourcesystem.h | 98 |
4 files changed, 186 insertions, 1 deletions
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp index da291bae69..5cd335e5e9 100644 --- a/engines/illusions/illusions.cpp +++ b/engines/illusions/illusions.cpp @@ -21,6 +21,7 @@ */ #include "illusions/illusions.h" +#include "illusions/resourcesystem.h" #include "audio/audiostream.h" #include "common/config-manager.h" diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk index 5b0823134b..17ff3f4072 100644 --- a/engines/illusions/module.mk +++ b/engines/illusions/module.mk @@ -2,7 +2,8 @@ MODULE := engines/illusions MODULE_OBJS := \ illusions.o \ - detection.o + detection.o \ + resourcesystem.o # This module can be built as a plugin ifeq ($(ENABLE_ILLUSIONS), DYNAMIC_PLUGIN) diff --git a/engines/illusions/resourcesystem.cpp b/engines/illusions/resourcesystem.cpp new file mode 100644 index 0000000000..b5b7f80b97 --- /dev/null +++ b/engines/illusions/resourcesystem.cpp @@ -0,0 +1,85 @@ +/* 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" + +namespace Illusions { + +ResourceSystem::ResourceSystem() { +} + +ResourceSystem::~ResourceSystem() { + // Delete all registered resource loaders + for (ResourceLoadersMapIterator it = _resourceLoaders.begin(); it != _resourceLoaders.end(); ++it) + delete (*it)._value; +} + +void ResourceSystem::addResourceLoader(uint32 resTypeId, BaseResourceLoader *resourceLoader) { + _resourceLoaders[resTypeId] = resourceLoader; +} + +void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) { + BaseResourceLoader *resourceLoader = getResourceLoader(resId); + + Resource *resource = new Resource(); + resource->_loaded = 0; + resource->_resId = resId; + resource->_tag = tag; + resource->_threadId = threadId; + resource->_resourceLoader = resourceLoader; + + 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); + } + + resourceLoader->load(resource); + + if (resourceLoader->isFlag(kRlfFreeDataAfterUse)) { + // TODO Move to Resource class? + delete resource->_data; + resource->_data = 0; + resource->_dataSize = 0; + } + + resource->_loaded = true; + + _resources.push_back(resource); + // TODO? Not sure if this is needed krnfileAdd(filenameb, taga); + +} + +BaseResourceLoader *ResourceSystem::getResourceLoader(uint32 resId) { + ResourceLoadersMapIterator it = _resourceLoaders.find(ResourceTypeId(resId)); + if (it != _resourceLoaders.end()) + return (*it)._value; + error("ResourceSystem::getResourceLoader() Could not find resource loader for resource id %08X", resId); +} + +} // End of namespace Illusions diff --git a/engines/illusions/resourcesystem.h b/engines/illusions/resourcesystem.h new file mode 100644 index 0000000000..f5e2dfe2dd --- /dev/null +++ b/engines/illusions/resourcesystem.h @@ -0,0 +1,98 @@ +/* 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_RESOURCESYSTEM_H +#define ILLUSIONS_RESOURCESYSTEM_H + +#include "common/array.h" +#include "common/file.h" +#include "common/hashmap.h" +#include "common/memstream.h" +#include "common/str.h" +#include "common/substream.h" +#include "common/system.h" + +namespace Illusions { + +#define ResourceTypeId(x) ((x) & 0xFFFF0000) + +class BaseResourceLoader; + +struct Resource { + bool _loaded; + uint32 _resId; + uint32 _tag; + uint32 _threadId; + byte *_data; + uint32 _dataSize; + BaseResourceLoader *_resourceLoader; + Common::String filename; // TODO Check if this is needed + Resource() : _loaded(false), _resId(0), _tag(0), _threadId(0), _data(0), _dataSize(0), + _resourceLoader(0) {} +}; + +struct ResourceLoaderInfo { + Resource *_res; + byte *_data; + uint32 _dataSize; +}; + +enum { + kRlfLoadFile, + kRlfFreeDataAfterUse +}; + +class BaseResourceLoader { +public: + virtual ~BaseResourceLoader() {} + virtual void load(Resource *resource) = 0; + virtual void unload(Resource *resource) = 0; + virtual void buildFilename(Resource *resource) = 0; + virtual bool isFlag(int flag) = 0; +}; + +// TODO Possibly split resource loaders from the system? + +class ResourceSystem { +public: + ResourceSystem(); + ~ResourceSystem(); + + void addResourceLoader(uint32 resTypeId, BaseResourceLoader *resourceLoader); + + // TODO Handle threadId in caller as well as pausing of timer + void loadResource(uint32 resId, uint32 tag, uint32 threadId); + +protected: + typedef Common::HashMap<uint32, BaseResourceLoader*> ResourceLoadersMap; + typedef ResourceLoadersMap::iterator ResourceLoadersMapIterator; + ResourceLoadersMap _resourceLoaders; + + Common::Array<Resource*> _resources; + + BaseResourceLoader *getResourceLoader(uint32 resId); + +}; + +} // End of namespace Illusions + +#endif // ILLUSIONS_ILLUSIONS_H |