ScummVM API documentation
resman.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 * Additional copyright for this file:
8 * Copyright (C) 1994-1998 Revolution Software Ltd.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef SWORD2_RESMAN_H
25#define SWORD2_RESMAN_H
26
27namespace Common {
28class File;
29}
30
31#define MAX_MEM_CACHE (8 * 1024 * 1024) // we keep up to 8 megs of resource data files in memory
32#define MAX_res_files 20
33
34namespace Sword2 {
35
36class Sword2Engine;
37
38struct Resource {
39 byte *ptr;
40 uint32 size;
41 uint32 refCount;
42 Resource *next, *prev;
43};
44
46 char fileName[20];
47 int32 numEntries;
48 uint32 *entryTab;
49 uint8 cd;
50};
51
53private:
54 Common::File *openCluFile(uint16 fileNum);
55 void readCluIndex(uint16 fileNum, Common::File *file);
56 void removeFromCacheList(Resource *res);
57 void addToCacheList(Resource *res);
58 void checkMemUsage();
59
60 Sword2Engine *_vm;
61
62 int _curCD;
63 uint32 _totalResFiles;
64 uint32 _totalClusters;
65
66 // Gode generated res-id to res number/rel number conversion table
67
68 uint16 *_resConvTable;
69 ResourceFile _resFiles[MAX_res_files];
70 Resource *_resList;
71
72 Resource *_cacheStart, *_cacheEnd;
73 uint32 _usedMem; // amount of used memory in bytes
74
75public:
76 ResourceManager(Sword2Engine *vm); // read in the config file
78
79 bool init();
80
81 uint32 getNumResFiles() { return _totalResFiles; }
82 uint32 getNumClusters() { return _totalClusters; }
83 ResourceFile *getResFiles() { return _resFiles; }
84 Resource *getResList() { return _resList; }
85
86 byte *openResource(uint32 res, bool dump = false);
87 void closeResource(uint32 res);
88
89 bool checkValid(uint32 res);
90 uint32 fetchLen(uint32 res);
91 uint8 fetchType(byte *ptr);
92 uint8 fetchType(uint32 res) {
93 byte *ptr = openResource(res);
94 uint8 type = fetchType(ptr);
95 closeResource(res);
96
97 return type;
98 }
99
100 byte *fetchName(uint32 res, byte *buf = nullptr) {
101 static byte tempbuf[NAME_LEN];
102
103 if (!buf)
104 buf = tempbuf;
105
106 byte *ptr = openResource(res);
107 memcpy(buf, ptr + 10, NAME_LEN);
108 closeResource(res);
109
110 return buf;
111 }
112
113 byte *fetchName(byte *ptr) {
114 return ptr + 10;
115 }
116
117 // Prompts the user for the specified CD.
118 void askForCD(int cd);
119
120 void setCD(int cd) {
121 if (cd)
122 _curCD = cd;
123 }
124
125 int getCD() {
126 return _curCD;
127 }
128
129 void remove(int res);
130 void removeAll();
131
132 // ----console commands
133
134 void killAll(bool wantInfo);
135 void killAllObjects(bool wantInfo);
136};
137
138} // End of namespace Sword2
139
140#endif
Definition: file.h:47
Definition: resman.h:52
Definition: sword2.h:99
Definition: algorithm.h:29
Definition: animation.h:37
Definition: resman.h:45
Definition: resman.h:38