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. |
||
6 | * See COPYING.txt for license details. |
||
7 | */ |
||
8 | |||
9 | #pragma once |
||
10 | |||
11 | #include <type_traits> |
||
12 | #include <physfs.h> |
||
13 | #include "maths.h" |
||
14 | |||
15 | #include <cstdint> |
||
16 | #include "cpp-valptridx.h" |
||
17 | |||
18 | namespace dcx { |
||
19 | constexpr std::integral_constant<std::size_t, 9000> MAX_SEGMENTS{}; |
||
20 | using segnum_t = uint16_t; |
||
21 | } |
||
22 | #ifdef dsx |
||
23 | namespace dcx { |
||
24 | struct shared_segment; |
||
25 | struct unique_segment; |
||
26 | struct segment; |
||
27 | |||
28 | template <typename S, typename U> |
||
29 | struct susegment; |
||
30 | |||
31 | using msmusegment = susegment<shared_segment, unique_segment>; |
||
32 | using mscusegment = susegment<shared_segment, const unique_segment>; /* unusual, but supported */ |
||
33 | using csmusegment = susegment<const shared_segment, unique_segment>; |
||
34 | using cscusegment = susegment<const shared_segment, const unique_segment>; |
||
35 | } |
||
36 | DXX_VALPTRIDX_DECLARE_SUBTYPE(dcx::, segment, segnum_t, MAX_SEGMENTS); |
||
37 | #endif |
||
38 | |||
39 | #include "fwd-valptridx.h" |
||
40 | #include "dsx-ns.h" |
||
41 | #include <array> |
||
42 | |||
43 | namespace dcx { |
||
44 | constexpr std::integral_constant<std::size_t, 8> MAX_VERTICES_PER_SEGMENT{}; |
||
45 | constexpr std::integral_constant<std::size_t, 6> MAX_SIDES_PER_SEGMENT{}; |
||
46 | constexpr std::integral_constant<std::size_t, 4> MAX_VERTICES_PER_POLY{}; |
||
47 | |||
48 | constexpr std::size_t MAX_SEGMENTS_ORIGINAL = 900; |
||
49 | constexpr std::integral_constant<std::size_t, 4 * MAX_SEGMENTS_ORIGINAL> MAX_SEGMENT_VERTICES_ORIGINAL{}; |
||
50 | constexpr std::integral_constant<std::size_t, 4 * MAX_SEGMENTS> MAX_SEGMENT_VERTICES{}; |
||
51 | } |
||
52 | #ifdef dsx |
||
53 | namespace dsx { |
||
54 | DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(segment, seg); |
||
55 | |||
56 | static constexpr valptridx<segment>::magic_constant<0xfffe> segment_exit{}; |
||
57 | static constexpr valptridx<segment>::magic_constant<0xffff> segment_none{}; |
||
58 | static constexpr valptridx<segment>::magic_constant<0> segment_first{}; |
||
59 | void delete_segment_from_group(vmsegptridx_t segment_num, unsigned group_num); |
||
60 | } |
||
61 | #endif |
||
62 | |||
63 | namespace dcx { |
||
64 | |||
65 | typedef uint_fast32_t sidenum_fast_t; |
||
66 | |||
67 | enum sidenum_t : uint8_t |
||
68 | { |
||
69 | WLEFT = 0, |
||
70 | WTOP = 1, |
||
71 | WRIGHT = 2, |
||
72 | WBOTTOM = 3, |
||
73 | WBACK = 4, |
||
74 | WFRONT = 5 |
||
75 | }; |
||
76 | |||
77 | //normal everyday vertices |
||
78 | |||
79 | constexpr std::integral_constant<fix, 0> DEFAULT_LIGHTING{}; // (F1_0/2) |
||
80 | |||
81 | #if DXX_USE_EDITOR //verts for the new segment |
||
82 | constexpr std::integral_constant<std::size_t, 8> NUM_NEW_SEG_VERTICES{}; |
||
83 | constexpr std::integral_constant<unsigned, MAX_SEGMENT_VERTICES> NEW_SEGMENT_VERTICES{}; |
||
84 | constexpr std::integral_constant<std::size_t, MAX_SEGMENT_VERTICES + NUM_NEW_SEG_VERTICES> MAX_VERTICES{}; |
||
85 | #else //No editor |
||
86 | constexpr std::integral_constant<std::size_t, MAX_SEGMENT_VERTICES> MAX_VERTICES{}; |
||
87 | #endif |
||
88 | |||
89 | struct uvl; |
||
90 | enum class side_type : uint8_t; |
||
91 | |||
92 | using wallnum_t = uint16_t; |
||
93 | struct shared_side; |
||
94 | struct unique_side; |
||
95 | |||
96 | struct vertex; |
||
97 | using vertnum_t = uint32_t; |
||
98 | } |
||
99 | |||
100 | /* `vertex` has only integer members, so wild reads are unlikely to |
||
101 | * cause serious harm. It is read far more than it is written, so |
||
102 | * eliminating checking on reads saves substantial code space. |
||
103 | * |
||
104 | * Vertex indices are only taken from map data, not network data, so |
||
105 | * errors are unlikely. Report them tersely to avoid recording the |
||
106 | * file+line of every access. |
||
107 | */ |
||
108 | #define DXX_VALPTRIDX_REPORT_ERROR_STYLE_const_vertex undefined |
||
109 | #define DXX_VALPTRIDX_REPORT_ERROR_STYLE_mutable_vertex trap_terse |
||
110 | DXX_VALPTRIDX_DECLARE_SUBTYPE(dcx::, vertex, vertnum_t, MAX_VERTICES); |
||
111 | |||
112 | typedef unsigned segment_type_t; |
||
113 | constexpr segment_type_t SEGMENT_IS_NOTHING = 0; |
||
114 | constexpr segment_type_t SEGMENT_IS_FUELCEN = 1; |
||
115 | constexpr segment_type_t SEGMENT_IS_REPAIRCEN = 2; |
||
116 | constexpr segment_type_t SEGMENT_IS_CONTROLCEN = 3; |
||
117 | constexpr segment_type_t SEGMENT_IS_ROBOTMAKER = 4; |
||
118 | #if defined(DXX_BUILD_DESCENT_I) |
||
119 | constexpr std::integral_constant<std::size_t, 5> MAX_CENTER_TYPES{}; |
||
120 | #elif defined(DXX_BUILD_DESCENT_II) |
||
121 | typedef unsigned s2f_ambient_t; |
||
122 | constexpr std::integral_constant<s2f_ambient_t, 1> S2F_AMBIENT_WATER{}; |
||
123 | constexpr std::integral_constant<s2f_ambient_t, 2> S2F_AMBIENT_LAVA{}; |
||
124 | constexpr std::integral_constant<std::size_t, 7> MAX_CENTER_TYPES{}; |
||
125 | constexpr segment_type_t SEGMENT_IS_GOAL_BLUE = 5; |
||
126 | constexpr segment_type_t SEGMENT_IS_GOAL_RED = 6; |
||
127 | #endif |
||
128 | |||
129 | namespace dcx { |
||
130 | DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(vertex, vert); |
||
131 | struct count_segment_array_t; |
||
132 | struct group; |
||
133 | |||
134 | struct d_level_shared_vertex_state; |
||
135 | struct d_level_shared_segment_state; |
||
136 | struct d_level_unique_segment_state; |
||
137 | |||
138 | #define Side_to_verts Side_to_verts_int |
||
139 | extern const std::array<std::array<unsigned, 4>, MAX_SIDES_PER_SEGMENT> Side_to_verts_int; // Side_to_verts[my_side] is list of vertices forming side my_side. |
||
140 | extern const std::array<uint8_t, MAX_SIDES_PER_SEGMENT> Side_opposite; // Side_opposite[my_side] returns side opposite cube from my_side. |
||
141 | |||
142 | void segment_side_wall_tmap_write(PHYSFS_File *fp, const shared_side &sside, const unique_side &uside); |
||
143 | } |
||
144 | void add_segment_to_group(segnum_t segment_num, int group_num); |
||
145 | |||
146 | #if defined(DXX_BUILD_DESCENT_II) |
||
147 | namespace dsx { |
||
148 | struct delta_light; |
||
149 | struct dl_index; |
||
150 | struct d_level_shared_destructible_light_state; |
||
151 | struct d_level_shared_segment_state; |
||
152 | |||
153 | constexpr std::integral_constant<std::size_t, 32000> MAX_DELTA_LIGHTS{}; // Original D2: 10000; |
||
154 | |||
155 | constexpr std::integral_constant<fix, 2048> DL_SCALE{}; // Divide light to allow 3 bits integer, 5 bits fraction. |
||
156 | |||
157 | using d_delta_light_array = std::array<delta_light, MAX_DELTA_LIGHTS>; |
||
158 | |||
159 | void clear_light_subtracted(); |
||
160 | |||
161 | void segment2_write(const cscusegment s2, PHYSFS_File *fp); |
||
162 | |||
163 | void delta_light_read(delta_light *dl, PHYSFS_File *fp); |
||
164 | void delta_light_write(const delta_light *dl, PHYSFS_File *fp); |
||
165 | |||
166 | void dl_index_read(dl_index *di, PHYSFS_File *fp); |
||
167 | void dl_index_write(const dl_index *di, PHYSFS_File *fp); |
||
168 | using dlindexnum_t = uint16_t; |
||
169 | } |
||
170 | #define DXX_VALPTRIDX_REPORT_ERROR_STYLE_default_dl_index trap_terse |
||
171 | DXX_VALPTRIDX_DECLARE_SUBTYPE(dsx::, dl_index, dlindexnum_t, 500); |
||
172 | namespace dsx { |
||
173 | DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(dl_index, dlindex); |
||
174 | int subtract_light(const d_level_shared_destructible_light_state &LevelSharedDestructibleLightState, vmsegptridx_t segnum, sidenum_fast_t sidenum); |
||
175 | int add_light(const d_level_shared_destructible_light_state &LevelSharedDestructibleLightState, vmsegptridx_t segnum, sidenum_fast_t sidenum); |
||
176 | } |
||
177 | #endif |
||
178 | |||
179 | namespace dcx { |
||
180 | |||
181 | template <unsigned bits> |
||
182 | class visited_segment_mask_t; |
||
183 | using visited_segment_bitarray_t = visited_segment_mask_t<1>; |
||
184 | |||
185 | constexpr std::integral_constant<int, MAX_SIDES_PER_SEGMENT> side_none{}; |
||
186 | constexpr std::integral_constant<int, -1> edge_none{}; |
||
187 | |||
188 | } |