1 /* $Id: segment.h,v 1.4 2003-10-04 03:14:47 btb Exp $ */
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.
17 * Include file for functions which need to access segment data structure.
20 * Revision 1.4 1995/11/03 12:53:11 allender
23 * Revision 1.3 1995/07/26 16:53:45 allender
24 * put sides and segment structure back the PC way for checksumming reasons
26 * Revision 1.2 1995/06/19 07:55:22 allender
27 * rearranged structure members for possible better alignment
29 * Revision 1.1 1995/05/16 16:02:22 allender
32 * Revision 2.1 1995/03/20 18:15:22 john
33 * Added code to not store the normals in the segment structure.
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.
39 * Revision 1.89 1995/01/24 15:07:55 yuan
40 * *** empty log message ***
42 * Revision 1.88 1994/12/12 01:04:06 yuan
43 * Boosted MAX_GAME_VERTS.
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.
48 * Revision 1.86 1994/12/08 15:07:29 yuan
49 * *** empty log message ***
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.
54 * Revision 1.84 1994/11/27 14:01:41 matt
55 * Fixed segment structure so LVLs work
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.
61 * Revision 1.82 1994/11/21 11:43:36 mike
62 * smaller segment and vertex buffers.
64 * Revision 1.81 1994/11/17 11:39:35 matt
65 * Ripped out code to load old mines
67 * Revision 1.80 1994/10/30 14:12:05 mike
68 * rip out local segments stuff.
70 * Revision 1.79 1994/10/27 11:33:58 mike
71 * lower number of segments by 100, saving 116K.
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.
76 * Revision 1.77 1994/08/11 18:58:16 mike
77 * Add prototype for Side_to_verts_int.
79 * Revision 1.76 1994/08/01 11:04:13 yuan
80 * New materialization centers.
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.
86 * Revision 1.74 1994/07/21 19:01:30 mike
87 * new lsegment structure.
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.
93 * Revision 1.72 1994/05/19 23:25:17 mike
94 * Change MINE_VERSION to 15, DEFAULT_LIGHTING to 0
96 * Revision 1.71 1994/05/12 14:45:54 mike
97 * New segment data structure (!!), group, special, object, value = short.
99 * Revision 1.70 1994/05/03 11:06:46 mike
100 * Remove constants VMAG and UMAG which are editor specific..
102 * Revision 1.69 1994/04/18 10:40:28 yuan
103 * Increased segment limit to 1000
116 //#include "inferno.h"
119 // Version 1 - Initial version
120 // Version 2 - Mike changed some shorts to bytes in segments, so incompatible!
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
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
137 #if defined(SHAREWARE)
138 # define MAX_SEGMENTS 800
139 # define MAX_SEGMENT_VERTICES 2800
141 # define MAX_SEGMENTS 900
142 # define MAX_SEGMENT_VERTICES 3600
145 //normal everyday vertices
147 #define DEFAULT_LIGHTING 0 // (F1_0/2)
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)
154 # define MAX_VERTICES (MAX_SEGMENT_VERTICES)
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)
161 //Structure for storing u,v,light values.
162 //NOTE: this structure should be the same as the one in 3d.h
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
175 //vms_vector normals[2]; // 2 normals, if quadrilateral, both the same.
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
185 vms_vector normals[2]; // 2 normals, if quadrilateral, both the same.
189 typedef struct segment {
191 short segnum; // segment number, not sure what it means
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
197 short group; // group number to which the segment belongs.
198 short objects; // pointer to objects in this segment
200 int objects; // pointer to objects in this segment
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.
207 //fix static_light; //average static light in segment
209 //short pad; //make structure longword aligned
213 #define S2F_AMBIENT_WATER 0x01
214 #define S2F_AMBIENT_LAVA 0x02
216 typedef struct segment2 {
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
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 );
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.
244 #define SS_REPAIR_CENTER 0x01 // Bitmask for this segment being part of repair center.
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;
254 short segments[MAX_SEGMENTS];
255 short vertices[MAX_VERTICES];
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;
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.
269 #define SEG_PTR_2_NUM(segptr) (Assert((unsigned) (segptr-Segments)<MAX_SEGMENTS),(segptr)-Segments)
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
280 // Light at segnum:sidenum casts light on count sides beginning at index (in array Delta_lights)
288 #define MAX_DL_INDICES 500
289 #define MAX_DELTA_LIGHTS 10000
291 #define DL_SCALE 2048 // Divide light to allow 3 bits integer, 5 bits fraction.
293 extern dl_index Dl_indices[MAX_DL_INDICES];
294 extern delta_light Delta_lights[MAX_DELTA_LIGHTS];
295 extern int Num_static_lights;
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);
302 extern ubyte Light_subtracted[MAX_SEGMENTS];
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!
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);
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);
319 // Set *nf = number of faces in segment s.
320 extern void med_get_num_faces(segment *s,int *nf);
322 void med_validate_segment_side(segment *sp,int side);
324 // Delete segment function added for curves.c
325 extern int med_delete_segment(segment *sp);
327 // Delete segment from group
328 extern void delete_segment_from_group(int segment_num, int group_num);
330 // Add segment to group
331 extern void add_segment_to_group(int segment_num, int group_num);
333 // Verify that all vertices are legal.
334 extern void med_check_all_vertices();
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)
342 * reads a segment2 structure from a CFILE
344 void segment2_read(segment2 *s2, CFILE *fp);
347 * reads a delta_light structure from a CFILE
349 void delta_light_read(delta_light *dl, CFILE *fp);
352 * reads a dl_index structure from a CFILE
354 void dl_index_read(dl_index *di, CFILE *fp);