2014-12-22 04:35:49 +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.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-12-24 18:12:17 +00:00
|
|
|
#include <type_traits>
|
2014-12-22 04:35:49 +00:00
|
|
|
#include <physfs.h>
|
|
|
|
#include "maths.h"
|
|
|
|
|
|
|
|
#include <cstdint>
|
2016-12-24 18:12:17 +00:00
|
|
|
#include "cpp-valptridx.h"
|
2016-12-24 18:12:17 +00:00
|
|
|
|
|
|
|
namespace dcx {
|
|
|
|
constexpr std::integral_constant<std::size_t, 9000> MAX_SEGMENTS{};
|
|
|
|
using segnum_t = uint16_t;
|
2020-08-28 00:18:45 +00:00
|
|
|
struct d_level_unique_automap_state;
|
2016-12-24 18:12:17 +00:00
|
|
|
}
|
2016-12-24 18:12:17 +00:00
|
|
|
#ifdef dsx
|
2017-07-26 03:15:58 +00:00
|
|
|
namespace dcx {
|
2018-06-24 05:06:14 +00:00
|
|
|
struct shared_segment;
|
|
|
|
struct unique_segment;
|
2016-12-24 18:12:17 +00:00
|
|
|
struct segment;
|
2019-12-22 05:34:08 +00:00
|
|
|
|
|
|
|
template <typename S, typename U>
|
|
|
|
struct susegment;
|
|
|
|
|
|
|
|
using msmusegment = susegment<shared_segment, unique_segment>;
|
|
|
|
using mscusegment = susegment<shared_segment, const unique_segment>; /* unusual, but supported */
|
|
|
|
using csmusegment = susegment<const shared_segment, unique_segment>;
|
|
|
|
using cscusegment = susegment<const shared_segment, const unique_segment>;
|
2016-12-24 18:12:17 +00:00
|
|
|
}
|
2017-08-11 23:43:52 +00:00
|
|
|
DXX_VALPTRIDX_DECLARE_SUBTYPE(dcx::, segment, segnum_t, MAX_SEGMENTS);
|
2016-12-24 18:12:17 +00:00
|
|
|
#endif
|
2016-12-24 18:12:17 +00:00
|
|
|
|
2015-10-09 02:46:11 +00:00
|
|
|
#include "fwd-valptridx.h"
|
2016-03-19 19:08:10 +00:00
|
|
|
#include "dsx-ns.h"
|
2020-05-02 21:18:42 +00:00
|
|
|
#include <array>
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, 8> MAX_VERTICES_PER_SEGMENT{};
|
|
|
|
constexpr std::integral_constant<std::size_t, 6> MAX_SIDES_PER_SEGMENT{};
|
|
|
|
constexpr std::integral_constant<std::size_t, 4> MAX_VERTICES_PER_POLY{};
|
2016-07-16 16:52:04 +00:00
|
|
|
|
|
|
|
constexpr std::size_t MAX_SEGMENTS_ORIGINAL = 900;
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, 4 * MAX_SEGMENTS_ORIGINAL> MAX_SEGMENT_VERTICES_ORIGINAL{};
|
|
|
|
constexpr std::integral_constant<std::size_t, 4 * MAX_SEGMENTS> MAX_SEGMENT_VERTICES{};
|
2020-10-01 03:25:27 +00:00
|
|
|
|
2016-01-09 16:38:15 +00:00
|
|
|
#ifdef dsx
|
2017-06-10 03:31:03 +00:00
|
|
|
DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(segment, seg);
|
2015-08-22 20:43:04 +00:00
|
|
|
|
2015-07-21 02:57:27 +00:00
|
|
|
static constexpr valptridx<segment>::magic_constant<0xfffe> segment_exit{};
|
|
|
|
static constexpr valptridx<segment>::magic_constant<0xffff> segment_none{};
|
|
|
|
static constexpr valptridx<segment>::magic_constant<0> segment_first{};
|
2020-10-01 03:25:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef dsx
|
|
|
|
namespace dsx {
|
2017-06-10 03:31:02 +00:00
|
|
|
void delete_segment_from_group(vmsegptridx_t segment_num, unsigned group_num);
|
2015-12-05 22:57:25 +00:00
|
|
|
}
|
2015-11-26 02:56:55 +00:00
|
|
|
#endif
|
2015-07-21 02:57:27 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2014-12-22 04:35:49 +00:00
|
|
|
|
|
|
|
typedef uint_fast32_t sidenum_fast_t;
|
|
|
|
|
|
|
|
enum sidenum_t : uint8_t
|
|
|
|
{
|
|
|
|
WLEFT = 0,
|
|
|
|
WTOP = 1,
|
|
|
|
WRIGHT = 2,
|
|
|
|
WBOTTOM = 3,
|
|
|
|
WBACK = 4,
|
|
|
|
WFRONT = 5
|
|
|
|
};
|
|
|
|
|
2020-09-11 03:08:02 +00:00
|
|
|
using texture_index = uint16_t;
|
|
|
|
enum class texture1_value : uint16_t;
|
2020-08-24 01:31:28 +00:00
|
|
|
enum class texture2_value : uint16_t;
|
|
|
|
enum class texture2_rotation_low : uint8_t;
|
|
|
|
enum class texture2_rotation_high : uint16_t;
|
|
|
|
|
2014-12-22 04:35:49 +00:00
|
|
|
//normal everyday vertices
|
|
|
|
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<fix, 0> DEFAULT_LIGHTING{}; // (F1_0/2)
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2016-09-11 18:49:16 +00:00
|
|
|
#if DXX_USE_EDITOR //verts for the new segment
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, 8> NUM_NEW_SEG_VERTICES{};
|
|
|
|
constexpr std::integral_constant<unsigned, MAX_SEGMENT_VERTICES> NEW_SEGMENT_VERTICES{};
|
|
|
|
constexpr std::integral_constant<std::size_t, MAX_SEGMENT_VERTICES + NUM_NEW_SEG_VERTICES> MAX_VERTICES{};
|
2014-12-22 04:35:49 +00:00
|
|
|
#else //No editor
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, MAX_SEGMENT_VERTICES> MAX_VERTICES{};
|
2014-12-22 04:35:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct uvl;
|
2020-07-16 02:31:04 +00:00
|
|
|
enum class side_type : uint8_t;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2020-12-26 21:17:29 +00:00
|
|
|
enum class wallnum_t : uint16_t;
|
2018-06-24 05:06:15 +00:00
|
|
|
struct shared_side;
|
|
|
|
struct unique_side;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2017-08-11 23:43:54 +00:00
|
|
|
struct vertex;
|
2020-12-26 21:17:29 +00:00
|
|
|
enum class vertnum_t : uint32_t;
|
2021-11-01 03:37:19 +00:00
|
|
|
enum class segment_special : uint8_t;
|
2015-12-05 22:57:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 23:43:54 +00:00
|
|
|
/* `vertex` has only integer members, so wild reads are unlikely to
|
|
|
|
* cause serious harm. It is read far more than it is written, so
|
|
|
|
* eliminating checking on reads saves substantial code space.
|
|
|
|
*
|
|
|
|
* Vertex indices are only taken from map data, not network data, so
|
|
|
|
* errors are unlikely. Report them tersely to avoid recording the
|
|
|
|
* file+line of every access.
|
|
|
|
*/
|
|
|
|
#define DXX_VALPTRIDX_REPORT_ERROR_STYLE_const_vertex undefined
|
|
|
|
#define DXX_VALPTRIDX_REPORT_ERROR_STYLE_mutable_vertex trap_terse
|
|
|
|
DXX_VALPTRIDX_DECLARE_SUBTYPE(dcx::, vertex, vertnum_t, MAX_VERTICES);
|
|
|
|
|
2014-12-22 04:35:49 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, 5> MAX_CENTER_TYPES{};
|
2014-12-22 04:35:49 +00:00
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2015-09-19 23:04:35 +00:00
|
|
|
typedef unsigned s2f_ambient_t;
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<s2f_ambient_t, 1> S2F_AMBIENT_WATER{};
|
|
|
|
constexpr std::integral_constant<s2f_ambient_t, 2> S2F_AMBIENT_LAVA{};
|
|
|
|
constexpr std::integral_constant<std::size_t, 7> MAX_CENTER_TYPES{};
|
2014-12-22 04:35:49 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2017-08-11 23:43:54 +00:00
|
|
|
DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(vertex, vert);
|
2014-12-22 04:35:49 +00:00
|
|
|
struct count_segment_array_t;
|
|
|
|
struct group;
|
|
|
|
|
2018-12-30 00:43:57 +00:00
|
|
|
struct d_level_shared_vertex_state;
|
2018-09-19 02:13:29 +00:00
|
|
|
struct d_level_shared_segment_state;
|
2018-09-19 02:13:30 +00:00
|
|
|
struct d_level_unique_segment_state;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2021-11-01 03:37:20 +00:00
|
|
|
extern const std::array<std::array<unsigned, 4>, MAX_SIDES_PER_SEGMENT> Side_to_verts; // Side_to_verts[my_side] is list of vertices forming side my_side.
|
2021-11-01 03:37:20 +00:00
|
|
|
extern const std::array<sidenum_t, MAX_SIDES_PER_SEGMENT> Side_opposite; // Side_opposite[my_side] returns side opposite cube from my_side.
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
void segment_side_wall_tmap_write(PHYSFS_File *fp, const shared_side &sside, const unique_side &uside);
|
2015-12-13 18:00:48 +00:00
|
|
|
}
|
2015-09-19 23:04:35 +00:00
|
|
|
void add_segment_to_group(segnum_t segment_num, int group_num);
|
|
|
|
|
2014-12-22 04:35:49 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dsx {
|
2014-12-22 04:35:49 +00:00
|
|
|
struct delta_light;
|
|
|
|
struct dl_index;
|
2018-12-30 00:43:58 +00:00
|
|
|
struct d_level_shared_destructible_light_state;
|
|
|
|
struct d_level_shared_segment_state;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<std::size_t, 32000> MAX_DELTA_LIGHTS{}; // Original D2: 10000;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<fix, 2048> DL_SCALE{}; // Divide light to allow 3 bits integer, 5 bits fraction.
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2020-05-02 21:18:42 +00:00
|
|
|
using d_delta_light_array = std::array<delta_light, MAX_DELTA_LIGHTS>;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
|
|
|
void clear_light_subtracted();
|
|
|
|
|
2019-12-22 05:34:08 +00:00
|
|
|
void segment2_write(const cscusegment s2, PHYSFS_File *fp);
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2016-01-09 16:38:14 +00:00
|
|
|
void delta_light_read(delta_light *dl, PHYSFS_File *fp);
|
2016-02-12 04:02:28 +00:00
|
|
|
void delta_light_write(const delta_light *dl, PHYSFS_File *fp);
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2016-01-09 16:38:14 +00:00
|
|
|
void dl_index_read(dl_index *di, PHYSFS_File *fp);
|
2016-02-12 04:02:28 +00:00
|
|
|
void dl_index_write(const dl_index *di, PHYSFS_File *fp);
|
2018-06-06 04:53:45 +00:00
|
|
|
using dlindexnum_t = uint16_t;
|
|
|
|
}
|
|
|
|
#define DXX_VALPTRIDX_REPORT_ERROR_STYLE_default_dl_index trap_terse
|
2020-12-19 16:13:26 +00:00
|
|
|
DXX_VALPTRIDX_DECLARE_SUBTYPE(dsx::, dl_index, ::dsx::dlindexnum_t, 500);
|
2018-06-06 04:53:45 +00:00
|
|
|
namespace dsx {
|
|
|
|
DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(dl_index, dlindex);
|
2018-12-30 00:43:58 +00:00
|
|
|
int subtract_light(const d_level_shared_destructible_light_state &LevelSharedDestructibleLightState, vmsegptridx_t segnum, sidenum_fast_t sidenum);
|
|
|
|
int add_light(const d_level_shared_destructible_light_state &LevelSharedDestructibleLightState, vmsegptridx_t segnum, sidenum_fast_t sidenum);
|
2015-12-13 18:00:48 +00:00
|
|
|
}
|
2014-12-22 04:35:49 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:25 +00:00
|
|
|
|
2014-12-22 04:35:49 +00:00
|
|
|
template <unsigned bits>
|
2018-04-09 00:58:28 +00:00
|
|
|
class visited_segment_mask_t;
|
|
|
|
using visited_segment_bitarray_t = visited_segment_mask_t<1>;
|
2014-12-22 04:35:49 +00:00
|
|
|
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<int, MAX_SIDES_PER_SEGMENT> side_none{};
|
|
|
|
constexpr std::integral_constant<int, -1> edge_none{};
|
2015-12-05 22:57:25 +00:00
|
|
|
|
|
|
|
}
|