-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmapfile.h
226 lines (189 loc) · 6.89 KB
/
mapfile.h
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#ifndef __MAPFILE_H
#define __MAPFILE_H
#include "byteorder.h"
#define SMALL_TILE_SIZE 680
#define MINIMAP_SIZE 699048
#define MINIMAP_NUM_MIPMAP 9
/*
map file (.smf) layout is like this
MapHeader
ExtraHeader
ExtraHeader
.
.
.
Chunk of data pointed to by header or extra headers
Chunk of data pointed to by header or extra headers
.
.
.
*/
struct MapHeader {
char magic[16]; //"spring map file\0"
int version; //must be 1 for now
int mapid; //sort of a checksum of the file
int mapx; //must be divisible by 128
int mapy; //must be divisible by 128
int squareSize; //distance between vertices. must be 8
int texelPerSquare; //number of texels per square, must be 8 for now
int tilesize; //number of texels in a tile, must be 32 for now
float minHeight; //height value that 0 in the heightmap corresponds to
float maxHeight; //height value that 0xffff in the heightmap corresponds to
int heightmapPtr; //file offset to elevation data (short int[(mapy+1)*(mapx+1)])
int typeMapPtr; //file offset to typedata (unsigned char[mapy/2 * mapx/2])
int tilesPtr; //file offset to tile data (see MapTileHeader)
int minimapPtr; //file offset to minimap (always 1024*1024 dxt1 compresed data with 9 mipmap sublevels)
int metalmapPtr; //file offset to metalmap (unsigned char[mapx/2 * mapy/2])
int featurePtr; //file offset to feature data (see MapFeatureHeader)
int numExtraHeaders; //numbers of extra headers following main header
};
#define READPTR_MAPHEADER(mh,srcptr) \
do { \
unsigned int __tmpdw; \
float __tmpfloat; \
(srcptr)->Read((mh).magic,sizeof((mh).magic)); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).version = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).mapid = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).mapx = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).mapy = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).squareSize = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).texelPerSquare = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).tilesize = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpfloat,sizeof(float)); \
(mh).minHeight = swabfloat(__tmpfloat); \
(srcptr)->Read(&__tmpfloat,sizeof(float)); \
(mh).maxHeight = swabfloat(__tmpfloat); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).heightmapPtr = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).typeMapPtr = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).tilesPtr = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).minimapPtr = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).metalmapPtr = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).featurePtr = (int)swabdword(__tmpdw); \
(srcptr)->Read(&__tmpdw,sizeof(unsigned int)); \
(mh).numExtraHeaders = (int)swabdword(__tmpdw); \
} while (0)
//start of every extra header must look like this, then comes data specific for header type
struct ExtraHeader {
int size; //size of extra header
int type;
};
//defined types for extra headers
#define MEH_None 0
//not sure why this one should be used
#define MEH_Vegetation 1
//this extension contains a offset to an unsigned char[mapx/4 * mapy/4] array that defines ground vegetation, if its missing there is no ground vegetation
//0=none
//1=grass
//rest undefined so far
//some structures used in the chunks of data later in the file
struct MapTileHeader
{
int numTileFiles;
int numTiles;
};
#define READ_MAPTILEHEADER(mth,src) \
do { \
unsigned int __tmpdw; \
(src).Read(&__tmpdw,sizeof(unsigned int)); \
(mth).numTileFiles = swabdword(__tmpdw); \
(src).Read(&__tmpdw,sizeof(unsigned int)); \
(mth).numTiles = swabdword(__tmpdw); \
} while (0)
#define READPTR_MAPTILEHEADER(mth,src) \
do { \
unsigned int __tmpdw; \
(src)->Read(&__tmpdw,sizeof(unsigned int)); \
(mth).numTileFiles = swabdword(__tmpdw); \
(src)->Read(&__tmpdw,sizeof(unsigned int)); \
(mth).numTiles = swabdword(__tmpdw); \
} while (0)
//this is followed by numTileFiles file definition where each file definition is an int followed by a zero terminated file name
//each file defines as many tiles the int indicates with the following files starting where the last one ended
//so if there is 2 files with 100 tiles each the first defines 0-99 and the second 100-199
//after this followes an int[mapx*texelPerSquare/tileSize * mapy*texelPerSquare/tileSize] which is indexes to the defined tiles
struct MapFeatureHeader
{
int numFeatureType;
int numFeatures;
};
#define READ_MAPFEATUREHEADER(mfh,src) \
do { \
unsigned int __tmpdw; \
(src)->Read(&__tmpdw,sizeof(unsigned int)); \
(mfh).numFeatureType = (int)swabdword(__tmpdw); \
(src)->Read(&__tmpdw,sizeof(unsigned int)); \
(mfh).numFeatures = (int)swabdword(__tmpdw); \
} while (0)
//this is followed by numFeatureType zero terminated strings indicating the names of the features in the map
//then follow numFeatures MapFeatureStructs
struct MapFeatureStruct
{
int featureType; //index to one of the strings above
float xpos;
float ypos;
float zpos;
float rotation;
float relativeSize; //not used at the moment keep 1
};
#define READ_MAPFEATURESTRUCT(mfs,src) \
do { \
unsigned int __tmpdw; \
float __tmpfloat; \
(src)->Read(&__tmpdw,sizeof(unsigned int)); \
(mfs).featureType = (int)swabdword(__tmpdw); \
(src)->Read(&__tmpfloat,sizeof(float)); \
(mfs).xpos = swabfloat(__tmpfloat); \
(src)->Read(&__tmpfloat,sizeof(float)); \
(mfs).ypos = swabfloat(__tmpfloat); \
(src)->Read(&__tmpfloat,sizeof(float)); \
(mfs).zpos = swabfloat(__tmpfloat); \
(src)->Read(&__tmpfloat,sizeof(float)); \
(mfs).rotation = swabfloat(__tmpfloat); \
(src)->Read(&__tmpfloat,sizeof(float)); \
(mfs).relativeSize = swabfloat(__tmpfloat); \
} while (0)
/*
map texture tile file (.smt) layout is like this
TileFileHeader
Tiles
.
.
.
*/
struct TileFileHeader
{
char magic[16]; //"spring tilefile\0"
int version; //must be 1 for now
int numTiles; //total number of tiles in this file
int tileSize; //must be 32 for now
int compressionType; //must be 1=dxt1 for now
};
#define READ_TILEFILEHEADER(tfh,src) \
do { \
unsigned int __tmpdw; \
(src).Read(&(tfh).magic,sizeof((tfh).magic)); \
(src).Read(&__tmpdw,sizeof(unsigned int)); \
(tfh).version = (int)swabdword(__tmpdw); \
(src).Read(&__tmpdw,sizeof(unsigned int)); \
(tfh).numTiles = (int)swabdword(__tmpdw); \
(src).Read(&__tmpdw,sizeof(unsigned int)); \
(tfh).tileSize = (int)swabdword(__tmpdw); \
(src).Read(&__tmpdw,sizeof(unsigned int)); \
(tfh).compressionType = (int)swabdword(__tmpdw);\
} while (0)
//this is followed by the raw data for the tiles
//
#endif //ndef __MAPFILE_H