Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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