2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Header file for stuff moved from segment.c to gameseg.c.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-10-18 21:01:20 +00:00
|
|
|
#pragma once
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#include "pstypes.h"
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "vecmat.h"
|
|
|
|
#include "segment.h"
|
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
2014-12-14 05:23:00 +00:00
|
|
|
#include <utility>
|
2013-12-15 17:01:40 +00:00
|
|
|
#include "dxxsconf.h"
|
2016-03-19 19:08:10 +00:00
|
|
|
#include "dsx-ns.h"
|
2013-12-21 05:12:38 +00:00
|
|
|
#include "compiler-array.h"
|
2012-11-11 22:12:51 +00:00
|
|
|
|
2015-12-22 04:18:50 +00:00
|
|
|
namespace dcx {
|
2013-12-22 22:03:07 +00:00
|
|
|
struct segmasks
|
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
short facemask; //which faces sphere pokes through (12 bits)
|
|
|
|
sbyte sidemask; //which sides sphere pokes through (6 bits)
|
|
|
|
sbyte centermask; //which sides center point is on back of (6 bits)
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-15 18:32:10 +00:00
|
|
|
struct segment_depth_array_t : public array<ubyte, MAX_SEGMENTS> {};
|
|
|
|
|
2014-09-20 23:47:27 +00:00
|
|
|
extern unsigned Highest_vertex_index; // Highest index in Vertices and Vertex_active, an efficiency hack
|
2015-12-22 04:18:50 +00:00
|
|
|
struct side_vertnum_list_t : array<int, 4> {};
|
|
|
|
|
|
|
|
struct vertex_array_list_t : array<int, 6> {};
|
|
|
|
struct vertex_vertnum_pair
|
|
|
|
{
|
|
|
|
int vertex, vertnum;
|
|
|
|
};
|
|
|
|
using vertex_vertnum_array_list = array<vertex_vertnum_pair, 6>;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2016-01-09 16:38:15 +00:00
|
|
|
#ifdef dsx
|
2015-12-22 04:18:50 +00:00
|
|
|
namespace dsx {
|
|
|
|
extern int Doing_lighting_hack_flag;
|
2014-10-30 03:32:27 +00:00
|
|
|
void compute_center_point_on_side(vms_vector &vp,vcsegptr_t sp,int side);
|
|
|
|
static inline vms_vector compute_center_point_on_side(const vcsegptr_t sp,int side)
|
|
|
|
{
|
|
|
|
vms_vector v;
|
|
|
|
return compute_center_point_on_side(v, sp, side), v;
|
|
|
|
}
|
2014-10-30 03:32:51 +00:00
|
|
|
void compute_segment_center(vms_vector &vp,vcsegptr_t sp);
|
|
|
|
static inline vms_vector compute_segment_center(vcsegptr_t sp)
|
|
|
|
{
|
|
|
|
vms_vector v;
|
|
|
|
compute_segment_center(v, sp);
|
|
|
|
return v;
|
|
|
|
}
|
2014-10-02 03:02:34 +00:00
|
|
|
int_fast32_t find_connect_side(vcsegptridx_t base_seg, vcsegptr_t con_seg) __attribute_warn_unused_result;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Fill in array with four absolute point numbers for a given side
|
2014-11-23 04:58:45 +00:00
|
|
|
void get_side_verts(side_vertnum_list_t &vertlist,vcsegptr_t segnum,int sidenum);
|
2014-12-14 05:23:00 +00:00
|
|
|
static inline side_vertnum_list_t get_side_verts(vcsegptr_t segnum,int sidenum)
|
|
|
|
{
|
|
|
|
side_vertnum_list_t r;
|
|
|
|
return get_side_verts(r, segnum, sidenum), r;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-12-14 05:23:00 +00:00
|
|
|
#ifdef EDITOR
|
2006-03-20 17:12:09 +00:00
|
|
|
// Create all vertex lists (1 or 2) for faces on a side.
|
|
|
|
// Sets:
|
|
|
|
// num_faces number of lists
|
|
|
|
// vertices vertices in all (1 or 2) faces
|
|
|
|
// If there is one face, it has 4 vertices.
|
|
|
|
// If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
|
|
|
|
// face #1 is stored in vertices 3,4,5.
|
|
|
|
// Note: these are not absolute vertex numbers, but are relative to the segment
|
|
|
|
// Note: for triagulated sides, the middle vertex of each trianle is the one NOT
|
|
|
|
// adjacent on the diagonal edge
|
2015-10-18 21:01:20 +00:00
|
|
|
uint_fast32_t create_all_vertex_lists(vertex_array_list_t &vertices, vcsegptr_t segnum, const side *sidep, uint_fast32_t sidenum);
|
2014-12-14 05:23:00 +00:00
|
|
|
__attribute_warn_unused_result
|
2015-10-18 21:01:20 +00:00
|
|
|
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_all_vertex_lists(vcsegptr_t segnum, const side *sidep, uint_fast32_t sidenum)
|
2014-12-14 05:23:00 +00:00
|
|
|
{
|
|
|
|
vertex_array_list_t r;
|
2015-10-18 21:01:20 +00:00
|
|
|
auto n = create_all_vertex_lists(r, segnum, sidep, sidenum);
|
2014-12-14 05:23:00 +00:00
|
|
|
return {n, r};
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//like create_all_vertex_lists(), but generate absolute point numbers
|
2015-10-18 21:01:20 +00:00
|
|
|
uint_fast32_t create_abs_vertex_lists(vertex_array_list_t &vertices, vcsegptr_t segnum, const side *sidep, uint_fast32_t sidenum);
|
|
|
|
|
2014-12-14 05:23:00 +00:00
|
|
|
__attribute_warn_unused_result
|
2015-10-18 21:01:20 +00:00
|
|
|
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_abs_vertex_lists(vcsegptr_t segnum, const side *sidep, uint_fast32_t sidenum)
|
2014-12-14 05:23:00 +00:00
|
|
|
{
|
|
|
|
vertex_array_list_t r;
|
2015-10-18 21:01:20 +00:00
|
|
|
auto n = create_abs_vertex_lists(r, segnum, sidep, sidenum);
|
2014-12-14 05:23:00 +00:00
|
|
|
return {n, r};
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-10-18 21:01:20 +00:00
|
|
|
__attribute_warn_unused_result
|
|
|
|
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_abs_vertex_lists(vcsegptr_t segp, uint_fast32_t sidenum)
|
|
|
|
{
|
|
|
|
return create_abs_vertex_lists(segp, &segp->sides[sidenum], sidenum);
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// -----------------------------------------------------------------------------------
|
|
|
|
// Like create all vertex lists, but returns the vertnums (relative to
|
|
|
|
// the side) for each of the faces that make up the side.
|
|
|
|
// If there is one face, it has 4 vertices.
|
|
|
|
// If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
|
|
|
|
// face #1 is stored in vertices 3,4,5.
|
2015-10-18 21:01:20 +00:00
|
|
|
void create_all_vertnum_lists(vertex_vertnum_array_list &vertnums, vcsegptr_t segnum, const side *const sidep, uint_fast32_t sidenum);
|
2014-12-14 05:23:00 +00:00
|
|
|
__attribute_warn_unused_result
|
2015-10-18 21:01:20 +00:00
|
|
|
static inline vertex_vertnum_array_list create_all_vertnum_lists(vcsegptr_t segnum, const side *const sidep, uint_fast32_t sidenum)
|
2014-12-14 05:23:00 +00:00
|
|
|
{
|
2015-10-18 21:01:20 +00:00
|
|
|
vertex_vertnum_array_list r;
|
|
|
|
return create_all_vertnum_lists(r, segnum, sidep, sidenum), r;
|
2014-12-14 05:23:00 +00:00
|
|
|
}
|
2015-12-22 04:18:50 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-22 04:18:50 +00:00
|
|
|
namespace dcx {
|
2006-03-20 17:12:09 +00:00
|
|
|
// Given a side, return the number of faces
|
2014-10-02 03:02:34 +00:00
|
|
|
int get_num_faces(const side *sidep);
|
2015-12-22 04:18:50 +00:00
|
|
|
struct WALL_IS_DOORWAY_mask_t;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-22 04:18:50 +00:00
|
|
|
namespace dsx {
|
2006-03-20 17:12:09 +00:00
|
|
|
//returns 3 different bitmasks with info telling if this sphere is in
|
|
|
|
//this segment. See segmasks structure for info on fields
|
2015-07-12 01:04:17 +00:00
|
|
|
segmasks get_seg_masks(const vms_vector &checkp, vcsegptr_t segnum, fix rad);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//this macro returns true if the segnum for an object is correct
|
2015-07-12 01:04:17 +00:00
|
|
|
#define check_obj_seg(obj) (get_seg_masks((obj)->pos, vcsegptr((obj)->segnum), 0).centermask == 0)
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//Tries to find a segment for a point, in the following way:
|
|
|
|
// 1. Check the given segment
|
|
|
|
// 2. Recursively trace through attached segments
|
|
|
|
// 3. Check all the segmentns
|
|
|
|
//Returns segnum if found, or -1
|
2014-10-02 03:02:34 +00:00
|
|
|
segptridx_t find_point_seg(const vms_vector &p,segptridx_t segnum);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------------------
|
|
|
|
// Determine whether seg0 and seg1 are reachable using wid_flag to go through walls.
|
|
|
|
// For example, set to WID_RENDPAST_FLAG to see if sound can get from one segment to the other.
|
|
|
|
// set to WID_FLY_FLAG to see if a robot could fly from one to the other.
|
|
|
|
// Search up to a maximum depth of max_depth.
|
|
|
|
// Return the distance.
|
2015-03-12 02:21:19 +00:00
|
|
|
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);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//create a matrix that describes the orientation of the given segment
|
2014-10-02 03:02:34 +00:00
|
|
|
void extract_orient_from_segment(vms_matrix *m,vcsegptr_t seg);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// In segment.c
|
|
|
|
// Make a just-modified segment valid.
|
|
|
|
// check all sides to see how many faces they each should have (0,1,2)
|
|
|
|
// create new vector normals
|
2014-10-02 03:02:34 +00:00
|
|
|
void validate_segment(vsegptridx_t sp);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
extern void validate_segment_all(void);
|
|
|
|
|
|
|
|
// Extract the forward vector from segment *sp, return in *vp.
|
|
|
|
// The forward vector is defined to be the vector from the the center of the front face of the segment
|
|
|
|
// to the center of the back face of the segment.
|
2014-10-02 03:02:34 +00:00
|
|
|
void extract_forward_vector_from_segment(vcsegptr_t sp,vms_vector &vp);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Extract the right vector from segment *sp, return in *vp.
|
|
|
|
// The forward vector is defined to be the vector from the the center of the left face of the segment
|
|
|
|
// to the center of the right face of the segment.
|
2014-10-02 03:02:34 +00:00
|
|
|
void extract_right_vector_from_segment(vcsegptr_t sp,vms_vector &vp);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Extract the up vector from segment *sp, return in *vp.
|
|
|
|
// The forward vector is defined to be the vector from the the center of the bottom face of the segment
|
|
|
|
// to the center of the top face of the segment.
|
2014-10-02 03:02:34 +00:00
|
|
|
void extract_up_vector_from_segment(vcsegptr_t sp,vms_vector &vp);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-02 03:02:34 +00:00
|
|
|
void create_walls_on_side(vsegptridx_t sp, int sidenum);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-30 03:32:38 +00:00
|
|
|
void pick_random_point_in_seg(vms_vector &new_pos, vcsegptr_t sp);
|
|
|
|
static inline vms_vector pick_random_point_in_seg(vcsegptr_t sp)
|
|
|
|
{
|
|
|
|
vms_vector v;
|
|
|
|
return pick_random_point_in_seg(v, sp), v;
|
|
|
|
}
|
|
|
|
|
2014-10-02 03:02:34 +00:00
|
|
|
void validate_segment_side(vsegptridx_t sp, int sidenum);
|
2012-11-11 00:14:30 +00:00
|
|
|
int check_segment_connections(void);
|
|
|
|
void flush_fcd_cache(void);
|
2013-12-15 18:32:10 +00:00
|
|
|
unsigned set_segment_depths(int start_seg, array<ubyte, MAX_SEGMENTS> *limit, segment_depth_array_t &depths);
|
2015-12-13 18:00:48 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2012-11-11 00:14:30 +00:00
|
|
|
void apply_all_changed_light(void);
|
|
|
|
void set_ambient_sound_flags(void);
|
2015-12-22 04:18:50 +00:00
|
|
|
#endif
|
2015-12-13 18:00:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|