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 ASYLUM_RESPACK_H 24 #define ASYLUM_RESPACK_H 25 26 #include "common/array.h" 27 #include "common/file.h" 28 #include "common/hashmap.h" 29 30 #include "asylum/shared.h" 31 32 namespace Asylum { 33 34 class ResourceManager; 35 36 struct ResourceEntry { 37 byte *data; 38 uint32 size; 39 uint32 offset; 40 ResourceEntryResourceEntry41 ResourceEntry() { 42 data = NULL; 43 size = 0; 44 offset = 0; 45 } 46 getDataResourceEntry47 uint32 getData(uint32 off) { 48 if (data == NULL) 49 error("[ResourceEntry::getData] Invalid data"); 50 51 return READ_UINT32(data + off); 52 } 53 }; 54 55 class ResourcePack { 56 public: 57 ResourceEntry *get(uint16 index); 58 59 protected: 60 ResourcePack(Common::String filename); 61 ~ResourcePack(); 62 63 private: 64 Common::Array<ResourceEntry> _resources; 65 Common::File _packFile; 66 67 void init(Common::String filename); 68 69 friend class ResourceManager; 70 }; 71 72 class ResourceManager { 73 public: 74 ResourceManager(); 75 ~ResourceManager(); 76 77 /** 78 * Get a resource entry 79 * 80 * @param id The ResourceId to get. 81 * 82 * @return the resource entry 83 */ 84 ResourceEntry *get(ResourceId id); 85 86 /** 87 * Unloads the resources associated with the id 88 * 89 * @param id The identifier. 90 */ 91 void unload(ResourcePackId id); 92 93 //int count(ResourceId id); 94 getCdNumber()95 int getCdNumber() { return _cdNumber; } setCdNumber(int cdNumber)96 void setCdNumber(int cdNumber) { _cdNumber = cdNumber; } setMusicPackId(ResourcePackId id)97 void setMusicPackId(ResourcePackId id) { _musicPackId = id; } clearSharedSoundCache()98 void clearSharedSoundCache() { _resources.erase(kResourcePackSharedSound); } clearMusicCache()99 void clearMusicCache() { _music.erase(kResourcePackMusic); } 100 101 private: 102 struct ResourcePackId_EqualTo { operatorResourcePackId_EqualTo103 bool operator()(const ResourcePackId &x, const ResourcePackId &y) const { return x == y; } 104 }; 105 106 struct ResourcePackId_Hash { operatorResourcePackId_Hash107 uint operator()(const ResourcePackId &x) const { return x; } 108 }; 109 110 typedef Common::HashMap<ResourcePackId, ResourcePack*, ResourcePackId_Hash, ResourcePackId_EqualTo> ResourceCache; 111 112 ResourceCache _resources; 113 ResourceCache _music; 114 115 int _cdNumber; 116 ResourcePackId _musicPackId; 117 }; 118 119 } // end of namespace Asylum 120 121 #endif // ASYLUM_RESPACK_H 122