1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef NEVERHOOD_RESOURCEMAN_H 24 #define NEVERHOOD_RESOURCEMAN_H 25 26 #include "common/array.h" 27 #include "common/file.h" 28 #include "common/hashmap.h" 29 #include "neverhood/neverhood.h" 30 #include "neverhood/blbarchive.h" 31 32 namespace Neverhood { 33 34 struct ResourceFileEntry { 35 int resourceHandle; 36 BlbArchive *archive; 37 BlbArchiveEntry *archiveEntry; 38 }; 39 40 struct Resource { 41 ResourceFileEntry *entry; 42 int useRefCount; 43 }; 44 45 struct ResourceData { 46 byte *data; 47 int dataRefCount; ResourceDataResourceData48 ResourceData() : data(NULL), dataRefCount() {} 49 }; 50 51 class ResourceMan; 52 53 struct ResourceHandle { 54 friend class ResourceMan; 55 public: 56 ResourceHandle(); 57 ~ResourceHandle(); isValidResourceHandle58 bool isValid() const { return _resourceFileEntry != NULL && _resourceFileEntry->archiveEntry != NULL; } typeResourceHandle59 byte type() const { return isValid() ? _resourceFileEntry->archiveEntry->type : 0; }; dataResourceHandle60 const byte *data() const { return _data; } sizeResourceHandle61 uint32 size() const { return isValid() ? _resourceFileEntry->archiveEntry->size : 0; }; extDataResourceHandle62 const byte *extData() const { return _extData; }; fileHashResourceHandle63 uint32 fileHash() const { return isValid() ? _resourceFileEntry->archiveEntry->fileHash : 0; }; 64 protected: 65 ResourceFileEntry *_resourceFileEntry; 66 const byte *_extData; 67 const byte *_data; 68 }; 69 70 class ResourceMan { 71 public: 72 ResourceMan(); 73 ~ResourceMan(); 74 void addArchive(const Common::String &filename); 75 ResourceFileEntry *findEntrySimple(uint32 fileHash); 76 ResourceFileEntry *findEntry(uint32 fileHash, ResourceFileEntry **firstEntry = NULL); 77 Common::SeekableReadStream *createStream(uint32 fileHash); getEntry(uint index)78 const ResourceFileEntry& getEntry(uint index) { return _entries[index]; } getEntryCount()79 uint getEntryCount() { return _entries.size(); } 80 void queryResource(uint32 fileHash, ResourceHandle &resourceHandle); 81 void loadResource(ResourceHandle &resourceHandle, bool applyResourceFixes); 82 void unloadResource(ResourceHandle &resourceHandle); 83 void purgeResources(); 84 protected: 85 typedef Common::HashMap<uint32, ResourceFileEntry> EntriesMap; 86 Common::Array<BlbArchive*> _archives; 87 EntriesMap _entries; 88 Common::HashMap<uint32, ResourceData*> _data; 89 Common::Array<Resource*> _resources; 90 }; 91 92 } // End of namespace Neverhood 93 94 #endif /* NEVERHOOD_RESOURCEMAN_H */ 95