icculus quake2 doxygen  1.0 dev
qfiles.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 
21 //
22 // qfiles.h: quake file formats
23 // This file must be identical in the quake and utils directories
24 //
25 
26 /*
27 ========================================================================
28 
29 The .pak files are just a linear collapse of a directory tree
30 
31 ========================================================================
32 */
33 
34 #define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
35 
36 typedef struct
37 {
38  char name[56];
39  int filepos, filelen;
40 } dpackfile_t;
41 
42 typedef struct
43 {
44  int ident; // == IDPAKHEADER
45  int dirofs;
46  int dirlen;
48 
49 #define MAX_FILES_IN_PACK 4096
50 
51 
52 /*
53 ========================================================================
54 
55 PCX files are used for as many images as possible
56 
57 ========================================================================
58 */
59 
60 typedef struct
61 {
63  char version;
64  char encoding;
66  unsigned short xmin,ymin,xmax,ymax;
67  unsigned short hres,vres;
68  unsigned char palette[48];
69  char reserved;
71  unsigned short bytes_per_line;
72  unsigned short palette_type;
73  char filler[58];
74  unsigned char data; // unbounded
75 } pcx_t;
76 
77 
78 /*
79 ========================================================================
80 
81 .MD2 triangle model file format
82 
83 ========================================================================
84 */
85 
86 #define IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
87 #define ALIAS_VERSION 8
88 
89 #define MAX_TRIANGLES 4096
90 #define MAX_VERTS 2048
91 #define MAX_FRAMES 512
92 #define MAX_MD2SKINS 32
93 #define MAX_SKINNAME 64
94 
95 typedef struct
96 {
97  short s;
98  short t;
99 } dstvert_t;
100 
101 typedef struct
102 {
103  short index_xyz[3];
104  short index_st[3];
105 } dtriangle_t;
106 
107 typedef struct
108 {
109  byte v[3]; // scaled byte to fit in frame mins/maxs
111 } dtrivertx_t;
112 
113 #define DTRIVERTX_V0 0
114 #define DTRIVERTX_V1 1
115 #define DTRIVERTX_V2 2
116 #define DTRIVERTX_LNI 3
117 #define DTRIVERTX_SIZE 4
118 
119 typedef struct
120 {
121  float scale[3]; // multiply byte verts by this
122  float translate[3]; // then add this
123  char name[16]; // frame name from grabbing
124  dtrivertx_t verts[1]; // variable sized
125 } daliasframe_t;
126 
127 
128 // the glcmd format:
129 // a positive integer starts a tristrip command, followed by that many
130 // vertex structures.
131 // a negative integer starts a trifan command, followed by -x vertexes
132 // a zero indicates the end of the command list.
133 // a vertex consists of a floating point s, a floating point t,
134 // and an integer vertex index.
135 
136 
137 typedef struct
138 {
139  int ident;
140  int version;
141 
144  int framesize; // byte size of each frame
145 
147  int num_xyz;
148  int num_st; // greater than num_xyz for seams
149  int num_tris;
150  int num_glcmds; // dwords in strip/fan command list
152 
153  int ofs_skins; // each skin is a MAX_SKINNAME string
154  int ofs_st; // byte offset from start for stverts
155  int ofs_tris; // offset for dtriangles
156  int ofs_frames; // offset for first frame
158  int ofs_end; // end of file
159 
160 } dmdl_t;
161 
162 /*
163 ========================================================================
164 
165 .SP2 sprite file format
166 
167 ========================================================================
168 */
169 
170 #define IDSPRITEHEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I')
171  // little-endian "IDS2"
172 #define SPRITE_VERSION 2
173 
174 typedef struct
175 {
176  int width, height;
177  int origin_x, origin_y; // raster coordinates inside pic
178  char name[MAX_SKINNAME]; // name of pcx file
179 } dsprframe_t;
180 
181 typedef struct {
182  int ident;
183  int version;
185  dsprframe_t frames[1]; // variable sized
186 } dsprite_t;
187 
188 /*
189 ==============================================================================
190 
191  .WAL texture file format
192 
193 ==============================================================================
194 */
195 
196 
197 #define MIPLEVELS 4
198 typedef struct miptex_s
199 {
200  char name[32];
201  unsigned width, height;
202  unsigned offsets[MIPLEVELS]; // four mip maps stored
203  char animname[32]; // next frame in animation chain
204  int flags;
205  int contents;
206  int value;
207 } miptex_t;
208 
209 
210 
211 /*
212 ==============================================================================
213 
214  .BSP file format
215 
216 ==============================================================================
217 */
218 
219 #define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I')
220  // little-endian "IBSP"
221 
222 #define BSPVERSION 38
223 
224 
225 // upper design bounds
226 // leaffaces, leafbrushes, planes, and verts are still bounded by
227 // 16 bit short limits
228 #define MAX_MAP_MODELS 1024
229 #define MAX_MAP_BRUSHES 8192
230 #define MAX_MAP_ENTITIES 2048
231 #define MAX_MAP_ENTSTRING 0x40000
232 #define MAX_MAP_TEXINFO 8192
233 
234 #define MAX_MAP_AREAS 256
235 #define MAX_MAP_AREAPORTALS 1024
236 #define MAX_MAP_PLANES 65536
237 #define MAX_MAP_NODES 65536
238 #define MAX_MAP_BRUSHSIDES 65536
239 #define MAX_MAP_LEAFS 65536
240 #define MAX_MAP_VERTS 65536
241 #define MAX_MAP_FACES 65536
242 #define MAX_MAP_LEAFFACES 65536
243 #define MAX_MAP_LEAFBRUSHES 65536
244 #define MAX_MAP_PORTALS 65536
245 #define MAX_MAP_EDGES 128000
246 #define MAX_MAP_SURFEDGES 256000
247 #define MAX_MAP_LIGHTING 0x200000
248 #define MAX_MAP_VISIBILITY 0x100000
249 
250 // key / value pair sizes
251 
252 #define MAX_KEY 32
253 #define MAX_VALUE 1024
254 
255 //=============================================================================
256 
257 typedef struct
258 {
259  int fileofs, filelen;
260 } lump_t;
261 
262 #define LUMP_ENTITIES 0
263 #define LUMP_PLANES 1
264 #define LUMP_VERTEXES 2
265 #define LUMP_VISIBILITY 3
266 #define LUMP_NODES 4
267 #define LUMP_TEXINFO 5
268 #define LUMP_FACES 6
269 #define LUMP_LIGHTING 7
270 #define LUMP_LEAFS 8
271 #define LUMP_LEAFFACES 9
272 #define LUMP_LEAFBRUSHES 10
273 #define LUMP_EDGES 11
274 #define LUMP_SURFEDGES 12
275 #define LUMP_MODELS 13
276 #define LUMP_BRUSHES 14
277 #define LUMP_BRUSHSIDES 15
278 #define LUMP_POP 16
279 #define LUMP_AREAS 17
280 #define LUMP_AREAPORTALS 18
281 #define HEADER_LUMPS 19
282 
283 typedef struct
284 {
285  int ident;
286  int version;
288 } dheader_t;
289 
290 typedef struct
291 {
292  float mins[3], maxs[3];
293  float origin[3]; // for sounds or lights
294  int headnode;
295  int firstface, numfaces; // submodels just draw faces
296  // without walking the bsp tree
297 } dmodel_t;
298 
299 
300 typedef struct
301 {
302  float point[3];
303 } dvertex_t;
304 
305 
306 // 0-2 are axial planes
307 #define PLANE_X 0
308 #define PLANE_Y 1
309 #define PLANE_Z 2
310 
311 // 3-5 are non-axial planes snapped to the nearest
312 #define PLANE_ANYX 3
313 #define PLANE_ANYY 4
314 #define PLANE_ANYZ 5
315 
316 // planes (x&~1) and (x&~1)+1 are always opposites
317 
318 typedef struct
319 {
320  float normal[3];
321  float dist;
322  int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
323 } dplane_t;
324 
325 
326 // contents flags are seperate bits
327 // a given brush can contribute multiple content bits
328 // multiple brushes can be in a single leaf
329 
330 // these definitions also need to be in q_shared.h!
331 
332 // lower bits are stronger, and will eat weaker brushes completely
333 #define CONTENTS_SOLID 1 // an eye is never valid in a solid
334 #define CONTENTS_WINDOW 2 // translucent, but not watery
335 #define CONTENTS_AUX 4
336 #define CONTENTS_LAVA 8
337 #define CONTENTS_SLIME 16
338 #define CONTENTS_WATER 32
339 #define CONTENTS_MIST 64
340 #define LAST_VISIBLE_CONTENTS 64
341 
342 // remaining contents are non-visible, and don't eat brushes
343 
344 #define CONTENTS_AREAPORTAL 0x8000
345 
346 #define CONTENTS_PLAYERCLIP 0x10000
347 #define CONTENTS_MONSTERCLIP 0x20000
348 
349 // currents can be added to any other contents, and may be mixed
350 #define CONTENTS_CURRENT_0 0x40000
351 #define CONTENTS_CURRENT_90 0x80000
352 #define CONTENTS_CURRENT_180 0x100000
353 #define CONTENTS_CURRENT_270 0x200000
354 #define CONTENTS_CURRENT_UP 0x400000
355 #define CONTENTS_CURRENT_DOWN 0x800000
356 
357 #define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity
358 
359 #define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game
360 #define CONTENTS_DEADMONSTER 0x4000000
361 #define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs
362 #define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans
363 #define CONTENTS_LADDER 0x20000000
364 
365 
366 
367 #define SURF_LIGHT 0x1 // value will hold the light strength
368 
369 #define SURF_SLICK 0x2 // effects game physics
370 
371 #define SURF_SKY 0x4 // don't draw, but add to skybox
372 #define SURF_WARP 0x8 // turbulent water warp
373 #define SURF_TRANS33 0x10
374 #define SURF_TRANS66 0x20
375 #define SURF_FLOWING 0x40 // scroll towards angle
376 #define SURF_NODRAW 0x80 // don't bother referencing the texture
377 
378 
379 
380 
381 typedef struct
382 {
383  int planenum;
384  int children[2]; // negative numbers are -(leafs+1), not nodes
385  short mins[3]; // for frustom culling
386  short maxs[3];
387  unsigned short firstface;
388  unsigned short numfaces; // counting both sides
389 } dnode_t;
390 
391 
392 typedef struct texinfo_s
393 {
394  float vecs[2][4]; // [s/t][xyz offset]
395  int flags; // miptex flags + overrides
396  int value; // light emission, etc
397  char texture[32]; // texture name (textures/*.wal)
398  int nexttexinfo; // for animations, -1 = end of chain
399 } texinfo_t;
400 
401 
402 // note that edge 0 is never used, because negative edge nums are used for
403 // counterclockwise use of the edge in a face
404 typedef struct
405 {
406  unsigned short v[2]; // vertex numbers
407 } dedge_t;
408 
409 #define MAXLIGHTMAPS 4
410 typedef struct
411 {
412  unsigned short planenum;
413  short side;
414 
415  int firstedge; // we must support > 64k edges
416  short numedges;
417  short texinfo;
418 
419 // lighting info
420  byte styles[MAXLIGHTMAPS];
421  int lightofs; // start of [numstyles*surfsize] samples
422 } dface_t;
423 
424 typedef struct
425 {
426  int contents; // OR of all brushes (not needed?)
427 
428  short cluster;
429  short area;
430 
431  short mins[3]; // for frustum culling
432  short maxs[3];
433 
434  unsigned short firstleafface;
435  unsigned short numleaffaces;
436 
437  unsigned short firstleafbrush;
438  unsigned short numleafbrushes;
439 } dleaf_t;
440 
441 typedef struct
442 {
443  unsigned short planenum; // facing out of the leaf
444  short texinfo;
445 } dbrushside_t;
446 
447 typedef struct
448 {
450  int numsides;
451  int contents;
452 } dbrush_t;
453 
454 #define ANGLE_UP -1
455 #define ANGLE_DOWN -2
456 
457 
458 // the visibility lump consists of a header with a count, then
459 // byte offsets for the PVS and PHS of each cluster, then the raw
460 // compressed bit vectors
461 #define DVIS_PVS 0
462 #define DVIS_PHS 1
463 typedef struct
464 {
466  int bitofs[8][2]; // bitofs[numclusters][2]
467 } dvis_t;
468 
469 // each area has a list of portals that lead into other areas
470 // when portals are closed, other areas may not be visible or
471 // hearable even if the vis info says that it should be
472 typedef struct
473 {
476 } dareaportal_t;
477 
478 typedef struct
479 {
482 } darea_t;
dpackheader_t::dirofs
int dirofs
Definition: qfiles.h:45
dareaportal_t
Definition: qfiles.h:472
dtrivertx_t::lightnormalindex
byte lightnormalindex
Definition: qfiles.h:110
dmdl_t::ofs_glcmds
int ofs_glcmds
Definition: qfiles.h:157
height
GLsizei height
Definition: qgl_win.c:69
dheader_t
Definition: qfiles.h:283
dface_t::numedges
short numedges
Definition: qfiles.h:416
texinfo_s::vecs
float vecs[2][4]
Definition: qfiles.h:394
dnode_t
Definition: qfiles.h:381
miptex_s::name
char name[32]
Definition: qfiles.h:200
darea_t::numareaportals
int numareaportals
Definition: qfiles.h:480
dplane_t
Definition: qfiles.h:318
dbrush_t
Definition: qfiles.h:447
pcx_t
Definition: qfiles.h:60
darea_t::firstareaportal
int firstareaportal
Definition: qfiles.h:481
miptex_s
Definition: qfiles.h:198
dareaportal_t::portalnum
int portalnum
Definition: qfiles.h:474
v
GLdouble v
Definition: qgl_win.c:143
dleaf_t::area
short area
Definition: qfiles.h:429
dmdl_t::num_tris
int num_tris
Definition: qfiles.h:149
dface_t::side
short side
Definition: qfiles.h:413
pcx_t::reserved
char reserved
Definition: qfiles.h:69
pcx_t::data
unsigned char data
Definition: qfiles.h:74
pcx_t::version
char version
Definition: qfiles.h:63
dmodel_t::headnode
int headnode
Definition: qfiles.h:294
dbrushside_t::texinfo
short texinfo
Definition: qfiles.h:444
dpackfile_t
Definition: qfiles.h:36
dstvert_t::s
short s
Definition: qfiles.h:97
dmdl_t::skinheight
int skinheight
Definition: qfiles.h:143
dtrivertx_t
Definition: qfiles.h:107
dvis_t
Definition: qfiles.h:463
dbrush_t::numsides
int numsides
Definition: qfiles.h:450
dplane_t::dist
float dist
Definition: qfiles.h:321
dleaf_t::firstleafface
unsigned short firstleafface
Definition: qfiles.h:434
dnode_t::firstface
unsigned short firstface
Definition: qfiles.h:387
HEADER_LUMPS
#define HEADER_LUMPS
Definition: qfiles.h:281
lump_t::fileofs
int fileofs
Definition: qfiles.h:259
darea_t
Definition: qfiles.h:478
dvertex_t
Definition: qfiles.h:300
dpackheader_t
Definition: qfiles.h:42
dleaf_t::firstleafbrush
unsigned short firstleafbrush
Definition: qfiles.h:437
dmodel_t::numfaces
int numfaces
Definition: qfiles.h:295
dsprite_t
Definition: qfiles.h:181
texinfo_t
struct texinfo_s texinfo_t
dmodel_t
Definition: qfiles.h:290
pcx_t::ymin
unsigned short ymin
Definition: qfiles.h:66
dbrushside_t
Definition: qfiles.h:441
dmdl_t::ofs_end
int ofs_end
Definition: qfiles.h:158
miptex_s::value
int value
Definition: qfiles.h:206
dleaf_t::numleafbrushes
unsigned short numleafbrushes
Definition: qfiles.h:438
miptex_t
struct miptex_s miptex_t
dmdl_t::ofs_frames
int ofs_frames
Definition: qfiles.h:156
dvis_t::numclusters
int numclusters
Definition: qfiles.h:465
dbrush_t::contents
int contents
Definition: qfiles.h:451
dmdl_t::num_glcmds
int num_glcmds
Definition: qfiles.h:150
dstvert_t
Definition: qfiles.h:95
dmdl_t::version
int version
Definition: qfiles.h:140
dedge_t
Definition: qfiles.h:404
dleaf_t::cluster
short cluster
Definition: qfiles.h:428
dareaportal_t::otherarea
int otherarea
Definition: qfiles.h:475
dstvert_t::t
short t
Definition: qfiles.h:98
dmdl_t::num_skins
int num_skins
Definition: qfiles.h:146
dleaf_t::contents
int contents
Definition: qfiles.h:426
dmdl_t::num_xyz
int num_xyz
Definition: qfiles.h:147
dplane_t::type
int type
Definition: qfiles.h:322
miptex_s::contents
int contents
Definition: qfiles.h:205
dmdl_t::ident
int ident
Definition: qfiles.h:139
dmdl_t::framesize
int framesize
Definition: qfiles.h:144
pcx_t::encoding
char encoding
Definition: qfiles.h:64
MIPLEVELS
#define MIPLEVELS
Definition: qfiles.h:197
dbrush_t::firstside
int firstside
Definition: qfiles.h:449
pcx_t::palette_type
unsigned short palette_type
Definition: qfiles.h:72
miptex_s::offsets
unsigned offsets[MIPLEVELS]
Definition: qfiles.h:202
pcx_t::bits_per_pixel
char bits_per_pixel
Definition: qfiles.h:65
dsprframe_t::width
int width
Definition: qfiles.h:176
name
cvar_t * name
Definition: cl_main.c:94
dleaf_t::numleaffaces
unsigned short numleaffaces
Definition: qfiles.h:435
MAXLIGHTMAPS
#define MAXLIGHTMAPS
Definition: qfiles.h:409
dheader_t::ident
int ident
Definition: qfiles.h:285
dsprite_t::ident
int ident
Definition: qfiles.h:182
dbrushside_t::planenum
unsigned short planenum
Definition: qfiles.h:443
dheader_t::version
int version
Definition: qfiles.h:286
texinfo_s
Definition: qfiles.h:392
dface_t::texinfo
short texinfo
Definition: qfiles.h:417
miptex_s::animname
char animname[32]
Definition: qfiles.h:203
miptex_s::flags
int flags
Definition: qfiles.h:204
lump_t
Definition: qfiles.h:257
miptex_s::width
unsigned width
Definition: qfiles.h:201
dsprite_t::numframes
int numframes
Definition: qfiles.h:184
dface_t::firstedge
int firstedge
Definition: qfiles.h:415
dnode_t::numfaces
unsigned short numfaces
Definition: qfiles.h:388
dsprframe_t::origin_y
int origin_y
Definition: qfiles.h:177
daliasframe_t
Definition: qfiles.h:119
dleaf_t
Definition: qfiles.h:424
dface_t
Definition: qfiles.h:410
pcx_t::manufacturer
char manufacturer
Definition: qfiles.h:62
dface_t::lightofs
int lightofs
Definition: qfiles.h:421
MAX_SKINNAME
#define MAX_SKINNAME
Definition: qfiles.h:93
texinfo_s::nexttexinfo
int nexttexinfo
Definition: qfiles.h:398
dmdl_t::ofs_skins
int ofs_skins
Definition: qfiles.h:153
texinfo_s::value
int value
Definition: qfiles.h:396
texinfo_s::texture
char texture[32]
Definition: qfiles.h:397
pcx_t::vres
unsigned short vres
Definition: qfiles.h:67
dsprframe_t
Definition: qfiles.h:174
texinfo_s::flags
int flags
Definition: qfiles.h:395
dmdl_t::skinwidth
int skinwidth
Definition: qfiles.h:142
dsprite_t::version
int version
Definition: qfiles.h:183
dmdl_t::ofs_st
int ofs_st
Definition: qfiles.h:154
dmdl_t::num_st
int num_st
Definition: qfiles.h:148
dmdl_t::ofs_tris
int ofs_tris
Definition: qfiles.h:155
dtriangle_t
Definition: qfiles.h:101
dpackfile_t::filepos
int filepos
Definition: qfiles.h:39
dface_t::planenum
unsigned short planenum
Definition: qfiles.h:412
pcx_t::color_planes
char color_planes
Definition: qfiles.h:70
miptex_s::height
unsigned height
Definition: qfiles.h:201
dmdl_t
Definition: qfiles.h:137
dnode_t::planenum
int planenum
Definition: qfiles.h:383
dmdl_t::num_frames
int num_frames
Definition: qfiles.h:151
dpackheader_t::dirlen
int dirlen
Definition: qfiles.h:46
pcx_t::bytes_per_line
unsigned short bytes_per_line
Definition: qfiles.h:71
dpackheader_t::ident
int ident
Definition: qfiles.h:44