1 /* 2 Copyright (C) 1996-2001 Id Software, Inc. 3 Copyright (C) 2002-2009 John Fitzgibbons and others 4 Copyright (C) 2010-2014 QuakeSpasm developers 5 Copyright (C) 2016 Axel Gneiting 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 16 See the GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 22 */ 23 24 #ifndef __MODEL__ 25 #define __MODEL__ 26 27 #include "modelgen.h" 28 #include "spritegn.h" 29 30 /* 31 32 d*_t structures are on-disk representations 33 m*_t structures are in-memory 34 35 */ 36 37 // entity effects 38 39 #define EF_BRIGHTFIELD 1 40 #define EF_MUZZLEFLASH 2 41 #define EF_BRIGHTLIGHT 4 42 #define EF_DIMLIGHT 8 43 44 45 /* 46 ============================================================================== 47 48 BRUSH MODELS 49 50 ============================================================================== 51 */ 52 53 54 // 55 // in memory representation 56 // 57 // !!! if this is changed, it must be changed in asm_draw.h too !!! 58 typedef struct 59 { 60 vec3_t position; 61 } mvertex_t; 62 63 #define SIDE_FRONT 0 64 #define SIDE_BACK 1 65 #define SIDE_ON 2 66 67 68 // plane_t structure 69 // !!! if this is changed, it must be changed in asm_i386.h too !!! 70 typedef struct mplane_s 71 { 72 vec3_t normal; 73 float dist; 74 byte type; // for texture axis selection and fast side tests 75 byte signbits; // signx + signy<<1 + signz<<1 76 byte pad[2]; 77 } mplane_t; 78 79 // ericw -- each texture has two chains, so we can clear the model chains 80 // without affecting the world 81 typedef enum { 82 chain_world = 0, 83 chain_model = 1 84 } texchain_t; 85 86 typedef struct texture_s 87 { 88 char name[16]; 89 unsigned width, height; 90 unsigned shift; // Q64 91 struct gltexture_s *gltexture; //johnfitz -- pointer to gltexture 92 struct gltexture_s *fullbright; //johnfitz -- fullbright mask texture 93 struct gltexture_s *warpimage; //johnfitz -- for water animation 94 qboolean update_warp; //johnfitz -- update warp this frame 95 struct msurface_s *texturechains[2]; // for texture chains 96 int anim_total; // total tenths in sequence ( 0 = no) 97 int anim_min, anim_max; // time for this frame min <=time< max 98 struct texture_s *anim_next; // in the animation sequence 99 struct texture_s *alternate_anims; // bmodels in frmae 1 use these 100 unsigned offsets[MIPLEVELS]; // four mip maps stored 101 } texture_t; 102 103 104 #define SURF_PLANEBACK 2 105 #define SURF_DRAWSKY 4 106 #define SURF_DRAWSPRITE 8 107 #define SURF_DRAWTURB 0x10 108 #define SURF_DRAWTILED 0x20 109 #define SURF_DRAWBACKGROUND 0x40 110 #define SURF_UNDERWATER 0x80 111 #define SURF_NOTEXTURE 0x100 //johnfitz 112 #define SURF_DRAWFENCE 0x200 113 #define SURF_DRAWLAVA 0x400 114 #define SURF_DRAWSLIME 0x800 115 #define SURF_DRAWTELE 0x1000 116 #define SURF_DRAWWATER 0x2000 117 118 // !!! if this is changed, it must be changed in asm_draw.h too !!! 119 typedef struct 120 { 121 unsigned int v[2]; 122 unsigned int cachededgeoffset; 123 } medge_t; 124 125 typedef struct 126 { 127 float vecs[2][4]; 128 texture_t *texture; 129 int flags; 130 } mtexinfo_t; 131 132 #define VERTEXSIZE 7 133 134 typedef struct glpoly_s 135 { 136 struct glpoly_s *next; 137 int numverts; 138 float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2) 139 } glpoly_t; 140 141 typedef struct msurface_s 142 { 143 int visframe; // should be drawn when node is crossed 144 145 mplane_t *plane; 146 int flags; 147 148 int firstedge; // look up in model->surfedges[], negative numbers 149 int numedges; // are backwards edges 150 151 short texturemins[2]; 152 short extents[2]; 153 154 int light_s, light_t; // gl lightmap coordinates 155 156 glpoly_t *polys; // multiple if warped 157 struct msurface_s *texturechain; 158 159 mtexinfo_t *texinfo; 160 161 int vbo_firstvert; // index of this surface's first vert in the VBO 162 163 // lighting info 164 int dlightframe; 165 unsigned int dlightbits[(MAX_DLIGHTS + 31) >> 5]; 166 // int is 32 bits, need an array for MAX_DLIGHTS > 32 167 168 int lightmaptexturenum; 169 byte styles[MAXLIGHTMAPS]; 170 int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap 171 qboolean cached_dlight; // true if dynamic light in cache 172 byte *samples; // [numstyles*surfsize] 173 } msurface_t; 174 175 typedef struct mnode_s 176 { 177 // common with leaf 178 int contents; // 0, to differentiate from leafs 179 float minmaxs[6]; // for bounding box culling 180 181 // node specific 182 unsigned int firstsurface; 183 unsigned int numsurfaces; 184 mplane_t *plane; 185 struct mnode_s *children[2]; 186 } mnode_t; 187 188 typedef struct mleaf_s 189 { 190 // common with node 191 int contents; // wil be a negative contents number 192 float minmaxs[6]; // for bounding box culling 193 194 // leaf specific 195 int nummarksurfaces; 196 byte ambient_sound_level[NUM_AMBIENTS]; 197 byte *compressed_vis; 198 int *firstmarksurface; 199 efrag_t *efrags; 200 } mleaf_t; 201 202 //johnfitz -- for clipnodes>32k 203 typedef struct mclipnode_s 204 { 205 int planenum; 206 int children[2]; // negative numbers are contents 207 } mclipnode_t; 208 //johnfitz 209 210 // !!! if this is changed, it must be changed in asm_i386.h too !!! 211 typedef struct 212 { 213 mclipnode_t *clipnodes; //johnfitz -- was dclipnode_t 214 mplane_t *planes; 215 int firstclipnode; 216 int lastclipnode; 217 vec3_t clip_mins; 218 vec3_t clip_maxs; 219 } hull_t; 220 221 typedef float soa_aabb_t[2 * 3 * 8]; // 8 AABB's in SoA form 222 typedef float soa_plane_t[4 * 8]; // 8 planes in SoA form 223 224 /* 225 ============================================================================== 226 227 SPRITE MODELS 228 229 ============================================================================== 230 */ 231 232 233 // FIXME: shorten these? 234 typedef struct mspriteframe_s 235 { 236 int width, height; 237 float up, down, left, right; 238 float smax, tmax; //johnfitz -- image might be padded 239 struct gltexture_s *gltexture; 240 } mspriteframe_t; 241 242 typedef struct 243 { 244 int numframes; 245 float *intervals; 246 mspriteframe_t *frames[1]; 247 } mspritegroup_t; 248 249 typedef struct 250 { 251 spriteframetype_t type; 252 mspriteframe_t *frameptr; 253 } mspriteframedesc_t; 254 255 typedef struct 256 { 257 int type; 258 int maxwidth; 259 int maxheight; 260 int numframes; 261 float beamlength; // remove? 262 void *cachespot; // remove? 263 mspriteframedesc_t frames[1]; 264 } msprite_t; 265 266 267 /* 268 ============================================================================== 269 270 ALIAS MODELS 271 272 Alias models are position independent, so the cache manager can move them. 273 ============================================================================== 274 */ 275 276 //-- from RMQEngine 277 // split out to keep vertex sizes down 278 typedef struct aliasmesh_s 279 { 280 float st[2]; 281 unsigned short vertindex; 282 } aliasmesh_t; 283 284 typedef struct meshxyz_s 285 { 286 byte xyz[4]; 287 signed char normal[4]; 288 } meshxyz_t; 289 290 typedef struct meshst_s 291 { 292 float st[2]; 293 } meshst_t; 294 //-- 295 296 typedef struct 297 { 298 int firstpose; 299 int numposes; 300 float interval; 301 trivertx_t bboxmin; 302 trivertx_t bboxmax; 303 int frame; 304 char name[16]; 305 } maliasframedesc_t; 306 307 typedef struct 308 { 309 trivertx_t bboxmin; 310 trivertx_t bboxmax; 311 int frame; 312 } maliasgroupframedesc_t; 313 314 typedef struct 315 { 316 int numframes; 317 int intervals; 318 maliasgroupframedesc_t frames[1]; 319 } maliasgroup_t; 320 321 // !!! if this is changed, it must be changed in asm_draw.h too !!! 322 typedef struct mtriangle_s { 323 int facesfront; 324 int vertindex[3]; 325 } mtriangle_t; 326 327 328 #define MAX_SKINS 32 329 typedef struct { 330 int ident; 331 int version; 332 vec3_t scale; 333 vec3_t scale_origin; 334 float boundingradius; 335 vec3_t eyeposition; 336 int numskins; 337 int skinwidth; 338 int skinheight; 339 int numverts; 340 int numtris; 341 int numframes; 342 synctype_t synctype; 343 int flags; 344 float size; 345 346 //ericw -- used to populate vbo 347 int numverts_vbo; // number of verts with unique x,y,z,s,t 348 intptr_t meshdesc; // offset into extradata: numverts_vbo aliasmesh_t 349 int numindexes; 350 intptr_t indexes; // offset into extradata: numindexes unsigned shorts 351 intptr_t vertexes; // offset into extradata: numposes*vertsperframe trivertx_t 352 //ericw -- 353 354 int numposes; 355 int poseverts; 356 int posedata; // numposes*poseverts trivert_t 357 int commands; // gl command list with embedded s/t 358 struct gltexture_s *gltextures[MAX_SKINS][4]; //johnfitz 359 struct gltexture_s *fbtextures[MAX_SKINS][4]; //johnfitz 360 int texels[MAX_SKINS]; // only for player skins 361 maliasframedesc_t frames[1]; // variable sized 362 } aliashdr_t; 363 364 #define MAXALIASVERTS 2000 //johnfitz -- was 1024 365 #define MAXALIASFRAMES 256 366 #define MAXALIASTRIS 4096 //ericw -- was 2048 367 extern aliashdr_t *pheader; 368 extern stvert_t stverts[MAXALIASVERTS]; 369 extern mtriangle_t triangles[MAXALIASTRIS]; 370 extern trivertx_t *poseverts[MAXALIASFRAMES]; 371 372 //=================================================================== 373 374 // 375 // Whole model 376 // 377 378 typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t; 379 380 #define EF_ROCKET 1 // leave a trail 381 #define EF_GRENADE 2 // leave a trail 382 #define EF_GIB 4 // leave a trail 383 #define EF_ROTATE 8 // rotate (bonus items) 384 #define EF_TRACER 16 // green split trail 385 #define EF_ZOMGIB 32 // small blood trail 386 #define EF_TRACER2 64 // orange split trail + rotate 387 #define EF_TRACER3 128 // purple trail 388 #define MF_HOLEY (1u<<14) // MarkV/QSS -- make index 255 transparent on mdl's 389 390 //johnfitz -- extra flags for rendering 391 #define MOD_NOLERP 256 //don't lerp when animating 392 #define MOD_FBRIGHTHACK 1024 //when fullbrights are disabled, use a hack to render this model brighter 393 //johnfitz 394 //spike -- added this for particle stuff 395 #define MOD_EMITREPLACE 2048 //particle effect completely replaces the model (for flames or whatever). 396 #define MOD_EMITFORWARDS 4096 //particle effect is emitted forwards, rather than downwards. why down? good question. 397 //spike 398 399 struct glheap_s; 400 struct glheapnode_s; 401 402 typedef struct qmodel_s 403 { 404 char name[MAX_QPATH]; 405 unsigned int path_id; // path id of the game directory 406 // that this model came from 407 qboolean needload; // bmodels and sprites don't cache normally 408 409 modtype_t type; 410 int numframes; 411 synctype_t synctype; 412 413 int flags; 414 415 #ifdef PSET_SCRIPT 416 int emiteffect; //spike -- this effect is emitted per-frame by entities with this model 417 int traileffect; //spike -- this effect is used when entities move 418 struct skytris_s *skytris; //spike -- surface-based particle emission for this model 419 struct skytriblock_s *skytrimem; //spike -- surface-based particle emission for this model (for better cache performance+less allocs) 420 double skytime; //doesn't really cope with multiples. oh well... 421 #endif 422 // 423 // volume occupied by the model graphics 424 // 425 vec3_t mins, maxs; 426 vec3_t ymins, ymaxs; //johnfitz -- bounds for entities with nonzero yaw 427 vec3_t rmins, rmaxs; //johnfitz -- bounds for entities with nonzero pitch or roll 428 //johnfitz -- removed float radius; 429 430 // 431 // solid volume for clipping 432 // 433 qboolean clipbox; 434 vec3_t clipmins, clipmaxs; 435 436 // 437 // brush model 438 // 439 int firstmodelsurface, nummodelsurfaces; 440 441 int numsubmodels; 442 dmodel_t *submodels; 443 444 int numplanes; 445 mplane_t *planes; 446 447 int numleafs; // number of visible leafs, not counting 0 448 mleaf_t *leafs; 449 450 int numvertexes; 451 mvertex_t *vertexes; 452 453 int numedges; 454 medge_t *edges; 455 456 int numnodes; 457 mnode_t *nodes; 458 459 int numtexinfo; 460 mtexinfo_t *texinfo; 461 462 int numsurfaces; 463 msurface_t *surfaces; 464 465 int numsurfedges; 466 int *surfedges; 467 468 int numclipnodes; 469 mclipnode_t *clipnodes; //johnfitz -- was dclipnode_t 470 471 int nummarksurfaces; 472 int *marksurfaces; 473 474 soa_aabb_t *soa_leafbounds; 475 byte *surfvis; 476 soa_plane_t *soa_surfplanes; 477 478 hull_t hulls[MAX_MAP_HULLS]; 479 480 int numtextures; 481 texture_t **textures; 482 483 byte *visdata; 484 byte *lightdata; 485 char *entities; 486 487 qboolean viswarn; // for Mod_DecompressVis() 488 489 int bspversion; 490 int contentstransparent; //spike -- added this so we can disable glitchy wateralpha where its not supported. 491 492 // 493 // alias model 494 // 495 VkBuffer vertex_buffer; 496 struct glheap_s * vertex_heap; 497 struct glheapnode_s * vertex_heap_node; 498 VkBuffer index_buffer; 499 struct glheap_s * index_heap; 500 struct glheapnode_s * index_heap_node; 501 int vboindexofs; // offset in vbo of the hdr->numindexes unsigned shorts 502 int vboxyzofs; // offset in vbo of hdr->numposes*hdr->numverts_vbo meshxyz_t 503 int vbostofs; // offset in vbo of hdr->numverts_vbo meshst_t 504 505 // 506 // additional model data 507 // 508 cache_user_t cache; // only access through Mod_Extradata 509 510 } qmodel_t; 511 512 //============================================================================ 513 514 void Mod_Init (void); 515 void Mod_ClearAll (void); 516 void Mod_ResetAll (void); // for gamedir changes (Host_Game_f) 517 qmodel_t *Mod_ForName (const char *name, qboolean crash); 518 void *Mod_Extradata (qmodel_t *mod); // handles caching 519 void Mod_TouchModel (const char *name); 520 521 mleaf_t *Mod_PointInLeaf (float *p, qmodel_t *model); 522 byte *Mod_LeafPVS (mleaf_t *leaf, qmodel_t *model); 523 byte *Mod_NoVisPVS (qmodel_t *model); 524 525 void Mod_SetExtraFlags (qmodel_t *mod); 526 527 #endif // __MODEL__ 528