]> icculus.org git repositories - btb/d2x.git/blob - main/segment.h
delete cruft
[btb/d2x.git] / main / segment.h
1 /* $Id: segment.h,v 1.4 2003-10-04 03:14:47 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Include file for functions which need to access segment data structure.
18  *
19  * Old Log:
20  * Revision 1.4  1995/11/03  12:53:11  allender
21  * shareware changes
22  *
23  * Revision 1.3  1995/07/26  16:53:45  allender
24  * put sides and segment structure back the PC way for checksumming reasons
25  *
26  * Revision 1.2  1995/06/19  07:55:22  allender
27  * rearranged structure members for possible better alignment
28  *
29  * Revision 1.1  1995/05/16  16:02:22  allender
30  * Initial revision
31  *
32  * Revision 2.1  1995/03/20  18:15:22  john
33  * Added code to not store the normals in the segment structure.
34  *
35  * Revision 2.0  1995/02/27  11:26:49  john
36  * New version 2.0, which has no anonymous unions, builds with
37  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
38  *
39  * Revision 1.89  1995/01/24  15:07:55  yuan
40  * *** empty log message ***
41  *
42  * Revision 1.88  1994/12/12  01:04:06  yuan
43  * Boosted MAX_GAME_VERTS.
44  *
45  * Revision 1.87  1994/12/11  16:18:14  mike
46  * add constants so we can detect too-large mines for game while in editor.
47  *
48  * Revision 1.86  1994/12/08  15:07:29  yuan
49  * *** empty log message ***
50  *
51  * Revision 1.85  1994/12/01  21:06:39  matt
52  * Moved plane tolerance constant to gameseg.c, the only file that used it.
53  *
54  * Revision 1.84  1994/11/27  14:01:41  matt
55  * Fixed segment structure so LVLs work
56  *
57  * Revision 1.83  1994/11/26  22:50:20  matt
58  * Removed editor-only fields from segment structure when editor is compiled
59  * out, and padded segment structure to even multiple of 4 bytes.
60  *
61  * Revision 1.82  1994/11/21  11:43:36  mike
62  * smaller segment and vertex buffers.
63  *
64  * Revision 1.81  1994/11/17  11:39:35  matt
65  * Ripped out code to load old mines
66  *
67  * Revision 1.80  1994/10/30  14:12:05  mike
68  * rip out local segments stuff.
69  *
70  * Revision 1.79  1994/10/27  11:33:58  mike
71  * lower number of segments by 100, saving 116K.
72  *
73  * Revision 1.78  1994/08/25  21:54:50  mike
74  * Add macro IS_CHILD to make checking for the presence of a child centralized.
75  *
76  * Revision 1.77  1994/08/11  18:58:16  mike
77  * Add prototype for Side_to_verts_int.
78  *
79  * Revision 1.76  1994/08/01  11:04:13  yuan
80  * New materialization centers.
81  *
82  * Revision 1.75  1994/07/25  00:04:19  matt
83  * Various changes to accomodate new 3d, which no longer takes point numbers
84  * as parms, and now only takes pointers to points.
85  *
86  * Revision 1.74  1994/07/21  19:01:30  mike
87  * new lsegment structure.
88  *
89  * Revision 1.73  1994/06/08  14:30:48  matt
90  * Added static_light field to segment structure, and padded side struct
91  * to be longword aligned.
92  *
93  * Revision 1.72  1994/05/19  23:25:17  mike
94  * Change MINE_VERSION to 15, DEFAULT_LIGHTING to 0
95  *
96  * Revision 1.71  1994/05/12  14:45:54  mike
97  * New segment data structure (!!), group, special, object, value = short.
98  *
99  * Revision 1.70  1994/05/03  11:06:46  mike
100  * Remove constants VMAG and UMAG which are editor specific..
101  *
102  * Revision 1.69  1994/04/18  10:40:28  yuan
103  * Increased segment limit to 1000
104  * (From 500)
105  *
106  *
107  */
108
109 #ifndef _SEGMENT_H
110 #define _SEGMENT_H
111
112 #include "pstypes.h"
113 #include "fix.h"
114 #include "vecmat.h"
115 //#include "3d.h"
116 //#include "inferno.h"
117 #include "cfile.h"
118
119 // Version 1 - Initial version
120 // Version 2 - Mike changed some shorts to bytes in segments, so incompatible!
121
122 #define SIDE_IS_QUAD    1   // render side as quadrilateral
123 #define SIDE_IS_TRI_02  2   // render side as two triangles, triangulated along edge from 0 to 2
124 #define SIDE_IS_TRI_13  3   // render side as two triangles, triangulated along edge from 1 to 3
125
126 // Set maximum values for segment and face data structures.
127 #define MAX_VERTICES_PER_SEGMENT    8
128 #define MAX_SIDES_PER_SEGMENT       6
129 #define MAX_VERTICES_PER_POLY       4
130 #define WLEFT                       0
131 #define WTOP                        1
132 #define WRIGHT                      2
133 #define WBOTTOM                     3
134 #define WBACK                       4
135 #define WFRONT                      5
136
137 #if defined(SHAREWARE)
138 # define MAX_SEGMENTS           800
139 # define MAX_SEGMENT_VERTICES   2800
140 #else
141 # define MAX_SEGMENTS           900
142 # define MAX_SEGMENT_VERTICES   3600
143 #endif
144
145 //normal everyday vertices
146
147 #define DEFAULT_LIGHTING        0   // (F1_0/2)
148
149 #ifdef EDITOR   //verts for the new segment
150 # define NUM_NEW_SEG_VERTICES   8
151 # define NEW_SEGMENT_VERTICES   (MAX_SEGMENT_VERTICES)
152 # define MAX_VERTICES           (MAX_SEGMENT_VERTICES+NUM_NEW_SEG_VERTICES)
153 #else           //No editor
154 # define MAX_VERTICES           (MAX_SEGMENT_VERTICES)
155 #endif
156
157 // Returns true if segnum references a child, else returns false.
158 // Note that -1 means no connection, -2 means a connection to the outside world.
159 #define IS_CHILD(segnum) (segnum > -1)
160
161 //Structure for storing u,v,light values.
162 //NOTE: this structure should be the same as the one in 3d.h
163 typedef struct uvl {
164         fix u, v, l;
165 } uvl;
166
167 #ifdef COMPACT_SEGS
168 typedef struct side {
169         sbyte   type;           // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
170         ubyte   pad;            //keep us longword alligned
171         short   wall_num;
172         short   tmap_num;
173         short   tmap_num2;
174         uvl     uvls[4];
175         //vms_vector normals[2];  // 2 normals, if quadrilateral, both the same.
176 } side;
177 #else
178 typedef struct side {
179         sbyte   type;           // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
180         ubyte   pad;            //keep us longword alligned
181         short   wall_num;
182         short   tmap_num;
183         short   tmap_num2;
184         uvl     uvls[4];
185         vms_vector normals[2];  // 2 normals, if quadrilateral, both the same.
186 } side;
187 #endif
188
189 typedef struct segment {
190 #ifdef EDITOR
191         short   segnum;     // segment number, not sure what it means
192 #endif
193         side    sides[MAX_SIDES_PER_SEGMENT];       // 6 sides
194         short   children[MAX_SIDES_PER_SEGMENT];    // indices of 6 children segments, front, left, top, right, bottom, back
195         short   verts[MAX_VERTICES_PER_SEGMENT];    // vertex ids of 4 front and 4 back vertices
196 #ifdef EDITOR
197         short   group;      // group number to which the segment belongs.
198         short   objects;    // pointer to objects in this segment
199 #else
200         int     objects;    // pointer to objects in this segment
201 #endif
202
203         // -- Moved to segment2 to make this struct 512 bytes long --
204         //ubyte   special;    // what type of center this is
205         //sbyte   matcen_num; // which center segment is associated with.
206         //short   value;
207         //fix     static_light; //average static light in segment
208         //#ifndef EDITOR
209         //short   pad;        //make structure longword aligned
210         //#endif
211 } segment;
212
213 #define S2F_AMBIENT_WATER   0x01
214 #define S2F_AMBIENT_LAVA    0x02
215
216 typedef struct segment2 {
217         ubyte   special;
218         sbyte   matcen_num;
219         sbyte   value;
220         ubyte   s2_flags;
221         fix     static_light;
222 } segment2;
223
224 //values for special field
225 #define SEGMENT_IS_NOTHING      0
226 #define SEGMENT_IS_FUELCEN      1
227 #define SEGMENT_IS_REPAIRCEN    2
228 #define SEGMENT_IS_CONTROLCEN   3
229 #define SEGMENT_IS_ROBOTMAKER   4
230 #define SEGMENT_IS_GOAL_BLUE    5
231 #define SEGMENT_IS_GOAL_RED     6
232 #define MAX_CENTER_TYPES        7
233
234 #ifdef COMPACT_SEGS
235 extern void get_side_normal(segment *sp, int sidenum, int normal_num, vms_vector * vm );
236 extern void get_side_normals(segment *sp, int sidenum, vms_vector * vm1, vms_vector *vm2 );
237 #endif
238
239 // Local segment data.
240 // This is stuff specific to a segment that does not need to get
241 // written to disk.  This is a handy separation because we can add to
242 // this structure without obsoleting existing data on disk.
243
244 #define SS_REPAIR_CENTER    0x01    // Bitmask for this segment being part of repair center.
245
246 //--repair-- typedef struct {
247 //--repair--    int     special_type;
248 //--repair--    short   special_segment; // if special_type indicates repair center, this is the base of the repair center
249 //--repair-- } lsegment;
250
251 typedef struct {
252         int     num_segments;
253         int     num_vertices;
254         short   segments[MAX_SEGMENTS];
255         short   vertices[MAX_VERTICES];
256 } group;
257
258 // Globals from mglobal.c
259 extern vms_vector   Vertices[];
260 extern segment      Segments[];
261 extern segment2     Segment2s[];
262 extern int          Num_segments;
263 extern int          Num_vertices;
264
265 extern sbyte Side_to_verts[MAX_SIDES_PER_SEGMENT][4];       // Side_to_verts[my_side] is list of vertices forming side my_side.
266 extern int  Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4];    // Side_to_verts[my_side] is list of vertices forming side my_side.
267 extern char Side_opposite[];                                // Side_opposite[my_side] returns side opposite cube from my_side.
268
269 #define SEG_PTR_2_NUM(segptr) (Assert((unsigned) (segptr-Segments)<MAX_SEGMENTS),(segptr)-Segments)
270
271 // New stuff, 10/14/95: For shooting out lights and monitors.
272 // Light cast upon vert_light vertices in segnum:sidenum by some light
273 typedef struct {
274         short   segnum;
275         sbyte   sidenum;
276         sbyte   dummy;
277         ubyte   vert_light[4];
278 } delta_light;
279
280 // Light at segnum:sidenum casts light on count sides beginning at index (in array Delta_lights)
281 typedef struct {
282         short   segnum;
283         sbyte   sidenum;
284         sbyte   count;
285         short   index;
286 } dl_index;
287
288 #define MAX_DL_INDICES      500
289 #define MAX_DELTA_LIGHTS    10000
290
291 #define DL_SCALE            2048    // Divide light to allow 3 bits integer, 5 bits fraction.
292
293 extern dl_index     Dl_indices[MAX_DL_INDICES];
294 extern delta_light  Delta_lights[MAX_DELTA_LIGHTS];
295 extern int          Num_static_lights;
296
297 extern int subtract_light(int segnum, int sidenum);
298 extern int add_light(int segnum, int sidenum);
299 extern void restore_all_lights_in_mine(void);
300 extern void clear_light_subtracted(void);
301
302 extern ubyte Light_subtracted[MAX_SEGMENTS];
303
304 // ----------------------------------------------------------------------------
305 // --------------------- Segment interrogation functions ----------------------
306 // Do NOT read the segment data structure directly.  Use these
307 // functions instead.  The segment data structure is GUARANTEED to
308 // change MANY TIMES.  If you read the segment data structure
309 // directly, your code will break, I PROMISE IT!
310
311 // Return a pointer to the list of vertex indices for the current
312 // segment in vp and the number of vertices in *nv.
313 extern void med_get_vertex_list(segment *s,int *nv,short **vp);
314
315 // Return a pointer to the list of vertex indices for face facenum in
316 // vp and the number of vertices in *nv.
317 extern void med_get_face_vertex_list(segment *s,int side, int facenum,int *nv,short **vp);
318
319 // Set *nf = number of faces in segment s.
320 extern void med_get_num_faces(segment *s,int *nf);
321
322 void med_validate_segment_side(segment *sp,int side);
323
324 // Delete segment function added for curves.c
325 extern int med_delete_segment(segment *sp);
326
327 // Delete segment from group
328 extern void delete_segment_from_group(int segment_num, int group_num);
329
330 // Add segment to group
331 extern void add_segment_to_group(int segment_num, int group_num);
332
333 // Verify that all vertices are legal.
334 extern void med_check_all_vertices();
335
336 #ifdef FAST_FILE_IO
337 #define segment2_read(s2, fp) cfread(s2, sizeof(segment2), 1, fp)
338 #define delta_light_read(dl, fp) cfread(dl, sizeof(delta_light), 1, fp)
339 #define dl_index_read(di, fp) cfread(di, sizeof(dl_index), 1, fp)
340 #else
341 /*
342  * reads a segment2 structure from a CFILE
343  */
344 void segment2_read(segment2 *s2, CFILE *fp);
345
346 /*
347  * reads a delta_light structure from a CFILE
348  */
349 void delta_light_read(delta_light *dl, CFILE *fp);
350
351 /*
352  * reads a dl_index structure from a CFILE
353  */
354 void dl_index_read(dl_index *di, CFILE *fp);
355 #endif
356
357 #endif