r_model.h 5.1 KB

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