SEGMENT.H 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. #ifndef _SEGMENT_H
  99. #define _SEGMENT_H
  100. #include "types.h"
  101. #include "fix.h"
  102. #include "vecmat.h"
  103. //#include "3d.h"
  104. //#include "inferno.h"
  105. // Version 1 - Initial version
  106. // Version 2 - Mike changed some shorts to bytes in segments, so incompatible!
  107. #define SIDE_IS_QUAD 1 // render side as quadrilateral
  108. #define SIDE_IS_TRI_02 2 // render side as two triangles, triangulated along edge from 0 to 2
  109. #define SIDE_IS_TRI_13 3 // render side as two triangles, triangulated along edge from 1 to 3
  110. // Set maximum values for segment and face data structures.
  111. #define MAX_VERTICES_PER_SEGMENT 8
  112. #define MAX_SIDES_PER_SEGMENT 6
  113. #define MAX_VERTICES_PER_POLY 4
  114. #define WLEFT 0
  115. #define WTOP 1
  116. #define WRIGHT 2
  117. #define WBOTTOM 3
  118. #define WBACK 4
  119. #define WFRONT 5
  120. #define MAX_GAME_SEGMENTS 800
  121. #define MAX_GAME_VERTICES 2800
  122. #if defined(SHAREWARE) && !defined(EDITOR)
  123. #define MAX_SEGMENTS MAX_GAME_SEGMENTS
  124. #define MAX_SEGMENT_VERTICES MAX_GAME_VERTICES
  125. #else
  126. #define MAX_SEGMENTS 900
  127. #define MAX_SEGMENT_VERTICES (4*MAX_SEGMENTS)
  128. #endif
  129. //normal everyday vertices
  130. #define DEFAULT_LIGHTING 0 // (F1_0/2)
  131. #ifdef EDITOR //verts for the new segment
  132. #define NUM_NEW_SEG_VERTICES 8
  133. #define NEW_SEGMENT_VERTICES (MAX_SEGMENT_VERTICES)
  134. #define MAX_VERTICES (MAX_SEGMENT_VERTICES+NUM_NEW_SEG_VERTICES)
  135. #else //No editor
  136. #define MAX_VERTICES (MAX_SEGMENT_VERTICES)
  137. #endif
  138. // Returns true if segnum references a child, else returns false.
  139. // Note that -1 means no connection, -2 means a connection to the outside world.
  140. #define IS_CHILD(segnum) (segnum > -1)
  141. //Structure for storing u,v,light values.
  142. //NOTE: this structure should be the same as the one in 3d.h
  143. typedef struct uvl {
  144. fix u,v,l;
  145. } uvl;
  146. #ifdef COMPACT_SEGS
  147. typedef struct side {
  148. byte type; // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  149. ubyte pad; //keep us longword alligned
  150. short wall_num;
  151. short tmap_num;
  152. short tmap_num2;
  153. uvl uvls[4];
  154. // vms_vector normals[2]; // 2 normals, if quadrilateral, both the same.
  155. } side;
  156. #else
  157. typedef struct side {
  158. byte type; // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  159. ubyte pad; //keep us longword alligned
  160. short wall_num;
  161. short tmap_num;
  162. short tmap_num2;
  163. uvl uvls[4];
  164. vms_vector normals[2]; // 2 normals, if quadrilateral, both the same.
  165. } side;
  166. #endif
  167. typedef struct segment {
  168. #ifdef EDITOR
  169. short segnum; // segment number, not sure what it means
  170. #endif
  171. side sides[MAX_SIDES_PER_SEGMENT]; // 6 sides
  172. short children[MAX_SIDES_PER_SEGMENT]; // indices of 6 children segments, front, left, top, right, bottom, back
  173. short verts[MAX_VERTICES_PER_SEGMENT]; // vertex ids of 4 front and 4 back vertices
  174. #ifdef EDITOR
  175. short group; // group number to which the segment belongs.
  176. #endif
  177. short objects; // pointer to objects in this segment
  178. ubyte special; // special property of a segment (such as damaging, trigger, etc.)
  179. byte matcen_num; // which center segment is associated with.
  180. short value;
  181. fix static_light; //average static light in segment
  182. #ifndef EDITOR
  183. short pad; //make structure longword aligned
  184. #endif
  185. } segment;
  186. #ifdef COMPACT_SEGS
  187. extern void get_side_normal(segment *sp, int sidenum, int normal_num, vms_vector * vm );
  188. extern void get_side_normals(segment *sp, int sidenum, vms_vector * vm1, vms_vector *vm2 );
  189. #endif
  190. // Local segment data.
  191. // This is stuff specific to a segment that does not need to get written to disk.
  192. // This is a handy separation because we can add to this structure without obsoleting
  193. // existing data on disk.
  194. #define SS_REPAIR_CENTER 0x01 // Bitmask for this segment being part of repair center.
  195. //--repair-- typedef struct {
  196. //--repair-- int special_type;
  197. //--repair-- short special_segment; // if special_type indicates repair center, this is the base of the repair center
  198. //--repair-- } lsegment;
  199. typedef struct {
  200. int num_segments;
  201. int num_vertices;
  202. short segments[MAX_SEGMENTS];
  203. short vertices[MAX_VERTICES];
  204. } group;
  205. // Globals from mglobal.c
  206. extern vms_vector Vertices[];
  207. extern segment Segments[];
  208. //--repair-- extern lsegment Lsegments[];
  209. extern int Num_segments;
  210. extern int Num_vertices;
  211. extern byte Side_to_verts[MAX_SIDES_PER_SEGMENT][4]; // Side_to_verts[my_side] is list of vertices forming side my_side.
  212. extern int Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4]; // Side_to_verts[my_side] is list of vertices forming side my_side.
  213. extern char Side_opposite[]; // Side_opposite[my_side] returns side opposite cube from my_side.
  214. #define SEG_PTR_2_NUM(segptr) (Assert((unsigned) (segptr-Segments)<MAX_SEGMENTS),(segptr)-Segments)
  215. // ----------------------------------------------------------------------------------------------------------
  216. // -------------------------- Segment interrogation functions ------------------------
  217. // Do NOT read the segment data structure directly. Use these functions instead.
  218. // The segment data structure is GUARANTEED to change MANY TIMES. If you read the
  219. // segment data structure directly, your code will break, I PROMISE IT!
  220. // Return a pointer to the list of vertex indices for the current segment in vp and
  221. // the number of vertices in *nv.
  222. extern void med_get_vertex_list(segment *s,int *nv,short **vp);
  223. // Return a pointer to the list of vertex indices for face facenum in vp and
  224. // the number of vertices in *nv.
  225. extern void med_get_face_vertex_list(segment *s,int side, int facenum,int *nv,short **vp);
  226. // Set *nf = number of faces in segment s.
  227. extern void med_get_num_faces(segment *s,int *nf);
  228. void med_validate_segment_side(segment *sp,int side);
  229. // Delete segment function added for curves.c
  230. extern int med_delete_segment(segment *sp);
  231. // Delete segment from group
  232. extern void delete_segment_from_group(int segment_num, int group_num);
  233. // Add segment to group
  234. extern void add_segment_to_group(int segment_num, int group_num);
  235. // Verify that all vertices are legal.
  236. extern void med_check_all_vertices();
  237. #endif
  238.