]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_shared.h
directional static lighting support (but not fast yet), for maps compiled with (as...
[xonotic/darkplaces.git] / model_shared.h
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 #ifndef SYNCTYPE_T
25 #define SYNCTYPE_T
26 typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
27 #endif
28
29 /*
30
31 d*_t structures are on-disk representations
32 m*_t structures are in-memory
33
34 */
35
36 typedef enum {mod_invalid, mod_brush, mod_sprite, mod_alias} modtype_t;
37
38 typedef struct animscene_s
39 {
40         char name[32]; // for viewthing support
41         int firstframe;
42         int framecount;
43         int loop; // true or false
44         float framerate;
45 }
46 animscene_t;
47
48 typedef struct skinframe_s
49 {
50         rtexture_t *base; // original texture minus pants/shirt/glow
51         rtexture_t *pants; // pants only (in greyscale)
52         rtexture_t *shirt; // shirt only (in greyscale)
53         rtexture_t *glow; // glow only
54         rtexture_t *merged; // original texture minus glow
55         rtexture_t *fog; // white texture with alpha of the base texture, NULL if not transparent
56 }
57 skinframe_t;
58
59 #define MAX_SKINS 256
60
61
62 #include "model_brush.h"
63 #include "model_sprite.h"
64 #include "model_alias.h"
65
66 typedef struct model_s
67 {
68         char                    name[MAX_QPATH];
69         // model needs to be loaded if this is true
70         qboolean                needload;
71         // set if the model is used in current map, models which are not, are purged
72         qboolean                used;
73         // CRC of the file this model was loaded from, to reload if changed
74         qboolean                crc;
75         // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
76         qboolean                isworldmodel;
77         // true if this model is a HalfLife .bsp file
78         qboolean                ishlbsp;
79
80         // mod_brush, mod_alias, mod_sprite
81         modtype_t               type;
82         // LordHavoc: Q2/ZYM model support
83         int                             aliastype;
84         // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
85         int                             fullbright;
86         // number of QC accessable frame(group)s in the model
87         int                             numframes;
88         // whether to randomize animated framegroups
89         synctype_t              synctype;
90
91         // used for sprites and models
92         int                             numtris;
93         // used for models
94         int                             numskins;
95         // used by models
96         int                             numverts;
97
98         // flags from the model file
99         int                             flags;
100         // engine calculated flags, ones that can not be set in the file
101         int                             flags2;
102
103         // all models use textures...
104         rtexturepool_t  *texturepool;
105
106         // volume occupied by the model
107         // bounding box at angles '0 0 0'
108         vec3_t                  normalmins, normalmaxs;
109         // bounding box if yaw angle is not 0, but pitch and roll are
110         vec3_t                  yawmins, yawmaxs;
111         // bounding box if pitch or roll are used
112         vec3_t                  rotatedmins, rotatedmaxs;
113         // usable at any angles
114 //      float                   modelradius;
115
116         // brush model specific
117         int                             firstmodelsurface, nummodelsurfaces;
118         // LordHavoc: sorted surface pointer array, sorted by shader type and then by texture
119         msurface_t              **modelsortedsurfaces; // [nummodelsurfaces]
120
121         // used for surfaces without a valid texture
122         texture_t               notexture;
123
124         // lightmap format, set to r_lightmaprgba when model is loaded
125         int                             lightmaprgba;
126
127         int                             numsubmodels;
128         dmodel_t                *submodels;
129
130         int                             numplanes;
131         mplane_t                *planes;
132
133         // number of visible leafs, not counting 0 (solid)
134         int                             numleafs;
135         mleaf_t                 *leafs;
136
137         int                             numvertexes;
138         mvertex_t               *vertexes;
139
140         int                             numedges;
141         medge_t                 *edges;
142
143         int                             numnodes;
144         mnode_t                 *nodes;
145
146         int                             numtexinfo;
147         mtexinfo_t              *texinfo;
148
149         int                             numsurfaces;
150         msurface_t              *surfaces;
151
152         int                             numsurfedges;
153         int                             *surfedges;
154
155         int                             numclipnodes;
156         dclipnode_t             *clipnodes;
157
158         int                             nummarksurfaces;
159         msurface_t              **marksurfaces;
160
161         hull_t                  hulls[MAX_MAP_HULLS];
162
163         int                             numtextures;
164         texture_t               **textures;
165
166         qbyte                   *visdata;
167         qbyte                   *lightdata;
168         char                    *entities;
169
170         int                             numportals;
171         mportal_t               *portals;
172
173         int                             numportalpoints;
174         mvertex_t               *portalpoints;
175
176         int                             numlights;
177         mlight_t                *lights;
178
179         // skin animation info
180         animscene_t             *skinscenes; // [numskins]
181         // skin frame info
182         skinframe_t             *skinframes;
183
184         animscene_t             *animscenes; // [numframes]
185
186         // Q1 and Q2 models are the same after loading
187         int                             *mdlmd2data_indices;
188         float                   *mdlmd2data_texcoords;
189         md2frame_t              *mdlmd2data_frames;
190         trivertx_t              *mdlmd2data_pose;
191
192         // for Zymotic models
193         void                    *zymdata_header;
194
195         int                             sprnum_type;
196         mspriteframe_t  *sprdata_frames;
197
198         // adds a box (or individual polygons) to the clipping engine,
199         // which will mark the entity visible if seen
200         void(*SERAddEntity)(void);
201         // draw the model
202         void(*Draw)(void);
203         // draw the model's sky polygons (only used by brush models)
204         void(*DrawSky)(void);
205         // draw the model's shadows
206         void(*DrawShadow)(void);
207
208         // memory pool for allocations
209         mempool_t               *mempool;
210 }
211 model_t;
212
213 //============================================================================
214
215 // model loading
216 extern model_t *loadmodel;
217 extern qbyte *mod_base;
218 // sky/water subdivision
219 extern cvar_t gl_subdivide_size;
220 // texture fullbrights
221 extern cvar_t r_fullbrights;
222
223 void Mod_Init (void);
224 void Mod_CheckLoaded (model_t *mod);
225 void Mod_ClearAll (void);
226 model_t *Mod_ForName (char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
227 void Mod_TouchModel (char *name);
228 void Mod_UnloadModel (model_t *mod);
229
230 mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
231 qbyte *Mod_LeafPVS (mleaf_t *leaf, model_t *model);
232
233 void Mod_ClearUsed(void);
234 void Mod_PurgeUnused(void);
235
236 extern model_t *loadmodel;
237 extern char loadname[32];       // for hunk tags
238
239 //extern model_t *Mod_LoadModel (model_t *mod, qboolean crash);
240
241 //extern float RadiusFromBounds (vec3_t mins, vec3_t maxs);
242 extern model_t *Mod_FindName (char *name);
243
244 #endif  // __MODEL__