File: resman.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (169 lines) | stat: -rw-r--r-- 4,779 bytes parent folder | download | duplicates (2)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef SWORD1_RESMAN_H
#define SWORD1_RESMAN_H

#include "sword1/memman.h"
#include "sword1/swordres.h"
#include "common/file.h"
#include "sword1/sworddefs.h"
#include "common/endian.h"
#include "common/mutex.h"

namespace Sword1 {

#define MAX_LABEL_SIZE (31+1)

#if defined(__PSP__)
#define MAX_OPEN_CLUS 4 // the PSP can't have more than 8 files open simultaneously
						// since we also need filehandles for music and sometimes savegames
						// set the maximum number of open clusters to 4.
#else
#define MAX_OPEN_CLUS 8 // don't open more than 8 files at once
#endif

struct Grp {
	uint32 noRes;
	MemHandle *resHandle;
	uint32 *offset;
	uint32 *length;
};

struct Clu {
	uint32 refCount;
	Common::File *file;
	char label[MAX_LABEL_SIZE];
	uint32 noGrp;
	Grp *grp;
	Clu *nextOpen;
};

struct Prj {
	uint32 noClu;
	Clu *clu;
};

class ResMan {
public:
	ResMan(const char *fileName, bool isMacFile, bool isKorean);
	~ResMan();
	void flush();
	void resClose(uint32 id);
	void resOpen(uint32 id);
	void *fetchRes(uint32 id);
	void dumpRes(uint32 id);
	void *openFetchRes(uint32 id);
	void *cptResOpen(uint32 id);
	Header *lockScript(uint32 scrID);
	void unlockScript(uint32 scrID);
	FrameHeader *fetchFrame(void *resourceData, uint32 frameNo);

	uint16 getUint16(uint16 value) {
		return (_isBigEndian) ? FROM_BE_16(value) : FROM_LE_16(value);
	}
	uint32 getUint32(uint32 value) {
		return (_isBigEndian) ? FROM_BE_32(value) : FROM_LE_32(value);
	}
	uint16 getLEUint16(uint16 value) {
		return FROM_LE_16(value);
	}
	uint32 getLEUint32(uint32 value) {
		return FROM_LE_32(value);
	}
	uint16 readUint16(const void *ptr) {
		return (_isBigEndian) ? READ_BE_UINT16(ptr) : READ_LE_UINT16(ptr);
	}
	uint32 readUint32(const void *ptr) {
		return (_isBigEndian) ? READ_BE_UINT32(ptr) : READ_LE_UINT32(ptr);
	}
	uint32 readLEUint32(const void *ptr) {
		return READ_LE_UINT32(ptr);
	}
	uint16 toUint16(uint16 value) {
		return (_isBigEndian) ? TO_BE_16(value) : TO_LE_16(value);
	}
	uint32 toUint32(uint32 value) {
		return (_isBigEndian) ? TO_BE_32(value) : TO_LE_32(value);
	}

	uint32 getDeathFontId();

private:
	uint32     resLength(uint32 id);
	MemHandle *resHandle(uint32 id);
	uint32     resOffset(uint32 id);
	Common::File      *resFile(uint32 id);

	void openCptResourceBigEndian(uint32 id);
	void openScriptResourceBigEndian(uint32 id);
	void openCptResourceLittleEndian(uint32 id);
	void openScriptResourceLittleEndian(uint32 id);

	void loadCluDescript(const char *fileName);
	void freeCluDescript();
	Prj _prj;
	MemMan *_memMan;
	static const uint32 _scriptList[TOTAL_SECTIONS];    //a table of resource tags
	Clu *_openCluStart, *_openCluEnd;
	int  _openClus;
	bool _isBigEndian;
	bool _isKorTrs = false;

	Common::Mutex _resourceAccessMutex;

	uint32 _srIdList[29] = {
		// the file numbers differ for the control panel file IDs, so we need this array
		OTHER_SR_FONT,    // SR_FONT
		0x04050000,       // SR_BUTTON
		OTHER_SR_REDFONT, // SR_REDFONT
		0x04050001,       // SR_PALETTE
		0x04050002,       // SR_PANEL_ENGLISH
		0x04050003,       // SR_PANEL_FRENCH
		0x04050004,       // SR_PANEL_GERMAN
		0x04050005,       // SR_PANEL_ITALIAN
		0x04050006,       // SR_PANEL_SPANISH
		0x04050007,       // SR_PANEL_AMERICAN
		0x04050008,       // SR_TEXT_BUTTON
		0x04050009,       // SR_SPEED
		0x0405000A,       // SR_SCROLL1
		0x0405000B,       // SR_SCROLL2
		0x0405000C,       // SR_CONFIRM
		0x0405000D,       // SR_VOLUME
		0x0405000E,       // SR_VLIGHT
		0x0405000F,       // SR_VKNOB
		0x04050010,       // SR_WINDOW
		0x04050011,       // SR_SLAB1
		0x04050012,       // SR_SLAB2
		0x04050013,       // SR_SLAB3
		0x04050014,       // SR_SLAB4
		0x04050015,       // SR_BUTUF
		0x04050016,       // SR_BUTUS
		0x04050017,       // SR_BUTDS
		0x04050018,       // SR_BUTDF
		0x04050019,       // SR_DEATHPANEL
		SR_DEATHFONT,
	};
};

} // End of namespace Sword1

#endif //RESMAN_H