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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Include file for functions which need to access segment data structure.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-12-22 04:35:49 +00:00
|
|
|
#pragma once
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-07-20 01:09:55 +00:00
|
|
|
#include <physfs.h>
|
2017-06-25 20:46:03 +00:00
|
|
|
#include <type_traits>
|
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"
|
2013-11-17 00:17:58 +00:00
|
|
|
#include "dxxsconf.h"
|
2016-03-19 19:08:10 +00:00
|
|
|
#include "dsx-ns.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
2014-07-20 01:09:55 +00:00
|
|
|
#include <cassert>
|
2013-12-26 22:21:16 +00:00
|
|
|
#include <cstdint>
|
2013-11-17 00:17:58 +00:00
|
|
|
#include <stdexcept>
|
2016-12-24 18:12:17 +00:00
|
|
|
#include "fwd-segment.h"
|
2013-12-11 23:59:36 +00:00
|
|
|
#include "countarray.h"
|
2014-10-02 03:02:34 +00:00
|
|
|
#include "valptridx.h"
|
2013-12-29 04:28:07 +00:00
|
|
|
#include "objnum.h"
|
2014-10-04 17:33:25 +00:00
|
|
|
#include "pack.h"
|
2012-11-11 22:12:51 +00:00
|
|
|
|
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 {
|
2006-03-20 17:12:09 +00:00
|
|
|
// Returns true if segnum references a child, else returns false.
|
|
|
|
// Note that -1 means no connection, -2 means a connection to the outside world.
|
2014-06-07 17:46:32 +00:00
|
|
|
static inline bool IS_CHILD(segnum_t s)
|
|
|
|
{
|
|
|
|
return s != segment_none && s != segment_exit;
|
|
|
|
}
|
2015-12-22 04:18:50 +00:00
|
|
|
}
|
2015-11-26 02:56:55 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-22 04:18:50 +00:00
|
|
|
namespace dcx {
|
|
|
|
|
2022-01-09 15:25:42 +00:00
|
|
|
static constexpr sidenum_t &operator++(sidenum_t &a)
|
|
|
|
{
|
|
|
|
return a = static_cast<sidenum_t>(static_cast<unsigned>(a) + 1);
|
|
|
|
}
|
|
|
|
|
2022-01-15 20:39:10 +00:00
|
|
|
static constexpr side_relative_vertnum &operator++(side_relative_vertnum &a)
|
|
|
|
{
|
|
|
|
return a = static_cast<side_relative_vertnum>(static_cast<uint8_t>(a) + 1);
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//Structure for storing u,v,light values.
|
|
|
|
//NOTE: this structure should be the same as the one in 3d.h
|
2013-12-22 22:03:07 +00:00
|
|
|
struct uvl
|
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
fix u, v, l;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2020-07-16 02:31:04 +00:00
|
|
|
enum class side_type : uint8_t
|
2014-09-06 22:36:58 +00:00
|
|
|
{
|
2020-07-16 02:31:04 +00:00
|
|
|
quad = 1, // render side as quadrilateral
|
|
|
|
tri_02 = 2, // render side as two triangles, triangulated along edge from 0 to 2
|
|
|
|
tri_13 = 3, // render side as two triangles, triangulated along edge from 1 to 3
|
2014-09-06 22:36:58 +00:00
|
|
|
};
|
|
|
|
|
2022-01-15 20:39:10 +00:00
|
|
|
enum class side_relative_vertnum : uint8_t
|
|
|
|
{
|
|
|
|
_0,
|
|
|
|
_1,
|
|
|
|
_2,
|
|
|
|
_3,
|
|
|
|
};
|
|
|
|
|
2022-01-09 15:25:42 +00:00
|
|
|
enum class segment_relative_vertnum : uint8_t
|
|
|
|
{
|
|
|
|
_0,
|
|
|
|
_1,
|
|
|
|
_2,
|
|
|
|
_3,
|
|
|
|
_4,
|
|
|
|
_5,
|
|
|
|
_6,
|
|
|
|
_7,
|
|
|
|
};
|
|
|
|
|
2021-11-01 03:37:19 +00:00
|
|
|
enum class segment_special : uint8_t
|
|
|
|
{
|
|
|
|
nothing,
|
|
|
|
fuelcen,
|
|
|
|
repaircen,
|
|
|
|
controlcen,
|
|
|
|
robotmaker,
|
|
|
|
goal_blue,
|
|
|
|
goal_red,
|
2014-10-04 17:30:18 +00:00
|
|
|
};
|
|
|
|
|
2021-11-01 03:37:20 +00:00
|
|
|
enum class materialization_center_number : uint8_t
|
|
|
|
{
|
|
|
|
None = 0xff,
|
|
|
|
};
|
|
|
|
|
2021-11-01 03:37:20 +00:00
|
|
|
enum class station_number : uint8_t
|
|
|
|
{
|
|
|
|
None = 0xff,
|
|
|
|
};
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
struct shared_side
|
2013-12-22 22:03:07 +00:00
|
|
|
{
|
2014-10-05 20:59:54 +00:00
|
|
|
struct illegal_type;
|
2014-09-06 22:36:58 +00:00
|
|
|
side_type m_type; // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
|
|
|
|
const side_type &get_type() const { return m_type; }
|
|
|
|
void set_type(side_type t) { m_type = t; }
|
2014-10-04 17:30:18 +00:00
|
|
|
wallnum_t wall_num;
|
2020-05-02 21:18:42 +00:00
|
|
|
std::array<vms_vector, 2> normals; // 2 normals, if quadrilateral, both the same.
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2022-02-19 14:52:17 +00:00
|
|
|
enum class sidemask_t : uint8_t
|
|
|
|
{
|
|
|
|
left = 1u << static_cast<uint8_t>(sidenum_t::WLEFT),
|
|
|
|
top = 1u << static_cast<uint8_t>(sidenum_t::WTOP),
|
|
|
|
right = 1u << static_cast<uint8_t>(sidenum_t::WRIGHT),
|
|
|
|
bottom = 1u << static_cast<uint8_t>(sidenum_t::WBOTTOM),
|
|
|
|
back = 1u << static_cast<uint8_t>(sidenum_t::WBACK),
|
|
|
|
front = 1u << static_cast<uint8_t>(sidenum_t::WFRONT),
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr uint8_t operator&(const sidemask_t a, const sidemask_t b)
|
|
|
|
{
|
|
|
|
return static_cast<uint8_t>(a) & static_cast<uint8_t>(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr sidemask_t &operator|=(sidemask_t &a, const sidemask_t b)
|
|
|
|
{
|
|
|
|
return a = static_cast<sidemask_t>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr sidemask_t build_sidemask(const sidenum_t s)
|
|
|
|
{
|
|
|
|
return static_cast<sidemask_t>(1u << static_cast<uint8_t>(s));
|
|
|
|
}
|
|
|
|
|
2020-09-11 03:08:02 +00:00
|
|
|
enum class texture1_value : uint16_t
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
};
|
|
|
|
|
2020-08-24 01:31:28 +00:00
|
|
|
/* texture2_value uses the low 14 bits for the array index and the high
|
|
|
|
* 2 bits for texture2_rotation_high
|
|
|
|
*/
|
|
|
|
enum class texture2_value : uint16_t
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class texture2_rotation_low : uint8_t
|
|
|
|
{
|
|
|
|
Normal = 0,
|
|
|
|
_1 = 1,
|
|
|
|
_2 = 2,
|
|
|
|
_3 = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TEXTURE2_ROTATION_SHIFT 14u
|
|
|
|
#define TEXTURE2_ROTATION_INDEX_MASK ((1u << TEXTURE2_ROTATION_SHIFT) - 1u)
|
|
|
|
|
|
|
|
enum class texture2_rotation_high : uint16_t
|
|
|
|
{
|
|
|
|
Normal = 0,
|
|
|
|
_1 = static_cast<uint16_t>(texture2_rotation_low::_1) << TEXTURE2_ROTATION_SHIFT,
|
|
|
|
_2 = static_cast<uint16_t>(texture2_rotation_low::_2) << TEXTURE2_ROTATION_SHIFT,
|
|
|
|
_3 = static_cast<uint16_t>(texture2_rotation_low::_3) << TEXTURE2_ROTATION_SHIFT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr texture2_rotation_high &operator++(texture2_rotation_high &t)
|
|
|
|
{
|
|
|
|
/* Cast to uint32, step to the next value, cast back. The cast back
|
|
|
|
* will truncate to the low 16 bits, causing
|
|
|
|
* texture2_rotation_high::_3 to roll over to
|
|
|
|
* texture2_rotation_high::Normal.
|
|
|
|
*/
|
|
|
|
return (t = static_cast<texture2_rotation_high>(static_cast<uint32_t>(t) + (1u << TEXTURE2_ROTATION_SHIFT)));
|
|
|
|
}
|
|
|
|
|
2020-09-11 03:08:02 +00:00
|
|
|
static constexpr texture_index get_texture_index(const texture1_value t)
|
|
|
|
{
|
|
|
|
return static_cast<texture_index>(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr texture_index get_texture_index(const texture2_value t)
|
2020-08-24 01:31:28 +00:00
|
|
|
{
|
2020-09-11 03:08:02 +00:00
|
|
|
return static_cast<texture_index>(static_cast<uint16_t>(t) & TEXTURE2_ROTATION_INDEX_MASK);
|
2020-08-24 01:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr texture2_rotation_high get_texture_rotation_high(const texture2_value t)
|
|
|
|
{
|
|
|
|
return static_cast<texture2_rotation_high>(static_cast<uint16_t>(t) & ~TEXTURE2_ROTATION_INDEX_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr texture2_rotation_low get_texture_rotation_low(const texture2_rotation_high t)
|
|
|
|
{
|
|
|
|
return static_cast<texture2_rotation_low>(static_cast<uint16_t>(t) >> TEXTURE2_ROTATION_SHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr texture2_rotation_low get_texture_rotation_low(const texture2_value t)
|
|
|
|
{
|
|
|
|
return get_texture_rotation_low(get_texture_rotation_high(t));
|
|
|
|
}
|
|
|
|
|
2020-09-11 03:08:02 +00:00
|
|
|
static constexpr texture1_value build_texture1_value(const texture_index t)
|
|
|
|
{
|
|
|
|
return static_cast<texture1_value>(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr texture2_value build_texture2_value(const texture_index t, const texture2_rotation_high rotation)
|
2020-08-24 01:31:28 +00:00
|
|
|
{
|
2020-09-11 03:08:02 +00:00
|
|
|
return static_cast<texture2_value>(static_cast<uint16_t>(t) | static_cast<uint16_t>(rotation));
|
2020-08-24 01:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef TEXTURE2_ROTATION_SHIFT
|
|
|
|
#undef TEXTURE2_ROTATION_INDEX_MASK
|
|
|
|
|
2022-01-15 20:39:10 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
static constexpr side_relative_vertnum next_side_vertex(const side_relative_vertnum a, unsigned add = 1)
|
|
|
|
{
|
|
|
|
return static_cast<side_relative_vertnum>((static_cast<uint8_t>(a) + add) & 3);
|
|
|
|
}
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
struct unique_side
|
|
|
|
{
|
2020-09-11 03:08:02 +00:00
|
|
|
texture1_value tmap_num;
|
2020-08-24 01:31:28 +00:00
|
|
|
texture2_value tmap_num2;
|
2022-01-15 20:39:10 +00:00
|
|
|
enumerated_array<uvl, 4, side_relative_vertnum> uvls;
|
2018-06-24 05:06:15 +00:00
|
|
|
};
|
|
|
|
|
2016-01-09 16:38:15 +00:00
|
|
|
#ifdef dsx
|
2018-06-24 05:06:14 +00:00
|
|
|
struct shared_segment
|
|
|
|
{
|
2016-09-11 18:49:16 +00:00
|
|
|
#if DXX_USE_EDITOR
|
2013-12-29 04:28:07 +00:00
|
|
|
segnum_t segnum; // segment number, not sure what it means
|
2013-03-16 02:54:33 +00:00
|
|
|
short group; // group number to which the segment belongs.
|
2006-03-20 17:12:09 +00:00
|
|
|
#endif
|
2022-01-15 20:39:10 +00:00
|
|
|
enumerated_array<segnum_t, MAX_SIDES_PER_SEGMENT, sidenum_t> children; // indices of 6 children segments, front, left, top, right, bottom, back
|
2022-01-09 15:25:42 +00:00
|
|
|
enumerated_array<vertnum_t, MAX_VERTICES_PER_SEGMENT, segment_relative_vertnum> verts; // vertex ids of 4 front and 4 back vertices
|
2021-11-01 03:37:19 +00:00
|
|
|
segment_special special; // what type of center this is
|
2021-11-01 03:37:20 +00:00
|
|
|
materialization_center_number matcen_num; // which center segment is associated with.
|
2021-11-01 03:37:20 +00:00
|
|
|
station_number station_idx;
|
2017-07-26 03:15:58 +00:00
|
|
|
/* if DXX_BUILD_DESCENT_II */
|
|
|
|
uint8_t s2_flags;
|
|
|
|
/* endif */
|
2022-01-15 20:39:10 +00:00
|
|
|
enumerated_array<shared_side, MAX_SIDES_PER_SEGMENT, sidenum_t> sides;
|
2013-03-16 02:54:33 +00:00
|
|
|
};
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2018-06-24 05:06:14 +00:00
|
|
|
struct unique_segment
|
|
|
|
{
|
|
|
|
objnum_t objects; // pointer to objects in this segment
|
|
|
|
// If bit n (1 << n) is set, then side #n in segment has had light subtracted from original (editor-computed) value.
|
|
|
|
uint8_t light_subtracted;
|
|
|
|
/* if DXX_BUILD_DESCENT_II */
|
2022-02-19 14:52:17 +00:00
|
|
|
sidemask_t slide_textures;
|
2018-06-24 05:06:14 +00:00
|
|
|
/* endif */
|
|
|
|
fix static_light;
|
2022-01-15 20:39:10 +00:00
|
|
|
enumerated_array<unique_side, MAX_SIDES_PER_SEGMENT, sidenum_t> sides;
|
2018-06-24 05:06:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct segment : unique_segment, shared_segment
|
|
|
|
{
|
|
|
|
};
|
2019-12-22 05:34:08 +00:00
|
|
|
|
|
|
|
template <typename S, typename U>
|
|
|
|
struct susegment
|
|
|
|
{
|
|
|
|
using qualified_segment = typename std::conditional<std::is_const<S>::value && std::is_const<U>::value, const segment, segment>::type;
|
|
|
|
S &s;
|
|
|
|
U &u;
|
|
|
|
constexpr susegment(qualified_segment &b) :
|
|
|
|
s(b), u(b)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
constexpr susegment(const susegment &) = default;
|
|
|
|
constexpr susegment(susegment &&) = default;
|
|
|
|
template <typename S2, typename U2, typename std::enable_if<std::is_convertible<S2 &, S &>::value && std::is_convertible<U2 &, U &>::value, int>::type = 0>
|
|
|
|
constexpr susegment(const susegment<S2, U2> &r) :
|
|
|
|
s(r.s), u(r.u)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
template <typename T, typename std::enable_if<std::is_convertible<T &&, qualified_segment &>::value, int>::type = 0>
|
|
|
|
constexpr susegment(T &&t) :
|
|
|
|
susegment(static_cast<qualified_segment &>(t))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
operator S &() const
|
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
operator U &() const
|
|
|
|
{
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
};
|
2015-07-18 21:01:55 +00:00
|
|
|
#endif
|
2013-03-16 02:54:33 +00:00
|
|
|
|
2014-10-02 03:02:34 +00:00
|
|
|
struct count_segment_array_t : public count_array_t<segnum_t, MAX_SEGMENTS> {};
|
2013-12-11 23:59:36 +00:00
|
|
|
|
2013-12-11 23:59:36 +00:00
|
|
|
struct group
|
|
|
|
{
|
2013-12-11 23:59:36 +00:00
|
|
|
struct segment_array_type_t : public count_segment_array_t {};
|
2020-12-26 21:17:29 +00:00
|
|
|
struct vertex_array_type_t : public count_array_t<vertnum_t, MAX_VERTICES> {};
|
2013-12-11 23:59:36 +00:00
|
|
|
segment_array_type_t segments;
|
|
|
|
vertex_array_type_t vertices;
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
segments.clear();
|
|
|
|
vertices.clear();
|
|
|
|
}
|
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2016-01-09 16:38:15 +00:00
|
|
|
#ifdef dsx
|
2016-01-09 16:38:14 +00:00
|
|
|
#define Highest_segment_index (Segments.get_count() - 1)
|
2017-06-10 03:31:03 +00:00
|
|
|
DXX_VALPTRIDX_DEFINE_GLOBAL_FACTORIES(segment, seg, Segments);
|
2015-07-18 21:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// Globals from mglobal.c
|
2014-10-02 03:02:34 +00:00
|
|
|
struct vertex : vms_vector
|
|
|
|
{
|
|
|
|
vertex() = default;
|
|
|
|
vertex(const fix &a, const fix &b, const fix &c) :
|
2015-12-05 22:57:25 +00:00
|
|
|
vms_vector{a, b, c}
|
2014-10-02 03:02:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
explicit vertex(const vms_vector &v) :
|
|
|
|
vms_vector(v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2020-12-26 21:17:29 +00:00
|
|
|
|
|
|
|
static constexpr vertnum_t operator++(vertnum_t &v)
|
|
|
|
{
|
|
|
|
return (v = static_cast<vertnum_t>(static_cast<unsigned>(v) + 1));
|
|
|
|
}
|
2022-01-09 15:25:42 +00:00
|
|
|
|
2015-12-05 22:57:25 +00:00
|
|
|
}
|
|
|
|
|
2016-01-09 16:38:15 +00:00
|
|
|
#ifdef dsx
|
2018-06-24 05:06:15 +00:00
|
|
|
struct shared_side::illegal_type : std::runtime_error
|
2014-10-05 20:59:54 +00:00
|
|
|
{
|
2018-06-24 05:06:14 +00:00
|
|
|
const shared_segment *const m_segment;
|
2018-06-24 05:06:15 +00:00
|
|
|
const shared_side *const m_side;
|
|
|
|
illegal_type(const shared_segment &seg, const shared_side &s) :
|
2014-10-05 20:59:54 +00:00
|
|
|
runtime_error("illegal side type"),
|
2018-06-24 05:06:14 +00:00
|
|
|
m_segment(&seg), m_side(&s)
|
2014-10-05 20:59:54 +00:00
|
|
|
{
|
|
|
|
}
|
2018-06-24 05:06:15 +00:00
|
|
|
illegal_type(const shared_side &s) :
|
2014-10-05 20:59:54 +00:00
|
|
|
runtime_error("illegal side type"),
|
2018-06-24 05:06:14 +00:00
|
|
|
m_segment(nullptr), m_side(&s)
|
2014-10-05 20:59:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dsx {
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
// New stuff, 10/14/95: For shooting out lights and monitors.
|
|
|
|
// Light cast upon vert_light vertices in segnum:sidenum by some light
|
2015-02-28 19:36:01 +00:00
|
|
|
struct delta_light : prohibit_void_ptr<delta_light>
|
|
|
|
{
|
2013-12-29 04:28:07 +00:00
|
|
|
segnum_t segnum;
|
2022-01-15 20:39:10 +00:00
|
|
|
sidenum_t sidenum;
|
2022-01-15 20:39:10 +00:00
|
|
|
enumerated_array<uint8_t, 4, side_relative_vertnum> vert_light;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Light at segnum:sidenum casts light on count sides beginning at index (in array Delta_lights)
|
2013-12-22 22:03:07 +00:00
|
|
|
struct dl_index {
|
2013-12-29 04:28:07 +00:00
|
|
|
segnum_t segnum;
|
2016-12-24 22:44:08 +00:00
|
|
|
uint8_t sidenum;
|
2014-11-23 04:36:59 +00:00
|
|
|
uint8_t count;
|
|
|
|
uint16_t index;
|
2017-01-15 00:03:14 +00:00
|
|
|
bool operator<(const dl_index &rhs) const
|
|
|
|
{
|
|
|
|
if (segnum < rhs.segnum)
|
|
|
|
return true;
|
|
|
|
if (segnum > rhs.segnum)
|
|
|
|
return false;
|
|
|
|
return sidenum < rhs.sidenum;
|
|
|
|
}
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2018-06-06 04:53:45 +00:00
|
|
|
|
2018-12-30 00:43:58 +00:00
|
|
|
struct d_level_shared_destructible_light_state
|
|
|
|
{
|
|
|
|
valptridx<dl_index>::array_managed_type Dl_indices;
|
2018-12-30 00:43:58 +00:00
|
|
|
d_delta_light_array Delta_lights;
|
2018-12-30 00:43:58 +00:00
|
|
|
};
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2015-12-05 22:57:25 +00:00
|
|
|
|
|
|
|
}
|
2015-11-26 02:56:55 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2018-12-13 02:31:38 +00:00
|
|
|
#ifdef dsx
|
2018-12-30 00:43:57 +00:00
|
|
|
struct d_level_shared_vertex_state
|
|
|
|
{
|
2020-12-26 21:17:29 +00:00
|
|
|
#if DXX_USE_EDITOR
|
|
|
|
/* Number of elements in Vertex_active which have a nonzero value.
|
|
|
|
* This can be less than the index of the highest defined vertex if
|
|
|
|
* there are unused vertices.
|
|
|
|
*/
|
2018-12-30 00:43:57 +00:00
|
|
|
unsigned Num_vertices;
|
2020-12-26 21:17:29 +00:00
|
|
|
#endif
|
2018-12-30 00:43:57 +00:00
|
|
|
private:
|
|
|
|
vertex_array Vertices;
|
2018-12-30 00:43:57 +00:00
|
|
|
#if DXX_USE_EDITOR
|
2020-12-26 21:17:29 +00:00
|
|
|
enumerated_array<uint8_t, MAX_VERTICES, vertnum_t> Vertex_active; // !0 means vertex is in use, 0 means not in use.
|
2018-12-30 00:43:57 +00:00
|
|
|
#endif
|
2018-12-30 00:43:57 +00:00
|
|
|
public:
|
|
|
|
auto &get_vertices()
|
|
|
|
{
|
|
|
|
return Vertices;
|
|
|
|
}
|
|
|
|
const auto &get_vertices() const
|
|
|
|
{
|
|
|
|
return Vertices;
|
|
|
|
}
|
2018-12-30 00:43:57 +00:00
|
|
|
#if DXX_USE_EDITOR
|
|
|
|
auto &get_vertex_active()
|
|
|
|
{
|
|
|
|
return Vertex_active;
|
|
|
|
}
|
|
|
|
const auto &get_vertex_active() const
|
|
|
|
{
|
|
|
|
return Vertex_active;
|
|
|
|
}
|
|
|
|
#endif
|
2018-12-30 00:43:57 +00:00
|
|
|
};
|
|
|
|
|
2018-09-19 02:13:29 +00:00
|
|
|
struct d_level_shared_segment_state
|
|
|
|
{
|
|
|
|
unsigned Num_segments;
|
2020-05-17 23:35:25 +00:00
|
|
|
d_level_shared_vertex_state LevelSharedVertexState;
|
2018-09-19 02:13:29 +00:00
|
|
|
auto &get_segments()
|
|
|
|
{
|
|
|
|
return Segments;
|
|
|
|
}
|
|
|
|
const auto &get_segments() const
|
|
|
|
{
|
|
|
|
return Segments;
|
|
|
|
}
|
2018-12-30 00:43:57 +00:00
|
|
|
auto &get_vertex_state()
|
2018-09-19 02:13:30 +00:00
|
|
|
{
|
2018-12-30 00:43:57 +00:00
|
|
|
return LevelSharedVertexState;
|
2018-09-19 02:13:30 +00:00
|
|
|
}
|
2018-12-30 00:43:57 +00:00
|
|
|
const auto &get_vertex_state() const
|
2018-09-19 02:13:30 +00:00
|
|
|
{
|
2018-12-30 00:43:57 +00:00
|
|
|
return LevelSharedVertexState;
|
2018-09-19 02:13:30 +00:00
|
|
|
}
|
2018-09-19 02:13:29 +00:00
|
|
|
};
|
|
|
|
|
2019-08-06 02:59:40 +00:00
|
|
|
struct d_level_unique_automap_state
|
|
|
|
{
|
2022-01-15 20:39:10 +00:00
|
|
|
enumerated_array<uint8_t, MAX_SEGMENTS, segnum_t> Automap_visited;
|
2019-08-06 02:59:40 +00:00
|
|
|
};
|
|
|
|
|
2018-09-19 02:13:30 +00:00
|
|
|
struct d_level_unique_segment_state
|
|
|
|
{
|
|
|
|
auto &get_segments()
|
|
|
|
{
|
|
|
|
return Segments;
|
|
|
|
}
|
|
|
|
const auto &get_segments() const
|
|
|
|
{
|
|
|
|
return Segments;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-06 02:59:40 +00:00
|
|
|
extern d_level_unique_automap_state LevelUniqueAutomapState;
|
2018-09-19 02:13:30 +00:00
|
|
|
extern d_level_unique_segment_state LevelUniqueSegmentState;
|
2018-12-13 02:31:38 +00:00
|
|
|
#endif
|
2018-09-19 02:13:29 +00:00
|
|
|
|
2018-04-09 00:58:28 +00:00
|
|
|
template <unsigned bits>
|
|
|
|
class visited_segment_mask_base
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
|
|
|
static_assert(bits == 1 || bits == 2 || bits == 4, "bits must align in bytes");
|
|
|
|
protected:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
divisor = 8 / bits,
|
|
|
|
};
|
2020-05-02 21:18:42 +00:00
|
|
|
using array_t = std::array<uint8_t, (MAX_SEGMENTS + (divisor - 1)) / divisor>;
|
2013-11-17 00:17:58 +00:00
|
|
|
typedef typename array_t::size_type size_type;
|
|
|
|
array_t a;
|
2018-04-09 00:58:28 +00:00
|
|
|
struct maskproxy_shift_count_type
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
using bitmask_low_aligned = std::integral_constant<unsigned, (1 << bits) - 1>;
|
|
|
|
const unsigned m_shift;
|
2012-12-02 18:57:09 +00:00
|
|
|
unsigned shift() const
|
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
return m_shift;
|
2012-12-02 18:57:09 +00:00
|
|
|
}
|
2013-11-17 00:17:58 +00:00
|
|
|
typename array_t::value_type mask() const
|
|
|
|
{
|
2012-12-02 18:57:09 +00:00
|
|
|
return bitmask_low_aligned() << shift();
|
2013-11-17 00:17:58 +00:00
|
|
|
}
|
2018-04-09 00:58:28 +00:00
|
|
|
maskproxy_shift_count_type(const unsigned s) :
|
|
|
|
m_shift(s * bits)
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename R>
|
2018-04-09 00:58:28 +00:00
|
|
|
struct maskproxy_byte_reference : public maskproxy_shift_count_type
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
|
|
|
R m_byte;
|
2018-04-09 00:58:28 +00:00
|
|
|
maskproxy_byte_reference(R byte, const unsigned s) :
|
|
|
|
maskproxy_shift_count_type(s), m_byte(byte)
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
|
|
|
}
|
2018-04-09 00:58:28 +00:00
|
|
|
operator uint8_t() const
|
|
|
|
{
|
|
|
|
return (this->m_byte >> this->shift()) & typename maskproxy_shift_count_type::bitmask_low_aligned();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename R>
|
|
|
|
struct maskproxy_assignable_type : maskproxy_byte_reference<R>
|
|
|
|
{
|
2022-01-09 15:25:42 +00:00
|
|
|
using maskproxy_byte_reference<R>::maskproxy_byte_reference;
|
2018-04-09 00:58:28 +00:00
|
|
|
using typename maskproxy_shift_count_type::bitmask_low_aligned;
|
|
|
|
maskproxy_assignable_type &operator=(const uint8_t u)
|
|
|
|
{
|
|
|
|
assert(!(u & ~bitmask_low_aligned()));
|
|
|
|
auto &byte = this->m_byte;
|
|
|
|
byte = (byte & ~this->mask()) | (u << this->shift());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
maskproxy_assignable_type &operator|=(const uint8_t u)
|
|
|
|
{
|
|
|
|
assert(!(u & ~bitmask_low_aligned()));
|
|
|
|
this->m_byte |= (u << this->shift());
|
|
|
|
return *this;
|
|
|
|
}
|
2013-11-17 00:17:58 +00:00
|
|
|
};
|
|
|
|
template <typename R, typename A>
|
2018-04-09 00:58:28 +00:00
|
|
|
static R make_maskproxy(A &a, const size_type segnum)
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
const size_type idx = segnum / divisor;
|
2013-11-17 00:17:58 +00:00
|
|
|
if (idx >= a.size())
|
|
|
|
throw std::out_of_range("index exceeds segment range");
|
2018-04-09 00:58:28 +00:00
|
|
|
const size_type bit = segnum % divisor;
|
2013-11-17 00:17:58 +00:00
|
|
|
return R(a[idx], bit);
|
|
|
|
}
|
|
|
|
public:
|
2018-04-09 00:58:28 +00:00
|
|
|
/* Explicitly invoke the default constructor for `a` so that the
|
|
|
|
* storage is cleared.
|
|
|
|
*/
|
|
|
|
visited_segment_mask_base() :
|
|
|
|
a()
|
2013-12-22 05:27:46 +00:00
|
|
|
{
|
|
|
|
}
|
2013-11-17 00:17:58 +00:00
|
|
|
void clear()
|
|
|
|
{
|
2015-09-29 02:41:22 +00:00
|
|
|
a = {};
|
2013-11-17 00:17:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-09 00:58:28 +00:00
|
|
|
template <>
|
|
|
|
template <typename R>
|
|
|
|
struct visited_segment_mask_base<1>::maskproxy_assignable_type : maskproxy_byte_reference<R>
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
2022-01-09 15:25:42 +00:00
|
|
|
using maskproxy_byte_reference<R>::maskproxy_byte_reference;
|
2018-04-09 00:58:28 +00:00
|
|
|
maskproxy_assignable_type &operator=(const bool b)
|
2013-11-17 00:17:58 +00:00
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
const auto m = this->mask();
|
|
|
|
auto &byte = this->m_byte;
|
|
|
|
if (b)
|
|
|
|
byte |= m;
|
|
|
|
else
|
|
|
|
byte &= ~m;
|
|
|
|
return *this;
|
2013-11-17 00:17:58 +00:00
|
|
|
}
|
|
|
|
};
|
2012-12-02 18:57:09 +00:00
|
|
|
|
2018-04-09 00:58:28 +00:00
|
|
|
/* This type must be separate so that its members are defined after the
|
|
|
|
* specialization of maskproxy_assignable_type. If these are defined
|
|
|
|
* inline in visited_segment_mask_base, gcc crashes.
|
|
|
|
* Known bad:
|
|
|
|
* gcc-4.9.4
|
|
|
|
* gcc-5.4.0
|
|
|
|
* gcc-6.4.0
|
|
|
|
* gcc-7.2.0
|
|
|
|
*/
|
2012-12-02 18:57:09 +00:00
|
|
|
template <unsigned bits>
|
2018-04-09 00:58:28 +00:00
|
|
|
class visited_segment_mask_t : visited_segment_mask_base<bits>
|
2012-12-02 18:57:09 +00:00
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
using base_type = visited_segment_mask_base<bits>;
|
2012-12-02 18:57:09 +00:00
|
|
|
public:
|
2018-04-09 00:58:28 +00:00
|
|
|
auto operator[](const typename base_type::size_type segnum)
|
2012-12-02 18:57:09 +00:00
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
return this->template make_maskproxy<typename base_type::template maskproxy_assignable_type<typename base_type::array_t::reference>>(this->a, segnum);
|
2012-12-02 18:57:09 +00:00
|
|
|
}
|
2018-04-09 00:58:28 +00:00
|
|
|
auto operator[](const typename base_type::size_type segnum) const
|
2012-12-02 18:57:09 +00:00
|
|
|
{
|
2018-04-09 00:58:28 +00:00
|
|
|
return this->template make_maskproxy<typename base_type::template maskproxy_assignable_type<typename base_type::array_t::const_reference>>(this->a, segnum);
|
2012-12-02 18:57:09 +00:00
|
|
|
}
|
|
|
|
};
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2018-12-30 00:43:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:27:37 +00:00
|
|
|
#ifdef dsx
|
2018-12-30 00:43:58 +00:00
|
|
|
namespace dsx {
|
|
|
|
|
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
|
|
|
struct d_level_shared_segment_state : ::dcx::d_level_shared_segment_state
|
|
|
|
{
|
|
|
|
d_level_shared_destructible_light_state DestructibleLights;
|
2019-08-06 02:59:41 +00:00
|
|
|
segnum_t Secret_return_segment;
|
2019-08-06 02:59:41 +00:00
|
|
|
vms_matrix Secret_return_orient;
|
2018-12-30 00:43:58 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern d_level_shared_segment_state LevelSharedSegmentState;
|
|
|
|
|
2015-12-05 22:57:25 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
#endif
|
2019-05-04 18:27:37 +00:00
|
|
|
#endif
|