model.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. #define EF_FLAG1 16
  29. #define EF_FLAG2 32
  30. #define EF_BLUE 64
  31. #define EF_RED 128
  32. /*
  33. ==============================================================================
  34. BRUSH MODELS
  35. ==============================================================================
  36. */
  37. //
  38. // in memory representation
  39. //
  40. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  41. typedef struct
  42. {
  43. vec3_t position;
  44. } mvertex_t;
  45. #define SIDE_FRONT 0
  46. #define SIDE_BACK 1
  47. #define SIDE_ON 2
  48. // plane_t structure
  49. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  50. typedef struct mplane_s
  51. {
  52. vec3_t normal;
  53. float dist;
  54. byte type; // for texture axis selection and fast side tests
  55. byte signbits; // signx + signy<<1 + signz<<1
  56. byte pad[2];
  57. } mplane_t;
  58. typedef struct texture_s
  59. {
  60. char name[16];
  61. unsigned width, height;
  62. int anim_total; // total tenths in sequence ( 0 = no)
  63. int anim_min, anim_max; // time for this frame min <=time< max
  64. struct texture_s *anim_next; // in the animation sequence
  65. struct texture_s *alternate_anims; // bmodels in frmae 1 use these
  66. unsigned offsets[MIPLEVELS]; // four mip maps stored
  67. } texture_t;
  68. #define SURF_PLANEBACK 2
  69. #define SURF_DRAWSKY 4
  70. #define SURF_DRAWSPRITE 8
  71. #define SURF_DRAWTURB 0x10
  72. #define SURF_DRAWTILED 0x20
  73. #define SURF_DRAWBACKGROUND 0x40
  74. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  75. typedef struct
  76. {
  77. unsigned short v[2];
  78. unsigned int cachededgeoffset;
  79. } medge_t;
  80. typedef struct
  81. {
  82. float vecs[2][4];
  83. float mipadjust;
  84. texture_t *texture;
  85. int flags;
  86. } mtexinfo_t;
  87. typedef struct msurface_s
  88. {
  89. int visframe; // should be drawn when node is crossed
  90. int dlightframe;
  91. int dlightbits;
  92. mplane_t *plane;
  93. int flags;
  94. int firstedge; // look up in model->surfedges[], negative numbers
  95. int numedges; // are backwards edges
  96. // surface generation data
  97. struct surfcache_s *cachespots[MIPLEVELS];
  98. short texturemins[2];
  99. short extents[2];
  100. mtexinfo_t *texinfo;
  101. // lighting info
  102. byte styles[MAXLIGHTMAPS];
  103. byte *samples; // [numstyles*surfsize]
  104. } msurface_t;
  105. typedef struct mnode_s
  106. {
  107. // common with leaf
  108. int contents; // 0, to differentiate from leafs
  109. int visframe; // node needs to be traversed if current
  110. short minmaxs[6]; // for bounding box culling
  111. struct mnode_s *parent;
  112. // node specific
  113. mplane_t *plane;
  114. struct mnode_s *children[2];
  115. unsigned short firstsurface;
  116. unsigned short numsurfaces;
  117. } mnode_t;
  118. typedef struct mleaf_s
  119. {
  120. // common with node
  121. int contents; // wil be a negative contents number
  122. int visframe; // node needs to be traversed if current
  123. short minmaxs[6]; // for bounding box culling
  124. struct mnode_s *parent;
  125. // leaf specific
  126. byte *compressed_vis;
  127. struct efrag_s *efrags;
  128. msurface_t **firstmarksurface;
  129. int nummarksurfaces;
  130. int key; // BSP sequence number for leaf's contents
  131. byte ambient_sound_level[NUM_AMBIENTS];
  132. } mleaf_t;
  133. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  134. typedef struct
  135. {
  136. dclipnode_t *clipnodes;
  137. mplane_t *planes;
  138. int firstclipnode;
  139. int lastclipnode;
  140. vec3_t clip_mins;
  141. vec3_t clip_maxs;
  142. } hull_t;
  143. /*
  144. ==============================================================================
  145. SPRITE MODELS
  146. ==============================================================================
  147. */
  148. // FIXME: shorten these?
  149. typedef struct mspriteframe_s
  150. {
  151. int width;
  152. int height;
  153. void *pcachespot; // remove?
  154. float up, down, left, right;
  155. byte pixels[4];
  156. } mspriteframe_t;
  157. typedef struct
  158. {
  159. int numframes;
  160. float *intervals;
  161. mspriteframe_t *frames[1];
  162. } mspritegroup_t;
  163. typedef struct
  164. {
  165. spriteframetype_t type;
  166. mspriteframe_t *frameptr;
  167. } mspriteframedesc_t;
  168. typedef struct
  169. {
  170. int type;
  171. int maxwidth;
  172. int maxheight;
  173. int numframes;
  174. float beamlength; // remove?
  175. void *cachespot; // remove?
  176. mspriteframedesc_t frames[1];
  177. } msprite_t;
  178. /*
  179. ==============================================================================
  180. ALIAS MODELS
  181. Alias models are position independent, so the cache manager can move them.
  182. ==============================================================================
  183. */
  184. typedef struct
  185. {
  186. aliasframetype_t type;
  187. trivertx_t bboxmin;
  188. trivertx_t bboxmax;
  189. int frame;
  190. char name[16];
  191. } maliasframedesc_t;
  192. typedef struct
  193. {
  194. aliasskintype_t type;
  195. void *pcachespot;
  196. int skin;
  197. } maliasskindesc_t;
  198. typedef struct
  199. {
  200. trivertx_t bboxmin;
  201. trivertx_t bboxmax;
  202. int frame;
  203. } maliasgroupframedesc_t;
  204. typedef struct
  205. {
  206. int numframes;
  207. int intervals;
  208. maliasgroupframedesc_t frames[1];
  209. } maliasgroup_t;
  210. typedef struct
  211. {
  212. int numskins;
  213. int intervals;
  214. maliasskindesc_t skindescs[1];
  215. } maliasskingroup_t;
  216. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  217. typedef struct mtriangle_s {
  218. int facesfront;
  219. int vertindex[3];
  220. } mtriangle_t;
  221. typedef struct {
  222. int model;
  223. int stverts;
  224. int skindesc;
  225. int triangles;
  226. maliasframedesc_t frames[1];
  227. } aliashdr_t;
  228. //===================================================================
  229. //
  230. // Whole model
  231. //
  232. typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t;
  233. #define EF_ROCKET 1 // leave a trail
  234. #define EF_GRENADE 2 // leave a trail
  235. #define EF_GIB 4 // leave a trail
  236. #define EF_ROTATE 8 // rotate (bonus items)
  237. #define EF_TRACER 16 // green split trail
  238. #define EF_ZOMGIB 32 // small blood trail
  239. #define EF_TRACER2 64 // orange split trail + rotate
  240. #define EF_TRACER3 128 // purple trail
  241. typedef struct model_s
  242. {
  243. char name[MAX_QPATH];
  244. qboolean needload; // bmodels and sprites don't cache normally
  245. modtype_t type;
  246. int numframes;
  247. synctype_t synctype;
  248. int flags;
  249. //
  250. // volume occupied by the model graphics
  251. //
  252. vec3_t mins, maxs;
  253. float radius;
  254. //
  255. // solid volume for clipping (sent from server)
  256. //
  257. qboolean clipbox;
  258. vec3_t clipmins, clipmaxs;
  259. //
  260. // brush model
  261. //
  262. int firstmodelsurface, nummodelsurfaces;
  263. int numsubmodels;
  264. dmodel_t *submodels;
  265. int numplanes;
  266. mplane_t *planes;
  267. int numleafs; // number of visible leafs, not counting 0
  268. mleaf_t *leafs;
  269. int numvertexes;
  270. mvertex_t *vertexes;
  271. int numedges;
  272. medge_t *edges;
  273. int numnodes;
  274. mnode_t *nodes;
  275. int numtexinfo;
  276. mtexinfo_t *texinfo;
  277. int numsurfaces;
  278. msurface_t *surfaces;
  279. int numsurfedges;
  280. int *surfedges;
  281. int numclipnodes;
  282. dclipnode_t *clipnodes;
  283. int nummarksurfaces;
  284. msurface_t **marksurfaces;
  285. hull_t hulls[MAX_MAP_HULLS];
  286. int numtextures;
  287. texture_t **textures;
  288. byte *visdata;
  289. byte *lightdata;
  290. char *entities;
  291. unsigned checksum; // for world models only
  292. unsigned checksum2; // for world models only
  293. //
  294. // additional model data
  295. //
  296. cache_user_t cache; // only access through Mod_Extradata
  297. } model_t;
  298. //============================================================================
  299. void Mod_Init (void);
  300. void Mod_ClearAll (void);
  301. model_t *Mod_ForName (char *name, qboolean crash);
  302. void *Mod_Extradata (model_t *mod); // handles caching
  303. void Mod_TouchModel (char *name);
  304. mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
  305. byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model);
  306. #endif // __MODEL__