| 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 |
#pragma once |
| 21 |
|
| 22 |
#include "dsx-ns.h" |
| 23 |
#include "fwd-d_array.h" |
| 24 |
#include "fwd-gr.h" |
| 25 |
#include "fwd-object.h" |
| 26 |
#include "fwd-player.h" |
| 27 |
#include "kconfig.h" |
| 28 |
#include "maths.h" |
| 29 |
#include <chrono> |
| 30 |
#include <cstdint> |
| 31 |
#include <type_traits> |
| 32 |
|
| 33 |
#ifdef DXX_BUILD_DESCENT |
| 34 |
#include <physfs.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
namespace dcx { |
| 38 |
|
| 39 |
constexpr std::integral_constant<int, 5> NDL{}; // Number of difficulty levels. |
| 40 |
|
| 41 |
constexpr std::integral_constant<unsigned, 30> DESIGNATED_GAME_FPS{}; // assuming the original intended Framerate was 30 |
| 42 |
constexpr std::integral_constant<int, F1_0 / DESIGNATED_GAME_FPS> DESIGNATED_GAME_FRAMETIME; |
| 43 |
|
| 44 |
#ifdef NDEBUG |
| 45 |
constexpr auto MINIMUM_FPS = DESIGNATED_GAME_FPS; |
| 46 |
constexpr std::integral_constant<unsigned, 200> MAXIMUM_FPS{}; |
| 47 |
#else |
| 48 |
constexpr std::integral_constant<unsigned, 1> MINIMUM_FPS{}; |
| 49 |
constexpr std::integral_constant<unsigned, 1000> MAXIMUM_FPS{}; |
| 50 |
#endif |
| 51 |
|
| 52 |
// from mglobal.c |
| 53 |
using d_time_fix = std::chrono::duration<uint32_t, std::ratio<1, F1_0>>; |
| 54 |
extern fix FrameTime; // time in seconds since last frame |
| 55 |
extern fix64 GameTime64; // time in game (sum of FrameTime) |
| 56 |
extern int d_tick_count; // increments according to DESIGNATED_GAME_FRAMETIME |
| 57 |
extern int d_tick_step; // true once in interval of DESIGNATED_GAME_FRAMETIME |
| 58 |
enum class gauge_inset_window_view : unsigned; |
| 59 |
enum class game_mode_flag : uint16_t; |
| 60 |
enum class game_mode_flags : uint16_t; |
| 61 |
enum class cockpit_mode_t : uint8_t; |
| 62 |
|
| 63 |
// The following bits define the game modes. |
| 64 |
#define GM_NETWORK game_mode_flag::network // You are in network mode |
| 65 |
#define GM_MULTI_ROBOTS game_mode_flag::multi_robots // You are in a multiplayer mode with robots. |
| 66 |
#define GM_MULTI_COOP game_mode_flag::multi_coop // You are in a multiplayer mode and can't hurt other players. |
| 67 |
#define GM_TEAM game_mode_flag::team // Team mode for network play |
| 68 |
#define GM_BOUNTY game_mode_flag::bounty // New bounty mode by Matt1360 |
| 69 |
#define GM_CAPTURE game_mode_flag::capture // Capture the flag mode for D2 |
| 70 |
#define GM_HOARD game_mode_flag::hoard // New hoard mode for D2 Christmas |
| 71 |
#define GM_NORMAL game_mode_flags::normal // You are in normal play mode, no multiplayer stuff |
| 72 |
#define GM_MULTI GM_NETWORK // You are in some type of multiplayer game (GM_NETWORK /* | GM_SERIAL | GM_MODEM */) |
| 73 |
extern game_mode_flags Game_mode; |
| 74 |
extern game_mode_flags Newdemo_game_mode; |
| 75 |
extern screen_mode Game_screen_mode; |
| 76 |
|
| 77 |
void calc_d_tick(); |
| 78 |
|
| 79 |
extern int Game_suspended; // if non-zero, nothing moves but player |
| 80 |
|
| 81 |
/* This must be a signed type. Some sites, such as `bump_this_object`, |
| 82 |
* use Difficulty_level_type in arithmetic expressions, and those |
| 83 |
* expressions must be signed to produce the correct result. |
| 84 |
*/ |
| 85 |
enum class Difficulty_level_type : signed int; |
| 86 |
|
| 87 |
struct d_game_shared_state; |
| 88 |
struct d_game_unique_state; |
| 89 |
|
| 90 |
extern int Global_missile_firing_count; |
| 91 |
|
| 92 |
extern int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd; |
| 93 |
|
| 94 |
#if DXX_USE_STEREOSCOPIC_RENDER |
| 95 |
// Stereo viewport formats |
| 96 |
enum class StereoFormat : uint8_t; |
| 97 |
|
| 98 |
extern StereoFormat VR_stereo; |
| 99 |
extern fix VR_eye_width; |
| 100 |
extern int VR_eye_offset; |
| 101 |
extern int VR_sync_width; |
| 102 |
extern grs_subcanvas VR_hud_left; |
| 103 |
extern grs_subcanvas VR_hud_right; |
| 104 |
#endif |
| 105 |
|
| 106 |
extern cockpit_mode_t last_drawn_cockpit; |
| 107 |
|
| 108 |
class pause_game_world_time; |
| 109 |
|
| 110 |
void stop_time(); |
| 111 |
void start_time(); |
| 112 |
void reset_time(); // called when starting level |
| 113 |
|
| 114 |
#if DXX_USE_SCREENSHOT |
| 115 |
/* The implementation is common, but is only called from similar code, so |
| 116 |
* omit the declaration when used in a common-only context. |
| 117 |
*/ |
| 118 |
#ifdef DXX_BUILD_DESCENT |
| 119 |
// If automap_flag == 1, then call automap routine to write message. |
| 120 |
#if DXX_USE_SCREENSHOT_FORMAT_LEGACY |
| 121 |
void write_bmp(PHYSFS_File *, unsigned w, unsigned h); |
| 122 |
#endif |
| 123 |
void save_screen_shot(int automap_flag); |
| 124 |
#endif |
| 125 |
#endif |
| 126 |
|
| 127 |
// force cockpit redraw next time. call this if you've trashed the screen |
| 128 |
void fly_init(object_base &obj); |
| 129 |
void reset_cockpit(); // called if you've trashed the screen |
| 130 |
|
| 131 |
// functions to save, clear, and resture palette flash effects |
| 132 |
void reset_palette_add(void); |
| 133 |
|
| 134 |
void game_init_render_sub_buffers(grs_canvas &, int x, int y, int w, int h); |
| 135 |
// Sets up the canvases we will be rendering to |
| 136 |
|
| 137 |
extern int netplayerinfo_on; |
| 138 |
extern int force_cockpit_redraw; |
| 139 |
} |
| 140 |
|
| 141 |
// Suspend flags |
| 142 |
#define SUSP_ROBOTS 1 // Robot AI doesn't move |
| 143 |
#define SHOW_EXIT_PATH 1 |
| 144 |
|
| 145 |
//sets the rgb values for palette flash |
| 146 |
#define PALETTE_FLASH_SET(_r,_g,_b) (static_cast<void>(PaletteRedAdd = {_r}), static_cast<void>(PaletteGreenAdd = {_g}), static_cast<void>(PaletteBlueAdd = {_b})) |
| 147 |
|
| 148 |
// from game.c |
| 149 |
void close_game(void); |
| 150 |
void calc_frame_time(void); |
| 151 |
|
| 152 |
#ifdef DXX_BUILD_DESCENT |
| 153 |
namespace dsx { |
| 154 |
|
| 155 |
enum class next_level_request_secret_flag : bool; |
| 156 |
|
| 157 |
struct game_window; |
| 158 |
extern game_window *Game_wind; |
| 159 |
|
| 160 |
void game(); |
| 161 |
void init_game(); |
| 162 |
#if DXX_USE_STEREOSCOPIC_RENDER |
| 163 |
void init_stereo(); |
| 164 |
#endif |
| 165 |
void init_cockpit(); |
| 166 |
void PALETTE_FLASH_ADD(int dr, int dg, int db); |
| 167 |
|
| 168 |
struct d_game_shared_state; |
| 169 |
|
| 170 |
#if DXX_BUILD_DESCENT == 2 |
| 171 |
struct d_game_unique_state; |
| 172 |
struct d_level_shared_seismic_state; |
| 173 |
struct d_level_unique_seismic_state; |
| 174 |
|
| 175 |
extern d_level_shared_seismic_state LevelSharedSeismicState; |
| 176 |
extern d_level_unique_seismic_state LevelUniqueSeismicState; |
| 177 |
#endif |
| 178 |
|
| 179 |
extern d_game_shared_state GameSharedState; |
| 180 |
extern d_game_unique_state GameUniqueState; |
| 181 |
|
| 182 |
void game_flush_respawn_inputs(control_info &Controls); |
| 183 |
void game_flush_inputs(control_info &Controls); // clear all inputs |
| 184 |
void palette_restore(void); |
| 185 |
void show_help(); |
| 186 |
void show_netgame_help(); |
| 187 |
|
| 188 |
// put up the help message |
| 189 |
void show_newdemo_help(); |
| 190 |
#if DXX_BUILD_DESCENT == 2 |
| 191 |
void full_palette_save(); // all of the above plus gr_palette_load(gr_palette) |
| 192 |
|
| 193 |
//Flickering light system |
| 194 |
struct flickering_light; |
| 195 |
struct d_flickering_light_state; |
| 196 |
|
| 197 |
extern d_flickering_light_state Flickering_light_state; |
| 198 |
|
| 199 |
extern uint8_t BigWindowSwitch; |
| 200 |
void compute_slide_segs(); |
| 201 |
|
| 202 |
// turn flickering off (because light has been turned off) |
| 203 |
void disable_flicker(d_flickering_light_state &fls, vmsegidx_t segnum, sidenum_t sidenum); |
| 204 |
|
| 205 |
// turn flickering off (because light has been turned on) |
| 206 |
void enable_flicker(d_flickering_light_state &fls, vmsegidx_t segnum, sidenum_t sidenum); |
| 207 |
|
| 208 |
/* |
| 209 |
* reads a flickering_light structure from a PHYSFS_File |
| 210 |
*/ |
| 211 |
void flickering_light_read(flickering_light &fl, NamedPHYSFS_File fp); |
| 212 |
void flickering_light_write(const flickering_light &fl, PHYSFS_File *fp); |
| 213 |
#endif |
| 214 |
|
| 215 |
//Cheats |
| 216 |
struct game_cheats; |
| 217 |
extern game_cheats cheats; |
| 218 |
|
| 219 |
game_window *game_setup(); |
| 220 |
bool allowed_to_fire_laser(const player_info &); |
| 221 |
void reset_globals_for_new_game(); |
| 222 |
void check_rear_view(control_info &Controls); |
| 223 |
int create_special_path(); |
| 224 |
#if DXX_BUILD_DESCENT == 2 |
| 225 |
extern uint8_t DemoDoingRight, DemoDoingLeft; |
| 226 |
extern fix64 Time_flash_last_played; |
| 227 |
|
| 228 |
playernum_t get_marker_owner(game_mode_flags, game_marker_index, unsigned max_numplayers); |
| 229 |
|
| 230 |
extern struct object *Missile_viewer; |
| 231 |
extern object_signature_t Missile_viewer_sig; |
| 232 |
|
| 233 |
extern enumerated_array<unsigned, 2, gauge_inset_window_view> Coop_view_player; // left & right |
| 234 |
extern enumerated_array<game_marker_index, 2, gauge_inset_window_view> Marker_viewer_num; // left & right |
| 235 |
#endif |
| 236 |
|
| 237 |
#if DXX_USE_EDITOR |
| 238 |
void dump_used_textures_all(); |
| 239 |
void move_player_2_segment(vmsegptridx_t seg, sidenum_t side); |
| 240 |
#endif |
| 241 |
} |
| 242 |
|
| 243 |
#if DXX_BUILD_DESCENT == 1 |
| 244 |
void palette_save(); |
| 245 |
#endif |
| 246 |
#endif |
| 247 |
|
| 248 |
#ifndef NDEBUG // if debugging, these are variables |
| 249 |
|
| 250 |
extern int Slew_on; // in slew or sim mode? |
| 251 |
|
| 252 |
#else // if not debugging, these are constants |
| 253 |
|
| 254 |
#define Slew_on 0 // no slewing in real game |
| 255 |
|
| 256 |
#endif |
| 257 |
|
| 258 |
extern int Rear_view; // if true, looking back. |
| 259 |
|
| 260 |
// selects a given cockpit (or lack of one). |
| 261 |
void select_cockpit(cockpit_mode_t mode); |
| 262 |
|
| 263 |
// show a message in a nice little box |
| 264 |
void show_boxed_message(grs_canvas &, const char *msg); |
| 265 |
|
| 266 |
// turns off rear view & rear view cockpit |
| 267 |
void reset_rear_view(void); |
| 268 |
|
| 269 |
void game_leave_menus(void); |
| 270 |
|
| 271 |
int8_t cheats_enabled(); |
| 272 |
void game_disable_cheats(); |
| 273 |
void toggle_cockpit(void); |
| 274 |
extern fix Show_view_text_timer; |
| 275 |
extern d_time_fix ThisLevelTime; |
| 276 |
|