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