r_model.h (5183B)
1 /* 2 Copyright (C) 1997-2001 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 /* 25 26 d*_t structures are on-disk representations 27 m*_t structures are in-memory 28 29 */ 30 31 32 /* 33 ============================================================================== 34 35 BRUSH MODELS 36 37 ============================================================================== 38 */ 39 40 41 // 42 // in memory representation 43 // 44 // !!! if this is changed, it must be changed in asm_draw.h too !!! 45 typedef struct 46 { 47 vec3_t position; 48 } mvertex_t; 49 50 #define SIDE_FRONT 0 51 #define SIDE_BACK 1 52 #define SIDE_ON 2 53 54 55 // plane_t structure 56 // !!! if this is changed, it must be changed in asm_i386.h too !!! 57 typedef struct mplane_s 58 { 59 vec3_t normal; 60 float dist; 61 byte type; // for texture axis selection and fast side tests 62 byte signbits; // signx + signy<<1 + signz<<1 63 byte pad[2]; 64 } mplane_t; 65 66 67 // FIXME: differentiate from texinfo SURF_ flags 68 #define SURF_PLANEBACK 2 69 #define SURF_DRAWSKY 4 // sky brush face 70 #define SURF_DRAWTURB 0x10 71 #define SURF_DRAWBACKGROUND 0x40 72 #define SURF_DRAWSKYBOX 0x80 // sky box 73 74 #define SURF_FLOW 0x100 //PGM 75 76 // !!! if this is changed, it must be changed in asm_draw.h too !!! 77 typedef struct 78 { 79 unsigned short v[2]; 80 unsigned int cachededgeoffset; 81 } medge_t; 82 83 typedef struct mtexinfo_s 84 { 85 float vecs[2][4]; 86 float mipadjust; 87 image_t *image; 88 int flags; 89 int numframes; 90 struct mtexinfo_s *next; // animation chain 91 } mtexinfo_t; 92 93 typedef struct msurface_s 94 { 95 int visframe; // should be drawn when node is crossed 96 97 int dlightframe; 98 int dlightbits; 99 100 mplane_t *plane; 101 int flags; 102 103 int firstedge; // look up in model->surfedges[], negative numbers 104 int numedges; // are backwards edges 105 106 // surface generation data 107 struct surfcache_s *cachespots[MIPLEVELS]; 108 109 short texturemins[2]; 110 short extents[2]; 111 112 mtexinfo_t *texinfo; 113 114 // lighting info 115 byte styles[MAXLIGHTMAPS]; 116 byte *samples; // [numstyles*surfsize] 117 118 struct msurface_s *nextalphasurface; 119 } msurface_t; 120 121 122 #define CONTENTS_NODE -1 123 typedef struct mnode_s 124 { 125 // common with leaf 126 int contents; // CONTENTS_NODE, to differentiate from leafs 127 int visframe; // node needs to be traversed if current 128 129 short minmaxs[6]; // for bounding box culling 130 131 struct mnode_s *parent; 132 133 // node specific 134 mplane_t *plane; 135 struct mnode_s *children[2]; 136 137 unsigned short firstsurface; 138 unsigned short numsurfaces; 139 } mnode_t; 140 141 142 143 typedef struct mleaf_s 144 { 145 // common with node 146 int contents; // wil be something other than CONTENTS_NODE 147 int visframe; // node needs to be traversed if current 148 149 short minmaxs[6]; // for bounding box culling 150 151 struct mnode_s *parent; 152 153 // leaf specific 154 int cluster; 155 int area; 156 157 msurface_t **firstmarksurface; 158 int nummarksurfaces; 159 int key; // BSP sequence number for leaf's contents 160 } mleaf_t; 161 162 163 //=================================================================== 164 165 // 166 // Whole model 167 // 168 169 typedef enum {mod_bad, mod_brush, mod_sprite, mod_alias } modtype_t; 170 171 typedef struct model_s 172 { 173 char name[MAX_QPATH]; 174 175 int registration_sequence; 176 177 modtype_t type; 178 int numframes; 179 180 int flags; 181 182 // 183 // volume occupied by the model graphics 184 // 185 vec3_t mins, maxs; 186 187 // 188 // solid volume for clipping (sent from server) 189 // 190 qboolean clipbox; 191 vec3_t clipmins, clipmaxs; 192 193 // 194 // brush model 195 // 196 int firstmodelsurface, nummodelsurfaces; 197 198 int numsubmodels; 199 dmodel_t *submodels; 200 201 int numplanes; 202 mplane_t *planes; 203 204 int numleafs; // number of visible leafs, not counting 0 205 mleaf_t *leafs; 206 207 int numvertexes; 208 mvertex_t *vertexes; 209 210 int numedges; 211 medge_t *edges; 212 213 int numnodes; 214 int firstnode; 215 mnode_t *nodes; 216 217 int numtexinfo; 218 mtexinfo_t *texinfo; 219 220 int numsurfaces; 221 msurface_t *surfaces; 222 223 int numsurfedges; 224 int *surfedges; 225 226 int nummarksurfaces; 227 msurface_t **marksurfaces; 228 229 dvis_t *vis; 230 231 byte *lightdata; 232 233 // for alias models and sprites 234 image_t *skins[MAX_MD2SKINS]; 235 void *extradata; 236 int extradatasize; 237 } model_t; 238 239 //============================================================================ 240 241 void Mod_Init (void); 242 void Mod_ClearAll (void); 243 model_t *Mod_ForName (char *name, qboolean crash); 244 void *Mod_Extradata (model_t *mod); // handles caching 245 void Mod_TouchModel (char *name); 246 247 mleaf_t *Mod_PointInLeaf (float *p, model_t *model); 248 byte *Mod_ClusterPVS (int cluster, model_t *model); 249 250 void Mod_Modellist_f (void); 251 void Mod_FreeAll (void); 252 void Mod_Free (model_t *mod); 253 254 extern int registration_sequence; 255 256 #endif // __MODEL__