1 /* 2 =========================================================================== 3 4 Return to Castle Wolfenstein multiplayer GPL Source Code 5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (RTCW MP Source Code). 8 9 RTCW MP Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 RTCW MP Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #ifndef __QFILES_H__ 30 #define __QFILES_H__ 31 32 // 33 // qfiles.h: quake file formats 34 // This file must be identical in the quake and utils directories 35 // 36 37 //Ignore __attribute__ on non-gcc platforms 38 #ifndef __GNUC__ 39 #ifndef __attribute__ 40 #define __attribute__(x) 41 #endif 42 #endif 43 44 // surface geometry should not exceed these limits 45 #define SHADER_MAX_VERTEXES 1000 // JPW NERVE was 4000, 1000 in q3ta 46 #define SHADER_MAX_INDEXES ( 6 * SHADER_MAX_VERTEXES ) 47 48 49 // the maximum size of game reletive pathnames 50 #define MAX_QPATH 64 51 52 /* 53 ======================================================================== 54 55 QVM files 56 57 ======================================================================== 58 */ 59 60 #define VM_MAGIC 0x12721444 61 #define VM_MAGIC_VER2 0x12721445 62 63 typedef struct { 64 int vmMagic; 65 66 int instructionCount; 67 68 int codeOffset; 69 int codeLength; 70 71 int dataOffset; 72 int dataLength; 73 int litLength; // ( dataLength - litLength ) should be byteswapped on load 74 int bssLength; // zero filled memory appended to datalength 75 76 //!!! below here is VM_MAGIC_VER2 !!! 77 int jtrgLength; // number of jump table targets 78 } vmHeader_t; 79 80 /* 81 ======================================================================== 82 83 .MD3 triangle model file format 84 85 ======================================================================== 86 */ 87 88 #define MD3_IDENT ( ( '3' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' ) 89 #define MD3_VERSION 15 90 91 // limits 92 #define MD3_MAX_LODS 1 93 #define MD3_MAX_TRIANGLES 8192 // per surface 94 #define MD3_MAX_VERTS 4096 // per surface 95 #define MD3_MAX_SHADERS 256 // per surface 96 #define MD3_MAX_FRAMES 1024 // per model 97 #define MD3_MAX_SURFACES 32 // per model 98 #define MD3_MAX_TAGS 16 // per frame 99 100 // vertex scales 101 #define MD3_XYZ_SCALE ( 1.0 / 64 ) 102 103 typedef struct md3Frame_s { 104 vec3_t bounds[2]; 105 vec3_t localOrigin; 106 float radius; 107 char name[16]; 108 } md3Frame_t; 109 110 typedef struct md3Tag_s { 111 char name[MAX_QPATH]; // tag name 112 vec3_t origin; 113 vec3_t axis[3]; 114 } md3Tag_t; 115 116 /* 117 ** md3Surface_t 118 ** 119 ** CHUNK SIZE 120 ** header sizeof( md3Surface_t ) 121 ** shaders sizeof( md3Shader_t ) * numShaders 122 ** triangles[0] sizeof( md3Triangle_t ) * numTriangles 123 ** st sizeof( md3St_t ) * numVerts 124 ** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames 125 */ 126 typedef struct { 127 int ident; // 128 129 char name[MAX_QPATH]; // polyset name 130 131 int flags; 132 int numFrames; // all surfaces in a model should have the same 133 134 int numShaders; // all surfaces in a model should have the same 135 int numVerts; 136 137 int numTriangles; 138 int ofsTriangles; 139 140 int ofsShaders; // offset from start of md3Surface_t 141 int ofsSt; // texture coords are common for all frames 142 int ofsXyzNormals; // numVerts * numFrames 143 144 int ofsEnd; // next surface follows 145 } md3Surface_t; 146 147 typedef struct { 148 char name[MAX_QPATH]; 149 int shaderIndex; // for in-game use 150 } md3Shader_t; 151 152 typedef struct { 153 int indexes[3]; 154 } md3Triangle_t; 155 156 typedef struct { 157 float st[2]; 158 } md3St_t; 159 160 typedef struct { 161 short xyz[3]; 162 short normal; 163 } md3XyzNormal_t; 164 165 typedef struct { 166 int ident; 167 int version; 168 169 char name[MAX_QPATH]; // model name 170 171 int flags; 172 173 int numFrames; 174 int numTags; 175 int numSurfaces; 176 177 int numSkins; 178 179 int ofsFrames; // offset for first frame 180 int ofsTags; // numFrames * numTags 181 int ofsSurfaces; // first surface, others follow 182 183 int ofsEnd; // end of file 184 } md3Header_t; 185 186 // Ridah, mesh compression 187 /* 188 ============================================================================== 189 190 MDC file format 191 192 ============================================================================== 193 */ 194 195 #define MDC_IDENT ( ( 'C' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' ) 196 #define MDC_VERSION 2 197 198 // version history: 199 // 1 - original 200 // 2 - changed tag structure so it only lists the names once 201 202 typedef struct { 203 unsigned int ofsVec; // offset direction from the last base frame 204 // unsigned short ofsVec; 205 } mdcXyzCompressed_t; 206 207 typedef struct { 208 char name[MAX_QPATH]; // tag name 209 } mdcTagName_t; 210 211 #define MDC_TAG_ANGLE_SCALE ( 360.0 / 32700.0 ) 212 213 typedef struct { 214 short xyz[3]; 215 short angles[3]; 216 } mdcTag_t; 217 218 /* 219 ** mdcSurface_t 220 ** 221 ** CHUNK SIZE 222 ** header sizeof( md3Surface_t ) 223 ** shaders sizeof( md3Shader_t ) * numShaders 224 ** triangles[0] sizeof( md3Triangle_t ) * numTriangles 225 ** st sizeof( md3St_t ) * numVerts 226 ** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numBaseFrames 227 ** XyzCompressed sizeof( mdcXyzCompressed ) * numVerts * numCompFrames 228 ** frameBaseFrames sizeof( short ) * numFrames 229 ** frameCompFrames sizeof( short ) * numFrames (-1 if frame is a baseFrame) 230 */ 231 typedef struct { 232 int ident; // 233 234 char name[MAX_QPATH]; // polyset name 235 236 int flags; 237 int numCompFrames; // all surfaces in a model should have the same 238 int numBaseFrames; // ditto 239 240 int numShaders; // all surfaces in a model should have the same 241 int numVerts; 242 243 int numTriangles; 244 int ofsTriangles; 245 246 int ofsShaders; // offset from start of md3Surface_t 247 int ofsSt; // texture coords are common for all frames 248 int ofsXyzNormals; // numVerts * numBaseFrames 249 int ofsXyzCompressed; // numVerts * numCompFrames 250 251 int ofsFrameBaseFrames; // numFrames 252 int ofsFrameCompFrames; // numFrames 253 254 int ofsEnd; // next surface follows 255 } mdcSurface_t; 256 257 typedef struct { 258 int ident; 259 int version; 260 261 char name[MAX_QPATH]; // model name 262 263 int flags; 264 265 int numFrames; 266 int numTags; 267 int numSurfaces; 268 269 int numSkins; 270 271 int ofsFrames; // offset for first frame, stores the bounds and localOrigin 272 int ofsTagNames; // numTags 273 int ofsTags; // numFrames * numTags 274 int ofsSurfaces; // first surface, others follow 275 276 int ofsEnd; // end of file 277 } mdcHeader_t; 278 // done. 279 280 /* 281 ============================================================================== 282 283 MDR file format 284 285 ============================================================================== 286 */ 287 288 /* 289 * Here are the definitions for Ravensoft's model format of md4. Raven stores their 290 * playermodels in .mdr files, in some games, which are pretty much like the md4 291 * format implemented by ID soft. It seems like ID's original md4 stuff is not used at all. 292 * MDR is being used in EliteForce, JediKnight2 and Soldiers of Fortune2 (I think). 293 * So this comes in handy for anyone who wants to make it possible to load player 294 * models from these games. 295 * This format has bone tags, which is similar to the thing you have in md3 I suppose. 296 * Raven has released their version of md3view under GPL enabling me to add support 297 * to this codebase. Thanks to Steven Howes aka Skinner for helping with example 298 * source code. 299 * 300 * - Thilo Schulz (arny@ats.s.bawue.de) 301 */ 302 303 #define MDR_IDENT (('5'<<24)+('M'<<16)+('D'<<8)+'R') 304 #define MDR_VERSION 2 305 #define MDR_MAX_BONES 128 306 307 typedef struct { 308 int boneIndex; // these are indexes into the boneReferences, 309 float boneWeight; // not the global per-frame bone list 310 vec3_t offset; 311 } mdrWeight_t; 312 313 typedef struct { 314 vec3_t normal; 315 vec2_t texCoords; 316 int numWeights; 317 mdrWeight_t weights[1]; // variable sized 318 } mdrVertex_t; 319 320 typedef struct { 321 int indexes[3]; 322 } mdrTriangle_t; 323 324 typedef struct { 325 int ident; 326 327 char name[MAX_QPATH]; // polyset name 328 char shader[MAX_QPATH]; 329 int shaderIndex; // for in-game use 330 331 int ofsHeader; // this will be a negative number 332 333 int numVerts; 334 int ofsVerts; 335 336 int numTriangles; 337 int ofsTriangles; 338 339 // Bone references are a set of ints representing all the bones 340 // present in any vertex weights for this surface. This is 341 // needed because a model may have surfaces that need to be 342 // drawn at different sort times, and we don't want to have 343 // to re-interpolate all the bones for each surface. 344 int numBoneReferences; 345 int ofsBoneReferences; 346 347 int ofsEnd; // next surface follows 348 } mdrSurface_t; 349 350 typedef struct { 351 float matrix[3][4]; 352 } mdrBone_t; 353 354 typedef struct { 355 vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame 356 vec3_t localOrigin; // midpoint of bounds, used for sphere cull 357 float radius; // dist from localOrigin to corner 358 char name[16]; 359 mdrBone_t bones[1]; // [numBones] 360 } mdrFrame_t; 361 362 typedef struct { 363 unsigned char Comp[24]; // MC_COMP_BYTES is in MatComp.h, but don't want to couple 364 } mdrCompBone_t; 365 366 typedef struct { 367 vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame 368 vec3_t localOrigin; // midpoint of bounds, used for sphere cull 369 float radius; // dist from localOrigin to corner 370 mdrCompBone_t bones[1]; // [numBones] 371 } mdrCompFrame_t; 372 373 typedef struct { 374 int numSurfaces; 375 int ofsSurfaces; // first surface, others follow 376 int ofsEnd; // next lod follows 377 } mdrLOD_t; 378 379 typedef struct { 380 int boneIndex; 381 char name[32]; 382 } mdrTag_t; 383 384 typedef struct { 385 int ident; 386 int version; 387 388 char name[MAX_QPATH]; // model name 389 390 // frames and bones are shared by all levels of detail 391 int numFrames; 392 int numBones; 393 int ofsFrames; // mdrFrame_t[numFrames] 394 395 // each level of detail has completely separate sets of surfaces 396 int numLODs; 397 int ofsLODs; 398 399 int numTags; 400 int ofsTags; 401 402 int ofsEnd; // end of file 403 } mdrHeader_t; 404 405 406 /* 407 ============================================================================== 408 409 MDS file format (Wolfenstein Skeletal Format) 410 411 ============================================================================== 412 */ 413 414 #define MDS_IDENT ( ( 'W' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'M' ) 415 #define MDS_VERSION 4 416 #define MDS_MAX_VERTS 6000 417 #define MDS_MAX_TRIANGLES 8192 418 #define MDS_MAX_BONES 128 419 #define MDS_MAX_SURFACES 32 420 #define MDS_MAX_TAGS 128 421 422 #define MDS_TRANSLATION_SCALE ( 1.0 / 64 ) 423 424 typedef struct { 425 int boneIndex; // these are indexes into the boneReferences, 426 float boneWeight; // not the global per-frame bone list 427 vec3_t offset; 428 } mdsWeight_t; 429 430 typedef struct { 431 vec3_t normal; 432 vec2_t texCoords; 433 int numWeights; 434 int fixedParent; // stay equi-distant from this parent 435 float fixedDist; 436 mdsWeight_t weights[1]; // variable sized 437 } mdsVertex_t; 438 439 typedef struct { 440 int indexes[3]; 441 } mdsTriangle_t; 442 443 typedef struct { 444 int ident; 445 446 char name[MAX_QPATH]; // polyset name 447 char shader[MAX_QPATH]; 448 int shaderIndex; // for in-game use 449 450 int minLod; 451 452 int ofsHeader; // this will be a negative number 453 454 int numVerts; 455 int ofsVerts; 456 457 int numTriangles; 458 int ofsTriangles; 459 460 int ofsCollapseMap; // numVerts * int 461 462 // Bone references are a set of ints representing all the bones 463 // present in any vertex weights for this surface. This is 464 // needed because a model may have surfaces that need to be 465 // drawn at different sort times, and we don't want to have 466 // to re-interpolate all the bones for each surface. 467 int numBoneReferences; 468 int ofsBoneReferences; 469 470 int ofsEnd; // next surface follows 471 } mdsSurface_t; 472 473 typedef struct { 474 //float angles[3]; 475 //float ofsAngles[2]; 476 short angles[4]; // to be converted to axis at run-time (this is also better for lerping) 477 short ofsAngles[2]; // PITCH/YAW, head in this direction from parent to go to the offset position 478 } mdsBoneFrameCompressed_t; 479 480 // NOTE: this only used at run-time 481 typedef struct { 482 float matrix[3][3]; // 3x3 rotation 483 vec3_t translation; // translation vector 484 } mdsBoneFrame_t; 485 486 typedef struct { 487 vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame 488 vec3_t localOrigin; // midpoint of bounds, used for sphere cull 489 float radius; // dist from localOrigin to corner 490 vec3_t parentOffset; // one bone is an ascendant of all other bones, it starts the hierachy at this position 491 mdsBoneFrameCompressed_t bones[1]; // [numBones] 492 } mdsFrame_t; 493 494 typedef struct { 495 int numSurfaces; 496 int ofsSurfaces; // first surface, others follow 497 int ofsEnd; // next lod follows 498 } mdsLOD_t; 499 500 typedef struct { 501 char name[MAX_QPATH]; // name of tag 502 float torsoWeight; 503 int boneIndex; // our index in the bones 504 } mdsTag_t; 505 506 #define BONEFLAG_TAG 1 // this bone is actually a tag 507 508 typedef struct { 509 char name[MAX_QPATH]; // name of bone 510 int parent; // not sure if this is required, no harm throwing it in 511 float torsoWeight; // scale torso rotation about torsoParent by this 512 float parentDist; 513 int flags; 514 } mdsBoneInfo_t; 515 516 typedef struct { 517 int ident; 518 int version; 519 520 char name[MAX_QPATH]; // model name 521 522 float lodScale; 523 float lodBias; 524 525 // frames and bones are shared by all levels of detail 526 int numFrames; 527 int numBones; 528 int ofsFrames; // mdsFrame_t[numFrames] 529 int ofsBones; // mdsBoneInfo_t[numBones] 530 int torsoParent; // index of bone that is the parent of the torso 531 532 int numSurfaces; 533 int ofsSurfaces; 534 535 // tag data 536 int numTags; 537 int ofsTags; // mdsTag_t[numTags] 538 539 int ofsEnd; // end of file 540 } mdsHeader_t; 541 542 /* 543 ============================================================================== 544 545 .BSP file format 546 547 ============================================================================== 548 */ 549 550 551 #define BSP_IDENT ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) 552 // little-endian "IBSP" 553 554 #define BSP_VERSION 47 555 556 557 // there shouldn't be any problem with increasing these values at the 558 // expense of more memory allocation in the utilities 559 //#define MAX_MAP_MODELS 0x400 560 #define MAX_MAP_MODELS 0x800 561 #define MAX_MAP_BRUSHES 0x8000 562 #define MAX_MAP_ENTITIES 0x800 563 #define MAX_MAP_ENTSTRING 0x40000 564 #define MAX_MAP_SHADERS 0x400 565 566 #define MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match! 567 #define MAX_MAP_FOGS 0x100 568 #define MAX_MAP_PLANES 0x20000 569 #define MAX_MAP_NODES 0x20000 570 #define MAX_MAP_BRUSHSIDES 0x20000 571 #define MAX_MAP_LEAFS 0x20000 572 #define MAX_MAP_LEAFFACES 0x20000 573 #define MAX_MAP_LEAFBRUSHES 0x40000 574 #define MAX_MAP_PORTALS 0x20000 575 #define MAX_MAP_LIGHTING 0x800000 576 #define MAX_MAP_LIGHTGRID 0x800000 577 #define MAX_MAP_VISIBILITY 0x200000 578 579 #define MAX_MAP_DRAW_SURFS 0x20000 580 #define MAX_MAP_DRAW_VERTS 0x80000 581 #define MAX_MAP_DRAW_INDEXES 0x80000 582 583 584 // key / value pair sizes in the entities lump 585 #define MAX_KEY 32 586 #define MAX_VALUE 1024 587 588 // the editor uses these predefined yaw angles to orient entities up or down 589 #define ANGLE_UP -1 590 #define ANGLE_DOWN -2 591 592 #define LIGHTMAP_WIDTH 128 593 #define LIGHTMAP_HEIGHT 128 594 595 #define MAX_WORLD_COORD ( 128 * 1024 ) 596 #define MIN_WORLD_COORD ( -128 * 1024 ) 597 #define WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD ) 598 599 //============================================================================= 600 601 602 typedef struct { 603 int fileofs, filelen; 604 } lump_t; 605 606 #define LUMP_ENTITIES 0 607 #define LUMP_SHADERS 1 608 #define LUMP_PLANES 2 609 #define LUMP_NODES 3 610 #define LUMP_LEAFS 4 611 #define LUMP_LEAFSURFACES 5 612 #define LUMP_LEAFBRUSHES 6 613 #define LUMP_MODELS 7 614 #define LUMP_BRUSHES 8 615 #define LUMP_BRUSHSIDES 9 616 #define LUMP_DRAWVERTS 10 617 #define LUMP_DRAWINDEXES 11 618 #define LUMP_FOGS 12 619 #define LUMP_SURFACES 13 620 #define LUMP_LIGHTMAPS 14 621 #define LUMP_LIGHTGRID 15 622 #define LUMP_VISIBILITY 16 623 #define HEADER_LUMPS 17 624 625 typedef struct { 626 int ident; 627 int version; 628 629 lump_t lumps[HEADER_LUMPS]; 630 } dheader_t; 631 632 typedef struct { 633 float mins[3], maxs[3]; 634 int firstSurface, numSurfaces; 635 int firstBrush, numBrushes; 636 } dmodel_t; 637 638 typedef struct { 639 char shader[MAX_QPATH]; 640 int surfaceFlags; 641 int contentFlags; 642 } dshader_t; 643 644 // planes x^1 is allways the opposite of plane x 645 646 typedef struct { 647 float normal[3]; 648 float dist; 649 } dplane_t; 650 651 typedef struct { 652 int planeNum; 653 int children[2]; // negative numbers are -(leafs+1), not nodes 654 int mins[3]; // for frustom culling 655 int maxs[3]; 656 } dnode_t; 657 658 typedef struct { 659 int cluster; // -1 = opaque cluster (do I still store these?) 660 int area; 661 662 int mins[3]; // for frustum culling 663 int maxs[3]; 664 665 int firstLeafSurface; 666 int numLeafSurfaces; 667 668 int firstLeafBrush; 669 int numLeafBrushes; 670 } dleaf_t; 671 672 typedef struct { 673 int planeNum; // positive plane side faces out of the leaf 674 int shaderNum; 675 } dbrushside_t; 676 677 typedef struct { 678 int firstSide; 679 int numSides; 680 int shaderNum; // the shader that determines the contents flags 681 } dbrush_t; 682 683 typedef struct { 684 char shader[MAX_QPATH]; 685 int brushNum; 686 int visibleSide; // the brush side that ray tests need to clip against (-1 == none) 687 } dfog_t; 688 689 typedef struct { 690 vec3_t xyz; 691 float st[2]; 692 float lightmap[2]; 693 vec3_t normal; 694 byte color[4]; 695 } drawVert_t; 696 697 #define drawVert_t_cleared(x) drawVert_t (x) = {{0, 0, 0}, {0, 0}, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}} 698 699 typedef enum { 700 MST_BAD, 701 MST_PLANAR, 702 MST_PATCH, 703 MST_TRIANGLE_SOUP, 704 MST_FLARE 705 } mapSurfaceType_t; 706 707 typedef struct { 708 int shaderNum; 709 int fogNum; 710 int surfaceType; 711 712 int firstVert; 713 int numVerts; 714 715 int firstIndex; 716 int numIndexes; 717 718 int lightmapNum; 719 int lightmapX, lightmapY; 720 int lightmapWidth, lightmapHeight; 721 722 vec3_t lightmapOrigin; 723 vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds 724 725 int patchWidth; 726 int patchHeight; 727 } dsurface_t; 728 729 //----(SA) added so I didn't change the dsurface_t struct (and thereby the bsp format) for something that doesn't need to be stored in the bsp 730 typedef struct { 731 char *lighttarg; 732 } drsurfaceInternal_t; 733 //----(SA) end 734 735 #endif 736