Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * Portions of this file are copyright Rebirth contributors and licensed as
3
 * described in COPYING.txt.
4
 * Portions of this file are copyright Parallax Software and licensed
5
 * according to the Parallax license below.
6
 * See COPYING.txt for license details.
7
 
8
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
10
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
16
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
18
*/
19
 
20
/*
21
 *
22
 * Header file for stuff moved from segment.c to gameseg.c.
23
 *
24
 */
25
 
26
#pragma once
27
 
28
#include "pstypes.h"
29
#include "maths.h"
30
#include "vecmat.h"
31
#include "segment.h"
32
 
33
#ifdef __cplusplus
34
#include <utility>
35
#include "dxxsconf.h"
36
#include "dsx-ns.h"
37
#include <array>
38
 
39
namespace dcx {
40
struct segmasks
41
{
42
   short facemask;     //which faces sphere pokes through (12 bits)
43
   sbyte sidemask;     //which sides sphere pokes through (6 bits)
44
   sbyte centermask;   //which sides center point is on back of (6 bits)
45
};
46
 
47
struct segment_depth_array_t : public std::array<ubyte, MAX_SEGMENTS> {};
48
 
49
struct side_vertnum_list_t : std::array<unsigned, 4> {};
50
 
51
struct vertex_array_list_t : std::array<unsigned, 6> {};
52
struct vertex_vertnum_pair
53
{
54
        unsigned vertex, vertnum;
55
};
56
using vertex_vertnum_array_list = std::array<vertex_vertnum_pair, 6>;
57
 
58
#ifdef dsx
59
__attribute_warn_unused_result
60
uint_fast32_t find_connect_side(vcsegidx_t base_seg, const shared_segment &con_seg);
61
 
62
void compute_center_point_on_side(fvcvertptr &vcvertptr, vms_vector &vp, const shared_segment &sp, unsigned side);
63
static inline vms_vector compute_center_point_on_side(fvcvertptr &vcvertptr, const shared_segment &sp, const unsigned side)
64
{
65
        vms_vector v;
66
        return compute_center_point_on_side(vcvertptr, v, sp, side), v;
67
}
68
void compute_segment_center(fvcvertptr &vcvertptr, vms_vector &vp, const shared_segment &sp);
69
static inline vms_vector compute_segment_center(fvcvertptr &vcvertptr, const shared_segment &sp)
70
{
71
        vms_vector v;
72
        compute_segment_center(vcvertptr, v, sp);
73
        return v;
74
}
75
 
76
// Fill in array with four absolute point numbers for a given side
77
void get_side_verts(side_vertnum_list_t &vertlist, const shared_segment &seg, unsigned sidenum);
78
static inline side_vertnum_list_t get_side_verts(const shared_segment &segnum, const unsigned sidenum)
79
{
80
        side_vertnum_list_t r;
81
        return get_side_verts(r, segnum, sidenum), r;
82
}
83
#endif
84
}
85
 
86
#ifdef dsx
87
namespace dsx {
88
#if defined(DXX_BUILD_DESCENT_II) || DXX_USE_EDITOR
89
extern int      Doing_lighting_hack_flag;
90
#endif
91
 
92
#if DXX_USE_EDITOR
93
//      Create all vertex lists (1 or 2) for faces on a side.
94
//      Sets:
95
//              num_faces               number of lists
96
//              vertices                        vertices in all (1 or 2) faces
97
//      If there is one face, it has 4 vertices.
98
//      If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
99
//      face #1 is stored in vertices 3,4,5.
100
// Note: these are not absolute vertex numbers, but are relative to the segment
101
// Note:  for triagulated sides, the middle vertex of each trianle is the one NOT
102
//   adjacent on the diagonal edge
103
uint_fast32_t create_all_vertex_lists(vertex_array_list_t &vertices, const shared_segment &seg, const shared_side &sidep, uint_fast32_t sidenum);
104
__attribute_warn_unused_result
105
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_all_vertex_lists(const shared_segment &segnum, const shared_side &sidep, const uint_fast32_t sidenum)
106
{
107
        vertex_array_list_t r;
108
        const auto &&n = create_all_vertex_lists(r, segnum, sidep, sidenum);
109
        return {n, r};
110
}
111
#endif
112
 
113
//like create_all_vertex_lists(), but generate absolute point numbers
114
uint_fast32_t create_abs_vertex_lists(vertex_array_list_t &vertices, const shared_segment &segnum, const shared_side &sidep, uint_fast32_t sidenum);
115
 
116
__attribute_warn_unused_result
117
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_abs_vertex_lists(const shared_segment &segnum, const shared_side &sidep, const uint_fast32_t sidenum)
118
{
119
        vertex_array_list_t r;
120
        const auto &&n = create_abs_vertex_lists(r, segnum, sidep, sidenum);
121
        return {n, r};
122
}
123
 
124
__attribute_warn_unused_result
125
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_abs_vertex_lists(const shared_segment &segp, const uint_fast32_t sidenum)
126
{
127
        return create_abs_vertex_lists(segp, segp.sides[sidenum], sidenum);
128
}
129
 
130
// -----------------------------------------------------------------------------------
131
// Like create all vertex lists, but returns the vertnums (relative to
132
// the side) for each of the faces that make up the side.
133
//      If there is one face, it has 4 vertices.
134
//      If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
135
//      face #1 is stored in vertices 3,4,5.
136
void create_all_vertnum_lists(vertex_vertnum_array_list &vertnums, const shared_segment &seg, const shared_side &sidep, uint_fast32_t sidenum);
137
__attribute_warn_unused_result
138
static inline vertex_vertnum_array_list create_all_vertnum_lists(const shared_segment &segnum, const shared_side &sidep, const uint_fast32_t sidenum)
139
{
140
        vertex_vertnum_array_list r;
141
        return create_all_vertnum_lists(r, segnum, sidep, sidenum), r;
142
}
143
}
144
 
