gl_model.h 8.9 KB

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