1 /* 2 Copyright (C) 1996-1997 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 21 #ifndef __MODEL__ 22 #define __MODEL__ 23 24 #include "modelgen.h" 25 #include "spritegn.h" 26 27 /* 28 29 d*_t structures are on-disk representations 30 m*_t structures are in-memory 31 32 */ 33 34 // entity effects 35 36 #define EF_BRIGHTFIELD 1 37 #define EF_MUZZLEFLASH 2 38 #define EF_BRIGHTLIGHT 4 39 #define EF_DIMLIGHT 8 40 41 42 /* 43 ============================================================================== 44 45 BRUSH MODELS 46 47 ============================================================================== 48 */ 49 50 51 // 52 // in memory representation 53 // 54 // !!! if this is changed, it must be changed in asm_draw.h too !!! 55 typedef struct 56 { 57 vec3_t position; 58 } mvertex_t; 59 60 #define SIDE_FRONT 0 61 #define SIDE_BACK 1 62 #define SIDE_ON 2 63 64 65 // plane_t structure 66 // !!! if this is changed, it must be changed in asm_i386.h too !!! 67 typedef struct mplane_s 68 { 69 vec3_t normal; 70 float dist; 71 byte type; // for texture axis selection and fast side tests 72 byte signbits; // signx + signy<<1 + signz<<1 73 byte pad[2]; 74 } mplane_t; 75 76 typedef struct texture_s 77 { 78 char name[16]; 79 unsigned width, height; 80 int gl_texturenum; 81 struct msurface_s *texturechain; // for gl_texsort drawing 82 int anim_total; // total tenths in sequence ( 0 = no) 83 int anim_min, anim_max; // time for this frame min <=time< max 84 struct texture_s *anim_next; // in the animation sequence 85 struct texture_s *alternate_anims; // bmodels in frmae 1 use these 86 unsigned offsets[MIPLEVELS]; // four mip maps stored 87 } texture_t; 88 89 90 #define SURF_PLANEBACK 2 91 #define SURF_DRAWSKY 4 92 #define SURF_DRAWSPRITE 8 93 #define SURF_DRAWTURB 0x10 94 #define SURF_DRAWTILED 0x20 95 #define SURF_DRAWBACKGROUND 0x40 96 #define SURF_UNDERWATER 0x80 97 98 // !!! if this is changed, it must be changed in asm_draw.h too !!! 99 typedef struct 100 { 101 unsigned short v[2]; 102 unsigned int cachededgeoffset; 103 } medge_t; 104 105 typedef struct 106 { 107 float vecs[2][4]; 108 float mipadjust; 109 texture_t *texture; 110 int flags; 111 } mtexinfo_t; 112 113 #define VERTEXSIZE 7 114 115 typedef struct glpoly_s 116 { 117 struct glpoly_s *next; 118 struct glpoly_s *chain; 119 int numverts; 120 int flags; // for SURF_UNDERWATER 121 float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2) 122 } glpoly_t; 123 124 typedef struct msurface_s 125 { 126 int visframe; // should be drawn when node is crossed 127 128 mplane_t *plane; 129 int flags; 130 131 int firstedge; // look up in model->surfedges[], negative numbers 132 int numedges; // are backwards edges 133 134 short texturemins[2]; 135 short extents[2]; 136 137 int light_s, light_t; // gl lightmap coordinates 138 139 glpoly_t *polys; // multiple if warped 140 struct msurface_s *texturechain; 141 142 mtexinfo_t *texinfo; 143 144 // lighting info 145 int dlightframe; 146 int dlightbits; 147 148 int lightmaptexturenum; 149 byte styles[MAXLIGHTMAPS]; 150 int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap 151 qboolean cached_dlight; // true if dynamic light in cache 152 byte *samples; // [numstyles*surfsize] 153 } msurface_t; 154 155 typedef struct mnode_s 156 { 157 // common with leaf 158 int contents; // 0, to differentiate from leafs 159 int visframe; // node needs to be traversed if current 160 161 float minmaxs[6]; // for bounding box culling 162 163 struct mnode_s *parent; 164 165 // node specific 166 mplane_t *plane; 167 struct mnode_s *children[2]; 168 169 unsigned short firstsurface; 170 unsigned short numsurfaces; 171 } mnode_t; 172 173 174 175 typedef struct mleaf_s 176 { 177 // common with node 178 int contents; // wil be a negative contents number 179 int visframe; // node needs to be traversed if current 180 181 float minmaxs[6]; // for bounding box culling 182 183 struct mnode_s *parent; 184 185 // leaf specific 186 byte *compressed_vis; 187 efrag_t *efrags; 188 189 msurface_t **firstmarksurface; 190 int nummarksurfaces; 191 int key; // BSP sequence number for leaf's contents 192 byte ambient_sound_level[NUM_AMBIENTS]; 193 } mleaf_t; 194 195 // !!! if this is changed, it must be changed in asm_i386.h too !!! 196 typedef struct 197 { 198 dclipnode_t *clipnodes; 199 mplane_t *planes; 200 int firstclipnode; 201 int lastclipnode; 202 vec3_t clip_mins; 203 vec3_t clip_maxs; 204 } hull_t; 205 206 /* 207 ============================================================================== 208 209 SPRITE MODELS 210 211 ============================================================================== 212 */ 213 214 215 // FIXME: shorten these? 216 typedef struct mspriteframe_s 217 { 218 int width; 219 int height; 220 float up, down, left, right; 221 int gl_texturenum; 222 } mspriteframe_t; 223 224 typedef struct 225 { 226 int numframes; 227 float *intervals; 228 mspriteframe_t *frames[1]; 229 } mspritegroup_t; 230 231 typedef struct 232 { 233 spriteframetype_t type; 234 mspriteframe_t *frameptr; 235 } mspriteframedesc_t; 236 237 typedef struct 238 { 239 int type; 240 int maxwidth; 241 int maxheight; 242 int numframes; 243 float beamlength; // remove? 244 void *cachespot; // remove? 245 mspriteframedesc_t frames[1]; 246 } msprite_t; 247 248 249 /* 250 ============================================================================== 251 252 ALIAS MODELS 253 254 Alias models are position independent, so the cache manager can move them. 255 ============================================================================== 256 */ 257 258 typedef struct 259 { 260 int firstpose; 261 int numposes; 262 float interval; 263 trivertx_t bboxmin; 264 trivertx_t bboxmax; 265 int frame; 266 char name[16]; 267 } maliasframedesc_t; 268 269 typedef struct 270 { 271 trivertx_t bboxmin; 272 trivertx_t bboxmax; 273 int frame; 274 } maliasgroupframedesc_t; 275 276 typedef struct 277 { 278 int numframes; 279 int intervals; 280 maliasgroupframedesc_t frames[1]; 281 } maliasgroup_t; 282 283 // !!! if this is changed, it must be changed in asm_draw.h too !!! 284 typedef struct mtriangle_s { 285 int facesfront; 286 int vertindex[3]; 287 } mtriangle_t; 288 289 290 #define MAX_SKINS 32 291 typedef struct { 292 int ident; 293 int version; 294 vec3_t scale; 295 vec3_t scale_origin; 296 float boundingradius; 297 vec3_t eyeposition; 298 int numskins; 299 int skinwidth; 300 int skinheight; 301 int numverts; 302 int numtris; 303 int numframes; 304 synctype_t synctype; 305 int flags; 306 float size; 307 308 int numposes; 309 int poseverts; 310 int posedata; // numposes*poseverts trivert_t 311 int commands; // gl command list with embedded s/t 312 int gl_texturenum[MAX_SKINS][4]; 313 int texels[MAX_SKINS]; // only for player skins 314 maliasframedesc_t frames[1]; // variable sized 315 } aliashdr_t; 316 317 #define MAXALIASVERTS 2000 //1024, now same as WinQuake 318 #define MAXALIASFRAMES 256 319 #define MAXALIASTRIS 2048 320 extern aliashdr_t *pheader; 321 extern stvert_t stverts[MAXALIASVERTS]; 322 extern mtriangle_t triangles[MAXALIASTRIS]; 323 extern trivertx_t *poseverts[MAXALIASFRAMES]; 324 325 //=================================================================== 326 327 // 328 // Whole model 329 // 330 331 typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t; 332 333 #define EF_ROCKET 1 // leave a trail 334 #define EF_GRENADE 2 // leave a trail 335 #define EF_GIB 4 // leave a trail 336 #define EF_ROTATE 8 // rotate (bonus items) 337 #define EF_TRACER 16 // green split trail 338 #define EF_ZOMGIB 32 // small blood trail 339 #define EF_TRACER2 64 // orange split trail + rotate 340 #define EF_TRACER3 128 // purple trail 341 342 #define AUTOBRIGHTS 2 343 344 typedef struct model_s 345 { 346 char name[MAX_QPATH]; 347 qboolean needload; // bmodels and sprites don't cache normally 348 qboolean fullbright; // for special models 349 int autobright[AUTOBRIGHTS]; 350 qboolean candle; 351 qboolean lantern; 352 qboolean eyes; 353 qboolean bolt; 354 qboolean missile; 355 qboolean quaddama; 356 qboolean invulner; 357 358 modtype_t type; 359 int numframes; 360 synctype_t synctype; 361 362 int flags; 363 364 // 365 // volume occupied by the model graphics 366 // 367 vec3_t mins, maxs; 368 float radius; 369 370 // 371 // solid volume for clipping 372 // 373 qboolean clipbox; 374 vec3_t clipmins, clipmaxs; 375 376 // 377 // brush model 378 // 379 int firstmodelsurface, nummodelsurfaces; 380 381 int numsubmodels; 382 dmodel_t *submodels; 383 384 int numplanes; 385 mplane_t *planes; 386 387 int numleafs; // number of visible leafs, not counting 0 388 mleaf_t *leafs; 389 390 int numvertexes; 391 mvertex_t *vertexes; 392 393 int numedges; 394 medge_t *edges; 395 396 int numnodes; 397 mnode_t *nodes; 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 dclipnode_t *clipnodes; 410 411 int nummarksurfaces; 412 msurface_t **marksurfaces; 413 414 hull_t hulls[MAX_MAP_HULLS]; 415 416 int numtextures; 417 texture_t **textures; 418 419 byte *visdata; 420 byte *lightdata; 421 char *entities; 422 423 // 424 // additional model data 425 // 426 cache_user_t cache; // only access through Mod_Extradata 427 428 } model_t; 429 430 //============================================================================ 431 432 void Mod_Init (void); 433 void Mod_ClearAll (void); 434 model_t *Mod_ForName (char *name, qboolean crash); 435 void *Mod_Extradata (model_t *mod); // handles caching 436 void Mod_TouchModel (char *name); 437 438 mleaf_t *Mod_PointInLeaf (float *p, model_t *model); 439 byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model); 440 441 #endif // __MODEL__ 442