home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / segment.h < prev    next >
Text File  |  1998-06-08  |  10KB  |  270 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/segment.h $
  15.  * $Revision: 2.1 $
  16.  * $Author: john $
  17.  * $Date: 1995/03/20 18:15:22 $
  18.  *
  19.  * Include file for functions which need to access segment data structure.
  20.  *
  21.  * $Log: segment.h $
  22.  * Revision 2.1  1995/03/20  18:15:22  john
  23.  * Added code to not store the normals in the segment structure.
  24.  * 
  25.  * Revision 2.0  1995/02/27  11:26:49  john
  26.  * New version 2.0, which has no anonymous unions, builds with
  27.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  28.  * 
  29.  * Revision 1.89  1995/01/24  15:07:55  yuan
  30.  * *** empty log message ***
  31.  * 
  32.  * Revision 1.88  1994/12/12  01:04:06  yuan
  33.  * Boosted MAX_GAME_VERTS.
  34.  * 
  35.  * Revision 1.87  1994/12/11  16:18:14  mike
  36.  * add constants so we can detect too-large mines for game while in editor.
  37.  * 
  38.  * Revision 1.86  1994/12/08  15:07:29  yuan
  39.  * *** empty log message ***
  40.  * 
  41.  * Revision 1.85  1994/12/01  21:06:39  matt
  42.  * Moved plane tolerance constant to gameseg.c, the only file that used it.
  43.  * 
  44.  * Revision 1.84  1994/11/27  14:01:41  matt
  45.  * Fixed segment structure so LVLs work
  46.  * 
  47.  * Revision 1.83  1994/11/26  22:50:20  matt
  48.  * Removed editor-only fields from segment structure when editor is compiled
  49.  * out, and padded segment structure to even multiple of 4 bytes.
  50.  * 
  51.  * Revision 1.82  1994/11/21  11:43:36  mike
  52.  * smaller segment and vertex buffers.
  53.  * 
  54.  * Revision 1.81  1994/11/17  11:39:35  matt
  55.  * Ripped out code to load old mines
  56.  * 
  57.  * Revision 1.80  1994/10/30  14:12:05  mike
  58.  * rip out local segments stuff.
  59.  * 
  60.  * Revision 1.79  1994/10/27  11:33:58  mike
  61.  * lower number of segments by 100, saving 116K.
  62.  * 
  63.  * Revision 1.78  1994/08/25  21:54:50  mike
  64.  * Add macro IS_CHILD to make checking for the presence of a child centralized.
  65.  * 
  66.  * Revision 1.77  1994/08/11  18:58:16  mike
  67.  * Add prototype for Side_to_verts_int.
  68.  * 
  69.  * Revision 1.76  1994/08/01  11:04:13  yuan
  70.  * New materialization centers.
  71.  * 
  72.  * Revision 1.75  1994/07/25  00:04:19  matt
  73.  * Various changes to accomodate new 3d, which no longer takes point numbers
  74.  * as parms, and now only takes pointers to points.
  75.  * 
  76.  * Revision 1.74  1994/07/21  19:01:30  mike
  77.  * new lsegment structure.
  78.  * 
  79.  * Revision 1.73  1994/06/08  14:30:48  matt
  80.  * Added static_light field to segment structure, and padded side struct
  81.  * to be longword aligned.
  82.  * 
  83.  * Revision 1.72  1994/05/19  23:25:17  mike
  84.  * Change MINE_VERSION to 15, DEFAULT_LIGHTING to 0
  85.  * 
  86.  * Revision 1.71  1994/05/12  14:45:54  mike
  87.  * New segment data structure (!!), group, special, object, value = short.
  88.  * 
  89.  * Revision 1.70  1994/05/03  11:06:46  mike
  90.  * Remove constants VMAG and UMAG which are editor specific..
  91.  * 
  92.  * Revision 1.69  1994/04/18  10:40:28  yuan
  93.  * Increased segment limit to 1000
  94.  * (From 500)
  95.  * 
  96.  * 
  97.  */
  98.  
  99. #ifndef _SEGMENT_H
  100. #define _SEGMENT_H
  101.  
  102. #include    "types.h"
  103. #include    "fix.h"
  104. #include "vecmat.h"
  105. //#include "3d.h"
  106. //#include "inferno.h"
  107.  
  108. // Version 1 - Initial version
  109. // Version 2 - Mike changed some shorts to bytes in segments, so incompatible!
  110.  
  111. #define    SIDE_IS_QUAD    1            // render side as quadrilateral
  112. #define    SIDE_IS_TRI_02    2            // render side as two triangles, triangulated along edge from 0 to 2
  113. #define    SIDE_IS_TRI_13    3            // render side as two triangles, triangulated along edge from 1 to 3
  114.  
  115. // Set maximum values for segment and face data structures.
  116. #define    MAX_VERTICES_PER_SEGMENT    8
  117. #define    MAX_SIDES_PER_SEGMENT        6
  118. #define    MAX_VERTICES_PER_POLY        4
  119. #define    WLEFT                                0
  120. #define    WTOP                                1
  121. #define    WRIGHT                            2
  122. #define    WBOTTOM                            3
  123. #define    WBACK                                4
  124. #define    WFRONT                            5
  125.  
  126. #define    MAX_GAME_SEGMENTS                800
  127. #define    MAX_GAME_VERTICES                2800
  128.  
  129. #if defined(SHAREWARE) && !defined(EDITOR)
  130.   #define    MAX_SEGMENTS                    MAX_GAME_SEGMENTS
  131.   #define    MAX_SEGMENT_VERTICES            MAX_GAME_VERTICES
  132. #else
  133.   #define    MAX_SEGMENTS                    900
  134.   #define    MAX_SEGMENT_VERTICES            (4*MAX_SEGMENTS)
  135. #endif
  136.  
  137. //normal everyday vertices
  138.  
  139. #define    DEFAULT_LIGHTING            0            // (F1_0/2)
  140.  
  141. #ifdef EDITOR    //verts for the new segment
  142.   #define    NUM_NEW_SEG_VERTICES        8
  143.   #define    NEW_SEGMENT_VERTICES        (MAX_SEGMENT_VERTICES)
  144.   #define    MAX_VERTICES                (MAX_SEGMENT_VERTICES+NUM_NEW_SEG_VERTICES)
  145. #else        //No editor
  146.   #define    MAX_VERTICES                (MAX_SEGMENT_VERTICES)
  147. #endif
  148.  
  149. //    Returns true if segnum references a child, else returns false.
  150. //    Note that -1 means no connection, -2 means a connection to the outside world.
  151. #define    IS_CHILD(segnum) (segnum > -1)
  152.  
  153. //Structure for storing u,v,light values. 
  154. //NOTE: this structure should be the same as the one in 3d.h
  155. typedef struct uvl {
  156.     fix u,v,l;
  157. } uvl;
  158.  
  159. #ifdef COMPACT_SEGS
  160. typedef struct side {
  161.     byte        type;                                    // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  162.     ubyte        pad;                                    //keep us longword alligned
  163.     short        wall_num;
  164.     short        tmap_num;
  165.     short        tmap_num2;
  166.     uvl        uvls[4];
  167.     // vms_vector    normals[2];                        // 2 normals, if quadrilateral, both the same.
  168. } side;
  169. #else
  170. typedef struct side {
  171.     byte        type;                                    // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  172.     ubyte        pad;                                    //keep us longword alligned
  173.     short        wall_num;
  174.     short        tmap_num;
  175.     short        tmap_num2;
  176.     uvl        uvls[4];
  177.     vms_vector    normals[2];                        // 2 normals, if quadrilateral, both the same.
  178. } side;
  179. #endif
  180.  
  181. typedef struct segment {
  182.     #ifdef    EDITOR
  183.     short        segnum;                                // segment number, not sure what it means
  184.     #endif
  185.     side        sides[MAX_SIDES_PER_SEGMENT];    // 6 sides
  186.     short        children[MAX_SIDES_PER_SEGMENT];    // indices of 6 children segments, front, left, top, right, bottom, back
  187.     short        verts[MAX_VERTICES_PER_SEGMENT];    // vertex ids of 4 front and 4 back vertices
  188.     #ifdef    EDITOR
  189.     short        group;                                // group number to which the segment belongs.
  190.     #endif
  191.     short        objects;                                // pointer to objects in this segment
  192.     ubyte        special;                                // special property of a segment (such as damaging, trigger, etc.)
  193.     byte        matcen_num;                            //    which center segment is associated with.
  194.     short        value;
  195.     fix        static_light;                        //average static light in segment
  196.     #ifndef    EDITOR
  197.     short        pad;            //make structure longword aligned
  198.     #endif
  199. } segment;
  200.  
  201. #ifdef COMPACT_SEGS
  202. extern void get_side_normal(segment *sp, int sidenum, int normal_num, vms_vector * vm );
  203. extern void get_side_normals(segment *sp, int sidenum, vms_vector * vm1, vms_vector *vm2 );
  204. #endif
  205.  
  206. //    Local segment data.
  207. //    This is stuff specific to a segment that does not need to get written to disk.
  208. //    This is a handy separation because we can add to this structure without obsoleting
  209. //    existing data on disk.
  210. #define    SS_REPAIR_CENTER    0x01                //    Bitmask for this segment being part of repair center.
  211.  
  212. //--repair-- typedef struct {
  213. //--repair--     int    special_type;
  214. //--repair--     short    special_segment;                        // if special_type indicates repair center, this is the base of the repair center
  215. //--repair-- } lsegment;
  216.  
  217. typedef struct {
  218.     int        num_segments;
  219.     int        num_vertices;
  220.     short        segments[MAX_SEGMENTS];
  221.     short        vertices[MAX_VERTICES];
  222. } group;
  223.  
  224. // Globals from mglobal.c
  225. extern    vms_vector    Vertices[];
  226. extern    segment        Segments[];
  227. //--repair-- extern    lsegment        Lsegments[];
  228. extern    int            Num_segments;
  229. extern    int            Num_vertices;
  230.  
  231. extern    byte        Side_to_verts[MAX_SIDES_PER_SEGMENT][4];    // Side_to_verts[my_side] is list of vertices forming side my_side.
  232. extern    int        Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4];    // Side_to_verts[my_side] is list of vertices forming side my_side.
  233. extern    char        Side_opposite[];                                    // Side_opposite[my_side] returns side opposite cube from my_side.
  234.  
  235. #define SEG_PTR_2_NUM(segptr) (Assert((unsigned) (segptr-Segments)<MAX_SEGMENTS),(segptr)-Segments)
  236.  
  237. // ----------------------------------------------------------------------------------------------------------
  238. // --------------------------  Segment interrogation functions ------------------------
  239. //       Do NOT read the segment data structure directly.  Use these functions instead.
  240. //            The segment data structure is GUARANTEED to change MANY TIMES.  If you read the
  241. //            segment data structure directly, your code will break, I PROMISE IT!
  242. //    Return a pointer to the list of vertex indices for the current segment in vp and
  243. //    the number of vertices in *nv.
  244. extern void med_get_vertex_list(segment *s,int *nv,short **vp);
  245.  
  246. //    Return a pointer to the list of vertex indices for face facenum in vp and
  247. //    the number of vertices in *nv.
  248. extern void med_get_face_vertex_list(segment *s,int side, int facenum,int *nv,short **vp);
  249.  
  250. //    Set *nf = number of faces in segment s.
  251. extern void med_get_num_faces(segment *s,int *nf);
  252.  
  253. void med_validate_segment_side(segment *sp,int side);
  254.  
  255. // Delete segment function added for curves.c
  256. extern int med_delete_segment(segment *sp);
  257.  
  258. //    Delete segment from group
  259. extern void delete_segment_from_group(int segment_num, int group_num);
  260.  
  261. //    Add segment to group
  262. extern void add_segment_to_group(int segment_num, int group_num);
  263.  
  264. // Verify that all vertices are legal.
  265. extern void med_check_all_vertices();
  266.  
  267. #endif
  268.  
  269. 
  270.