]> icculus.org git repositories - btb/d2x.git/blob - main/gameseg.h
move old per-file change logs into new file ChangeLog-old
[btb/d2x.git] / main / gameseg.h
1 /* $Id: gameseg.h,v 1.5 2004-08-28 23:17:45 schaffner 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  * Header file for stuff moved from segment.c to gameseg.c.
18  *
19  */
20
21
22 #ifndef _GAMESEG_H
23 #define _GAMESEG_H
24
25 #include "pstypes.h"
26 #include "fix.h"
27 #include "vecmat.h"
28 #include "segment.h"
29
30 //figure out what seg the given point is in, tracing through segments
31 int get_new_seg(vms_vector *p0,int startseg);
32
33 typedef struct segmasks {
34    short facemask;     //which faces sphere pokes through (12 bits)
35    sbyte sidemask;     //which sides sphere pokes through (6 bits)
36    sbyte centermask;   //which sides center point is on back of (6 bits)
37 } segmasks;
38
39 extern int      Highest_vertex_index;                   // Highest index in Vertices and Vertex_active, an efficiency hack
40 extern int      Highest_segment_index;          // Highest index in Segments, an efficiency hack
41
42 extern void compute_center_point_on_side(vms_vector *vp,segment *sp,int side);
43 extern void compute_segment_center(vms_vector *vp,segment *sp);
44 extern int find_connect_side(segment *base_seg, segment *con_seg);
45
46 // Fill in array with four absolute point numbers for a given side
47 void get_side_verts(short *vertlist,int segnum,int sidenum);
48
49 //      Create all vertex lists (1 or 2) for faces on a side.
50 //      Sets:
51 //              num_faces               number of lists
52 //              vertices                        vertices in all (1 or 2) faces
53 //      If there is one face, it has 4 vertices.
54 //      If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
55 //      face #1 is stored in vertices 3,4,5.
56 // Note: these are not absolute vertex numbers, but are relative to the segment
57 // Note:  for triagulated sides, the middle vertex of each trianle is the one NOT
58 //   adjacent on the diagonal edge
59 extern void create_all_vertex_lists(int *num_faces, int *vertices, int segnum, int sidenum);
60
61 //like create_all_vertex_lists(), but generate absolute point numbers
62 extern void create_abs_vertex_lists(int *num_faces, int *vertices, int segnum, int sidenum, char *calling_file, int calling_linenum);
63
64 // -----------------------------------------------------------------------------------
65 // Like create all vertex lists, but returns the vertnums (relative to
66 // the side) for each of the faces that make up the side.
67 //      If there is one face, it has 4 vertices.
68 //      If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
69 //      face #1 is stored in vertices 3,4,5.
70 void create_all_vertnum_lists(int *num_faces, int *vertnums, int segnum, int sidenum);
71
72 //      Given a side, return the number of faces
73 extern int get_num_faces(side *sidep);
74
75 //returns 3 different bitmasks with info telling if this sphere is in
76 //this segment.  See segmasks structure for info on fields
77 segmasks get_seg_masks(vms_vector *checkp, int segnum, fix rad, char *calling_file, int calling_linenum);
78
79 //this macro returns true if the segnum for an object is correct
80 #define check_obj_seg(obj) (get_seg_masks(&(obj)->pos,(obj)->segnum,0).centermask == 0)
81
82 //Tries to find a segment for a point, in the following way:
83 // 1. Check the given segment
84 // 2. Recursively trace through attached segments
85 // 3. Check all the segmentns
86 //Returns segnum if found, or -1
87 int find_point_seg(vms_vector *p,int segnum);
88
89 //--repair-- // Create data specific to segments which does not need to get written to disk.
90 //--repair-- extern void create_local_segment_data(void);
91
92 //      Sort of makes sure create_local_segment_data has been called for the currently executing mine.
93 //      Returns 1 if Lsegments appears valid, 0 if not.
94 int check_lsegments_validity(void);
95
96 //      ----------------------------------------------------------------------------------------------------------
97 //      Determine whether seg0 and seg1 are reachable using wid_flag to go through walls.
98 //      For example, set to WID_RENDPAST_FLAG to see if sound can get from one segment to the other.
99 //      set to WID_FLY_FLAG to see if a robot could fly from one to the other.
100 //      Search up to a maximum depth of max_depth.
101 //      Return the distance.
102 extern fix find_connected_distance(vms_vector *p0, int seg0, vms_vector *p1, int seg1, int max_depth, int wid_flag);
103
104 //create a matrix that describes the orientation of the given segment
105 extern void extract_orient_from_segment(vms_matrix *m,segment *seg);
106
107 //      In segment.c
108 //      Make a just-modified segment valid.
109 //              check all sides to see how many faces they each should have (0,1,2)
110 //              create new vector normals
111 extern void validate_segment(segment *sp);
112
113 extern void validate_segment_all(void);
114
115 //      Extract the forward vector from segment *sp, return in *vp.
116 //      The forward vector is defined to be the vector from the the center of the front face of the segment
117 // to the center of the back face of the segment.
118 extern  void extract_forward_vector_from_segment(segment *sp,vms_vector *vp);
119
120 //      Extract the right vector from segment *sp, return in *vp.
121 //      The forward vector is defined to be the vector from the the center of the left face of the segment
122 // to the center of the right face of the segment.
123 extern  void extract_right_vector_from_segment(segment *sp,vms_vector *vp);
124
125 //      Extract the up vector from segment *sp, return in *vp.
126 //      The forward vector is defined to be the vector from the the center of the bottom face of the segment
127 // to the center of the top face of the segment.
128 extern  void extract_up_vector_from_segment(segment *sp,vms_vector *vp);
129
130 extern void create_walls_on_side(segment *sp, int sidenum);
131
132 extern void pick_random_point_in_seg(vms_vector *new_pos, int segnum);
133
134 #endif
135
136