Debian Codegraph @

code/qcommon/qfiles.h

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