Fix redundant glTexEnv calls
[neverball] / share / solid_base.h
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #ifndef SOLID_BASE_H
16 #define SOLID_BASE_H
17
18 #include "base_config.h"
19
20 /*
21  * Some might  be taken  aback at  the terseness of  the names  of the
22  * structure  members and  the variables  used by  the  functions that
23  * access them.  Yes, yes, I know:  readability.  I  contend that once
24  * the naming  convention is embraced, the names  become more readable
25  * than any  verbose alternative, and their brevity  and uniformity do
26  * more to augment readability than longVariableNames ever could.
27  *
28  * Members  and variables  are named  XY.   X determines  the type  of
29  * structure to which the variable  refers.  Y determines the usage of
30  * the variable.
31  *
32  * The Xs are as documented by struct s_base:
33  *
34  *     f  File          (struct s_base)
35  *     m  Material      (struct b_mtrl)
36  *     v  Vertex        (struct b_vert)
37  *     e  Edge          (struct b_edge)
38  *     s  Side          (struct b_side)
39  *     t  Texture coord (struct b_texc)
40  *     g  Geometry      (struct b_geom)
41  *     o  Offset        (struct b_offs)
42  *     l  Lump          (struct b_lump)
43  *     n  Node          (struct b_node)
44  *     p  Path          (struct b_path)
45  *     b  Body          (struct b_body)
46  *     h  Item          (struct b_item)
47  *     z  Goal          (struct b_goal)
48  *     j  Jump          (struct b_jump)
49  *     x  Switch        (struct b_swch)
50  *     r  Billboard     (struct b_bill)
51  *     u  User          (struct b_ball)
52  *     w  Viewpoint     (struct b_view)
53  *     d  Dictionary    (struct b_dict)
54  *     i  Index         (int)
55  *     a  Text          (char)
56  *
57  * The Ys are as follows:
58  *
59  *     c  Counter
60  *     p  Pointer
61  *     v  Vector (array)
62  *     0  Index of the first
63  *     i  Index
64  *     j  Subindex
65  *     k  Subsubindex
66  *
67  * Thus "up" is a pointer to  a user structure.  "lc" is the number of
68  * lumps.  "ei" and "ej" are  edge indices into some "ev" edge vector.
69  * An edge is  defined by two vertices, so  an edge structure consists
70  * of "vi" and "vj".  And so on.
71  *
72  * Those members that do not conform to this convention are explicitly
73  * documented with a comment.
74  *
75  * These prefixes are still available: c k q y.
76  */
77
78 /*
79  * Additionally, solid data is split into three main parts: static
80  * data (base), simulation data (vary), and rendering data (draw).
81  */
82
83 /*---------------------------------------------------------------------------*/
84
85 /* Material type flags */
86
87 #define M_REFLECTIVE  (1 <<  8)
88 #define M_TRANSPARENT (1 <<  7)
89 #define M_SHADOWED    (1 <<  6)
90 #define M_DECAL       (1 <<  5)
91 #define M_ENVIRONMENT (1 <<  4)
92 #define M_TWO_SIDED   (1 <<  3)
93 #define M_ADDITIVE    (1 <<  2)
94 #define M_CLAMP_S     (1 <<  1)
95 #define M_CLAMP_T     (1 <<  0)
96
97 /* Billboard types. */
98
99 #define B_EDGE     1
100 #define B_FLAT     2
101 #define B_ADDITIVE 4
102 #define B_NOFACE   8
103
104 /* Lump flags. */
105
106 #define L_DETAIL   1
107
108 /* Item types. */
109
110 #define ITEM_NONE       0
111 #define ITEM_COIN       1
112 #define ITEM_GROW       2
113 #define ITEM_SHRINK     3
114
115 /* Path flags. */
116
117 #define P_ORIENTED 1
118
119 /*---------------------------------------------------------------------------*/
120
121 struct b_mtrl
122 {
123     float d[4];                                /* diffuse color              */
124     float a[4];                                /* ambient color              */
125     float s[4];                                /* specular color             */
126     float e[4];                                /* emission color             */
127     float h[1];                                /* specular exponent          */
128     float angle;
129
130     int fl;                                    /* material flags             */
131
132     char   f[PATHMAX];                         /* texture file name          */
133 };
134
135 struct b_vert
136 {
137     float p[3];                                /* vertex position            */
138 };
139
140 struct b_edge
141 {
142     int vi;
143     int vj;
144 };
145
146 struct b_side
147 {
148     float n[3];                                /* plane normal vector        */
149     float d;                                   /* distance from origin       */
150 };
151
152 struct b_texc
153 {
154     float u[2];                                /* texture coordinate         */
155 };
156
157 struct b_offs
158 {
159     int ti, si, vi;
160 };
161
162 struct b_geom
163 {
164     int mi;
165     int oi, oj, ok;
166 };
167
168 struct b_lump
169 {
170     int fl;                                    /* lump flags                 */
171     int v0, vc;
172     int e0, ec;
173     int g0, gc;
174     int s0, sc;
175 };
176
177 struct b_node
178 {
179     int si;
180     int ni;
181     int nj;
182     int l0;
183     int lc;
184 };
185
186 struct b_path
187 {
188     float p[3];                                /* starting position          */
189     float e[4];                                /* orientation (quaternion)   */
190     float t;                                   /* travel time                */
191     int   tm;                                  /* milliseconds               */
192
193     int pi;
194     int f;                                     /* enable flag                */
195     int s;                                     /* smooth flag                */
196
197     int fl;                                    /* flags                      */
198
199     /* TODO: merge enable and smooth into flags. */
200 };
201
202 struct b_body
203 {
204     int pi;
205     int ni;
206     int l0;
207     int lc;
208     int g0;
209     int gc;
210 };
211
212 struct b_item
213 {
214     float p[3];                                /* position                   */
215     int   t;                                   /* type                       */
216     int   n;                                   /* value                      */
217 };
218
219 struct b_goal
220 {
221     float p[3];                                /* position                   */
222     float r;                                   /* radius                     */
223 };
224
225 struct b_swch
226 {
227     float p[3];                                /* position                   */
228     float r;                                   /* radius                     */
229     int  pi;                                   /* the linked path            */
230
231     float t;                                   /* default timer              */
232     int   tm;                                  /* milliseconds               */
233     int   f;                                   /* default state              */
234     int   i;                                   /* is invisible?              */
235 };
236
237 struct b_bill
238 {
239     int  fl;
240     int  mi;
241     float t;                                   /* repeat time interval       */
242     float d;                                   /* distance                   */
243
244     float w[3];                                /* width coefficients         */
245     float h[3];                                /* height coefficients        */
246
247     float rx[3];                               /* X rotation coefficients    */
248     float ry[3];                               /* Y rotation coefficients    */
249     float rz[3];                               /* Z rotation coefficients    */
250
251     float p[3];
252 };
253
254 struct b_jump
255 {
256     float p[3];                                /* position                   */
257     float q[3];                                /* target position            */
258     float r;                                   /* radius                     */
259 };
260
261 struct b_ball
262 {
263     float p[3];                                /* position vector            */
264     float r;                                   /* radius                     */
265 };
266
267 struct b_view
268 {
269     float p[3];
270     float q[3];
271 };
272
273 struct b_dict
274 {
275     int ai;
276     int aj;
277 };
278
279 struct s_base
280 {
281     int ac;
282     int mc;
283     int vc;
284     int ec;
285     int sc;
286     int tc;
287     int oc;
288     int gc;
289     int lc;
290     int nc;
291     int pc;
292     int bc;
293     int hc;
294     int zc;
295     int jc;
296     int xc;
297     int rc;
298     int uc;
299     int wc;
300     int dc;
301     int ic;
302
303     char          *av;
304     struct b_mtrl *mv;
305     struct b_vert *vv;
306     struct b_edge *ev;
307     struct b_side *sv;
308     struct b_texc *tv;
309     struct b_offs *ov;
310     struct b_geom *gv;
311     struct b_lump *lv;
312     struct b_node *nv;
313     struct b_path *pv;
314     struct b_body *bv;
315     struct b_item *hv;
316     struct b_goal *zv;
317     struct b_jump *jv;
318     struct b_swch *xv;
319     struct b_bill *rv;
320     struct b_ball *uv;
321     struct b_view *wv;
322     struct b_dict *dv;
323     int           *iv;
324 };
325
326 /*---------------------------------------------------------------------------*/
327
328 int  sol_load_base(struct s_base *, const char *);
329 int  sol_load_meta(struct s_base *, const char *);
330 void sol_free_base(struct s_base *);
331 int  sol_stor_base(struct s_base *, const char *);
332
333 /*---------------------------------------------------------------------------*/
334
335 #endif