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