From 012bbc6a746aa5cc4ac93a60ddaf8d0024a8c651 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 24 Aug 2024 15:43:54 +0100 Subject: [PATCH] Refactor how Profile cvar toggles are set when applying changes Reduces the number of unique places to update when adding new ones --- src/k_profiles.cpp | 17 ++++++++++++++++- src/k_profiles.h | 5 +++++ src/menus/options-profiles-edit-1.c | 10 ++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/k_profiles.cpp b/src/k_profiles.cpp index 0b9425fcb..f054e84d3 100644 --- a/src/k_profiles.cpp +++ b/src/k_profiles.cpp @@ -564,7 +564,7 @@ static void PR_ApplyProfile_Appearance(profile_t *p, UINT8 playernum) static void PR_ApplyProfile_Settings(profile_t *p, UINT8 playernum) { - // toggles + // toggles -- be sure to also adjust M_ProfileEditApply CV_StealthSetValue(&cv_kickstartaccel[playernum], p->kickstartaccel); CV_StealthSetValue(&cv_autoroulette[playernum], p->autoroulette); CV_StealthSetValue(&cv_litesteer[playernum], p->litesteer); @@ -621,6 +621,21 @@ void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum) PR_ApplyProfile_Appearance(p, playernum); } +void PR_ApplyProfileToggles(UINT8 profilenum, UINT8 playernum) +{ + profile_t *p = PR_GetProfile(profilenum); + + // this CAN happen!! + if (p == NULL) + { + // no need to be as loud... + profilenum = 0; // make sure to set this so that the cvar is set properly. + p = PR_GetProfile(profilenum); + } + + PR_ApplyProfile_Settings(p, playernum); +} + void PR_ApplyProfilePretend(UINT8 profilenum, UINT8 playernum) { profile_t *p = PR_GetProfile(profilenum); diff --git a/src/k_profiles.h b/src/k_profiles.h index 247a08e9f..988101f98 100644 --- a/src/k_profiles.h +++ b/src/k_profiles.h @@ -230,6 +230,11 @@ void PR_ApplyProfile(UINT8 profilenum, UINT8 playernum); // Controls, kickstartaccel and "current profile" data is *not* modified. void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum); +// PR_ApplyProfileToggles(UINT8 profilenum, UINT8 playernum) +// Applies ONLY controls and kickstartaccel. +// Exposed for menu code exclusively. +void PR_ApplyProfileToggles(UINT8 profilenum, UINT8 playernum); + // PR_ApplyProfilePretend(UINT8 profilenum, UINT8 playernum) // ONLY modifies "current profile" data. // Exists because any other option inteferes with rapid testing. diff --git a/src/menus/options-profiles-edit-1.c b/src/menus/options-profiles-edit-1.c index 234a0efda..8bdd552c2 100644 --- a/src/menus/options-profiles-edit-1.c +++ b/src/menus/options-profiles-edit-1.c @@ -103,16 +103,10 @@ static void M_ProfileEditApply(void) optionsmenu.profile->fov = cv_dummyprofilefov.value; // If this profile is in-use by anyone, apply the changes immediately upon exiting. - // Don't apply the profile itself as that would lead to issues mid-game. + // Don't apply the full profile itself as that would lead to issues mid-game. if (belongsto > -1 && belongsto < MAXSPLITSCREENPLAYERS) { - extern consvar_t cv_fov[MAXSPLITSCREENPLAYERS]; - CV_SetValue(&cv_kickstartaccel[belongsto], cv_dummyprofilekickstart.value); - CV_SetValue(&cv_autoroulette[belongsto], cv_dummyprofileautoroulette.value); - CV_SetValue(&cv_litesteer[belongsto], cv_dummyprofilelitesteer.value); - CV_SetValue(&cv_autoring[belongsto], cv_dummyprofileautoring.value); - CV_SetValue(&cv_rumble[belongsto], cv_dummyprofilerumble.value); - CV_SetValue(&cv_fov[belongsto], cv_dummyprofilefov.value); + PR_ApplyProfileToggles(optionsmenu.profilen, belongsto); } // Reapply player 1's real profile ID.