From d97db8f2302b58cef877e413c741393c3e2dc069 Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 18 Aug 2024 19:40:58 +0100 Subject: [PATCH 1/2] Do not reapply P1's Profile in full in edit menu flow Prevents changing player skin/color cvar when backing out (resolves KartKrew/RingRacers#34) --- src/menus/options-profiles-edit-1.c | 9 ++------- src/menus/options-profiles-edit-controls.c | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/menus/options-profiles-edit-1.c b/src/menus/options-profiles-edit-1.c index 93d44049a..234a0efda 100644 --- a/src/menus/options-profiles-edit-1.c +++ b/src/menus/options-profiles-edit-1.c @@ -115,15 +115,10 @@ static void M_ProfileEditApply(void) CV_SetValue(&cv_fov[belongsto], cv_dummyprofilefov.value); } - // Reapply player 1's real profile. - // (And then we do this for P1 anyway. I didn't write - // this code so I'm not sure why it's doing this, but it - // can override cv_skin if forcecharacter is in effect! - // I suspect this is intended to set cv_currprofile. - // FIXME?) + // Reapply player 1's real profile ID. if (cv_currprofile.value > -1) { - PR_ApplyProfile(cv_lastprofile[0].value, 0); + PR_ApplyProfilePretend(cv_lastprofile[0].value, 0); } } diff --git a/src/menus/options-profiles-edit-controls.c b/src/menus/options-profiles-edit-controls.c index 3be0e117d..2c5dcec9e 100644 --- a/src/menus/options-profiles-edit-controls.c +++ b/src/menus/options-profiles-edit-controls.c @@ -278,10 +278,10 @@ void M_ProfileControlsConfirm(INT32 choice) M_ProfileControlSaveResponse(MA_YES); - // Reapply player 1's real profile. + // Reapply player 1's real profile ID. if (cv_currprofile.value > -1) { - PR_ApplyProfile(cv_lastprofile[0].value, 0); + PR_ApplyProfilePretend(cv_lastprofile[0].value, 0); } } From 012bbc6a746aa5cc4ac93a60ddaf8d0024a8c651 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 24 Aug 2024 15:43:54 +0100 Subject: [PATCH 2/2] 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.