| 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 <random> |
| 29 |
#include "pstypes.h" |
| 30 |
#include "maths.h" |
| 31 |
#include "vecmat.h" |
| 32 |
#include "segment.h" |
| 33 |
|
| 34 |
#include <utility> |
| 35 |
#include "dxxsconf.h" |
| 36 |
#include "dsx-ns.h" |
| 37 |
#include "d_array.h" |
| 38 |
|
| 39 |
namespace dcx { |
| 40 |
|
| 41 |
struct segmasks |
| 42 |
{ |
| 43 |
short facemask; //which faces sphere pokes through (12 bits) |
| 44 |
sidemask_t sidemask; //which sides sphere pokes through (6 bits) |
| 45 |
sidemask_t centermask; //which sides center point is on back of (6 bits) |
| 46 |
}; |
| 47 |
|
| 48 |
struct segment_depth_array_t : public enumerated_array<uint8_t, MAX_SEGMENTS, segnum_t> |
| 49 |
{ |
| 50 |
}; |
| 51 |
|
| 52 |
struct side_vertnum_list_t : std::array<vertnum_t, 4> {}; |
| 53 |
|
| 54 |
enum class vertex_array_side_type : bool |
| 55 |
{ |
| 56 |
quad, |
| 57 |
triangle, |
| 58 |
}; |
| 59 |
|
| 60 |
#if DXX_BUILD_DESCENT == 2 || DXX_USE_EDITOR |
| 61 |
#define DXX_internal_feature_lighting_hack 1 |
| 62 |
enum class lighting_hack : bool |
| 63 |
{ |
| 64 |
normal, |
| 65 |
ignore_out_of_mine_location, |
| 66 |
}; |
| 67 |
#else |
| 68 |
#define DXX_internal_feature_lighting_hack 0 |
| 69 |
#endif |
| 70 |
|
| 71 |
struct vertnum_array_list_t : std::array<vertnum_t, 6> {}; |
| 72 |
struct vertex_array_list_t : std::array<segment_relative_vertnum, 6> |
| 73 |
{ |
| 74 |
vertex_array_side_type side_type; |
| 75 |
}; |
| 76 |
|
| 77 |
struct vertex_vertnum_pair |
| 78 |
{ |
| 79 |
vertnum_t vertex; |
| 80 |
side_relative_vertnum vertnum; |
| 81 |
}; |
| 82 |
using vertex_vertnum_array_list = std::array<vertex_vertnum_pair, 6>; |
| 83 |
|
| 84 |
struct abs_vertex_list_result |
| 85 |
{ |
| 86 |
vertex_array_side_type num_faces; |
| 87 |
vertnum_array_list_t vertex_list; |
| 88 |
}; |
| 89 |
|
| 90 |
#ifdef DXX_BUILD_DESCENT |
| 91 |
[[nodiscard]] |
| 92 |
sidenum_t find_connect_side(vcsegidx_t base_seg, const shared_segment &con_seg); |
| 93 |
|
| 94 |
[[nodiscard]] |
| 95 |
vms_vector compute_center_point_on_side(fvcvertptr &vcvertptr, const shared_segment &sp, sidenum_t side); |
| 96 |
|
| 97 |
[[nodiscard]] |
| 98 |
vms_vector compute_segment_center(fvcvertptr &vcvertptr, const shared_segment &sp); |
| 99 |
|
| 100 |
// Fill in array with four absolute point numbers for a given side |
| 101 |
side_vertnum_list_t get_side_verts(const shared_segment &segnum, sidenum_t sidenum); |
| 102 |
#endif |
| 103 |
|
| 104 |
enum class wall_is_doorway_mask : uint8_t; |
| 105 |
|
| 106 |
#if DXX_USE_EDITOR |
| 107 |
// Create all vertex lists (1 or 2) for faces on a side. |
| 108 |
// Sets: |
| 109 |
// num_faces number of lists |
| 110 |
// vertices vertices in all (1 or 2) faces |
| 111 |
// If there is one face, it has 4 vertices. |
| 112 |
// If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2, |
| 113 |
// face #1 is stored in vertices 3,4,5. |
| 114 |
// Note: these are not absolute vertex numbers, but are relative to the segment |
| 115 |
// Note: for triangulated sides, the middle vertex of each trianle is the one NOT |
| 116 |
// adjacent on the diagonal edge |
| 117 |
[[nodiscard]] |
| 118 |
vertex_array_list_t create_all_vertex_lists(const shared_segment &segnum, const shared_side &sidep, const sidenum_t sidenum); |
| 119 |
#endif |
| 120 |
|
| 121 |
// ----------------------------------------------------------------------------------- |
| 122 |
// Like create all vertex lists, but returns the vertnums (relative to |
| 123 |
// the side) for each of the faces that make up the side. |
| 124 |
// If there is one face, it has 4 vertices. |
| 125 |
// If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2, |
| 126 |
// face #1 is stored in vertices 3,4,5. |
| 127 |
[[nodiscard]] |
| 128 |
vertex_vertnum_array_list create_all_vertnum_lists(const shared_segment &seg, const shared_side &sidep, sidenum_t sidenum); |
| 129 |
|
| 130 |
//like create_all_vertex_lists(), but generate absolute point numbers |
| 131 |
[[nodiscard]] |
| 132 |
abs_vertex_list_result create_abs_vertex_lists(const shared_segment &segnum, const shared_side &sidep, sidenum_t sidenum); |
| 133 |
|
| 134 |
//create a matrix that describes the orientation of the given segment |
| 135 |
[[nodiscard]] |
| 136 |
vms_matrix extract_orient_from_segment(fvcvertptr &vcvertptr, const shared_segment &seg); |
| 137 |
|
| 138 |
#if DXX_USE_EDITOR |
| 139 |
// Extract the forward vector from segment *sp, return it by value. |
| 140 |
// The forward vector is defined to be the vector from the center of the front face of the segment |
| 141 |
// to the center of the back face of the segment. |
| 142 |
[[nodiscard]] |
| 143 |
vms_vector extract_forward_vector_from_segment(fvcvertptr &, const shared_segment &sp); |
| 144 |
|
| 145 |
// Extract the right vector from segment *sp, return it by value. |
| 146 |
// The forward vector is defined to be the vector from the center of the left face of the segment |
| 147 |
// to the center of the right face of the segment. |
| 148 |
[[nodiscard]] |
| 149 |
vms_vector extract_right_vector_from_segment(fvcvertptr &, const shared_segment &sp); |
| 150 |
|
| 151 |
// Extract the up vector from segment *sp, return it by value. |
| 152 |
// The forward vector is defined to be the vector from the center of the bottom face of the segment |
| 153 |
// to the center of the top face of the segment. |
| 154 |
[[nodiscard]] |
| 155 |
vms_vector extract_up_vector_from_segment(fvcvertptr &, const shared_segment &sp); |
| 156 |
#endif |
| 157 |
|
| 158 |
void validate_segment_all(d_level_shared_segment_state &); |
| 159 |
|
| 160 |
#if DXX_USE_EDITOR |
| 161 |
// In segment.c |
| 162 |
// Make a just-modified segment valid. |
| 163 |
// check all sides to see how many faces they each should have (0,1,2) |
| 164 |
// create new vector normals |
| 165 |
void validate_segment(fvcvertptr &vcvertptr, vmsegptridx_t sp); |
| 166 |
|
| 167 |
void create_walls_on_side(fvcvertptr &, shared_segment &sp, sidenum_t sidenum); |
| 168 |
|
| 169 |
void validate_segment_side(fvcvertptr &, vmsegptridx_t sp, sidenum_t sidenum); |
| 170 |
#endif |
| 171 |
|
| 172 |
[[nodiscard]] |
| 173 |
vms_vector pick_random_point_in_seg(fvcvertptr &vcvertptr, const shared_segment &sp, std::minstd_rand r); |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
#ifdef DXX_BUILD_DESCENT |
| 178 |
namespace dcx { |
| 179 |
// Given a side, return the number of faces |
| 180 |
bool get_side_is_quad(const shared_side &sidep); |
| 181 |
|
| 182 |
//returns 3 different bitmasks with info telling if this sphere is in |
| 183 |
//this segment. See segmasks structure for info on fields |
| 184 |
segmasks get_seg_masks(fvcvertptr &, const vms_vector &checkp, const shared_segment &segnum, fix rad); |
| 185 |
int check_segment_connections(); |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
namespace dsx { |
| 190 |
|
| 191 |
#if DXX_internal_feature_lighting_hack |
| 192 |
extern lighting_hack Doing_lighting_hack_flag; |
| 193 |
#endif |
| 194 |
|
| 195 |
//this macro returns true if the segnum for an object is correct |
| 196 |
#define check_obj_seg(vcvertptr, obj) (get_seg_masks(vcvertptr, (obj)->pos, vcsegptr((obj)->segnum), 0).centermask == 0) |
| 197 |
|
| 198 |
//Tries to find a segment for a point, in the following way: |
| 199 |
// 1. Check the given segment |
| 200 |
// 2. Recursively trace through attached segments |
| 201 |
// 3. Check all the segmentns |
| 202 |
//Returns segnum if found, or -1 |
| 203 |
imsegptridx_t find_point_seg(const d_level_shared_segment_state &, d_level_unique_segment_state &, const vms_vector &p, imsegptridx_t segnum); |
| 204 |
icsegptridx_t find_point_seg(const d_level_shared_segment_state &, const vms_vector &p, icsegptridx_t segnum); |
| 205 |
|
| 206 |
// ---------------------------------------------------------------------------------------------------------- |
| 207 |
// Determine whether seg0 and seg1 are reachable using wid_flag to go through walls. |
| 208 |
// For example, set to WALL_IS_DOORWAY::rendpast to see if sound can get from one segment to the other. |
| 209 |
// set to WALL_IS_DOORWAY::fly to see if a robot could fly from one to the other. |
| 210 |
// Search up to a maximum depth of max_depth. |
| 211 |
// Return the distance. |
| 212 |
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 wid_flag); |
| 213 |
|
| 214 |
#if DXX_BUILD_DESCENT == 1 |
| 215 |
static inline void flush_fcd_cache() {} |
| 216 |
#elif DXX_BUILD_DESCENT == 2 |
| 217 |
void flush_fcd_cache(); |
| 218 |
void apply_all_changed_light(const d_level_shared_destructible_light_state &LevelSharedDestructibleLightState, fvmsegptridx &vmsegptridx); |
| 219 |
void set_ambient_sound_flags(void); |
| 220 |
#endif |
| 221 |
} |
| 222 |
#endif |