1 #ifndef mdsprite_h_
2 # define mdsprite_h_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #ifdef USE_OPENGL
9 #include "hightile.h"
10 
11 #if defined(_M_IX86) || defined(_M_AMD64) || defined(__i386) || defined(__x86_64)
12 #define SHIFTMOD32(a) (a)
13 #else
14 #define SHIFTMOD32(a) ((a)&31)
15 #endif
16 
17 #define SHARED_MODEL_DATA int32_t mdnum, shadeoff; \
18                   float scale, bscale, zadd, yoffset; \
19                   GLuint *texid; \
20                   int32_t flags;
21 
22 #define IDMODEL_SHARED_DATA int32_t numframes, cframe, nframe, fpssc, usesalpha; \
23                        float oldtime, curtime, interpol; \
24                        mdanim_t *animations; \
25                        mdskinmap_t *skinmap; \
26                        int32_t numskins, skinloaded;
27 
28 #define IDP2_MAGIC 0x32504449
29 #define IDP3_MAGIC 0x33504449
30 
31 typedef struct
32 {
33     SHARED_MODEL_DATA;
34 } mdmodel_t;
35 
36 typedef struct _mdanim_t
37 {
38     int32_t startframe, endframe;
39     int32_t fpssc, flags;
40     struct _mdanim_t *next;
41 } mdanim_t;
42 
43 #define MDANIM_LOOP 0
44 #define MDANIM_ONESHOT 1
45 
46 typedef struct _mdskinmap_t
47 {
48     uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hicreplctyp
49     int32_t skinnum, surfnum;   // Skin identifier, surface number
50     char *fn;   // Skin filename
51     GLuint texid[HICTINT_MEMORY_COMBINATIONS];   // OpenGL texture numbers for effect variations
52     struct _mdskinmap_t *next;
53     float param, specpower, specfactor;
54 } mdskinmap_t;
55 
56 
57 //This MD2 code is based on the source code from David Henry (tfc_duke(at)hotmail.com)
58 //   Was at http://tfc.duke.free.fr/us/tutorials/models/md2.htm
59 //   Available from http://web.archive.org/web/20030816010242/http://tfc.duke.free.fr/us/tutorials/models/md2.htm
60 //   Now at http://tfc.duke.free.fr/coding/md2.html (in French)
61 //He probably wouldn't recognize it if he looked at it though :)
62 
63 typedef struct
64 {
65     int32_t id, vers, skinxsiz, skinysiz, framebytes; //id:"IPD2", vers:8
66     int32_t numskins, numverts, numuv, numtris, numglcmds, numframes;
67     int32_t ofsskins, ofsuv, ofstris, ofsframes, ofsglcmds, ofseof; //ofsskins: skin names (64 bytes each)
68 } md2head_t;
69 
70 typedef struct { uint8_t v[3], ni; } md2vert_t; //compressed vertex coords (x,y,z)
71 typedef struct
72 {
73     vec3f_t mul, add; //scale&translation vector
74     char name[16];    //frame name
75     md2vert_t verts[1]; //first vertex of this frame
76 } md2frame_t;
77 
78 typedef struct { int16_t u, v; } md2uv_t;
79 typedef struct
80 {
81     uint16_t v[3];
82     uint16_t u[3];
83 } md2tri_t;
84 
85 typedef struct
86 {
87     SHARED_MODEL_DATA;
88     IDMODEL_SHARED_DATA;
89 
90     //MD2 specific stuff:
91     int32_t numverts, numglcmds, framebytes, *glcmds;
92     char *frames;
93     char *basepath;   // pointer to string of base path
94     char *skinfn;   // pointer to first of numskins 64-char strings
95     md2uv_t *uv;
96     md2tri_t* tris;
97 } md2model_t;
98 
99 
100 typedef struct { char nam[64]; int32_t i; } md3shader_t; //ascz path of shader, shader index
101 typedef struct { int32_t i[3]; } md3tri_t; //indices of tri
102 typedef struct { float u, v; } md3uv_t;
103 typedef struct { int16_t x, y, z; uint8_t nlat, nlng; } md3xyzn_t; //xyz are [10:6] ints
104 
105 typedef struct
106 {
107     vec3f_t min, max, cen; //bounding box&origin
108     float r; //radius of bounding sphere
109     char nam[16]; //ascz frame name
110 } md3frame_t;
111 
112 typedef struct
113 {
114     char nam[64]; //ascz tag name
115     vec3f_t p, x, y, z; //tag object pos&orient
116 } md3tag_t;
117 
118 typedef struct
119 {
120     int32_t id; //IDP3(0x33806873)
121     char nam[64]; //ascz surface name
122     int32_t flags; //?
123     int32_t numframes, numshaders, numverts, numtris; //numframes same as md3head,max shade=~256,vert=~4096,tri=~8192
124     int32_t ofstris;
125     int32_t ofsshaders;
126     int32_t ofsuv;
127     int32_t ofsxyzn;
128     int32_t ofsend;
129     // DO NOT read directly to this structure
130     // the following block is NOT in the file format
131     // be sure to use the SIZEOF_MD3SURF_T macro
132     md3tri_t *tris;
133     md3shader_t *shaders;
134     md3uv_t *uv;
135     md3xyzn_t *xyzn;
136     float *geometry;  // used by Polymer
137 } md3surf_t;
138 
139 #define SIZEOF_MD3SURF_T (11*sizeof(int32_t) + 64*sizeof(char))
140 
141 typedef struct
142 {
143     int32_t id, vers; //id=IDP3(0x33806873), vers=15
144     char nam[64]; //ascz path in PK3
145     int32_t flags; //?
146     int32_t numframes, numtags, numsurfs, numskins; //max=~1024,~16,~32,numskins=artifact of MD2; use shader field instead
147     int32_t ofsframes;
148     int32_t ofstags;
149     int32_t ofssurfs;
150     int32_t eof;
151     // DO NOT read directly to this structure
152     // the following block is NOT in the file format
153     // be sure to use the SIZEOF_MD3HEAD_T macro
154     md3frame_t *frames;
155     md3tag_t *tags;
156     md3surf_t *surfs;
157 } md3head_t;
158 
159 #define SIZEOF_MD3HEAD_T (sizeof(md3head_t)-3*sizeof(void*))
160 
161 typedef struct
162 {
163     SHARED_MODEL_DATA;
164     IDMODEL_SHARED_DATA;
165 
166     //MD3 specific
167     md3head_t head;
168     vec3f_t *muladdframes;
169 
170     uint16_t *indexes;
171     uint16_t *vindexes;
172 
173     float *maxdepths;
174     GLuint *vbos;
175     // polymer VBO names after that, allocated per surface
176     GLuint *indices;
177     GLuint *texcoords;
178     GLuint *geometry;
179 } md3model_t;
180 
181 #define VOXBORDWIDTH 1 //use 0 to save memory, but has texture artifacts; 1 looks better...
182 #define VOXUSECHAR 0
183 
184 #if (VOXUSECHAR != 0)
185 typedef struct { uint8_t x, y, z, u, v; } vert_t;
186 #else
187 typedef struct { uint16_t x, y, z, u, v; } vert_t;
188 #endif
189 
190 typedef struct { vert_t v[4]; } voxrect_t;
191 
192 typedef struct
193 {
194     //WARNING: This top block is a union of md2model,md3model,voxmodel: Make sure it matches!
195     int32_t mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure!
196     int32_t shadeoff;
197     float scale, bscale, zadd, yoffset;
198     uint32_t *texid;    // skins for palettes
199     int32_t flags;
200 
201     //VOX specific stuff:
202     voxrect_t *quad; int32_t qcnt, qfacind[7];
203     int32_t *mytex, mytexx, mytexy;
204     vec3_t siz;
205     vec3f_t piv;
206     int32_t is8bit;
207     uint32_t texid8bit;
208     GLuint vbo, vboindex;
209 } voxmodel_t;
210 
211 EXTERN mdmodel_t **models;
212 
213 void updateanimation(md2model_t *m, tspriteptr_t tspr, uint8_t lpal);
214 int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf);
215 void mdinit(void);
216 void freeallmodels(void);
217 void clearskins(int32_t type);
218 int32_t polymost_mddraw(tspriteptr_t tspr);
219 EXTERN void md3_vox_calcmat_common(tspriteptr_t tspr, const vec3f_t *a0, float f, float mat[16]);
220 
221 EXTERN int32_t mdpause;
222 EXTERN int32_t nextmodelid;
223 EXTERN voxmodel_t *voxmodels[MAXVOXELS];
224 
225 #ifdef USE_GLEXT
226 void voxvboalloc(voxmodel_t *vm);
227 void voxvbofree(voxmodel_t *vm);
228 #endif
229 
230 void voxfree(voxmodel_t *m);
231 voxmodel_t *voxload(const char *filnam);
232 voxmodel_t *loadkvxfrombuf(const char *buffer, int32_t length);
233 int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr);
234 
235 int      md3postload_polymer(md3model_t* m);
236 //int32_t md_thinoutmodel(int32_t modelid, uint8_t *usedframebitmap);
237 EXTERN void md_freevbos(void);
238 
239 #endif // defined USE_OPENGL
240 
241 enum {
242     HUDFLAG_HIDE = 1,
243     HUDFLAG_NOBOB = 2,
244     HUDFLAG_FLIPPED = 4,
245     HUDFLAG_NODEPTH = 8,
246 };
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif // !mdsprite_h_
253