1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/* 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.
*
* $URL$
* $Id$
*
*/
#ifndef M4_RESOURCE_H
#define M4_RESOURCE_H
#include "common/scummsys.h"
#include "common/stream.h"
#include "common/endian.h"
#include "common/file.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/list.h"
#include "common/ptr.h"
/*
TODO:
- change array to HashMap if it turns out to be slow
*/
namespace M4 {
#define MAX_RESOURCES 128
#define kM4MaxFilenameSize 33
enum {
kResourcePurge = 1 << 1
};
class FileSystem {
public:
struct HashHagEntry {
char filename[kM4MaxFilenameSize];
byte fileIndex;
Common::File *hagFile;
};
struct HashFileEntry {
char filename[kM4MaxFilenameSize];
byte hagfile;
uint32 offset, size;
};
FileSystem(const char *hashFilename);
~FileSystem();
Common::SeekableReadStream *loadFile(const char *resourceName, bool preloadFlag);
static void changeExtension(char *destName, const char *sourceName, const char *extension);
const HashFileEntry *getHashFileEntry(const char *filename);
private:
typedef Common::HashMap<Common::String,HashFileEntry,Common::IgnoreCase_Hash,Common::IgnoreCase_EqualTo> FileHashMap;
HashHagEntry _hagEntries[10]; // GLOBAL.HAG and SECTION1.HAG to SECTION9.HAG
FileHashMap _fileEntries;
};
struct Resource {
char name[64];
Common::SeekableReadStream *stream;
uint8 *buffer;
uint8 flags;
};
class ResourceManager {
protected:
typedef Common::List<Common::SharedPtr<Resource> > ResourceList;
typedef ResourceList::iterator ResourceIterator;
ResourceList _resources;
M4Engine *_vm;
virtual Common::SeekableReadStream *loadResource(const char *resourceName, bool loadFlag) = 0;
public:
ResourceManager(M4Engine *vm): _vm(vm) {};
virtual ~ResourceManager();
Common::SeekableReadStream *get(const char *resourceName, bool loadFlag = true);
void toss(const char *resourceName);
void purge();
void dump();
virtual bool resourceExists(const char *resourceName) = 0;
Common::SeekableReadStream *openFile(const char *resourceName) { return get(resourceName, false); }
void changeExtension(char *destName, const char *sourceName, const char *extension) {
FileSystem::changeExtension(destName, sourceName, extension);
}
};
enum ResourceType {RESTYPE_ROOM, RESTYPE_SC, RESTYPE_TEXT, RESTYPE_QUO, RESTYPE_I,
RESTYPE_OB, RESTYPE_FONT, RESTYPE_SOUND, RESTYPE_SPEECH, RESTYPE_HAS_EXT, RESTYPE_NO_EXT};
class MADSResourceManager: public ResourceManager {
private:
ResourceType getResourceType(const char *resourceName);
const char *getResourceFilename(const char *resourceName);
protected:
Common::SeekableReadStream *loadResource(const char *resourceName, bool loadFlag);
public:
MADSResourceManager(M4Engine *vm): ResourceManager(vm) {};
bool resourceExists(const char *resourceName);
};
class M4ResourceManager: public ResourceManager {
protected:
Common::SeekableReadStream *loadResource(const char *resourceName, bool loadFlag);
public:
M4ResourceManager(M4Engine *vm);
~M4ResourceManager();
bool resourceExists(const char *resourceName);
private:
FileSystem *_hfs;
};
} // End of namespace M4
#endif
|