]> icculus.org git repositories - divverent/darkplaces.git/blob - model_shared.h
remove an unused variable (and kill the one incorrect use of it)
[divverent/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, mod_brushq2, mod_brushq3} 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 without 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 (fullbrights)
54         rtexture_t *merged; // original texture without glow
55         rtexture_t *fog; // alpha of the base texture (if not opaque)
56         rtexture_t *nmap; // normalmap (bumpmap for dot3)
57         rtexture_t *gloss; // glossmap (for dot3)
58         rtexture_t *detail; // detail texture (silly bumps for non-dot3)
59 }
60 skinframe_t;
61
62 #define MAX_SKINS 256
63
64 #define SHADOWMESHVERTEXHASH 1024
65 typedef struct shadowmeshvertexhash_s
66 {
67         struct shadowmeshvertexhash_s *next;
68 }
69 shadowmeshvertexhash_t;
70
71 typedef struct shadowmesh_s
72 {
73         struct shadowmesh_s *next;
74         int numverts, maxverts;
75         int numtriangles, maxtriangles;
76         float *vertex3f;
77         int *element3i;
78         int *neighbor3i;
79         // these are NULL after Mod_ShadowMesh_Finish is performed, only used
80         // while building meshes
81         shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
82 }
83 shadowmesh_t;
84
85
86 #include "matrixlib.h"
87
88 #include "model_brush.h"
89 #include "model_sprite.h"
90 #include "model_alias.h"
91
92 typedef struct model_alias_s
93 {
94         // LordHavoc: Q2/ZYM model support
95         int                             aliastype;
96
97         // mdl/md2/md3 models are the same after loading
98         int                             aliasnum_meshes;
99         aliasmesh_t             *aliasdata_meshes;
100
101         int                             aliasnum_tags;
102         int                             aliasnum_tagframes;
103         aliastag_t              *aliasdata_tags;
104
105         // for Zymotic models
106         int                             zymnum_verts;
107         int                             zymnum_tris;
108         int                             zymnum_shaders;
109         int                             zymnum_bones;
110         int                             zymnum_scenes;
111         float                   *zymdata_texcoords;
112         rtexture_t              **zymdata_textures;
113         qbyte                   *zymdata_trizone;
114         zymbone_t               *zymdata_bones;
115         unsigned int    *zymdata_vertbonecounts;
116         zymvertex_t             *zymdata_verts;
117         unsigned int    *zymdata_renderlist;
118         float                   *zymdata_poses;
119 }
120 model_alias_t;
121
122 typedef struct model_sprite_s
123 {
124         int                             sprnum_type;
125         mspriteframe_t  *sprdata_frames;
126 }
127 model_sprite_t;
128
129 struct trace_s;
130
131 typedef struct model_brush_s
132 {
133         char *entities;
134         void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius);
135         void (*TraceBox)(struct model_s *model, struct trace_s *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs);
136 }
137 model_brush_t;
138
139 typedef struct model_brushq1_s
140 {
141         // true if this model is a HalfLife .bsp file
142         qboolean                ishlbsp;
143
144         int                             firstmodelsurface, nummodelsurfaces;
145
146         // lightmap format, set to r_lightmaprgba when model is loaded
147         int                             lightmaprgba;
148
149         int                             numsubmodels;
150         dmodel_t                *submodels;
151
152         int                             numplanes;
153         mplane_t                *planes;
154
155         // number of visible leafs, not counting 0 (solid)
156         int                             numleafs;
157         mleaf_t                 *leafs;
158
159         int                             numvertexes;
160         mvertex_t               *vertexes;
161
162         int                             numedges;
163         medge_t                 *edges;
164
165         int                             numnodes;
166         mnode_t                 *nodes;
167
168         int                             numtexinfo;
169         mtexinfo_t              *texinfo;
170
171         int                             numsurfaces;
172         msurface_t              *surfaces;
173         int                             *surfacevisframes;
174         int                             *surfacepvsframes;
175         msurface_t              *surfacepvsnext;
176         surfmesh_t              *entiremesh;
177         surfmesh_t              *surfmeshes;
178
179         int                             numsurfedges;
180         int                             *surfedges;
181
182         int                             numclipnodes;
183         dclipnode_t             *clipnodes;
184
185         int                             nummarksurfaces;
186         int                             *marksurfaces;
187
188         hull_t                  hulls[MAX_MAP_HULLS];
189
190         int                             numtextures;
191         texture_t               *textures;
192
193         qbyte                   *visdata;
194         qbyte                   *lightdata;
195
196         int                             numportals;
197         mportal_t               *portals;
198
199         int                             numportalpoints;
200         mvertex_t               *portalpoints;
201
202         int                             numlights;
203         mlight_t                *lights;
204
205         // pvs visibility marking
206         mleaf_t                 *pvsviewleaf;
207         int                             pvsviewleafnovis;
208         int                             pvsframecount;
209         mleaf_t                 *pvsleafchain;
210         int                             *pvssurflist;
211         int                             pvssurflistlength;
212         // these get rebuilt as the player moves around if this is the world,
213         // otherwise they are left alone (no pvs for bmodels)
214         msurface_t              ***pvstexturechains;
215         msurface_t              **pvstexturechainsbuffer;
216         int                             *pvstexturechainslength;
217
218         // lightmap update chains for light styles
219         int                             light_styles;
220         qbyte                   *light_style;
221         int                             *light_stylevalue;
222         msurface_t              ***light_styleupdatechains;
223         msurface_t              **light_styleupdatechainsbuffer;
224         int                             light_scalebit;
225         float                   light_ambient;
226
227         mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p);
228         qbyte *(*LeafPVS)(struct model_s *model, mleaf_t *leaf);
229         void (*BuildPVSTextureChains)(struct model_s *model);
230 }
231 model_brushq1_t;
232
233 /* MSVC can't compile empty structs, so this is commented out for now
234 typedef struct model_brushq2_s
235 {
236 }
237 model_brushq2_t;
238 */
239
240 typedef struct q3mtexture_s
241 {
242         char name[Q3PATHLENGTH];
243         int surfaceflags;
244         int contents;
245
246         int number;
247         skinframe_t skin;
248 }
249 q3mtexture_t;
250
251 typedef struct q3mnode_s
252 {
253         int isnode; // true
254         struct q3mnode_s *parent;
255         struct mplane_s *plane;
256         struct q3mnode_s *children[2];
257 }
258 q3mnode_t;
259
260 typedef struct q3mleaf_s
261 {
262         int isnode; // false
263         struct q3mnode_s *parent;
264         int clusterindex;
265         int areaindex;
266         int numleaffaces;
267         struct q3mface_s **firstleafface;
268         int numleafbrushes;
269         struct q3mbrush_s **firstleafbrush;
270         vec3_t mins;
271         vec3_t maxs;
272 }
273 q3mleaf_t;
274
275 typedef struct q3mmodel_s
276 {
277         vec3_t mins;
278         vec3_t maxs;
279         int numfaces;
280         struct q3mface_s *firstface;
281         int numbrushes;
282         struct q3mbrush_s *firstbrush;
283 }
284 q3mmodel_t;
285
286 typedef struct q3mbrush_s
287 {
288         int numbrushsides;
289         struct q3mbrushside_s *firstbrushside;
290         struct q3mtexture_s *texture;
291 }
292 q3mbrush_t;
293
294 typedef struct q3mbrushside_s
295 {
296         struct mplane_s *plane;
297         struct q3mtexture_s *texture;
298 }
299 q3mbrushside_t;
300
301 typedef struct q3meffect_s
302 {
303         char shadername[Q3PATHLENGTH];
304         struct q3mbrush_s *brush;
305         int unknown; // 5 or -1
306 }
307 q3meffect_t;
308
309 typedef struct q3mface_s
310 {
311         struct q3mtexture_s *texture;
312         struct q3meffect_s *effect;
313         rtexture_t *lightmaptexture;
314         int type;
315         int firstvertex;
316         int numvertices;
317         int firstelement;
318         int numelements;
319         int patchsize[2];
320
321         float *data_vertex3f;
322         float *data_texturetexcoord2f;
323         float *data_lightmaptexcoord2f;
324         float *data_svector3f;
325         float *data_tvector3f;
326         float *data_normal3f;
327         float *data_color4f;
328         int numtriangles;
329         int *data_element3i;
330         int *data_neighbor3i;
331 }
332 q3mface_t;
333
334 typedef struct model_brushq3_s
335 {
336         int num_textures;
337         q3mtexture_t *data_textures;
338
339         int num_planes;
340         mplane_t *data_planes;
341
342         int num_nodes;
343         q3mnode_t *data_nodes;
344
345         int num_leafs;
346         q3mleaf_t *data_leafs;
347
348         int num_leafbrushes;
349         q3mbrush_t **data_leafbrushes;
350
351         int num_leaffaces;
352         q3mface_t **data_leaffaces;
353
354         int num_models;
355         q3mmodel_t *data_models;
356         // each submodel gets its own model struct so this is different for each.
357         q3mmodel_t data_thismodel;
358
359         int num_brushes;
360         q3mbrush_t *data_brushes;
361
362         int num_brushsides;
363         q3mbrushside_t *data_brushsides;
364
365         int num_vertices;
366         float *data_vertex3f;
367         float *data_texturetexcoord2f;
368         float *data_lightmaptexcoord2f;
369         float *data_svector3f;
370         float *data_tvector3f;
371         float *data_normal3f;
372         float *data_color4f;
373
374         int num_triangles;
375         int *data_element3i;
376         int *data_neighbor3i;
377
378         int num_effects;
379         q3meffect_t *data_effects;
380
381         int num_faces;
382         q3mface_t *data_faces;
383
384         // lightmap textures
385         int num_lightmaps;
386         rtexture_t **data_lightmaps;
387
388         // voxel light data with directional shading
389         int num_lightgrid;
390         q3dlightgrid_t *data_lightgrid;
391         // size of each cell (may vary by map, typically 64 64 128)
392         float num_lightgrid_cellsize[3];
393         // 1.0 / num_lightgrid_cellsize
394         float num_lightgrid_scale[3];
395         // dimensions of the world model in lightgrid cells
396         int num_lightgrid_imins[3];
397         int num_lightgrid_imaxs[3];
398         int num_lightgrid_isize[3];
399         // indexing/clamping
400         int num_lightgrid_dimensions[3];
401         // transform modelspace coordinates to lightgrid index
402         matrix4x4_t num_lightgrid_indexfromworld;
403
404         // pvs
405         int num_pvsclusters;
406         int num_pvschainlength;
407         unsigned char *data_pvschains;
408         // example
409         //pvschain = model->brushq3.data_pvschains + mycluster * model->brushq3.num_pvschainlength;
410         //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
411 }
412 model_brushq3_t;
413
414 typedef struct model_s
415 {
416         // name and path of model, for example "progs/player.mdl"
417         char                    name[MAX_QPATH];
418         // model needs to be loaded if this is true
419         qboolean                needload;
420         // set if the model is used in current map, models which are not, are purged
421         qboolean                used;
422         // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
423         qboolean                isworldmodel;
424         // CRC of the file this model was loaded from, to reload if changed
425         unsigned int    crc;
426         // mod_brush, mod_alias, mod_sprite
427         modtype_t               type;
428         // memory pool for allocations
429         mempool_t               *mempool;
430         // all models use textures...
431         rtexturepool_t  *texturepool;
432         // flags from the model file
433         int                             flags;
434         // engine calculated flags, ones that can not be set in the file
435         int                             flags2;
436         // LordHavoc: if true (normally only for sprites) the model/sprite/bmodel is always rendered fullbright
437         int                             fullbright;
438         // number of QC accessible frame(group)s in the model
439         int                             numframes;
440         // number of QC accessible skin(group)s in the model
441         int                             numskins;
442         // whether to randomize animated framegroups
443         synctype_t              synctype;
444         // bounding box at angles '0 0 0'
445         vec3_t                  normalmins, normalmaxs;
446         // bounding box if yaw angle is not 0, but pitch and roll are
447         vec3_t                  yawmins, yawmaxs;
448         // bounding box if pitch or roll are used
449         vec3_t                  rotatedmins, rotatedmaxs;
450         // sphere radius, usable at any angles
451         float                   radius;
452         // squared sphere radius for easier comparisons
453         float                   radius2;
454         // skin animation info
455         animscene_t             *skinscenes; // [numskins]
456         // skin animation info
457         animscene_t             *animscenes; // [numframes]
458         // draw the model's sky polygons (only used by brush models)
459         void(*DrawSky)(struct entity_render_s *ent);
460         // draw the model using lightmap/dlight shading
461         void(*Draw)(struct entity_render_s *ent);
462         // draw a fake shadow for the model
463         void(*DrawFakeShadow)(struct entity_render_s *ent);
464         // draw a shadow volume for the model based on light source
465         void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
466         // draw the lighting on a model (through stencil)
467         void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz);
468         // fields belonging to each type of model
469         model_alias_t   alias;
470         model_sprite_t  sprite;
471         model_brush_t   brush;
472         model_brushq1_t brushq1;
473         /* MSVC can't handle an empty struct, so this is commented out for now
474         model_brushq2_t brushq2;
475         */
476         model_brushq3_t brushq3;
477 }
478 model_t;
479
480 //============================================================================
481
482 // this can be used for anything without a valid texture
483 extern rtexture_t *r_notexture;
484 #define NUM_DETAILTEXTURES 1
485 extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
486 // every texture must be in a pool...
487 extern rtexturepool_t *mod_shared_texturepool;
488
489 // model loading
490 extern model_t *loadmodel;
491 extern qbyte *mod_base;
492 // sky/water subdivision
493 //extern cvar_t gl_subdivide_size;
494 // texture fullbrights
495 extern cvar_t r_fullbrights;
496
497 void Mod_Init (void);
498 void Mod_CheckLoaded (model_t *mod);
499 void Mod_ClearAll (void);
500 model_t *Mod_FindName (const char *name);
501 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
502 void Mod_TouchModel (const char *name);
503 void Mod_UnloadModel (model_t *mod);
504
505 void Mod_ClearUsed(void);
506 void Mod_PurgeUnused(void);
507 void Mod_LoadModels(void);
508
509 extern model_t *loadmodel;
510 extern char loadname[32];       // for hunk tags
511
512 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore);
513 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
514 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
515 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
516
517 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts);
518 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh);
519 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *v);
520 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, float *vert0, float *vert1, float *vert2);
521 void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts);
522 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, float *verts, int numtris, int *elements);
523 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int initialnumtriangles);
524 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh);
525 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
526 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
527
528 int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture);
529 int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height);
530
531 extern cvar_t r_mipskins;
532
533 typedef struct skinfileitem_s
534 {
535         struct skinfileitem_s *next;
536         char name[MAX_QPATH];
537         char replacement[MAX_QPATH];
538 }
539 skinfileitem_t;
540
541 typedef struct skinfile_s
542 {
543         struct skinfile_s *next;
544         skinfileitem_t *items;
545 }
546 skinfile_t;
547
548 skinfile_t *Mod_LoadSkinFiles(void);
549 void Mod_FreeSkinFiles(skinfile_t *skinfile);
550 int Mod_CountSkinFiles(skinfile_t *skinfile);
551
552 #endif  // __MODEL__
553