ScummVM API documentation
respack.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ASYLUM_RESPACK_H
23 #define ASYLUM_RESPACK_H
24 
25 #include "common/array.h"
26 #include "common/file.h"
27 #include "common/hashmap.h"
28 
29 #include "asylum/asylum.h"
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 
41  ResourceEntry() {
42  data = NULL;
43  size = 0;
44  offset = 0;
45  }
46 
47  uint32 getData(uint32 off) {
48  if (data == NULL)
49  error("[ResourceEntry::getData] Invalid data");
50 
51  return READ_LE_UINT32(data + off);
52  }
53 };
54 
55 class ResourcePack {
56 public:
57  ResourceEntry *get(uint16 index);
58 
59 protected:
60  ResourcePack(const Common::Path &filename);
61  ~ResourcePack();
62 
63 private:
65  Common::File _packFile;
66 
67  void init(const Common::Path &filename);
68 
69  friend class ResourceManager;
70 };
71 
73 public:
75  ~ResourceManager();
76 
84  ResourceEntry *get(ResourceId id);
85 
91  void unload(ResourcePackId id);
92 
93  //int count(ResourceId id);
94 
95  int getCdNumber() { return _cdNumber; }
96  void setCdNumber(int cdNumber) { _cdNumber = cdNumber; }
97  void setMusicPackId(ResourcePackId id) { _musicPackId = id; }
98  void clearSharedSoundCache() { _resources.erase(kResourcePackSharedSound); }
99  void clearMusicCache() { _music.erase(kResourcePackMusic); }
100 
101 private:
102  struct ResourcePackId_EqualTo {
103  bool operator()(const ResourcePackId &x, const ResourcePackId &y) const { return x == y; }
104  };
105 
106  struct ResourcePackId_Hash {
107  uint operator()(const ResourcePackId &x) const { return x; }
108  };
109 
111 
112  ResourceCache _resources;
113  ResourceCache _music;
114 
115  int _cdNumber;
116  ResourcePackId _musicPackId;
117  AsylumEngine *_vm;
118 };
119 
120 } // end of namespace Asylum
121 
122 #endif // ASYLUM_RESPACK_H
Definition: array.h:52
Definition: asylum.h:53
Definition: path.h:52
Definition: respack.h:36
Definition: file.h:47
Definition: asylum.h:70
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: respack.h:55
Definition: respack.h:72