145
namespace dcx {
146
//      Given a side, return the number of faces
147
bool get_side_is_quad(const shared_side &sidep);
148
struct WALL_IS_DOORWAY_mask_t;
149
}
150
 
151
namespace dsx {
152
//returns 3 different bitmasks with info telling if this sphere is in
153
//this segment.  See segmasks structure for info on fields
154
segmasks get_seg_masks(fvcvertptr &, const vms_vector &checkp, const shared_segment &segnum, fix rad);
155
 
156
//this macro returns true if the segnum for an object is correct
157
#define check_obj_seg(vcvertptr, obj) (get_seg_masks(vcvertptr, (obj)->pos, vcsegptr((obj)->segnum), 0).centermask == 0)
158
 
159
//Tries to find a segment for a point, in the following way:
160
// 1. Check the given segment
161
// 2. Recursively trace through attached segments
162
// 3. Check all the segmentns
163
//Returns segnum if found, or -1
164
imsegptridx_t find_point_seg(const d_level_shared_segment_state &, d_level_unique_segment_state &, const vms_vector &p, imsegptridx_t segnum);
165
icsegptridx_t find_point_seg(const d_level_shared_segment_state &, const vms_vector &p, icsegptridx_t segnum);
166
 
167
//      ----------------------------------------------------------------------------------------------------------
168
//      Determine whether seg0 and seg1 are reachable using wid_flag to go through walls.
169
//      For example, set to WID_RENDPAST_FLAG to see if sound can get from one segment to the other.
170
//      set to WID_FLY_FLAG to see if a robot could fly from one to the other.
171
//      Search up to a maximum depth of max_depth.
172
//      Return the distance.
173
vm_distance find_connected_distance(const vms_vector &p0, vcsegptridx_t seg0, const vms_vector &p1, vcsegptridx_t seg1, int max_depth, WALL_IS_DOORWAY_mask_t wid_flag);
174
 
175
//create a matrix that describes the orientation of the given segment
176
void extract_orient_from_segment(fvcvertptr &vcvertptr, vms_matrix &m, const shared_segment &seg);
177
 
178
void validate_segment_all(d_level_shared_segment_state &);
179
 
180
#if DXX_USE_EDITOR
181
//      In segment.c
182
//      Make a just-modified segment valid.
183
//              check all sides to see how many faces they each should have (0,1,2)
184
//              create new vector normals
185
void validate_segment(fvcvertptr &vcvertptr, vmsegptridx_t sp);
186
 
187
//      Extract the forward vector from segment *sp, return in *vp.
188
//      The forward vector is defined to be the vector from the the center of the front face of the segment
189
// to the center of the back face of the segment.
190
void extract_forward_vector_from_segment(fvcvertptr &, const shared_segment &sp, vms_vector &vp);
191
 
192
//      Extract the right vector from segment *sp, return in *vp.
193
//      The forward vector is defined to be the vector from the the center of the left face of the segment
194
// to the center of the right face of the segment.
195
void extract_right_vector_from_segment(fvcvertptr &, const shared_segment &sp, vms_vector &vp);
196
 
197
//      Extract the up vector from segment *sp, return in *vp.
198
//      The forward vector is defined to be the vector from the the center of the bottom face of the segment
199
// to the center of the top face of the segment.
200
void extract_up_vector_from_segment(fvcvertptr &, const shared_segment &sp, vms_vector &vp);
201
 
202
void create_walls_on_side(fvcvertptr &, shared_segment &sp, unsigned sidenum);
203
 
204
void validate_segment_side(fvcvertptr &, vmsegptridx_t sp, unsigned sidenum);
205
#endif
206
 
207
void pick_random_point_in_seg(fvcvertptr &vcvertptr, vms_vector &new_pos, const shared_segment &sp);
208
static inline vms_vector pick_random_point_in_seg(fvcvertptr &vcvertptr, const shared_segment &sp)
209
{
210
        vms_vector v;
211
        return pick_random_point_in_seg(vcvertptr, v, sp), v;
212
}
213
 
214
int check_segment_connections(void);
215
unsigned set_segment_depths(vcsegidx_t start_seg, const std::array<uint8_t, MAX_SEGMENTS> *limit, segment_depth_array_t &depths);
216
#if defined(DXX_BUILD_DESCENT_I)
217
static inline void flush_fcd_cache() {}
218
#elif defined(DXX_BUILD_DESCENT_II)
219
void flush_fcd_cache();
220
void apply_all_changed_light(const d_level_shared_destructible_light_state &LevelSharedDestructibleLightState, fvmsegptridx &vmsegptridx);
221
void    set_ambient_sound_flags(void);
222
#endif
223
}
224
#endif
225
 
226
#endif