Debian Codegraph @

code/qcommon/qfiles.h

raw
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, 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 Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 #ifndef __QFILES_H__
23 #define __QFILES_H__
24
25 //
26 // qfiles.h: quake file formats
27 // This file must be identical in the quake and utils directories
28 //
29
30 //Ignore __attribute__ on non-gcc platforms
31 #ifndef __GNUC__
32 #ifndef __attribute__
33 #define __attribute__(x)
34 #endif
35 #endif
36
37 // surface geometry should not exceed these limits
38 #define SHADER_MAX_VERTEXES 1000
39 #define SHADER_MAX_INDEXES (6*SHADER_MAX_VERTEXES)
40
41
42 // the maximum size of game relative pathnames
43 #define MAX_QPATH 64
44
45 /*
46 ========================================================================
47
48 QVM files
49
50 ========================================================================
51 */
52
53 #define VM_MAGIC 0x12721444
54 #define VM_MAGIC_VER2 0x12721445
55 typedef struct {
56 int vmMagic;
57
58 int instructionCount;
59
60 int codeOffset;
61 int codeLength;
62
63 int dataOffset;
64 int dataLength;
65 int litLength; // ( dataLength - litLength ) should be byteswapped on load
66 int bssLength; // zero filled memory appended to datalength
67
68 //!!! below here is VM_MAGIC_VER2 !!!
69 int jtrgLength; // number of jump table targets
70 } vmHeader_t;
71
72 /*
73 ========================================================================
74
75 .MD3 triangle model file format
76
77 ========================================================================
78 */
79
80 #define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
81 #define MD3_VERSION 15
82
83 // limits
84 #define MD3_MAX_LODS 3
85 #define MD3_MAX_TRIANGLES 8192 // per surface
86 #define MD3_MAX_VERTS 4096 // per surface
87 #define MD3_MAX_SHADERS 256 // per surface
88 #define MD3_MAX_FRAMES 1024 // per model
89 #define MD3_MAX_SURFACES 32 // per model
90 #define MD3_MAX_TAGS 16 // per frame
91
92 // vertex scales
93 #define MD3_XYZ_SCALE (1.0/64)
94
95 typedef struct md3Frame_s {
96 vec3_t bounds[2];
97 vec3_t localOrigin;
98 float radius;
99 char name[16];
100 } md3Frame_t;
101
102 typedef struct md3Tag_s {
103 char name[MAX_QPATH]; // tag name
104 vec3_t origin;
105 vec3_t axis[3];
106 } md3Tag_t;
107
108 /*
109 ** md3Surface_t
110 **
111 ** CHUNK SIZE
112 ** header sizeof( md3Surface_t )
113 ** shaders sizeof( md3Shader_t ) * numShaders
114 ** triangles[0] sizeof( md3Triangle_t ) * numTriangles
115 ** st sizeof( md3St_t ) * numVerts
116 ** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames
117 */
118 typedef struct {
119 int ident; //
120
121 char name[MAX_QPATH]; // polyset name
122
123 int flags;
124 int numFrames; // all surfaces in a model should have the same
125
126 int numShaders; // all surfaces in a model should have the same
127 int numVerts;
128
129 int numTriangles;
130 int ofsTriangles;
131
132 int ofsShaders; // offset from start of md3Surface_t
133 int ofsSt; // texture coords are common for all frames
134 int ofsXyzNormals; // numVerts * numFrames
135
136 int ofsEnd; // next surface follows
137 } md3Surface_t;
138
139 typedef struct {
140 char name[MAX_QPATH];
141 int shaderIndex; // for in-game use
142 } md3Shader_t;
143
144 typedef struct {
145 int indexes[3];
146 } md3Triangle_t;
147
148 typedef struct {
149 float st[2];
150 } md3St_t;
151
152 typedef struct {
153 short xyz[3];
154 short normal;
155 } md3XyzNormal_t;
156
157 typedef struct {
158 int ident;
159 int version;
160
161 char name[MAX_QPATH]; // model name
162
163 int flags;
164
165 int numFrames;
166 int numTags;
167 int numSurfaces;
168
169 int numSkins;
170
171 int ofsFrames; // offset for first frame
172 int ofsTags; // numFrames * numTags
173 int ofsSurfaces; // first surface, others follow
174
175 int ofsEnd; // end of file
176 } md3Header_t;
177
178 /*
179 ==============================================================================
180
181 MD4 file format
182
183 ==============================================================================
184 */
185
186 #define MD4_IDENT (('4'<<24)+('P'<<16)+('D'<<8)+'I')
187 #define MD4_VERSION 1
188 #define MD4_MAX_BONES 128
189
190 typedef struct {
191 int boneIndex; // these are indexes into the boneReferences,
192 float boneWeight; // not the global per-frame bone list
193 vec3_t offset;
194 } md4Weight_t;
195
196 typedef struct {
197 vec3_t normal;
198 vec2_t texCoords;
199 int numWeights;
200 md4Weight_t weights[1]; // variable sized
201 } md4Vertex_t;
202
203 typedef struct {
204 int indexes[3];
205 } md4Triangle_t;
206
207 typedef struct {
208 int ident;
209
210 char name[MAX_QPATH]; // polyset name
211 char shader[MAX_QPATH];
212 int shaderIndex; // for in-game use
213
214 int ofsHeader; // this will be a negative number
215
216 int numVerts;
217 int ofsVerts;
218
219 int numTriangles;
220 int ofsTriangles;
221
222 // Bone references are a set of ints representing all the bones
223 // present in any vertex weights for this surface. This is
224 // needed because a model may have surfaces that need to be
225 // drawn at different sort times, and we don't want to have
226 // to re-interpolate all the bones for each surface.
227 int numBoneReferences;
228 int ofsBoneReferences;
229
230 int ofsEnd; // next surface follows
231 } md4Surface_t;
232
233 typedef struct {
234 float matrix[3][4];
235 } md4Bone_t;
236
237 typedef struct {
238 vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame
239 vec3_t localOrigin; // midpoint of bounds, used for sphere cull
240 float radius; // dist from localOrigin to corner
241 md4Bone_t bones[1]; // [numBones]
242 } md4Frame_t;
243
244 typedef struct {
245 int numSurfaces;
246 int ofsSurfaces; // first surface, others follow
247 int ofsEnd; // next lod follows
248 } md4LOD_t;
249
250 typedef struct {
251 int ident;
252 int version;
253
254 char name[MAX_QPATH]; // model name
255
256 // frames and bones are shared by all levels of detail
257 int numFrames;
258 int numBones;
259 int ofsBoneNames; // char name[ MAX_QPATH ]
260 int ofsFrames; // md4Frame_t[numFrames]
261
262 // each level of detail has completely separate sets of surfaces
263 int numLODs;
264 int ofsLODs;
265
266 int ofsEnd; // end of file
267 } md4Header_t;
268
269 /*
270 * Here are the definitions for Ravensoft's model format of md4. Raven stores their
271 * playermodels in .mdr files, in some games, which are pretty much like the md4
272 * format implemented by ID soft. It seems like ID's original md4 stuff is not used at all.
273 * MDR is being used in EliteForce, JediKnight2 and Soldiers of Fortune2 (I think).
274 * So this comes in handy for anyone who wants to make it possible to load player
275 * models from these games.
276 * This format has bone tags, which is similar to the thing you have in md3 I suppose.
277 * Raven has released their version of md3view under GPL enabling me to add support
278 * to this codebase. Thanks to Steven Howes aka Skinner for helping with example
279 * source code.
280 *
281 * - Thilo Schulz ([email protected])
282 */
283
284 // If you want to enable support for Raven's .mdr / md4 format, uncomment the next
285 // line.
286 //#define RAVENMD4
287
288 #ifdef RAVENMD4
289
290 #define MDR_IDENT (('5'<<24)+('M'<<16)+('D'<<8)+'R')
291 #define MDR_VERSION 2
292 #define MDR_MAX_BONES 128
293
294 typedef struct {
295 int boneIndex; // these are indexes into the boneReferences,
296 float boneWeight; // not the global per-frame bone list
297 vec3_t offset;
298 } mdrWeight_t;
299
300 typedef struct {
301 vec3_t normal;
302 vec2_t texCoords;
303 int numWeights;
304 mdrWeight_t weights[1]; // variable sized
305 } mdrVertex_t;
306
307 typedef struct {
308 int indexes[3];
309 } mdrTriangle_t;
310
311 typedef struct {
312 int ident;
313
314 char name[MAX_QPATH]; // polyset name
315 char shader[MAX_QPATH];
316 int shaderIndex; // for in-game use
317
318 int ofsHeader; // this will be a negative number
319
320 int numVerts;
321 int ofsVerts;
322
323 int numTriangles;
324 int ofsTriangles;
325
326 // Bone references are a set of ints representing all the bones
327 // present in any vertex weights for this surface. This is
328 // needed because a model may have surfaces that need to be
329 // drawn at different sort times, and we don't want to have
330 // to re-interpolate all the bones for each surface.
331 int numBoneReferences;
332 int ofsBoneReferences;
333
334 int ofsEnd; // next surface follows
335 } mdrSurface_t;
336
337 typedef struct {
338 float matrix[3][4];
339 } mdrBone_t;
340
341 typedef struct {
342 vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame
343 vec3_t localOrigin; // midpoint of bounds, used for sphere cull
344 float radius; // dist from localOrigin to corner
345 char name[16];
346 mdrBone_t bones[1]; // [numBones]
347 } mdrFrame_t;
348
349 typedef struct {
350 unsigned char Comp[24]; // MC_COMP_BYTES is in MatComp.h, but don't want to couple
351 } mdrCompBone_t;
352
353 typedef struct {
354 vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame
355 vec3_t localOrigin; // midpoint of bounds, used for sphere cull
356 float radius; // dist from localOrigin to corner
357 mdrCompBone_t bones[1]; // [numBones]
358 } mdrCompFrame_t;
359
360 typedef struct {
361 int numSurfaces;
362 int ofsSurfaces; // first surface, others follow
363 int ofsEnd; // next lod follows
364 } mdrLOD_t;
365
366 typedef struct {
367 int boneIndex;
368 char name[32];
369 } mdrTag_t;
370
371 typedef struct {
372 int ident;
373 int version;
374
375 char name[MAX_QPATH]; // model name
376
377 // frames and bones are shared by all levels of detail
378 int numFrames;
379 int numBones;
380 int ofsFrames; // mdrFrame_t[numFrames]
381
382 // each level of detail has completely separate sets of surfaces
383 int numLODs;
384 int ofsLODs;
385
386 int numTags;
387 int ofsTags;
388
389 int ofsEnd; // end of file
390 } mdrHeader_t;
391
392 #endif
393
394 /*
395 ==============================================================================
396
397 .BSP file format
398
399 ==============================================================================
400 */
401
402
403 #define BSP_IDENT (('P'<<24)+('S'<<16)+('B'<<8)+'I')
404 // little-endian "IBSP"
405
406 #define BSP_VERSION 46
407
408
409 // there shouldn't be any problem with increasing these values at the
410 // expense of more memory allocation in the utilities
411 #define MAX_MAP_MODELS 0x400
412 #define MAX_MAP_BRUSHES 0x8000
413 #define MAX_MAP_ENTITIES 0x800
414 #define MAX_MAP_ENTSTRING 0x40000
415 #define MAX_MAP_SHADERS 0x400
416
417 #define MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match!
418 #define MAX_MAP_FOGS 0x100
419 #define MAX_MAP_PLANES 0x20000
420 #define MAX_MAP_NODES 0x20000
421 #define MAX_MAP_BRUSHSIDES 0x20000
422 #define MAX_MAP_LEAFS 0x20000
423 #define MAX_MAP_LEAFFACES 0x20000
424 #define MAX_MAP_LEAFBRUSHES 0x40000
425 #define MAX_MAP_PORTALS 0x20000
426 #define MAX_MAP_LIGHTING 0x800000
427 #define MAX_MAP_LIGHTGRID 0x800000
428 #define MAX_MAP_VISIBILITY 0x200000
429
430 #define MAX_MAP_DRAW_SURFS 0x20000
431 #define MAX_MAP_DRAW_VERTS 0x80000
432 #define MAX_MAP_DRAW_INDEXES 0x80000
433
434
435 // key / value pair sizes in the entities lump
436 #define MAX_KEY 32
437 #define MAX_VALUE 1024
438
439 // the editor uses these predefined yaw angles to orient entities up or down
440 #define ANGLE_UP -1
441 #define ANGLE_DOWN -2
442
443 #define LIGHTMAP_WIDTH 128
444 #define LIGHTMAP_HEIGHT 128
445
446 #define MAX_WORLD_COORD ( 128*1024 )
447 #define MIN_WORLD_COORD ( -128*1024 )
448 #define WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD )
449
450 //=============================================================================
451
452
453 typedef struct {
454 int fileofs, filelen;
455 } lump_t;
456
457 #define LUMP_ENTITIES 0
458 #define LUMP_SHADERS 1
459 #define LUMP_PLANES 2
460 #define LUMP_NODES 3
461 #define LUMP_LEAFS 4
462 #define LUMP_LEAFSURFACES 5
463 #define LUMP_LEAFBRUSHES 6
464 #define LUMP_MODELS 7
465 #define LUMP_BRUSHES 8
466 #define LUMP_BRUSHSIDES 9
467 #define LUMP_DRAWVERTS 10
468 #define LUMP_DRAWINDEXES 11
469 #define LUMP_FOGS 12
470 #define LUMP_SURFACES 13
471 #define LUMP_LIGHTMAPS 14
472 #define LUMP_LIGHTGRID 15
473 #define LUMP_VISIBILITY 16
474 #define HEADER_LUMPS 17
475
476 typedef struct {
477 int ident;
478 int version;
479
480 lump_t lumps[HEADER_LUMPS];
481 } dheader_t;
482
483 typedef struct {
484 float mins[3], maxs[3];
485 int firstSurface, numSurfaces;
486 int firstBrush, numBrushes;
487 } dmodel_t;
488
489 typedef struct {
490 char shader[MAX_QPATH];
491 int surfaceFlags;
492 int contentFlags;
493 } dshader_t;
494
495 // planes x^1 is allways the opposite of plane x
496
497 typedef struct {
498 float normal[3];
499 float dist;
500 } dplane_t;
501
502 typedef struct {
503 int planeNum;
504 int children[2]; // negative numbers are -(leafs+1), not nodes
505 int mins[3]; // for frustom culling
506 int maxs[3];
507 } dnode_t;
508
509 typedef struct {
510 int cluster; // -1 = opaque cluster (do I still store these?)
511 int area;
512
513 int mins[3]; // for frustum culling
514 int maxs[3];
515
516 int firstLeafSurface;
517 int numLeafSurfaces;
518
519 int firstLeafBrush;
520 int numLeafBrushes;
521 } dleaf_t;
522
523 typedef struct {
524 int planeNum; // positive plane side faces out of the leaf
525 int shaderNum;
526 } dbrushside_t;
527
528 typedef struct {
529 int firstSide;
530 int numSides;
531 int shaderNum; // the shader that determines the contents flags
532 } dbrush_t;
533
534 typedef struct {
535 char shader[MAX_QPATH];
536 int brushNum;
537 int visibleSide; // the brush side that ray tests need to clip against (-1 == none)
538 } dfog_t;
539
540 typedef struct {
541 vec3_t xyz;
542 float st[2];
543 float lightmap[2];
544 vec3_t normal;
545 byte color[4];
546 } drawVert_t;
547
548 #define drawVert_t_cleared(x) drawVert_t (x) = {{0, 0, 0}, {0, 0}, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}}
549
550 typedef enum {
551 MST_BAD,
552 MST_PLANAR,
553 MST_PATCH,
554 MST_TRIANGLE_SOUP,
555 MST_FLARE
556 } mapSurfaceType_t;
557
558 typedef struct {
559 int shaderNum;
560 int fogNum;
561 int surfaceType;
562
563 int firstVert;
564 int numVerts;
565
566 int firstIndex;
567 int numIndexes;
568
569 int lightmapNum;
570 int lightmapX, lightmapY;
571 int lightmapWidth, lightmapHeight;
572
573 vec3_t lightmapOrigin;
574 vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds
575
576 int patchWidth;
577 int patchHeight;
578 } dsurface_t;
579
580
581 #endif