ScummVM API documentation
resourceman.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 NEVERHOOD_RESOURCEMAN_H
23#define NEVERHOOD_RESOURCEMAN_H
24
25#include "common/array.h"
26#include "common/file.h"
27#include "common/hashmap.h"
28#include "neverhood/neverhood.h"
29#include "neverhood/blbarchive.h"
30#include "neverhood/nhcarchive.h"
31
32namespace Neverhood {
33
34class ResourceMan;
35struct ResourceHandle;
36
38private:
39 int resourceHandle;
40 BlbArchive *archive;
41 BlbArchiveEntry *archiveEntry;
42
43 NhcArchive *nhcArchive;
44 NhcArchiveEntry *nhcArchiveEntry;
45
46 friend struct ResourceHandle;
47 friend class ResourceMan;
48
49public:
50 ResourceFileEntry() : resourceHandle(-1), archive(nullptr), archiveEntry(nullptr), nhcArchive(nullptr), nhcArchiveEntry(nullptr) {}
51};
52
53struct Resource {
54 ResourceFileEntry *entry;
55 int useRefCount;
56};
57
59 byte *data;
60 int dataRefCount;
61 ResourceData() : data(NULL), dataRefCount() {}
62};
63
65friend class ResourceMan;
66public:
69 bool isValid() const { return _resourceFileEntry != NULL
70 && (_resourceFileEntry->archiveEntry != NULL
71 || (_resourceFileEntry->nhcArchiveEntry != NULL && _resourceFileEntry->nhcArchiveEntry->isNormal())); }
72 byte type() const {
73 if (_resourceFileEntry == NULL)
74 return 0;
75 if (_resourceFileEntry->nhcArchiveEntry != NULL && _resourceFileEntry->nhcArchiveEntry->isNormal())
76 return _resourceFileEntry->nhcArchiveEntry->type;
77 if (_resourceFileEntry->archiveEntry != NULL)
78 return _resourceFileEntry->archiveEntry->type;
79 return 0;
80 }
81 const byte *data() const { return _data; }
82 uint32 size() const {
83 if (_resourceFileEntry == NULL)
84 return 0;
85 if (_resourceFileEntry->nhcArchiveEntry != NULL && _resourceFileEntry->nhcArchiveEntry->isNormal())
86 return _resourceFileEntry->nhcArchiveEntry->size;
87 if (_resourceFileEntry->archiveEntry != NULL)
88 return _resourceFileEntry->archiveEntry->size;
89 return 0;
90 }
91 const byte *extData() const { return _extData; }
92 uint32 fileHash() const {
93 if (_resourceFileEntry == NULL)
94 return 0;
95 if (_resourceFileEntry->nhcArchiveEntry != NULL && _resourceFileEntry->nhcArchiveEntry->isNormal())
96 return _resourceFileEntry->nhcArchiveEntry->fileHash;
97 if (_resourceFileEntry->archiveEntry != NULL)
98 return _resourceFileEntry->archiveEntry->fileHash;
99 return 0;
100 }
101protected:
102 ResourceFileEntry *_resourceFileEntry;
103 const byte *_extData;
104 const byte *_data;
105};
106
108public:
109 ResourceMan();
110 ~ResourceMan();
111 void addArchive(const Common::Path &filename, bool isOptional = false);
112 bool addNhcArchive(const Common::Path &filename);
113 ResourceFileEntry *findEntrySimple(uint32 fileHash);
114 ResourceFileEntry *findEntry(uint32 fileHash, ResourceFileEntry **firstEntry = NULL);
115 Common::SeekableReadStream *createStream(uint32 fileHash);
116 Common::SeekableReadStream *createNhcStream(uint32 fileHash, uint32 type);
117 bool nhcExists(uint32 fileHash, uint32 type);
118 bool exists(uint32 fileHash);
119 const ResourceFileEntry& getEntry(uint index) { return _entries[index]; }
120 uint getEntryCount() { return _entries.size(); }
121 void queryResource(uint32 fileHash, ResourceHandle &resourceHandle);
122 void loadResource(ResourceHandle &resourceHandle, bool applyResourceFixes);
123 void unloadResource(ResourceHandle &resourceHandle);
124 void purgeResources();
125protected:
128 Common::Array<NhcArchive*> _nhcArchives;
129 EntriesMap _entries;
131 Common::Array<Resource*> _resources;
132};
133
134} // End of namespace Neverhood
135
136#endif /* NEVERHOOD_RESOURCEMAN_H */
Definition: array.h:52
Definition: path.h:52
Definition: stream.h:745
Definition: blbarchive.h:53
Definition: nhcarchive.h:48
Definition: resourceman.h:37
Definition: resourceman.h:107
Definition: blbarchive.h:42
Definition: nhcarchive.h:34
Definition: resourceman.h:58
Definition: resourceman.h:64
Definition: resourceman.h:53