From 620afa0c1e4dafe96e7309bb8d68d2b32e284773 Mon Sep 17 00:00:00 2001 From: Mike Nelson Date: Mon, 25 Mar 2024 04:28:24 -0700 Subject: [PATCH] Cockpit fov option (#5924) * add cockpit fov to in-game options and use a define for the default fov value for both fov options * Add a controlling toggle option * constexpr * localization --- code/camera/camera.cpp | 46 +++++++++++++++++++++++++++++++--- code/camera/camera.h | 2 ++ code/cmdline/cmdline.cpp | 2 +- code/localization/localize.cpp | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/code/camera/camera.cpp b/code/camera/camera.cpp index a2693d79a9a..90bd4a5fb15 100644 --- a/code/camera/camera.cpp +++ b/code/camera/camera.cpp @@ -14,8 +14,8 @@ #include "ship/ship.h" //compute_slew_matrix //*************************IMPORTANT GLOBALS************************* -fov_t VIEWER_ZOOM_DEFAULT = 0.75f; // Default viewer zoom, 0.625 as per multi-lateral agreement on 3/24/97 -fov_t COCKPIT_ZOOM_DEFAULT = 0.75f; +fov_t VIEWER_ZOOM_DEFAULT = DEFAULT_FOV; +fov_t COCKPIT_ZOOM_DEFAULT = DEFAULT_FOV; float Sexp_fov = 0.0f; warp_camera Warp_camera; @@ -54,6 +54,9 @@ APPLY_TO_FOV_T(*, mul) APPLY_TO_FOV_T(+, add) APPLY_TO_FOV_T(-, sub) +// Used to set the default value for in-game options +static constexpr float fov_default = DEFAULT_FOV; + static SCP_string fov_display(float val) { auto degrees = fl_degrees(val); @@ -71,11 +74,48 @@ auto FovOption = options::OptionBuilder("Graphics.FOV", return true; }) .display(fov_display) - .default_val(0.75f) + .default_val(fov_default) .level(options::ExpertLevel::Advanced) .importance(60) .finish(); +bool Use_cockpit_fov = false; + +auto CockpitFOVToggleOption = options::OptionBuilder("Graphics.CockpitFOVToggle", + std::pair{"Cockpit FOV Toggle", 1838}, + std::pair{"Whether or not to use a different FOV for cockpit rendering from normal rendering", 1839}) + .category(std::make_pair("Graphics", 1825)) + .default_val(false) + .change_listener([](bool val, bool) { + if (!val) { + COCKPIT_ZOOM_DEFAULT = VIEWER_ZOOM_DEFAULT; + } + return true; // This option will always persist so we never return false + }) + .level(options::ExpertLevel::Advanced) + .bind_to(&Use_cockpit_fov) + .importance(61) + .finish(); + +auto CockpitFovOption = options::OptionBuilder("Graphics.CockpitFOV", + std::pair{"Cockpit Field Of View", 1840}, + std::pair{"The vertical field of view for cockpit rendering. Only works if cockpits are active and cockpit FOV toggle is turned on.", 1841}) + .category(std::make_pair("Graphics", 1825)) + .range(0.436332f, 1.5708f) + .change_listener([](const float& val, bool) { + if (Use_cockpit_fov){ + COCKPIT_ZOOM_DEFAULT = val; + } else { + COCKPIT_ZOOM_DEFAULT = VIEWER_ZOOM_DEFAULT; + } + return true; + }) + .display(fov_display) + .default_val(fov_default) + .level(options::ExpertLevel::Advanced) + .importance(62) + .finish(); + //*************************CLASS: camera************************* //This is where the camera class begins! :D camera::camera(const char *in_name, int in_signature) diff --git a/code/camera/camera.h b/code/camera/camera.h index 063a5ae04c5..972e5871066 100644 --- a/code/camera/camera.h +++ b/code/camera/camera.h @@ -20,6 +20,8 @@ #define EXTERN_CAM_BBOX_CONSTANT_PADDING 5.0f #define EXTERN_CAM_BBOX_MULTIPLIER_PADDING 1.5f +#define DEFAULT_FOV 0.75f; + struct asymmetric_fov { float left, right, up, down; friend asymmetric_fov operator* (const asymmetric_fov&, const float&); diff --git a/code/cmdline/cmdline.cpp b/code/cmdline/cmdline.cpp index ad569b675f0..83201d4582d 100644 --- a/code/cmdline/cmdline.cpp +++ b/code/cmdline/cmdline.cpp @@ -1900,7 +1900,7 @@ bool SetCmdlineParams() if (val > 0.1) { VIEWER_ZOOM_DEFAULT = val; } else { - VIEWER_ZOOM_DEFAULT = 0.75f; + VIEWER_ZOOM_DEFAULT = DEFAULT_FOV; } } diff --git a/code/localization/localize.cpp b/code/localization/localize.cpp index 915d2d98b3f..4fc0e5f0a3f 100644 --- a/code/localization/localize.cpp +++ b/code/localization/localize.cpp @@ -64,7 +64,7 @@ bool *Lcl_unexpected_tstring_check = nullptr; // NOTE: with map storage of XSTR strings, the indexes no longer need to be contiguous, // but internal strings should still increment XSTR_SIZE to avoid collisions. // retail XSTR_SIZE = 1570 -// #define XSTR_SIZE 1838 // This is the next available ID +// #define XSTR_SIZE 1842 // This is the next available ID // struct to allow for strings.tbl-determined x offset