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