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 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 | * Global variables for main directory |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | #include "maths.h" |
||
27 | #include "vecmat.h" |
||
28 | #include "inferno.h" |
||
29 | #include "lighting.h" |
||
30 | #include "cntrlcen.h" |
||
31 | #include "effects.h" |
||
32 | #include "fuelcen.h" |
||
33 | #include "segment.h" |
||
34 | #include "switch.h" |
||
35 | #include "object.h" |
||
36 | #include "player.h" |
||
37 | #include "bm.h" |
||
38 | #include "robot.h" |
||
39 | #include "3d.h" |
||
40 | #include "game.h" |
||
41 | #include "textures.h" |
||
42 | #include "valptridx.tcc" |
||
43 | #include "wall.h" |
||
44 | |||
45 | namespace dcx { |
||
46 | |||
47 | template <typename T> |
||
48 | static void reconstruct_global_variable(T &t) |
||
49 | { |
||
50 | t.~T(); |
||
51 | new(&t) T(); |
||
52 | } |
||
53 | |||
54 | d_interface_unique_state InterfaceUniqueState; |
||
55 | d_game_view_unique_state GameViewUniqueState; |
||
56 | d_player_unique_endlevel_state PlayerUniqueEndlevelState; |
||
57 | d_level_unique_automap_state LevelUniqueAutomapState; |
||
58 | d_level_unique_fuelcenter_state LevelUniqueFuelcenterState; |
||
59 | d_level_unique_robot_awareness_state LevelUniqueRobotAwarenessState; |
||
60 | d_level_unique_segment_state LevelUniqueSegmentState; |
||
61 | // Global array of vertices, common to one mine. |
||
62 | valptridx<player>::array_managed_type Players; |
||
63 | valptridx<segment>::array_managed_type Segments; |
||
64 | } |
||
65 | std::array<g3s_point, MAX_VERTICES> Segment_points; |
||
66 | |||
67 | namespace dcx { |
||
68 | fix FrameTime = 0x1000; // Time since last frame, in seconds |
||
69 | fix64 GameTime64 = 0; // Time in game, in seconds |
||
70 | |||
71 | int d_tick_count = 0; // increments every 33.33ms |
||
72 | int d_tick_step = 0; // true once every 33.33ms |
||
73 | |||
74 | // This is the global mine which create_new_mine returns. |
||
75 | //lsegment Lsegments[MAX_SEGMENTS]; |
||
76 | |||
77 | // Number of vertices in current mine (ie, Vertices, pointed to by Vp) |
||
78 | |||
79 | // Translate table to get opposite side of a face on a segment. |
||
80 | |||
81 | const std::array<uint8_t, MAX_SIDES_PER_SEGMENT> Side_opposite{{ |
||
82 | WRIGHT, WBOTTOM, WLEFT, WTOP, WFRONT, WBACK |
||
83 | }}; |
||
84 | |||
85 | #define TOLOWER(c) ((((c)>='A') && ((c)<='Z'))?((c)+('a'-'A')):(c)) |
||
86 | |||
87 | const std::array<std::array<unsigned, 4>, MAX_SIDES_PER_SEGMENT> Side_to_verts_int{{ |
||
88 | {{7,6,2,3}}, // left |
||
89 | {{0,4,7,3}}, // top |
||
90 | {{0,1,5,4}}, // right |
||
91 | {{2,6,5,1}}, // bottom |
||
92 | {{4,5,6,7}}, // back |
||
93 | {{3,2,1,0}}, // front |
||
94 | }}; |
||
95 | |||
96 | // Texture map stuff |
||
97 | |||
98 | //--unused-- fix Laser_delay_time = F1_0/6; // Delay between laser fires. |
||
99 | |||
100 | static void reset_globals_for_new_game() |
||
101 | { |
||
102 | reconstruct_global_variable(LevelSharedBossState); |
||
103 | reconstruct_global_variable(LevelUniqueFuelcenterState); |
||
104 | reconstruct_global_variable(LevelUniqueSegmentState); |
||
105 | reconstruct_global_variable(Players); |
||
106 | reconstruct_global_variable(Segments); |
||
107 | } |
||
108 | |||
109 | } |
||
110 | |||
111 | #if DXX_HAVE_POISON_UNDEFINED |
||
112 | template <typename managed_type> |
||
113 | valptridx<managed_type>::array_managed_type::array_managed_type() |
||
114 | { |
||
115 | DXX_MAKE_MEM_UNDEFINED(this->begin(), this->end()); |
||
116 | } |
||
117 | #endif |
||
118 | |||
119 | namespace dsx { |
||
120 | d_game_shared_state GameSharedState; |
||
121 | d_game_unique_state GameUniqueState; |
||
122 | d_level_shared_boss_state LevelSharedBossState; |
||
123 | #if defined(DXX_BUILD_DESCENT_II) |
||
124 | d_level_shared_control_center_state LevelSharedControlCenterState; |
||
125 | #endif |
||
126 | d_level_unique_effects_clip_state LevelUniqueEffectsClipState; |
||
127 | d_level_shared_segment_state LevelSharedSegmentState; |
||
128 | d_level_unique_object_state LevelUniqueObjectState; |
||
129 | d_level_unique_light_state LevelUniqueLightState; |
||
130 | d_level_shared_polygon_model_state LevelSharedPolygonModelState; |
||
131 | d_level_shared_robotcenter_state LevelSharedRobotcenterState; |
||
132 | d_level_shared_robot_info_state LevelSharedRobotInfoState; |
||
133 | d_level_shared_robot_joint_state LevelSharedRobotJointState; |
||
134 | d_level_unique_wall_subsystem_state LevelUniqueWallSubsystemState; |
||
135 | d_level_unique_tmap_info_state LevelUniqueTmapInfoState; |
||
136 | |||
137 | #if defined(DXX_BUILD_DESCENT_II) |
||
138 | d_level_shared_seismic_state LevelSharedSeismicState; |
||
139 | d_level_unique_seismic_state LevelUniqueSeismicState; |
||
140 | #endif |
||
141 | |||
142 | void reset_globals_for_new_game() |
||
143 | { |
||
144 | ::dcx::reset_globals_for_new_game(); |
||
145 | /* Skip LevelUniqueEffectsClipState because it contains some fields |
||
146 | * that are initialized from game data, and those fields should not |
||
147 | * be reconstructed. |
||
148 | */ |
||
149 | reconstruct_global_variable(LevelUniqueObjectState); |
||
150 | reconstruct_global_variable(LevelUniqueLightState); |
||
151 | reconstruct_global_variable(LevelUniqueWallSubsystemState); |
||
152 | /* Same for LevelUniqueTmapInfoState */ |
||
153 | } |
||
154 | } |
||
155 | |||
156 | /* |
||
157 | * If not specified otherwise by the user, enable full instantiation if |
||
158 | * the compiler inliner is not enabled. This is required because |
||
159 | * non-inline builds contain link time references to functions that are |
||
160 | * not used. |
||
161 | * |
||
162 | * Force full instantiation for non-inline builds so that these |
||
163 | * references are satisfied. For inline-enabled builds, instantiate |
||
164 | * only the classes that are known to be used. |
||
165 | * |
||
166 | * Force full instantiation for AddressSanitizer builds. In gcc-7 (and |
||
167 | * possibly other versions), AddressSanitizer inhibits an optimization |
||
168 | * that deletes an unnecessary nullptr check, causing references to |
||
169 | * class null_pointer_exception. |
||
170 | */ |
||
171 | #ifndef DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION |
||
172 | #if (defined(__NO_INLINE__) && __NO_INLINE__ > 0) || defined(__SANITIZE_ADDRESS__) |
||
173 | #define DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION 1 |
||
174 | #else |
||
175 | #define DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION 0 |
||
176 | #endif |
||
177 | #endif |
||
178 | |||
179 | #if DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION |
||
180 | template class valptridx<dcx::active_door>; |
||
181 | template class valptridx<dcx::vertex>; |
||
182 | #if defined(DXX_BUILD_DESCENT_II) |
||
183 | template class valptridx<dsx::cloaking_wall>; |
||
184 | #endif |
||
185 | template class valptridx<dsx::object>; |
||
186 | template class valptridx<dcx::player>; |
||
187 | template class valptridx<dcx::segment>; |
||
188 | template class valptridx<dsx::trigger>; |
||
189 | template class valptridx<dsx::wall>; |
||
190 | |||
191 | #else |
||
192 | namespace { |
||
193 | |||
194 | /* Explicit instantiation cannot be conditional on a truth |
||
195 | * expression, but the exception types only need to be instantiated |
||
196 | * if they are used. To reduce code bloat, use |
||
197 | * `instantiation_guard` to instantiate the real exception class if |
||
198 | * it is used (as reported by |
||
199 | * `valptridx<T>::report_error_uses_exception`), but otherwise |
||
200 | * instantiate a stub class with no members. The stub class must be |
||
201 | * a member of a template that depends on `T` because duplicate |
||
202 | * explicit instantiations are not allowed. If the stub did not |
||
203 | * depend on `T`, each type `T` that used the stubs would |
||
204 | * instantiate the same stub. |
||
205 | * |
||
206 | * Hide `instantiation_guard` in an anonymous namespace to encourage |
||
207 | * the compiler to optimize away any unused pieces of it. |
||
208 | */ |
||
209 | template <typename T, bool = valptridx<T>::report_error_uses_exception::value> |
||
210 | struct instantiation_guard |
||
211 | { |
||
212 | using type = valptridx<T>; |
||
213 | }; |
||
214 | |||
215 | template <typename T> |
||
216 | struct instantiation_guard<T, false> |
||
217 | { |
||
218 | struct type |
||
219 | { |
||
220 | class index_mismatch_exception {}; |
||
221 | class index_range_exception {}; |
||
222 | class null_pointer_exception {}; |
||
223 | }; |
||
224 | }; |
||
225 | |||
226 | } |
||
227 | |||
228 | template class instantiation_guard<dcx::active_door>::type::index_range_exception; |
||
229 | template class instantiation_guard<dcx::vertex>::type::index_range_exception; |
||
230 | #if defined(DXX_BUILD_DESCENT_II) |
||
231 | template class instantiation_guard<dsx::cloaking_wall>::type::index_range_exception; |
||
232 | #endif |
||
233 | |||
234 | template class instantiation_guard<dsx::object>::type::index_mismatch_exception; |
||
235 | template class instantiation_guard<dsx::object>::type::index_range_exception; |
||
236 | template class instantiation_guard<dsx::object>::type::null_pointer_exception; |
||
237 | |||
238 | template class instantiation_guard<dcx::player>::type::index_range_exception; |
||
239 | |||
240 | template class instantiation_guard<dcx::segment>::type::index_mismatch_exception; |
||
241 | template class instantiation_guard<dcx::segment>::type::index_range_exception; |
||
242 | template class instantiation_guard<dcx::segment>::type::null_pointer_exception; |
||
243 | |||
244 | template class instantiation_guard<dsx::trigger>::type::index_range_exception; |
||
245 | template class instantiation_guard<dsx::wall>::type::index_range_exception; |
||
246 | |||
247 | #endif |