Added Yaw only / Yaw + Pitch / Full rotation options to first-person

This commit is contained in:
iChris4 committed 2026-09-08 22:17:50 +02:00
1 parent bd106dd1fe
commit 0e3e2c3dc0
6 files changed
+283 -42

No files matched your search

+28
View File
@@ -62,6 +62,7 @@ struct RuntimeUserConfig {
std::optional<float> vrFirstPersonHeadRightMeters;
std::optional<bool> vrFirstPersonHideDriver;
std::optional<int32_t> vrFirstPersonHiddenModel;
std::optional<std::string> vrFirstPersonRotation;
std::optional<std::string> vrRecenterKey;
std::optional<float> vrLeanBackDegrees;
std::optional<float> audioVolume;
@@ -148,6 +149,12 @@ inline constexpr float kVrFirstPersonHeadRightDefault = 0.0f;
inline constexpr bool kVrFirstPersonHideDriverDefault = true;
inline constexpr int32_t kVrFirstPersonHiddenModelDefault = 0;
inline constexpr float kVrFirstPersonHeadOffsetLimit = 10.0f;
// "yaw", "yaw_pitch" or "full", matching FirstPersonRotation.
inline constexpr const char* kVrFirstPersonRotationDefault = "yaw";
inline bool IsSupportedVrFirstPersonRotation(std::string_view value) {
return value == "yaw" || value == "yaw_pitch" || value == "full";
}
// SDL scancode name, spelled the way SDL_GetScancodeName produces it. An
// empty string leaves the recenter hotkey unbound, menu button only.
inline constexpr std::string_view kVrRecenterKeyDefault = "F9";
@@ -385,6 +392,10 @@ inline void EnsureConfigFile() {
"# 0 is the driver, which is the usual choice. -1 hides every\n"
"# model of your kart, the vehicle included.\n"
"first_person_hidden_model = 0\n"
"# Where the view's orientation comes from: \"yaw\" levels the\n"
"# horizon, \"yaw_pitch\" adds the kart's climb but no roll, and\n"
"# \"full\" takes the kart's whole orientation so the view banks.\n"
"first_person_rotation = \"yaw\"\n\n"
"# Keyboard shortcut that recenters the VR view, naming the key the\n"
"# way SDL does (F9, Home, Keypad 5, ...). It moves the race view to\n"
"# where you are sitting now and brings the menu screen back upright in\n"
@@ -587,6 +598,10 @@ inline RuntimeUserConfig ParseConfigDocument(const toml::value& document) {
value && *value >= -kVrLeanBackDegreesLimit && *value <= kVrLeanBackDegreesLimit) {
config.vrLeanBackDegrees = static_cast<float>(*value);
}
if (auto value = FindConfigValue<std::string>(document, "vr", "first_person_rotation");
value && IsSupportedVrFirstPersonRotation(*value)) {
config.vrFirstPersonRotation = *value;
}
if (auto value = FindConfigInt(document, "vr", "first_person_hidden_model");
value && *value >= -1 && *value <= 31) {
config.vrFirstPersonHiddenModel = static_cast<int32_t>(*value);
@@ -880,6 +895,14 @@ inline bool SetVrFirstPersonHideDriver(bool value) {
return WriteSetting("vr", "first_person_hide_driver", value ? "true" : "false");
}
inline bool SetVrFirstPersonRotation(std::string value) {
if (!IsSupportedVrFirstPersonRotation(value)) {
return false;
}
Mutable().vrFirstPersonRotation = value;
return WriteSetting("vr", "first_person_rotation", FormatString(value));
}
inline bool SetVrFirstPersonHiddenModel(int32_t value) {
value = std::clamp(value, -1, 31);
Mutable().vrFirstPersonHiddenModel = value;
@@ -1180,6 +1203,11 @@ inline bool VrFirstPersonHideDriver(bool fallback = kVrFirstPersonHideDriverDefa
return Get().vrFirstPersonHideDriver.value_or(fallback);
}
inline std::string VrFirstPersonRotation(std::string fallback = kVrFirstPersonRotationDefault) {
const auto& value = Get().vrFirstPersonRotation;
return value && IsSupportedVrFirstPersonRotation(*value) ? *value : std::move(fallback);
}
inline int32_t VrFirstPersonHiddenModel(int32_t fallback = kVrFirstPersonHiddenModelDefault) {
return std::clamp(Get().vrFirstPersonHiddenModel.value_or(fallback), -1, 31);
}