]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_shared.h
you can now (try to) play in maps you don't have, and models you don't have are shown...
[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         // lightmap format, set to r_lightmaprgba when model is loaded
122         int                             lightmaprgba;
123
124         int                             numsubmodels;
125         dmodel_t                *submodels;
126
127         int                             numplanes;
128         mplane_t                *planes;
129
130         // number of visible leafs, not counting 0 (solid)
131         int                             numleafs;
132         mleaf_t                 *leafs;
133
134         int                             numvertexes;
135         mvertex_t               *vertexes;
136
137         int                             numedges;
138         medge_t                 *edges;
139
140         int                             numnodes;
141         mnode_t                 *nodes;
142
143         int                             numtexinfo;
144         mtexinfo_t              *texinfo;
145
146         int                             numsurfaces;
147         msurface_t              *surfaces;
148
149         int                             numsurfedges;
150         int                             *surfedges;
151
152         int                             numclipnodes;
153         dclipnode_t             *clipnodes;
154
155         int                             nummarksurfaces;
156         msurface_t              **marksurfaces;
157
158         hull_t                  hulls[MAX_MAP_HULLS];
159
160         int                             numtextures;
161         texture_t               **textures;
162
163         qbyte                   *visdata;
164         qbyte                   *lightdata;
165         char                    *entities;
166
167         int                             numportals;
168         mportal_t               *portals;
169
170         int                             numportalpoints;
171         mvertex_t               *portalpoints;
172
173         int                             numlights;
174         mlight_t                *lights;
175
176         // skin animation info
177         animscene_t             *skinscenes; // [numskins]
178         // skin frame info
179         skinframe_t             *skinframes;
180
181         animscene_t             *animscenes; // [numframes]
182
183         // Q1 and Q2 models are the same after loading
184         int                             *mdlmd2data_indices;
185         float                   *mdlmd2data_texcoords;
186         md2frame_t              *mdlmd2data_frames;
187         trivertx_t              *mdlmd2data_pose;
188
189         // for Zymotic models
190         void                    *zymdata_header;
191
192         int                             sprnum_type;
193         mspriteframe_t  *sprdata_frames;
194
195         // draw the model
196         void(*Draw)(struct entity_render_s *ent);
197         // draw the model's sky polygons (only used by brush models)
198         void(*DrawSky)(struct entity_render_s *ent);
199         // draw the model's shadows
200         void(*DrawShadow)(struct entity_render_s *ent);
201
202         // memory pool for allocations
203         mempool_t               *mempool;
204 }
205 model_t;
206
207 //============================================================================
208
209 // this can be used for anything without a valid texture
210 extern rtexture_t *r_notexture;
211 // every texture must be in a pool...
212 extern rtexturepool_t *r_notexturepool;
213
214 // model loading
215 extern model_t *loadmodel;
216 extern qbyte *mod_base;
217 // sky/water subdivision
218 //extern cvar_t gl_subdivide_size;
219 // texture fullbrights
220 extern cvar_t r_fullbrights;
221
222 void Mod_Init (void);
223 void Mod_CheckLoaded (model_t *mod);
224 void Mod_ClearAll (void);
225 model_t *Mod_ForName (char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
226 void Mod_TouchModel (char *name);
227 void Mod_UnloadModel (model_t *mod);
228
229 void Mod_ClearUsed(void);
230 void Mod_PurgeUnused(void);
231
232 extern model_t *loadmodel;
233 extern char loadname[32];       // for hunk tags
234
235 extern model_t *Mod_FindName (char *name);
236
237 #endif  // __MODEL__
238