1 /* 2 model.h 3 4 (description) 5 6 Copyright (C) 1996-1997 Id Software, Inc. 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 17 See the GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to: 21 22 Free Software Foundation, Inc. 23 59 Temple Place - Suite 330 24 Boston, MA 02111-1307, USA 25 26 */ 27 28 #ifndef _MODEL_H 29 #define _MODEL_H 30 31 #include "QF/qtypes.h" 32 #include "QF/bspfile.h" 33 #include "QF/spritegn.h" 34 #include "QF/modelgen.h" 35 #include "QF/zone.h" 36 37 extern struct vid_model_funcs_s *mod_funcs; 38 39 /* 40 d*_t structures are on-disk representations 41 m*_t structures are in-memory 42 */ 43 44 // entity effects ============================================================= 45 46 #define EF_BRIGHTFIELD 1 47 #define EF_MUZZLEFLASH 2 48 #define EF_BRIGHTLIGHT 4 49 #define EF_DIMLIGHT 8 50 #define EF_FLAG1 16 51 #define EF_FLAG2 32 52 #define EF_BLUE 64 53 #define EF_RED 128 54 55 // BRUSH MODELS =============================================================== 56 57 typedef struct efrag_s { 58 struct mleaf_s *leaf; 59 struct efrag_s *leafnext; 60 struct entity_s *entity; 61 struct efrag_s *entnext; 62 } efrag_t; 63 64 65 // in memory representation =================================================== 66 67 // !!! if this is changed, it must be changed in asm_draw.h too !!! 68 typedef struct { 69 vec3_t position; 70 } mvertex_t; 71 72 /** Instanced surface data. 73 74 There will be one of these for each surface in the world model. This 75 covers the sub-models in the world model. These instanced surfaces will 76 be allocated in one block at map load time and then never freed until 77 the next map load. 78 79 However, for instanced brush models (ammo boxes, health boxes, etc), an 80 instanced surface will be allocated for each surface for each model 81 once per frame. These instanced surfaces will be mass-freed each frame. 82 */ 83 typedef struct instsurf_s { 84 struct instsurf_s *_next; ///< next in free/alloc list 85 struct instsurf_s *tex_chain; ///< next in texture chain 86 struct instsurf_s *lm_chain; ///< next in lightmap chain 87 struct msurface_s *surface; ///< surface to render 88 vec_t *transform; 89 float *color; 90 } instsurf_t; 91 92 typedef struct texture_s { 93 char name[16]; 94 unsigned int width, height; 95 int gl_texturenum; 96 int gl_fb_texturenum; 97 int sky_tex[2]; 98 instsurf_t *tex_chain; // for gl_texsort drawing 99 instsurf_t **tex_chain_tail; 100 struct elechain_s *elechain; 101 struct elechain_s **elechain_tail; 102 int anim_total; // total tenths in sequence ( 0 = no) 103 int anim_min, anim_max; // time for this frame min <=time< max 104 struct texture_s *anim_next; // in the animation sequence 105 struct texture_s *alternate_anims; // bmodels in frmae 1 use these 106 unsigned int offsets[MIPLEVELS]; // four mip maps stored 107 } texture_t; 108 109 110 #define SURF_PLANEBACK 2 111 #define SURF_DRAWSKY 4 112 #define SURF_DRAWSPRITE 8 113 #define SURF_DRAWTURB 0x10 114 #define SURF_DRAWTILED 0x20 115 #define SURF_DRAWBACKGROUND 0x40 116 #define SURF_UNDERWATER 0x80 117 #define SURF_DONTWARP 0x100 118 #define SURF_DRAWNOALPHA 0x200 119 #define SURF_DRAWFULLBRIGHT 0x400 120 #define SURF_LIGHTBOTHSIDES 0x800 121 122 // !!! if this is changed, it must be changed in asm_draw.h too !!! 123 typedef struct { 124 unsigned int v[2]; 125 unsigned int cachededgeoffset; 126 } medge_t; 127 128 typedef struct { 129 float vecs[2][4]; 130 float mipadjust; 131 texture_t *texture; 132 int flags; 133 } mtexinfo_t; 134 135 #define VERTEXSIZE 7 136 137 typedef struct glpoly_s { 138 struct glpoly_s *next; 139 int numverts; 140 int flags; // for SURF_UNDERWATER 141 float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2) 142 } glpoly_t; 143 144 #define MAX_DLIGHTS 128 145 146 typedef struct msurface_s { 147 int visframe; // should be drawn when node is crossed 148 149 plane_t *plane; 150 int flags; 151 152 int firstedge; // look up in model->surfedges[], negative numbers 153 int numedges; // are backwards edges 154 155 struct surfcache_s *cachespots[MIPLEVELS]; 156 157 short texturemins[2]; 158 unsigned short extents[2]; 159 160 int light_s, light_t; // gl lightmap coordinates 161 162 glpoly_t *polys; // multiple if warped 163 instsurf_t *instsurf; ///< null if not part of world model/sub-model 164 instsurf_t *tinst; ///< for instance models 165 166 mtexinfo_t *texinfo; 167 int ec_index; 168 byte *base; 169 170 // lighting info 171 struct subpic_s *lightpic; ///< light map texture ref (glsl) 172 int dlightframe; 173 uint32_t dlightbits[(MAX_DLIGHTS + 31) >> 5]; 174 175 int lightmaptexturenum; 176 byte styles[MAXLIGHTMAPS]; 177 int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap 178 qboolean cached_dlight; // true if dynamic light in cache 179 byte *samples; // [numstyles*surfsize] 180 } msurface_t; 181 182 typedef struct mnode_s { 183 // common with leaf 184 int contents; // 0, to differentiate from leafs 185 int visframe; // node needs to be traversed if current 186 187 float minmaxs[6]; // for bounding box culling 188 189 struct mnode_s *parent; 190 191 // node specific 192 plane_t *plane; 193 struct mnode_s *children[2]; 194 195 unsigned int firstsurface; 196 unsigned int numsurfaces; 197 } mnode_t; 198 199 typedef struct mleaf_s { 200 // common with node 201 int contents; // wil be a negative contents number 202 int visframe; // node needs to be traversed if current 203 204 // for bounding box culling 205 float mins[3]; 206 float maxs[3]; 207 208 struct mnode_s *parent; 209 210 // leaf specific 211 byte *compressed_vis; 212 efrag_t *efrags; 213 214 msurface_t **firstmarksurface; 215 int nummarksurfaces; 216 int key; // BSP sequence number for leaf's contents 217 byte ambient_sound_level[NUM_AMBIENTS]; 218 } mleaf_t; 219 220 typedef struct mclipnode_s { 221 int planenum; 222 int children[2]; 223 } mclipnode_t; 224 225 typedef struct hull_s { 226 mclipnode_t *clipnodes; 227 plane_t *planes; 228 int firstclipnode; 229 int lastclipnode; 230 vec3_t clip_mins; 231 vec3_t clip_maxs; 232 struct nodeleaf_s *nodeleafs; 233 int depth; ///< maximum depth of the tree 234 } hull_t; 235 236 // SPRITE MODELS ============================================================== 237 238 // FIXME: shorten these? 239 typedef struct mspriteframe_s { 240 int width; 241 int height; 242 float up, down, left, right; 243 byte pixels[4]; 244 int gl_texturenum; 245 } mspriteframe_t; 246 247 typedef struct { 248 int numframes; 249 float *intervals; 250 mspriteframe_t *frames[1]; 251 } mspritegroup_t; 252 253 typedef struct { 254 spriteframetype_t type; 255 mspriteframe_t *frameptr; 256 } mspriteframedesc_t; 257 258 typedef struct { 259 int type; 260 int maxwidth; 261 int maxheight; 262 int numframes; 263 float beamlength; // remove? 264 void *cachespot; // remove? 265 mspriteframedesc_t frames[1]; 266 } msprite_t; 267 268 269 // ALIAS MODELS =============================================================== 270 // Alias models are position independent, so the cache manager can move them. 271 272 // NOTE: the first three lines must match maliasgroupframedesc_t 273 typedef struct { 274 trivertx_t bboxmin; 275 trivertx_t bboxmax; 276 int frame; 277 aliasframetype_t type; 278 int firstpose; 279 int numposes; 280 float interval; 281 char name[16]; 282 } maliasframedesc_t; 283 284 typedef struct { 285 aliasskintype_t type; 286 int skin; 287 int texnum; 288 int fb_texnum; 289 } maliasskindesc_t; 290 291 typedef struct { 292 int numframes; 293 int intervals; 294 maliasframedesc_t frames[1]; 295 } maliasgroup_t; 296 297 typedef struct { 298 int numskins; 299 int intervals; 300 maliasskindesc_t skindescs[1]; 301 } maliasskingroup_t; 302 303 // !!! if this is changed, it must be changed in asm_draw.h too !!! 304 typedef struct mtriangle_s { 305 int facesfront; 306 int vertindex[3]; 307 } mtriangle_t; 308 309 310 #define MAX_SKINS 32 311 typedef struct { 312 int model; 313 int stverts; 314 int skindesc; 315 int triangles; 316 317 mdl_t mdl; 318 int tex_coord; 319 int numposes; 320 int poseverts; 321 int posedata; // numposes * poseverts trivert_t 322 int commands; // gl command list with embedded s/t 323 324 unsigned short crc; 325 326 maliasframedesc_t frames[1]; 327 } aliashdr_t; 328 329 #define MAXALIASFRAMES 256 330 extern aliashdr_t *pheader; 331 extern stvert_t *stverts; 332 extern mtriangle_t *triangles; 333 extern trivertx_t *poseverts[MAXALIASFRAMES]; 334 extern int aliasbboxmins[3]; 335 extern int aliasbboxmaxs[3]; 336 337 // Whole model ================================================================ 338 339 typedef enum {mod_brush, mod_sprite, mod_alias, mod_iqm} modtype_t; 340 341 #define EF_ROCKET 1 // leave a trail 342 #define EF_GRENADE 2 // leave a trail 343 #define EF_GIB 4 // leave a trail 344 #define EF_ROTATE 8 // rotate (bonus items) 345 #define EF_TRACER 16 // green split trail 346 #define EF_ZOMGIB 32 // small blood trail 347 #define EF_TRACER2 64 // orange split trail + rotate 348 #define EF_TRACER3 128 // purple trail 349 #define EF_GLOWTRAIL 4096 // glowcolor particle trail 350 351 typedef struct model_s { 352 char name[MAX_QPATH]; 353 qboolean needload; // bmodels and sprites don't cache normally 354 aliashdr_t *aliashdr; // if not null, alias model is not cached 355 qboolean hasfullbrights; 356 357 modtype_t type; 358 int numframes; 359 synctype_t synctype; 360 361 int flags; 362 363 // lighting info 364 float min_light; 365 byte shadow_alpha; // 255 = 1.0 366 byte fullbright; 367 368 // coarse cull, for fine culling, axis-aligned bbox isn't good enough 369 float radius; 370 // FIXME: bbox cruft has to stay until sw rendering gets updated 371 vec3_t mins, maxs; 372 373 // solid volume for clipping 374 qboolean clipbox; 375 vec3_t clipmins, clipmaxs; 376 377 // brush model 378 int firstmodelsurface, nummodelsurfaces; 379 380 int numsubmodels; 381 dmodel_t *submodels; 382 383 int numplanes; 384 plane_t *planes; 385 386 int numleafs; // number of visible leafs, not counting 0 387 mleaf_t *leafs; 388 389 int numvertexes; 390 mvertex_t *vertexes; 391 392 int numedges; 393 medge_t *edges; 394 395 int numnodes; 396 mnode_t *nodes; 397 int depth; ///< maximum depth of the tree 398 399 int numtexinfo; 400 mtexinfo_t *texinfo; 401 402 int numsurfaces; 403 msurface_t *surfaces; 404 405 int numsurfedges; 406 int *surfedges; 407 408 int numclipnodes; 409 mclipnode_t *clipnodes; 410 411 int nummarksurfaces; 412 msurface_t **marksurfaces; 413 414 hull_t hulls[MAX_MAP_HULLS]; 415 hull_t *hull_list[MAX_MAP_HULLS]; 416 417 int numtextures; 418 texture_t **textures; 419 texture_t *skytexture; 420 421 byte *visdata; 422 byte *lightdata; 423 char *entities; 424 425 unsigned int checksum; 426 unsigned int checksum2; 427 428 // additional model data 429 cache_user_t cache; 430 void (*clear) (struct model_s *m); 431 } model_t; 432 433 // ============================================================================ 434 435 extern float RadiusFromBounds (const vec3_t mins, const vec3_t maxs); 436 void Mod_Init (void); 437 void Mod_Init_Cvars (void); 438 void Mod_ClearAll (void); 439 model_t *Mod_ForName (const char *name, qboolean crash); 440 void *Mod_Extradata (model_t *mod); // handles caching 441 void Mod_TouchModel (const char *name); 442 443 mleaf_t *Mod_PointInLeaf (const vec3_t p, model_t *model); 444 byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model); 445 model_t *Mod_FindName (const char *name); 446 int Mod_CalcFullbright (byte *in, byte *out, int pixels); 447 int Mod_Fullbright (byte * skin, int width, int height, char *name); 448 449 void *Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame, 450 int extra); 451 void *Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame, 452 int extra); 453 454 void Mod_FindClipDepth (hull_t *hull); 455 void Mod_LoadBrushModel (model_t *mod, void *buffer); 456 void Mod_FloodFillSkin (byte * skin, int skinwidth, int skinheight); 457 458 void Mod_Print (void); 459 460 extern struct cvar_s *gl_mesh_cache; 461 extern struct cvar_s *gl_subdivide_size; 462 extern struct cvar_s *gl_alias_render_tri; 463 extern struct cvar_s *gl_textures_external; 464 extern model_t *loadmodel; 465 extern char *loadname; 466 extern byte *mod_base; 467 extern byte mod_novis[MAX_MAP_LEAFS / 8]; 468 extern int mod_lightmap_bytes; 469 470 #endif // _MODEL_H 471