1 //-----------------------------------------------------------------------------
2 // Types
3 // Defines base types
4 //-----------------------------------------------------------------------------
5 
6 /**
7  * This file contents the declaration of some types of base. These types
8  * are used everywhere in the engine.
9  */
10 
11 #ifndef __TYPES_H__
12 #define __TYPES_H__
13 
14 #include "definitions.h"
15 #include "shaderflags.h"
16 #include <string.h>         // for NULL pointer + memset
17 
18 class Messages;
19 class Var;                  // Variable
20 class Vars;                 // Variables list
21 class Commands;
22 class LogFile;              // Log file support
23 class Console;              // Console
24 class FrameWork;            // FrameWork
25 class Timer;                // Timer
26 class Render;               // Render
27 class Camera;               // Camera
28 class Frustum;              // Frustum
29 class Entity;               // Entity
30 class Surface;
31 class Overlay;
32 class TextureManager;
33 class LayerManager;
34 class ShaderManager;
35 class EntityManager;
36 class World;
37 class Client;
38 class Alias;
39 class Q3BSP;
40 class BezierPatch;
41 class App;                  // Application
42 
43 typedef float vec_t;
44 typedef vec_t vec2_t[2];
45 typedef vec_t vec3_t[3];
46 typedef vec_t vec4_t[4];
47 typedef vec_t vec5_t[5];
48 
49 typedef float texcoord_t[2];        /**< Texture s&t coordinates */
50 typedef int bbox_t[6];              /**< Integer bounding box (mins, maxs) */
51 typedef float bboxf_t[6];           /**< Float bounding box */
52 typedef unsigned char colour_t[4];  /**< RGBA */
53 
54 // Undo any Windows defines.
55 #undef BYTE
56 #undef WORD
57 #undef DWORD
58 #undef INT
59 #undef UINT
60 #undef FLOAT
61 #undef MAXBYTE
62 #undef MAXWORD
63 #undef MAXDWORD
64 #undef MAXINT
65 #undef CDECL
66 #undef BOOL
67 
68 // Unsigned base types.
69 typedef unsigned char     BYTE;     /**< 8-bit  unsigned. */
70 typedef unsigned int      UINT;
71 typedef unsigned short    WORD;     /**< 16-bit unsigned. */
72 typedef unsigned int     DWORD;    /**< 32-bit unsigned. */
73 #ifdef WIN32
74 typedef unsigned __int64  QWORD;    /**< 64-bit unsigned. */
75 #endif
76 
77 // Signed base types.
78 typedef signed char       SBYTE;    /**< 8-bit  signed. */
79 typedef signed short      SWORD;    /**< 16-bit signed. */
80 typedef signed int        INT;      /**< 32-bit signed. */
81 #ifdef WIN32
82 typedef signed __int64    SQWORD;   // 64-bit signed. */
83 #endif
84 
85 // small letter version:
86 typedef unsigned char     byte;
87 typedef unsigned short    word;
88 typedef unsigned int      dword;
89 
90 // other types.
91 typedef float       FLOAT;
92 typedef double      DOUBLE;         /**< 64-bit IEEE double. */
93 typedef INT         BOOL;
94 typedef int        LONG;
95 
96 /**
97  * Engine states.
98  * The states engines are used to mark different steps in engine execution.
99  * Depending on the current state, some functions or some features are
100  * enabled or disabled.
101  */
102 typedef enum
103 {
104   INACTIVE = 0,               /**< the engine is inactive */
105   INITIALIZING = 1,           /**< the engine is in initialization phase */
106   RUNNING = 2,                /**< the engine is running */
107   SHUTING = 3                 /**< the engine is shuting down */
108 } EngineState;
109 
110 //-----------------------------------------------------------------------------
111 
112 // content masks
113 #define MASK_ALL          (-1)
114 #define MASK_SOLID        (CONTENTS_SOLID)
115 #define MASK_PLAYERSOLID  (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_BODY)
116 #define MASK_DEADSOLID    (CONTENTS_SOLID|CONTENTS_PLAYERCLIP)
117 #define MASK_MONSTERSOLID (CONTENTS_SOLID|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER)
118 #define MASK_WATER        (CONTENTS_WATER|CONTENTS_LAVA|CONTENTS_SLIME)
119 #define MASK_OPAQUE       (CONTENTS_SOLID|CONTENTS_SLIME|CONTENTS_LAVA)
120 #define MASK_SHOT         (CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_CORPSE)
121 #define MASK_CURRENT      (CONTENTS_CURRENT_0|CONTENTS_CURRENT_90|CONTENTS_CURRENT_180|CONTENTS_CURRENT_270|CONTENTS_CURRENT_UP|CONTENTS_CURRENT_DOWN)
122 
123 //-----------------------------------------------------------------------------
124 
125 /**
126  * Interleaved vertex info.
127  * The vertexes lump stores lists of vertices used to describe faces. There is a
128  * position, texture and lightmap coordinates, the vertex normal and color. There
129  * are a total of length / sizeof(vertex) records in the lump, where length is
130  * the size of the lump itself, as specified in the lump directory.
131  */
132 typedef struct
133 {
134   vec3_t v_point;     /**< vertex position */
135   texcoord_t tex_st;  /**< surface texture coords */
136   texcoord_t lm_st;   /**< lightmap texture coords */
137   vec3_t v_norm;      /**< vertex normal */
138   colour_t colour;    /**< colour used for vertex lighting (RGBA) */
139 } vertex_t;
140 
141 /**
142  * Faces (or surfaces).
143  * The faces lump stores information used to render the surfaces of the map.
144  * There are a total of length / sizeof(faces) records in the lump, where length
145  * is the size of the lump itself, as specified in the lump directory.<br><br>
146  *
147  * There are four types of faces:
148  *   - polygons, which are described by a loop of vertices
149  *   - biquadratic Bezier patches, which are described by a two-dimensional grid
150  *     of control vertices
151  *   - triangle meshes, which contain independent triangles described by a set
152  *     of vertices and a list of vertex indices
153  *   - billboards for flares, which are represented using a single vertex.
154  *
155  * Note: Several components have different meanings depending on the face type.
156  * Note: This struct isn't used in the code (another is used instead)<br><br>
157  *
158  * The lm_ variables are primarily used to deal with lightmap data. A face that
159  * has a lightmap has a non-negative lm_index. For such a face, lm_index is the
160  * index of the image in the lightmaps lump that contains the lighting data for
161  * the face. The data in the lightmap image can be located using the rectangle
162  * specified by lm_start and lm_size.<br><br>
163  *
164  * For type 1 faces (polygons) only, lm_origin and lm_vecs can be used to compute
165  * the world-space positions corresponding to lightmap samples. These positions
166  * can in turn be used to compute dynamic lighting across the face.<br><br>
167  *
168  * None of the lm_ variables are used to compute texture coordinates for indexing
169  * into lightmaps. In fact, lightmap coordinates need not be computed. Instead,
170  * lightmap coordinates are simply stored with the vertices used to describe each
171  * face.<br><br>
172  *
173  * For type 1 faces (polygons), meshvert and n_meshverts describe a valid polygon
174  * triangulation. This is in addition to the loop of vertices described by vertex
175  * and n_vertexes. For certain polygons, the meshverts describe a triangulation
176  * built entirely from the original polygon vertices. For other polygons, the
177  * meshverts describe a triangulation built by adding a central vertex and
178  * building a fan around that vertex.
179  */
180 typedef struct
181 {
182   int shader;           /**< shader reference (texture index) */
183   int effect;           /**< index into lump 12 (Effects), or -1 if n/a */
184   int facetype;         /**< face type: 1=polygon, 2=patch, 3=mesh, 4=billboard */
185   int firstvert,        /**< index of first vertex  */
186       numverts;         /**< number of vertices */
187   int firstelem,        /**< index of first meshvert */
188       numelems;         /**< number of meshverts */
189   int lm_texnum;        /**< lightmap index */
190   int lm_offset[2];     /**< corner of this face's lightmap image in lightmap */
191   int lm_size[2];       /**< size of this face's lightmap image in lightmap */
192   vec3_t v_orig;        /**< world space origin of lightmap (FACETYPE_NORMAL only) */
193   bboxf_t bbox;         /**< world space lightmap s and t unit vectors (FACETYPE_MESH only) */
194   vec3_t v_norm;        /**< surface normal (FACETYPE_NORMAL only) */
195   int mesh_cp[2];       /**< patch dimensions (mesh control point dimensions) */
196 } face_t;
197 
198 /**
199  * Texture info.
200  */
201 typedef struct
202 {
203   int num;              /**< tex index */
204   byte *mem;            /**< data */
205   int width;            /**< texture width */
206   int height;           /**< texture height */
207   int bpp;              /**< texture bits per pixel */
208 } texinfo;
209 
210 typedef struct _texrefs
211 {
212   char *name;
213   int count;            /**< @todo count could be used to give them priorities */
214   int flags;
215   texinfo *info;        /**< each texref has an unique texinfo */
216 } TexRefs;
217 
218 /**
219  * List of functions for sucesive vertex or coordinates modification.
220  */
221 typedef struct _funclist
222 {
223   int func;
224   int parameters;
225   float p[MAX_PARAMS];
226   _funclist *next;
227 } funclist;
228 
229 typedef struct Node_s
230 {
231   int     lightmap;
232   vertex_t *  firstvert;
233   int     numverts;
234   int *   firstelem;
235   int     numelems;
236 } Node;
237 
238 /**
239  * Layers are used for multiple passes on shaders.
240  */
241 typedef struct
242 {
243   int       flags;              /**< layer flags */
244 
245   float     anim_speed;         /**< speed of the animation */
246   int       num_maps;           /**< number of texures (for animated layers) */
247   texinfo   *map[MAX_ANIMFRAMES]; /**< array of the maps */
248 
249   funclist  *tcMod;             /**< texture coordinates modifiers */
250   funclist  *aGen;              /**< alpha color generation */
251 
252   TCGEN     tcGen;
253 
254   RGBGEN    rgbGen;
255   float     rgbGenParams[5];
256 
257   ALPHAGEN  alphaGen;           /**< alpha channel generation */
258   float     alphaGenParams[5];  /**< alpha channel parameter */
259 
260   int       alphafunc;          /**< alpha function */
261   float     alphafuncref;
262 
263   int       blendsrc;           /**< blend function */
264   int       blenddst;
265 
266   int       depthFunc;          /**< depth func */
267   int       depthWrite;         /**< touch depth buffer */
268 } Layer;
269 
270 /**
271  * Deformed vertex.
272  * @see DEFORMVERTEXES
273  */
274 typedef struct
275 {
276   DEFORMVERTEXES    type;
277   float       params[8];
278 } DeformVertexes;
279 
280 /**
281  * Sky parameters.
282  * @see SkyBox
283  */
284 typedef struct
285 {
286   int num_layers;         /**< 2 layers max */
287   Layer* layer[2][6];     /**< layers used by farbox and nearbox */
288   int cloudheight;        /**< apparent curvature of the cloud layers (default is 128) */
289 } SkyParms;
290 
291 /**
292  * Fog parameters.
293  */
294 typedef struct
295 {
296   Layer* layer;
297   float params[5];
298 } FogParms;
299 
300 /**
301  * A shader describes how a surface is rendered.
302  */
303 typedef struct
304 {
305   char  shadername[64];   /**< shader name - used for debug only */
306 
307   int   surface_flags;    /**< surface_flags (described in surface_flags, come from the bsp,
308                                and not from the shader definition) */
309   int   content_flags;    /**< contents of the shader ? */
310   int   cull;             /**< culling type */
311 
312   int   sortvalue;        /**< @todo Carmack changed int sortvalues to float, why? */
313 
314   /**
315    * Flags to determine misc properties of the shader, like polygonoffset,
316    * multitexture, mipmap, nopicmip, haslightmap, portal... and to determine
317    * which info of the datasource we need to render the surface
318    */
319   int   flags;
320 
321   int   num_layers;           /**< number of layers */
322   Layer * layer[MAX_LAYERS];  /**< layers of stages (passes) table */
323 
324   int         num_deforms;            /**< number of deformations for the shader */
325   DeformVertexes    deformVertexes[MAX_DEFORMS];  /**< vertex deformation */
326 
327   SkyParms      sky_params;           /**< sky parameters */
328   FogParms      fog_params;           /**< fog parameters */
329 } Shader;
330 
331 typedef struct
332 {
333   int   num_nodes;
334   Node* list;           /**< list of elements asociated with this shader */
335 
336   int   ref_count;      /**< number of times this shader has been referenced (for cache issues) */
337   Shader* shader;       /**< the shader itself */
338 
339   char  name[64];       /**< name of the shader */
340   int   flags;          /**< surface flags */
341   int   contents;       /**< content flags */
342   int   type;           /**< ? */
343 } ShaderHash;
344 
345 typedef struct
346 {
347   char *keyword;
348   int minargs, maxargs;
349   void (* func)(Shader *shader, Layer *layer);
350 } shaderkey_t;
351 
352 //-----------------------------------------------------------------------------
353 // BSP Data types
354 //-----------------------------------------------------------------------------
355 
356 /**
357  * BSP lumps in the order they appear in the header
358  */
359 typedef enum
360 {
361   ENTITIES,         /**< Game-related object descriptions */
362   SHADERREFS,       /**< Shader descriptions */
363   _PLANES,          /**< Planes used by map geometry */
364   NODES,            /**< BSP tree nodes */
365   LEAFS,            /**< BSP tree leaves */
366   LFACES,           /**< Leaf faces - Lists of leaf's indices into faces, one list per leaf */
367   LBRUSHES,         /**< Leaf brushes - Lists of leaf's indices into brushes, one list per leaf */
368   MODELS,           /**< Descriptions of rigid world geometry in map */
369   BRUSHES,          /**< Convex polyhedra used to describe solid space */
370   BRUSH_SIDES,      /**< Brush surfaces info */
371   VERTS,            /**< Vertices used to describe faces */
372   ELEMS,            /**< Lists of offsets, one list per mesh */
373   EFFECTS,          /**< List of special map effects */
374   FACES,            /**< Surface geometry */
375   LIGHTMAPS,        /**< Packed lightmap data */
376   LIGHTVOLS,        /**< Local illumination data */
377   VISIBILITY,       /**< Cluster-cluster visibility data */
378   NUM_LUMPS         /**< Number of lumps */
379 } lumps;
380 
381 //-----------------------------------------------------------------------------
382 
383 /**
384  * Shader references (indexed from faces).
385  * The shaders lump stores information about surfaces and volumes, which are in
386  * turn associated with faces, brushes, and brushsides. There are a total of
387  * length / sizeof(texture) records in the lump, where length is the size of the
388  * lump itself, as specified in the lump directory.
389  */
390 typedef struct
391 {
392   char name[64];          /**< Shader name */
393   int surface_flags;      /**< Surface flags */
394   int content_flags;      /**< Content flags */
395 } shaderref_t;
396 
397 /**
398  * Planes.
399  * The planes lump stores a generic set of planes that are in turn referenced by
400  * nodes and brushsides. There are a total of length / sizeof(plane) records in
401  * the lump, where length is the size of the lump itself, as specified in the lump
402  * directory.
403  * Note that planes are paired. The pair of planes with indices i and i ^ 1 are
404  * coincident planes with opposing normals.
405  * @see cplane_t
406  */
407 typedef struct
408 {
409   vec3_t normal;        /**< Plane normal */
410   float dist;           /**< Distance from origin to plane along normal */
411 } plane_t;
412 
413 /**
414  * Nodes in the BSP tree.
415  * The nodes lump stores all of the nodes in the map's BSP tree. The BSP tree is
416  * used primarily as a spatial subdivision scheme, dividing the world into convex
417  * regions called leafs. The first node in the lump is the tree's root node. The
418  * BSP is not used for rendering so much in Quake3, but for collision detection.
419  * The node holds the splitter plane index, the front and back index, aloong with
420  * the bounding box for the node. If the front or back indices are negative, then
421  * it's an index into the leafs array. Since negative numbers can't constitute an
422  * array index, you need to use the ~ operator or -(index + 1) to find the correct
423  * index. This is because 0 is the starting index. There are a total of
424  * length / sizeof(node) records in the lump, where length is the size of the lump
425  * itself, as specified in the lump directory.
426  * @see cnode_t
427  */
428 typedef struct
429 {
430   int plane;            /**< Dividing plane index (index into planes array) */
431   int children[2];      /**< Left and right node. Negatives are leafs indices : -(leaf+1) */
432   bbox_t bbox;          /**< Integer bounding box (order : 3 min + 3 max) */
433 } node_t;
434 
435 /**
436  * Leafs in BSP tree.
437  * The leafs lump stores the leaves of the map's BSP tree. Each leaf is a convex
438  * region that contains, among other things, a cluster index (for determining the
439  * other leafs potentially visible from withing the leaf), a list of faces (for
440  * rendering), and a list of brushes (for collision detection). There are a total
441  * of length / sizeof(leaf) records in the lump, where length is the size of the
442  * lump itself, as specified in the lump directory.
443  * @see cleaf_t
444  */
445 typedef struct
446 {
447   int cluster;        /**< Visibility cluster number */
448   int area;           /**< area minus one ??? */
449   bbox_t bbox;        /**< Integer bounding box (order : 3 min + 3 max) */
450   int firstface,      /**< First leafface for leaf */
451   numfaces;           /**< Number of leaffaces for leaf */
452   int firstbrush,     /**< First leafbrush for leaf */
453   numbrushes;         /**< Number of leafbrushes for leaf */
454 } leaf_t;
455 
456 /**
457  * Leaffaces lump.
458  * The leaffaces lump stores lists of face indices, with one list per leaf. The leaf
459  * faces are used to index into faces array. You might at first think this is strange
460  * to have leaf structure have an index into the lface array, which in turn is just an
461  * index into the faces array. This is because it's set up to start with a starting
462  * point (leafface) and a count to go from there for each face (number of leaffaces).
463  * The faces array is not contiguous (in a row) according to each leaf. That is where
464  * the leaffaces array comes into play. It's kinda like the same concept of model
465  * loaders where they store the vertices and then havefaces that store the indices
466  * into the vertex array for that face. There are a total of length / sizeof(leafface)
467  * records in the lump, where length is the size of the lump itself, as specified in
468  * the lump directory.<br>
469  * Note : this is directly used as int in the code
470  */
471 typedef struct
472 {
473   int face;         /**< Face index */
474 } lface_t;
475 
476 /**
477  * Leafbrushes lump.
478  * The leafbrushes lump stores lists of brush indices, with one list per leaf.
479  * There are a total of length / sizeof(leafbrush) records in the lump, where
480  * length is the size of the lump itself, as specified in the lump directory.<br>
481  * Note : this is directly used as int in the code
482  */
483 typedef struct
484 {
485   int brush;          /**< Brush index */
486 } lbrush_t;
487 
488 /**
489  * Model 0 is the main map, others are doors, gates, buttons, etc.
490  * The models lump describes rigid groups of world geometry. The first model
491  * correponds to the base portion of the map while the remaining models correspond
492  * movable portions of the map, such as the map's doors, platforms, and buttons.
493  * Each model has a list of faces and list of brushes; these are especially
494  * important for the movable parts of the map, which (unlike the base portion of
495  * the map) do not have BSP trees associated with them. There are a total of
496  * length / sizeof(models) records in the lump, where length is the size of the
497  * lump itself, as specified in the lump directory.
498  * @see cmodel_t
499  */
500 typedef struct
501 {
502   bboxf_t bbox;         /**< Bonunding box (order : 3 min + 3 max) */
503   int firstface;        /**< First face for model */
504   int numfaces;         /**< Number of faces for model */
505   int firstbrush;       /**< First brush for model */
506   int numbrushes;       /**< Number of brushes for model */
507 } model_t;
508 
509 /**
510  * Brushes in BSP tree.
511  * The brushes lump stores a set of brushes, which are in turn used for collision
512  * detection. Each brush describes a convex volume as defined by its surrounding
513  * surfaces, the brush sides. There are a total of length / sizeof(brushes) records
514  * in the lump, where length is the size of the lump itself, as specified in the
515  * lump directory.
516  * @see cbrush_t
517  */
518 typedef struct
519 {
520   int firstside;      /**< First brushside for brush */
521   int numsides;       /**< Number of brushsides for brush */
522   int shader;         /**< Texture index */
523 } brush_t;
524 
525 /**
526  * Brushes sides in BSP tree.
527  * The brushsides lump stores descriptions of brush bounding surfaces. There are a
528  * total of length / sizeof(brushsides) records in the lump, where length is the
529  * size of the lump itself, as specified in the lump directory.
530  */
531 typedef struct
532 {
533   int planeidx;       /**< Plane index */
534   int shader;         /**< Texture index (shader) */
535 } brushside_t;
536 
537 /**
538  * Meshverts lump.
539  * The meshverts lump stores lists of vertex offsets, used to describe generalized
540  * triangle meshes. There are a total of length / sizeof(meshvert) records in the
541  * lump, where length is the size of the lump itself, as specified in the lump
542  * directory.<br>
543  * Note : this is directly used as int in the code
544  */
545 typedef struct
546 {
547   int offset;         /**< Vertex index offset, relative to first vertex of corresponding face */
548 } meshvert_t;
549 
550 /**
551  * Effect lump.
552  * The effects lump stores references to volumetric shaders (typically fog) which
553  * affect the rendering of a particular group of faces. There are a total of
554  * length / sizeof(effect) records in the lump, where length is the size of the
555  * lump itself, as specified in the lump directory.
556  * @see ceffect_t
557  */
558 typedef struct
559 {
560   char name[64];      /**< Effect shader */
561   int brush;          /**< Brush that generated this effect */
562   int visibleside;    /**< The brush side that ray tests need to clip against (-1 == none) */
563 } effect_t;
564 
565 /**
566  * Lightmaps lump.
567  * The lightmaps lump stores the light map textures used make surface lighting
568  * look more realistic. There are a total of length / sizeof(lightmap) records in
569  * the lump, where length is the size of the lump itself, as specified in the lump
570  * directory.<br>
571  * Note : this is directly used as BYTE in the code
572  */
573 typedef struct
574 {
575   BYTE map[128][128][3];    /**< Lightmap color data (RGB) */
576 } lightmap_t;
577 
578 /**
579  * Lightvols lump.
580  * The lightvols lump stores a uniform grid of lighting information used to
581  * illuminate non-map objects. There are a total of length / sizeof(lightvol)
582  * records in the lump, where length is the size of the lump itself, as specified
583  * in the lump directory.
584  * <br>
585  * Lightvols make up a 3D grid whose dimensions are:
586  * <pre>
587   nx = floor(models[0].maxs[0] / 64) - ceil(models[0].mins[0] / 64) + 1
588   ny = floor(models[0].maxs[1] / 64) - ceil(models[0].mins[1] / 64) + 1
589   nz = floor(models[0].maxs[2] / 128) - ceil(models[0].mins[2] / 128) + 1
590  * </pre>
591  */
592 typedef struct
593 {
594   BYTE ambient[3];      /**< Ambient color component. RGB. */
595   BYTE directional[3];  /**< Directional color component. RGB. */
596   BYTE dir[2];          /**< Direction to light. 0=phi, 1=theta. */
597 } lightvols_t;
598 
599 /**
600  * Visibility info.
601  * The visdata lump stores bit vectors that provide cluster-to-cluster visibility
602  * information. There is exactly one visdata record, with a length equal to that
603  * specified in the lump directory.<br>
604  * Cluster x is visible from cluster y if the <code>(1 << y % 8)</code> bit of
605  * <code>vecs[x * sz_vecs + y / 8]</code> is set. (cf. BSP_TESTVIS macro)<br>
606  * Note that clusters are associated with leaves.
607  */
608 typedef struct
609 {
610     int numclusters;    /**< Number of PVS clusters (vectors) */
611     int rowsize;        /**< Size of each vector, in bytes */
612     BYTE data[1];       /**< Visibility data. One bit per cluster per vector */
613                         /**<  => size : BYTE data[numclusters*rowsize] */
614 } visibility_t;
615 
616 //-----------------------------------------------------------------------------
617 // Data of the bsp (internal structure of the engine)
618 //-----------------------------------------------------------------------------
619 
620 /**
621  * Faces (or surfaces).
622  */
623 typedef struct
624 {
625   int shader;           /**< Shader reference */
626   int facetype;         /**< FACETYPE enum */
627   vertex_t *firstvert;
628   int numverts;
629   int *firstelem;
630   int numelems;
631   int lm_texnum;
632   vec3_t v_orig;        /**< FACETYPE_NORMAL only */
633   vec3_t v_norm;        /**< FACETYPE_NORMAL only */
634   float planedist;
635 } cnormalface_t;
636 
637 /**
638  * Planes.
639  * @see plane_t
640  */
641 typedef struct cplane_s
642 {
643   vec3_t  normal;     /**< plane normal */
644   float dist;
645   BYTE  type;         /**< for fast side tests: 0,1,2 = axial, 3 = nonaxial */
646   BYTE  signbits;     /**< signx + (signy<<1) + (signz<<2), used as lookup during collision */
647   BYTE  pad[2];       /**< 2 bytes for padding puspouses */
648 } cplane_t;
649 
650 /**
651  * Brushes sides in BSP tree.
652  * The brushsides lump stores descriptions of brush bounding surfaces. There are a
653  * total of length / sizeof(brushsides) records in the lump, where length is the
654  * size of the lump itself, as specified in the lump directory.
655  */
656 typedef struct
657 {
658   int planeidx;       /**< Plane index */
659   int shader;         /**< Texture index (shader) */
660 } cbrushside_t;
661 
662 /**
663  * Model structure.
664  * @see model_t
665  */
666 typedef struct
667 {
668   bboxf_t bbox;         /**< Bonunding box (order : 3 min + 3 max) */
669   int headnode;         /**< First node for model */
670   int firstface;        /**< First face for model */
671   int numfaces;         /**< Number of faces for model */
672   int firstbrush;       /**< First brush for model */
673   int numbrushes;       /**< Number of brushes for model */
674 
675   Entity* entity;       /**< Corresponding entity */
676   bool render;          /**< Is model renderable ? */
677 } cmodel_t;
678 
679 /**
680  * Brushes in BSP tree.
681  * @see brush_t
682  */
683 typedef struct
684 {
685   int firstbrushside;   /**< side index in r_brushsides */
686   int numsides;         /**< number of sides */
687   int shader;           /**< shader */
688   int effect;           /**< effect index (-1 if none) */
689   int contents;         /**< brush content (determined after having loaded all brushes and leafs) */
690   int checkcount;       /**< to avoid repeated testings */
691 } cbrush_t;
692 
693 typedef struct
694 {
695   vec3_t absmins, absmaxs;
696 
697   int numbrushes;
698   int firstbrush;
699 
700   int shader;           /**< patch shader */
701   int checkcount;       /**< to avoid repeated testings */
702 } cpatch_t;
703 
704 /**
705  * Nodes in the BSP tree.
706  * @see node_t
707  */
708 typedef struct cnode_s
709 {
710   cnode_s * parent;
711   int     framenum;
712   int     planeidx;     /**< dividing plane (corresponding variable is r_clipplanes) */
713   int     children[2];  /**< left and right node. Negatives are leafs */
714   bbox_t  bbox;         /**< bounding box */
715 } cnode_t;
716 
717 /**
718  * Leafs in BSP tree.
719  * @see leaf_t
720  */
721 typedef struct
722 {
723   cnode_s * parent;
724   int     framenum;
725   int     contents;   /**< leaf content (determined after having loaded all brushes and leafs) */
726   int     cluster;    /**< visibility cluster number */
727   int     area;       /**< area minus one ??? */
728   bbox_t  bbox;
729   int     firstleafface;  /**< index of leafface in the faces data (get leafface i by using r_leaffaces[firstleafface+i]) */
730   int     numleaffaces;
731   int     firstleafbrush; /**< index of leafbrush in the brush data (get leafbrush i by using r_leafbrushes[firstleafbrush+i]) */
732   int     numleafbrushes;
733   int     firstleafpatch; /**< index of leafpatch in the patch data (get leafpatch i by using r_leafpatches[firstleafpatch+i]) */
734   int     numleafpatches;
735 } cleaf_t;
736 
737 typedef struct
738 {
739   Surface *face;
740   int sort_value;
741 } render_face_s;
742 
743 /**
744  * Effect.
745  * @see effect_t
746  */
747 typedef struct
748 {
749   int shader;         /**< shader reference */
750   int brush;
751   int visibleside;    /**< the brush side that ray tests need to clip against (-1 == none) */
752   int planeidx;       /**< the plane where the effect (fog) starts */
753 } ceffect_t;
754 
755 /**
756  * Surface class.
757  * A surface is a form of face that have following properties:
758  * - the surface is composed with more subfaces, having all the same shader
759  * - the surface can have different tesselation levels (this is used for
760  *   progressive curves subdivisions for isntance)
761  * The advantage of surface is that texture is linked once for each subfaces.
762  * Subfaces can be tied up (cf. skybox) or not (cf. some autosprites).
763  * @todo Try to write an optimization for tied up faces by using a triangle
764  * strip function.
765  * In the case of bezier patches, level 0 stores bsp informations (control
766  * points) as for other faces type and higher levels get patch subdivided faces.
767  */
768 class Surface
769 {
770   public:
771     Surface(void);
772     ~Surface(void);
773 
774     /**
775      * Surface initialization.
776      * This initialize the surface and creates the levels tables. If
777      * surfaces was already initialized, old settings and data are lost.
778      * @param lvl the level for vertices and elems
779      */
780     void Init(int lvl = 1);
781 
782     /**
783      * Destroys the surface content.
784      * The function intialize the surface content and frees the used memory.
785      */
786     void Shut(void);
787 
788     int     levels;       /**< tesselation level */
789     int     currentlevel;
790 
791     int     indextype;    /**< surface index in facetype array */
792 
793     int     model;        /**< model that uses this face */
794 
795     int     framenum;
796 
797     int     facetype;     /**< FACETYPE enum */
798 
799     int     shader;       /**< Shader reference in world shaders manager */
800     int     lm_texnum;    /**< lightmap info */
801 
802     vertex_t ** firstvert;    /**< @todo Should be 'void *' + 'int vertex_id' */
803     int *   numverts;
804     int **    firstelem;
805     int *   numelems;
806 
807     short   dist;
808     vec3_t    v_norm;
809     vec3_t    v_orig;
810 
811     bboxf_t   bbox;
812 
813     int     patch_cp[2];
814 
815     int     autosprite2_axis;
816 
817     int     effect;
818 #if MODIF_FOG
819     cplane_t *  fogplane;   /**< fog plane */
820 #else
821     float     fog[5];       /**< fog parameters */
822 #endif
823 };
824 
825 /**
826  * Movement structure used for collision detection.
827  * A trace is returned when a box is swept through the world.
828  */
829 typedef struct
830 {
831   float   fraction;       /**< Movement fraction (1.0 = didn't hit anything) */
832 
833   vec3_t    start;        /**< Movement start position */
834   vec3_t    end;          /**< Movement end position */
835 
836   vec3_t    size;         /**< Half size of bounding box */
837   vec3_t    mins, maxs;
838   vec3_t    absmins, absmaxs;
839 
840   bool    allSolid;
841   bool    startSolid;
842 
843   cplane_t  plane;
844 
845   int     tracemask;      /**< Collide against these types of surfaces */
846   int     contents;       /**< Content mask */
847   int     shader;
848 
849 //  Entity *  ent;
850 
851   bool    isPoint;        /**< The trace is a point */
852 } trace_t;
853 
854 /*
855  * link_t is only used for entity area links now
856  */
857 typedef struct link_s
858 {
859   struct link_s *prev, *next;
860 } link_t;
861 
862 #endif  /* __TYPES_H__ */
863