| 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 "ai.h" |
| 40 |
#include "3d.h" |
| 41 |
#include "game.h" |
| 42 |
#include "textures.h" |
| 43 |
#include "valptridx.tcc" |
| 44 |
#include "wall.h" |
| 45 |
#include "d_levelstate.h" |
| 46 |
|
| 47 |
namespace dcx { |
| 48 |
|
| 49 |
template <typename T> |
| 50 |
static void reconstruct_global_variable(T &t) |
| 51 |
{ |
| 52 |
t.~T(); |
| 53 |
new(&t) T(); |
| 54 |
} |
| 55 |
|
| 56 |
d_interface_unique_state InterfaceUniqueState; |
| 57 |
d_game_view_unique_state GameViewUniqueState; |
| 58 |
d_player_unique_endlevel_state PlayerUniqueEndlevelState; |
| 59 |
d_level_unique_automap_state LevelUniqueAutomapState; |
| 60 |
d_level_unique_fuelcenter_state LevelUniqueFuelcenterState; |
| 61 |
d_level_unique_robot_awareness_state LevelUniqueRobotAwarenessState; |
| 62 |
d_level_unique_segment_state LevelUniqueSegmentState; |
| 63 |
valptridx<player>::array_managed_type Players; |
| 64 |
valptridx<segment>::array_managed_type Segments; |
| 65 |
} |
| 66 |
enumerated_array<g3s_reusable_point, MAX_VERTICES, vertnum_t> Segment_points; |
| 67 |
|
| 68 |
namespace dcx { |
| 69 |
fix FrameTime = 0x1000; // Time since last frame, in seconds |
| 70 |
fix64 GameTime64{0}; // Time in game, in seconds |
| 71 |
|
| 72 |
int d_tick_count{0}; // increments every 33.33ms |
| 73 |
int d_tick_step{0}; // true once every 33.33ms |
| 74 |
|
| 75 |
static void reset_globals_for_new_game() |
| 76 |
{ |
| 77 |
reconstruct_global_variable(LevelSharedBossState); |
| 78 |
reconstruct_global_variable(LevelUniqueFuelcenterState); |
| 79 |
reconstruct_global_variable(LevelUniqueSegmentState); |
| 80 |
reconstruct_global_variable(Players); |
| 81 |
reconstruct_global_variable(Segments); |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
#if DXX_HAVE_POISON_UNDEFINED |
| 87 |
template <typename managed_type> |
| 88 |
valptridx<managed_type>::array_managed_type::array_managed_type() |
| 89 |
{ |
| 90 |
DXX_MAKE_MEM_UNDEFINED(std::span(static_cast<array_base_storage_type &>(*this))); |
| 91 |
} |
| 92 |
#endif |
| 93 |
|
| 94 |
namespace dsx { |
| 95 |
d_game_shared_state GameSharedState; |
| 96 |
d_game_unique_state GameUniqueState; |
| 97 |
d_level_shared_boss_state LevelSharedBossState; |
| 98 |
#if DXX_BUILD_DESCENT == 2 |
| 99 |
d_level_shared_control_center_state LevelSharedControlCenterState; |
| 100 |
#endif |
| 101 |
d_level_unique_effects_clip_state LevelUniqueEffectsClipState; |
| 102 |
d_level_shared_segment_state LevelSharedSegmentState; |
| 103 |
d_level_unique_object_state LevelUniqueObjectState; |
| 104 |
d_level_unique_light_state LevelUniqueLightState; |
| 105 |
d_level_shared_polygon_model_state LevelSharedPolygonModelState; |
| 106 |
d_level_shared_robotcenter_state LevelSharedRobotcenterState; |
| 107 |
d_level_shared_robot_info_state LevelSharedRobotInfoState; |
| 108 |
d_level_shared_robot_joint_state LevelSharedRobotJointState; |
| 109 |
d_level_unique_wall_subsystem_state LevelUniqueWallSubsystemState; |
| 110 |
d_level_unique_tmap_info_state LevelUniqueTmapInfoState; |
| 111 |
|
| 112 |
#if DXX_BUILD_DESCENT == 2 |
| 113 |
d_level_shared_seismic_state LevelSharedSeismicState; |
| 114 |
d_level_unique_seismic_state LevelUniqueSeismicState; |
| 115 |
#endif |
| 116 |
|
| 117 |
void reset_globals_for_new_game() |
| 118 |
{ |
| 119 |
::dcx::reset_globals_for_new_game(); |
| 120 |
/* Skip LevelUniqueEffectsClipState because it contains some fields |
| 121 |
* that are initialized from game data, and those fields should not |
| 122 |
* be reconstructed. |
| 123 |
*/ |
| 124 |
reconstruct_global_variable(LevelUniqueObjectState); |
| 125 |
reconstruct_global_variable(LevelUniqueLightState); |
| 126 |
reconstruct_global_variable(LevelUniqueWallSubsystemState); |
| 127 |
/* Same for LevelUniqueTmapInfoState */ |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
/* |
| 132 |
* If not specified otherwise by the user, enable full instantiation if |
| 133 |
* the compiler inliner is not enabled. This is required because |
| 134 |
* non-inline builds contain link time references to functions that are |
| 135 |
* not used. |
| 136 |
* |
| 137 |
* Force full instantiation for non-inline builds so that these |
| 138 |
* references are satisfied. For inline-enabled builds, instantiate |
| 139 |
* only the classes that are known to be used. |
| 140 |
* |
| 141 |
* Force full instantiation for AddressSanitizer builds. In gcc-7 (and |
| 142 |
* possibly other versions), AddressSanitizer inhibits an optimization |
| 143 |
* that deletes an unnecessary nullptr check, causing references to |
| 144 |
* class null_pointer_exception. |
| 145 |
*/ |
| 146 |
#ifndef DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION |
| 147 |
#if (defined(__NO_INLINE__) && __NO_INLINE__ > 0) || defined(__SANITIZE_ADDRESS__) |
| 148 |
#define DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION 1 |
| 149 |
#else |
| 150 |
#define DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION 0 |
| 151 |
#endif |
| 152 |
#endif |
| 153 |
|
| 154 |
#if DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION |
| 155 |
template class valptridx<dcx::active_door>; |
| 156 |
template class valptridx<dcx::vertex>; |
| 157 |
#if DXX_BUILD_DESCENT == 2 |
| 158 |
template class valptridx<dsx::cloaking_wall>; |
| 159 |
#endif |
| 160 |
template class valptridx<dsx::object>; |
| 161 |
template class valptridx<dcx::player>; |
| 162 |
template class valptridx<dcx::segment>; |
| 163 |
template class valptridx<dsx::trigger>; |
| 164 |
template class valptridx<dsx::wall>; |
| 165 |
|
| 166 |
#else |
| 167 |
namespace { |
| 168 |
|
| 169 |
/* Explicit instantiation cannot be conditional on a truth |
| 170 |
* expression, but the exception types only need to be instantiated |
| 171 |
* if they are used. To reduce code bloat, use |
| 172 |
* `instantiation_guard` to instantiate the real exception class if |
| 173 |
* it is used (as reported by |
| 174 |
* `valptridx<T>::report_error_uses_exception`), but otherwise |
| 175 |
* instantiate a stub class with no members. The stub class must be |
| 176 |
* a member of a template that depends on `T` because duplicate |
| 177 |
* explicit instantiations are not allowed. If the stub did not |
| 178 |
* depend on `T`, each type `T` that used the stubs would |
| 179 |
* instantiate the same stub. |
| 180 |
* |
| 181 |
* Hide `instantiation_guard` in an anonymous namespace to encourage |
| 182 |
* the compiler to optimize away any unused pieces of it. |
| 183 |
*/ |
| 184 |
template <typename T, bool = valptridx<T>::report_error_uses_exception::value> |
| 185 |
struct instantiation_guard |
| 186 |
{ |
| 187 |
using type = valptridx<T>; |
| 188 |
}; |
| 189 |
|
| 190 |
template <typename T> |
| 191 |
struct instantiation_guard<T, false> |
| 192 |
{ |
| 193 |
struct type |
| 194 |
{ |
| 195 |
class index_mismatch_exception {}; |
| 196 |
class index_range_exception {}; |
| 197 |
class null_pointer_exception {}; |
| 198 |
}; |
| 199 |
}; |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
template class instantiation_guard<dcx::active_door>::type::index_range_exception; |
| 204 |
template class instantiation_guard<dcx::vertex>::type::index_range_exception; |
| 205 |
#if DXX_BUILD_DESCENT == 2 |
| 206 |
template class instantiation_guard<dsx::cloaking_wall>::type::index_range_exception; |
| 207 |
#endif |
| 208 |
|
| 209 |
template class instantiation_guard<dsx::object>::type::index_mismatch_exception; |
| 210 |
template class instantiation_guard<dsx::object>::type::index_range_exception; |
| 211 |
template class instantiation_guard<dsx::object>::type::null_pointer_exception; |
| 212 |
|
| 213 |
template class instantiation_guard<dcx::player>::type::index_range_exception; |
| 214 |
|
| 215 |
template class instantiation_guard<dcx::segment>::type::index_mismatch_exception; |
| 216 |
template class instantiation_guard<dcx::segment>::type::index_range_exception; |
| 217 |
template class instantiation_guard<dcx::segment>::type::null_pointer_exception; |
| 218 |
|
| 219 |
template class instantiation_guard<dsx::trigger>::type::index_range_exception; |
| 220 |
template class instantiation_guard<dsx::wall>::type::index_range_exception; |
| 221 |
|
| 222 |
#endif |