model.h 7.6 KB

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