sparselines.map: Re-texture level as per RlksNotes
[neverball] / share / solid.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 SOL_H
16 #define SOL_H
17
18 #include "glext.h"
19 #include "base_config.h"
20
21 /*
22  * Some might  be taken  aback at  the terseness of  the names  of the
23  * structure  members and  the variables  used by  the  functions that
24  * access them.  Yes, yes, I know:  readability.  I  contend that once
25  * the naming  convention is embraced, the names  become more readable
26  * than any  verbose alternative, and their brevity  and uniformity do
27  * more to augment readability than longVariableNames ever could.
28  *
29  * Members  and variables  are named  XY.   X determines  the type  of
30  * structure to which the variable  refers.  Y determines the usage of
31  * the variable.
32  *
33  * The Xs are as documented by struct s_file:
34  *
35  *     f  File          (struct s_file)
36  *     m  Material      (struct s_mtrl)
37  *     v  Vertex        (struct s_vert)
38  *     e  Edge          (struct s_edge)
39  *     s  Side          (struct s_side)
40  *     t  Texture coord (struct s_texc)
41  *     g  Geometry      (struct s_geom)
42  *     l  Lump          (struct s_lump)
43  *     n  Node          (struct s_node)
44  *     p  Path          (struct s_path)
45  *     b  Body          (struct s_body)
46  *     h  Item          (struct s_item)
47  *     z  Goal          (struct s_goal)
48  *     j  Jump          (struct s_jump)
49  *     x  Switch        (struct s_swch)
50  *     r  Billboard     (struct s_bill)
51  *     u  User          (struct s_ball)
52  *     w  Viewpoint     (struct s_view)
53  *     d  Dictionary    (struct s_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 o q y.
76  */
77
78 /*---------------------------------------------------------------------------*/
79
80 /* Material type flags */
81
82 #define M_OPAQUE       1
83 #define M_TRANSPARENT  2
84 #define M_REFLECTIVE   4
85 #define M_ENVIRONMENT  8
86 #define M_ADDITIVE    16
87 #define M_CLAMPED     32
88 #define M_DECAL       64
89 #define M_TWO_SIDED  128
90 #define M_SHADOWED   256
91
92 /* Billboard types. */
93
94 #define B_EDGE     1
95 #define B_FLAT     2
96 #define B_ADDITIVE 4
97 #define B_NOFACE   8
98
99 /* Lump flags. */
100
101 #define L_DETAIL   1
102
103 /* Item types. */
104
105 #define ITEM_NONE       0
106 #define ITEM_COIN       1
107 #define ITEM_GROW       2
108 #define ITEM_SHRINK     3
109
110 /* Path flags. */
111
112 #define P_ORIENTED 1
113
114 /*---------------------------------------------------------------------------*/
115
116 struct s_mtrl
117 {
118     float d[4];                                /* diffuse color              */
119     float a[4];                                /* ambient color              */
120     float s[4];                                /* specular color             */
121     float e[4];                                /* emission color             */
122     float h[1];                                /* specular exponent          */
123     float angle;
124
125     int fl;                                    /* material flags             */
126
127     GLuint o;                                  /* OpenGL texture object      */
128     char   f[PATHMAX];                         /* texture file name          */
129 };
130
131 struct s_vert
132 {
133     float p[3];                                /* vertex position            */
134 };
135
136 struct s_edge
137 {
138     int vi;
139     int vj;
140 };
141
142 struct s_side
143 {
144     float n[3];                                /* plane normal vector        */
145     float d;                                   /* distance from origin       */
146 };
147
148 struct s_texc
149 {
150     float u[2];                                /* texture coordinate         */
151 };
152
153 struct s_geom
154 {
155     int mi;
156     int ti, si, vi;
157     int tj, sj, vj;
158     int tk, sk, vk;
159 };
160
161 struct s_lump
162 {
163     int fl;                                    /* lump flags                 */
164     int v0, vc;
165     int e0, ec;
166     int g0, gc;
167     int s0, sc;
168 };
169
170 struct s_node
171 {
172     int si;
173     int ni;
174     int nj;
175     int l0;
176     int lc;
177 };
178
179 struct s_path
180 {
181     float p[3];                                /* starting position          */
182     float e[4];                                /* orientation (quaternion)   */
183     float t;                                   /* travel time                */
184     int   tm;                                  /* milliseconds               */
185
186     int pi;
187     int f;                                     /* enable flag                */
188     int s;                                     /* smooth flag                */
189
190     int fl;                                    /* flags                      */
191
192     /* TODO: merge enable and smooth into flags. */
193 };
194
195 struct s_body
196 {
197     float t;                                   /* time on current path       */
198     int   tm;                                  /* milliseconds               */
199
200     GLuint ol;                                 /* opaque geometry list       */
201     GLuint tl;                                 /* transparent geometry list  */
202     GLuint rl;                                 /* reflective geometry list   */
203     GLuint sl;                                 /* shadowed geometry list     */
204
205     int pi;
206     int ni;
207     int l0;
208     int lc;
209     int g0;
210     int gc;
211 };
212
213 struct s_item
214 {
215     float p[3];                                /* position                   */
216     int   t;                                   /* type                       */
217     int   n;                                   /* value                      */
218 };
219
220 struct s_goal
221 {
222     float p[3];                                /* position                   */
223     float r;                                   /* radius                     */
224 };
225
226 struct s_swch
227 {
228     float p[3];                                /* position                   */
229     float r;                                   /* radius                     */
230     int  pi;                                   /* the linked path            */
231
232     float t0;                                  /* default timer              */
233     int   t0m;                                 /* milliseconds               */
234     float t;                                   /* current timer              */
235     int   tm;                                  /* milliseconds               */
236     int   f0;                                  /* default state              */
237     int   f;                                   /* current state              */
238     int   i;                                   /* is invisible?              */
239     int   e;                                   /* is a ball inside it?       */
240 };
241
242 struct s_bill
243 {
244     int  fl;
245     int  mi;
246     float t;                                   /* repeat time interval       */
247     float d;                                   /* distance                   */
248
249     float w[3];                                /* width coefficients         */
250     float h[3];                                /* height coefficients        */
251
252     float rx[3];                               /* X rotation coefficients    */
253     float ry[3];                               /* Y rotation coefficients    */
254     float rz[3];                               /* Z rotation coefficients    */
255
256     float p[3];
257 };
258
259 struct s_jump
260 {
261     float p[3];                                /* position                   */
262     float q[3];                                /* target position            */
263     float r;                                   /* radius                     */
264 };
265
266 struct s_ball
267 {
268     float e[3][3];                             /* basis of orientation       */
269     float p[3];                                /* position vector            */
270     float v[3];                                /* velocity vector            */
271     float w[3];                                /* angular velocity vector    */
272     float E[3][3];                             /* basis of pendulum          */
273     float W[3];                                /* angular pendulum velocity  */
274     float r;                                   /* radius                     */
275 };
276
277 struct s_view
278 {
279     float p[3];
280     float q[3];
281 };
282
283 struct s_dict
284 {
285     int ai;
286     int aj;
287 };
288
289 struct s_file
290 {
291     int ac;
292     int mc;
293     int vc;
294     int ec;
295     int sc;
296     int tc;
297     int gc;
298     int lc;
299     int nc;
300     int pc;
301     int bc;
302     int hc;
303     int zc;
304     int jc;
305     int xc;
306     int rc;
307     int uc;
308     int wc;
309     int dc;
310     int ic;
311
312     char          *av;
313     struct s_mtrl *mv;
314     struct s_vert *vv;
315     struct s_edge *ev;
316     struct s_side *sv;
317     struct s_texc *tv;
318     struct s_geom *gv;
319     struct s_lump *lv;
320     struct s_node *nv;
321     struct s_path *pv;
322     struct s_body *bv;
323     struct s_item *hv;
324     struct s_goal *zv;
325     struct s_jump *jv;
326     struct s_swch *xv;
327     struct s_bill *rv;
328     struct s_ball *uv;
329     struct s_view *wv;
330     struct s_dict *dv;
331     int           *iv;
332 };
333
334 /*---------------------------------------------------------------------------*/
335
336 int   sol_load_only_file(struct s_file *, const char *);
337 int   sol_load_only_head(struct s_file *, const char *);
338 int   sol_stor(struct s_file *, const char *);
339 void  sol_free(struct s_file *);
340
341 /*---------------------------------------------------------------------------*/
342
343 #endif