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;
47 } dpackheader_t;
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 {
62     char	manufacturer;
63     char	version;
64     char	encoding;
65     char	bits_per_pixel;
66     unsigned short	xmin,ymin,xmax,ymax;
67     unsigned short	hres,vres;
68     unsigned char	palette[48];
69     char	reserved;
70     char	color_planes;
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 	float s;
104 	float t;
105 } fstvert_t;
106 
107 typedef struct
108 {
109 	short	index_xyz[3];
110 	short	index_st[3];
111 } dtriangle_t;
112 
113 typedef struct
114 {
115 	byte	v[3];			// scaled byte to fit in frame mins/maxs
116 	byte	lightnormalindex;
117 } dtrivertx_t;
118 
119 #define DTRIVERTX_V0   0
120 #define DTRIVERTX_V1   1
121 #define DTRIVERTX_V2   2
122 #define DTRIVERTX_LNI  3
123 #define DTRIVERTX_SIZE 4
124 
125 typedef struct
126 {
127 	float		scale[3];	// multiply byte verts by this
128 	float		translate[3];	// then add this
129 	char		name[16];	// frame name from grabbing
130 	dtrivertx_t	verts[1];	// variable sized
131 } daliasframe_t;
132 
133 
134 // the glcmd format:
135 // a positive integer starts a tristrip command, followed by that many
136 // vertex structures.
137 // a negative integer starts a trifan command, followed by -x vertexes
138 // a zero indicates the end of the command list.
139 // a vertex consists of a floating point s, a floating point t,
140 // and an integer vertex index.
141 
142 
143 typedef struct
144 {
145 	int			ident;
146 	int			version;
147 
148 	int			skinwidth;
149 	int			skinheight;
150 	int			framesize;		// byte size of each frame
151 
152 	int			num_skins;
153 	int			num_xyz;
154 	int			num_st;			// greater than num_xyz for seams
155 	int			num_tris;
156 	int			num_glcmds;		// dwords in strip/fan command list
157 	int			num_frames;
158 
159 	int			ofs_skins;		// each skin is a MAX_SKINNAME string
160 	int			ofs_st;			// byte offset from start for stverts
161 	int			ofs_tris;		// offset for dtriangles
162 	int			ofs_frames;		// offset for first frame
163 	int			ofs_glcmds;
164 	int			ofs_end;		// end of file
165 
166 } dmdl_t;
167 
168 /*
169 ==============================================================================
170 
171   .WAL texture file format
172 
173 ==============================================================================
174 */
175 
176 
177 #define	MIPLEVELS	4
178 typedef struct miptex_s
179 {
180 	char		name[32];
181 	unsigned	width, height;
182 	unsigned	offsets[MIPLEVELS];		// four mip maps stored
183 	char		animname[32];			// next frame in animation chain
184 	int			flags;
185 	int			contents;
186 	int			value;
187 } miptex_t;
188 
189 
190 
191 /*
192 ==============================================================================
193 
194   .BSP file format
195 
196 ==============================================================================
197 */
198 
199 #define IDBSPHEADER	(('P'<<24)+('S'<<16)+('B'<<8)+'I')
200 		// little-endian "IBSP"
201 
202 #define BSPVERSION	38
203 
204 
205 // upper design bounds
206 // leaffaces, leafbrushes, planes, and verts are still bounded by
207 // 16 bit short limits
208 #define	MAX_MAP_MODELS		1024
209 #define	MAX_MAP_BRUSHES		8192
210 #define	MAX_MAP_ENTITIES	2048
211 #define	MAX_MAP_ENTSTRING	0x40000
212 #define	MAX_MAP_TEXINFO		8192
213 
214 #define	MAX_MAP_AREAS		256
215 #define	MAX_MAP_AREAPORTALS	1024
216 #define	MAX_MAP_PLANES		65536
217 #define	MAX_MAP_NODES		65536
218 #define	MAX_MAP_BRUSHSIDES	65536
219 #define	MAX_MAP_LEAFS		65536
220 #define	MAX_MAP_VERTS		65536
221 #define	MAX_MAP_FACES		65536
222 #define	MAX_MAP_LEAFFACES	65536
223 #define	MAX_MAP_LEAFBRUSHES 65536
224 #define	MAX_MAP_PORTALS		65536
225 #define	MAX_MAP_EDGES		128000
226 #define	MAX_MAP_SURFEDGES	256000
227 #define	MAX_MAP_LIGHTING	0x200000
228 #define	MAX_MAP_VISIBILITY	0x100000
229 
230 // key / value pair sizes
231 
232 #define	MAX_KEY		32
233 #define	MAX_VALUE	1024
234 
235 //=============================================================================
236 
237 typedef struct
238 {
239 	int		fileofs, filelen;
240 } lump_t;
241 
242 #define	LUMP_ENTITIES		0
243 #define	LUMP_PLANES			1
244 #define	LUMP_VERTEXES		2
245 #define	LUMP_VISIBILITY		3
246 #define	LUMP_NODES			4
247 #define	LUMP_TEXINFO		5
248 #define	LUMP_FACES			6
249 #define	LUMP_LIGHTING		7
250 #define	LUMP_LEAFS			8
251 #define	LUMP_LEAFFACES		9
252 #define	LUMP_LEAFBRUSHES	10
253 #define	LUMP_EDGES			11
254 #define	LUMP_SURFEDGES		12
255 #define	LUMP_MODELS			13
256 #define	LUMP_BRUSHES		14
257 #define	LUMP_BRUSHSIDES		15
258 #define	LUMP_POP			16
259 #define	LUMP_AREAS			17
260 #define	LUMP_AREAPORTALS	18
261 #define	HEADER_LUMPS		19
262 
263 typedef struct
264 {
265 	int			ident;
266 	int			version;
267 	lump_t		lumps[HEADER_LUMPS];
268 } dheader_t;
269 
270 qboolean checkLumps (lump_t *l, size_t header_size, int *lump_order, void *_file_base, int num_lumps, int file_len);
271 
272 typedef struct
273 {
274 	float		mins[3], maxs[3];
275 	float		origin[3];		// for sounds or lights
276 	int			headnode;
277 	int			firstface, numfaces;	// submodels just draw faces
278 										// without walking the bsp tree
279 } dmodel_t;
280 
281 
282 typedef struct
283 {
284 	float	point[3];
285 } dvertex_t;
286 
287 
288 // 0-2 are axial planes
289 #define	PLANE_X			0
290 #define	PLANE_Y			1
291 #define	PLANE_Z			2
292 
293 // 3-5 are non-axial planes snapped to the nearest
294 #define	PLANE_ANYX		3
295 #define	PLANE_ANYY		4
296 #define	PLANE_ANYZ		5
297 
298 // planes (x&~1) and (x&~1)+1 are always opposites
299 
300 typedef struct
301 {
302 	float	normal[3];
303 	float	dist;
304 	int		type;		// PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
305 } dplane_t;
306 
307 
308 // contents flags are seperate bits
309 // a given brush can contribute multiple content bits
310 // multiple brushes can be in a single leaf
311 
312 // these definitions also need to be in q_shared.h!
313 
314 // lower bits are stronger, and will eat weaker brushes completely
315 #define	CONTENTS_SOLID			1		// an eye is never valid in a solid
316 #define	CONTENTS_WINDOW			2		// translucent, but not watery
317 #define	CONTENTS_AUX			4
318 #define	CONTENTS_LAVA			8
319 #define	CONTENTS_SLIME			16
320 #define	CONTENTS_WATER			32
321 #define	CONTENTS_MIST			64
322 #define	LAST_VISIBLE_CONTENTS	64
323 
324 // remaining contents are non-visible, and don't eat brushes
325 
326 #define	CONTENTS_AREAPORTAL		0x8000
327 
328 #define	CONTENTS_PLAYERCLIP		0x10000
329 #define	CONTENTS_MONSTERCLIP	0x20000
330 
331 // currents can be added to any other contents, and may be mixed
332 #define	CONTENTS_CURRENT_0		0x40000
333 #define	CONTENTS_CURRENT_90		0x80000
334 #define	CONTENTS_CURRENT_180	0x100000
335 #define	CONTENTS_CURRENT_270	0x200000
336 #define	CONTENTS_CURRENT_UP		0x400000
337 #define	CONTENTS_CURRENT_DOWN	0x800000
338 
339 #define	CONTENTS_ORIGIN			0x1000000	// removed before bsping an entity
340 
341 #define	CONTENTS_MONSTER		0x2000000	// should never be on a brush, only in game
342 #define	CONTENTS_DEADMONSTER	0x4000000
343 #define	CONTENTS_DETAIL			0x8000000	// brushes to be added after vis leafs
344 #define	CONTENTS_TRANSLUCENT	0x10000000	// auto set if any surface has trans
345 #define	CONTENTS_LADDER			0x20000000
346 
347 
348 
349 #define	SURF_LIGHT		0x1		// value will hold the light strength
350 
351 #define	SURF_SLICK		0x2		// effects game physics
352 
353 #define	SURF_SKY		0x4		// don't draw, but add to skybox
354 #define	SURF_WARP		0x8		// turbulent water warp
355 #define	SURF_TRANS33	0x10
356 #define	SURF_TRANS66	0x20
357 #define	SURF_FLOWING	0x40	// scroll towards angle
358 #define	SURF_NODRAW		0x80	// don't bother referencing the texture
359 #define SURF_BLOOD		0x400	// dripping blood surface
360 #define SURF_WATER		0x800	// dripping water surface
361 #define SURF_SHINY		0x1000  // shiny wet surface
362 #define SURF_UNDERWATER	0x2000	// reflecting ripples; applied automatically
363 								// to underwater surfs but could be applied
364 								// manually as well
365 
366 typedef struct
367 {
368 	int			planenum;
369 	int			children[2];	// negative numbers are -(leafs+1), not nodes
370 	short		mins[3];		// for frustum culling
371 	short		maxs[3];
372 	unsigned short	firstface;
373 	unsigned short	numfaces;	// counting both sides
374 } dnode_t;
375 
376 
377 typedef struct texinfo_s
378 {
379 	float		vecs[2][4];		// [s/t][xyz offset]
380 	int			flags;			// miptex flags + overrides
381 	int			value;			// light emission, etc
382 	char		texture[32];	// texture name (textures/*.wal)
383 	int			nexttexinfo;	// for animations, -1 = end of chain
384 } texinfo_t;
385 
386 
387 // note that edge 0 is never used, because negative edge nums are used for
388 // counterclockwise use of the edge in a face
389 typedef struct
390 {
391 	unsigned short	v[2];		// vertex numbers
392 } dedge_t;
393 
394 #define	MAXLIGHTMAPS	4
395 typedef struct
396 {
397 	unsigned short	planenum;
398 	short		side;
399 
400 	int			firstedge;		// we must support > 64k edges
401 	short		numedges;
402 	short		texinfo;
403 
404 // lighting info
405 	byte		styles[MAXLIGHTMAPS];
406 	int			lightofs;		// start of [numstyles*surfsize] samples
407 } dface_t;
408 
409 typedef struct
410 {
411 	int				contents;			// OR of all brushes (not needed?)
412 
413 	short			cluster;
414 	short			area;
415 
416 	short			mins[3];			// for frustum culling
417 	short			maxs[3];
418 
419 	unsigned short	firstleafface;
420 	unsigned short	numleaffaces;
421 
422 	unsigned short	firstleafbrush;
423 	unsigned short	numleafbrushes;
424 } dleaf_t;
425 
426 typedef struct
427 {
428 	unsigned short	planenum;		// facing out of the leaf
429 	short	texinfo;
430 } dbrushside_t;
431 
432 typedef struct
433 {
434 	int			firstside;
435 	int			numsides;
436 	int			contents;
437 } dbrush_t;
438 
439 #define	ANGLE_UP	-1
440 #define	ANGLE_DOWN	-2
441 
442 
443 // the visibility lump consists of a header with a count, then
444 // byte offsets for the PVS and PHS of each cluster, then the raw
445 // compressed bit vectors
446 #define	DVIS_PVS	0
447 #define	DVIS_PHS	1
448 typedef struct
449 {
450 	int			numclusters;
451 	int			bitofs[8][2];	// bitofs[numclusters][2]
452 } dvis_t;
453 
454 // each area has a list of portals that lead into other areas
455 // when portals are closed, other areas may not be visible or
456 // hearable even if the vis info says that it should be
457 typedef struct
458 {
459 	int		portalnum;
460 	int		otherarea;
461 } dareaportal_t;
462 
463 typedef struct
464 {
465 	int		numareaportals;
466 	int		firstareaportal;
467 } darea_t;
468 
469 // FOR REFINE
470 
471 #define MAX_OVERRIDE_LIGHTING	0x6000000	//2048*2048*8*3
472 
473 // little-endian "LTMP" for "lightmap"
474 #define IDLIGHTMAPHEADER	(('P'<<24)+('M'<<16)+('T'<<8)+'L')
475 // Increase this number whenever incompatible changes are made to the file
476 // format
477 #define LTMPVERSION			2
478 // Increase this number whenever backwards-compatible changes are made to the
479 // file format
480 #define LTMPVERSION_MINOR	0
481 
482 #define LTMP_LUMP_FACELOOKUP	0
483 #define LTMP_LUMP_LIGHTING		1
484 #define LTMP_LUMPS				2
485 
486 // Each override has its own pixel format. Currently, the only one is 24-bit
487 // RGB, but we may eventually add S3TC/ASTC formats as well.
488 #define LTMP_PIXFMT_RGB24			0
489 #define LTMP_NUM_SUPPORTED_PIXFMTS	1
490 
491 // Current versions of the client will refuse to open lightmap files with more
492 // data than this. However, current versions of the map compiler will refuse
493 // to create files anywhere near this big, and the client has other, stricter
494 // restrictions on how much lightmap data it will actually use.
495 #define LTMP_MAX_UNCOMPRESSED_DATA (\
496 	sizeof(lightmapheader_t)+\
497 	sizeof(ltmp_facelookup_t)*MAX_MAP_FACES*4+\
498 	MAX_OVERRIDE_LIGHTING*4+16\
499 )
500 
501 typedef struct
502 {
503 	int			ident;
504 	int			version;
505 	int			version_minor;
506 	lump_t		lumps[LTMP_LUMPS];
507 } lightmapheader_t;
508 
509 // There may be zero or more of these for each surface (maximum total number
510 // of these is four times the maximum number of surfaces.) The client is
511 // responsible for picking which if any to use for each surface. Current
512 // behavior of the client is to skip any pixel formats it doesn't understand,
513 // and otherwise pick the last one in the list for each surface. However, that
514 // behavior may change arbitrarily in the future.
515 typedef struct
516 {
517 	int			offset;		// an offset in LTMP_LUMP_LIGHTING, starting at 1
518 	int			facenum;	// the face being overridden by this entry,
519 							// starting at 0
520 	int			format;		// currently only LTMP_PIXFMT_RGB24
521 	// qrad3 may output different hights/widths for each face at some point in
522 	// the future
523 	int			width;		// width in pixels
524 	int			height;	 	// height in pixels
525 	// qrad3 may output heights scaled differently from widths at some point
526 	// in the future
527 	float		xscale;     // xscale in game units per lightmap pixel
528 	float		yscale;		// yscale in game units per lightmap pixel
529 } ltmp_facelookup_t;
530