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