ScummVM API documentation
utils.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 NGI_UTILS_H
23
#define NGI_UTILS_H
24
25
#include "common/hash-ptr.h"
26
#include "common/hash-str.h"
27
#include "common/array.h"
28
#include "common/file.h"
29
30
namespace
NGI
{
31
32
class
CObject;
33
class
NGIArchive;
34
35
typedef
Common::HashMap<void *, int>
ObjHash;
36
37
typedef
Common::HashMap<Common::String, int, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>
ClassMap;
38
39
class
MfcArchive
:
public
Common::SeekableReadStream
,
public
Common::WriteStream
{
40
ClassMap _classMap;
41
Common::Array<CObject *>
_objectMap;
42
Common::Array<int>
_objectIdMap;
43
ObjHash _objectHash;
44
45
int
_lastIndex;
46
int
_level;
47
48
Common::SeekableReadStream
*_stream;
49
Common::WriteStream
*_wstream;
50
51
public
:
52
MfcArchive
(
Common::SeekableReadStream
*file);
53
MfcArchive
(
Common::WriteStream
*file);
54
55
Common::String
readPascalString(
bool
twoByte =
false
);
56
void
writePascalString(
const
Common::String
&str,
bool
twoByte =
false
);
57
int
readCount();
58
CObject
*parseClass(
bool
*isCopyReturned);
59
61
template
<
typename
T>
62
T *
readClass
() {
63
CObject
*obj = readBaseClass();
64
if
(!obj)
65
return
nullptr
;
66
67
T *res =
dynamic_cast<
T *
>
(obj);
68
assert(res);
69
return
res;
70
}
71
72
void
writeObject(
CObject
*obj);
73
74
void
incLevel() { _level++; }
75
void
decLevel() { _level--; }
76
int
getLevel() {
return
_level; }
77
78
bool
eos
()
const override
{
return
_stream->
eos
(); }
79
uint32
read
(
void
*dataPtr, uint32 dataSize)
override
{
return
_stream->
read
(dataPtr, dataSize); }
80
int64
pos
()
const override
{
return
_stream ? _stream->
pos
() : _wstream->
pos
(); }
81
int64
size
()
const override
{
return
_stream->
size
(); }
82
bool
seek
(int64 offset,
int
whence = SEEK_SET)
override
{
return
_stream->
seek
(offset, whence); }
83
84
uint32
write
(
const
void
*dataPtr, uint32 dataSize)
override
{
return
_wstream->
write
(dataPtr, dataSize); }
85
86
private
:
87
void
init();
88
CObject
*readBaseClass();
89
};
90
91
enum
ObjType {
92
kObjTypeDefault,
93
kObjTypeExCommand,
94
kObjTypeExCommand2,
95
kObjTypeModalSaveGame,
96
kObjTypeMovGraph,
97
kObjTypeMovGraphLink,
98
kObjTypeMovGraphNode,
99
kObjTypeMctlCompound,
100
kObjTypeObjstateCommand,
101
kObjTypePictureObject,
102
kObjTypeStaticANIObject,
103
kObjTypeGameVar
104
};
105
106
class
CObject
{
107
public
:
108
ObjType _objtype;
109
uint _cnum;
110
111
CObject
() : _objtype(kObjTypeDefault), _cnum(0) {}
112
virtual
bool
load(
MfcArchive
&in) {
return
true
; }
113
virtual
void
save(
MfcArchive
&out) {
error
(
"Not implemented for obj type: %d"
, _objtype); }
114
virtual
~
CObject
() {}
115
116
bool
loadFile(
const
Common::Path
&fname);
117
};
118
119
template
<
class
T>
120
class
ObList
:
public
Common::List
<T *>,
public
CObject
{
121
public
:
122
bool
load(
MfcArchive
&file)
override
{
123
debugC
(5, kDebugLoading,
"ObList::load()"
);
124
int
count = file.readCount();
125
126
debugC
(9, kDebugLoading,
"ObList::count: %d:"
, count);
127
128
for
(
int
i = 0; i < count; i++) {
129
debugC
(9, kDebugLoading,
"ObList::[%d]"
, i);
130
T *t = file.
readClass
<T>();
131
132
this->push_back(t);
133
}
134
135
return
true
;
136
}
137
};
138
139
class
MemoryObject
:
CObject
{
140
friend
class
Picture
;
141
friend
class
Scene
;
142
143
protected
:
144
Common::Path
_memfilename;
145
int
_mfield_8;
146
int
_mfield_C;
147
int
_mfield_10;
148
char
_mfield_14;
149
byte *_data;
150
int
_dataSize;
151
int
_mflags;
152
NGIArchive
*_libHandle;
153
154
public
:
155
MemoryObject
();
156
~
MemoryObject
()
override
;
157
158
bool
load(
MfcArchive
&file)
override
;
159
void
loadFile(
const
Common::Path
&filename);
160
void
load() { loadFile(_memfilename); }
161
byte *getData();
162
byte *loadData();
163
int
getDataSize()
const
{
return
_dataSize; }
164
165
bool
testFlags();
166
167
void
freeData();
168
};
169
170
class
MemoryObject2
:
public
MemoryObject
{
171
friend
class
Picture
;
172
173
protected
:
174
byte **_rows;
175
176
public
:
177
MemoryObject2
();
178
~
MemoryObject2
()
override
;
179
bool
load(
MfcArchive
&file)
override
;
180
181
void
copyData(byte *src,
int
dataSize);
182
};
183
184
class
ObArray
:
public
Common::Array
<CObject>,
public
CObject
{
185
public
:
186
bool
load(
MfcArchive
&file)
override
;
187
};
188
189
class
DWordArray
:
public
Common::Array
<int32>,
public
CObject
{
190
public
:
191
bool
load(
MfcArchive
&file)
override
;
192
};
193
194
Common::Path
genFileName(
int
superId,
int
sceneId,
const
char
*ext);
195
byte *transCyrillic(
const
Common::String
&str);
196
197
}
// End of namespace NGI
198
199
#endif
/* NGI_UTILS_H */
NGI::MfcArchive::read
uint32 read(void *dataPtr, uint32 dataSize) override
Definition:
utils.h:79
Common::SeekableReadStream::size
virtual int64 size() const =0
Common::String
Definition:
str.h:59
NGI::MfcArchive::write
uint32 write(const void *dataPtr, uint32 dataSize) override
Definition:
utils.h:84
NGI::MfcArchive::readClass
T * readClass()
Definition:
utils.h:62
Common::SeekableReadStream::pos
virtual int64 pos() const =0
NGI::ObArray
Definition:
utils.h:184
NGI::MfcArchive
Definition:
utils.h:39
Common::WriteStream
Definition:
stream.h:77
NGI::MfcArchive::pos
int64 pos() const override
Definition:
utils.h:80
Common::Array
Definition:
array.h:52
Common::SeekableReadStream::seek
virtual bool seek(int64 offset, int whence=SEEK_SET)=0
Common::ReadStream::eos
virtual bool eos() const =0
NGI::MfcArchive::size
int64 size() const override
Definition:
utils.h:81
Common::List
Definition:
list.h:44
Common::Path
Definition:
path.h:52
Common::SeekableReadStream
Definition:
stream.h:745
NGI::NGIArchive
Definition:
ngiarchive.h:44
Common::WriteStream::pos
virtual int64 pos() const =0
NGI::Picture
Definition:
gfx.h:80
Common::HashMap< void *, int >
NGI::MfcArchive::seek
bool seek(int64 offset, int whence=SEEK_SET) override
Definition:
utils.h:82
NGI::MfcArchive::eos
bool eos() const override
Definition:
utils.h:78
error
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
NGI::Scene
Definition:
scene.h:32
NGI
Definition:
anihandler.h:25
NGI::ObList
Definition:
utils.h:120
debugC
void void void void void debugC(int level, uint32 debugChannels, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
Common::WriteStream::write
virtual uint32 write(const void *dataPtr, uint32 dataSize)=0
NGI::DWordArray
Definition:
utils.h:189
NGI::MemoryObject
Definition:
utils.h:139
NGI::CObject
Definition:
utils.h:106
NGI::MemoryObject2
Definition:
utils.h:170
Common::ReadStream::read
virtual uint32 read(void *dataPtr, uint32 dataSize)=0
engines
ngi
utils.h
Generated on Sun Dec 22 2024 09:14:26 for ScummVM API documentation by
1.8.13