Refactor how Profile cvar toggles are set when applying changes

Reduces the number of unique places to update when adding new ones
This commit is contained in:
toaster 2024-08-24 15:43:54 +01:00
parent d97db8f230
commit 012bbc6a74
3 changed files with 23 additions and 9 deletions

View file

@ -564,7 +564,7 @@ static void PR_ApplyProfile_Appearance(profile_t *p, UINT8 playernum)
static void PR_ApplyProfile_Settings(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_kickstartaccel[playernum], p->kickstartaccel);
CV_StealthSetValue(&cv_autoroulette[playernum], p->autoroulette); CV_StealthSetValue(&cv_autoroulette[playernum], p->autoroulette);
CV_StealthSetValue(&cv_litesteer[playernum], p->litesteer); CV_StealthSetValue(&cv_litesteer[playernum], p->litesteer);
@ -621,6 +621,21 @@ void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum)
PR_ApplyProfile_Appearance(p, 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) void PR_ApplyProfilePretend(UINT8 profilenum, UINT8 playernum)
{ {
profile_t *p = PR_GetProfile(profilenum); profile_t *p = PR_GetProfile(profilenum);

View file

@ -230,6 +230,11 @@ void PR_ApplyProfile(UINT8 profilenum, UINT8 playernum);
// Controls, kickstartaccel and "current profile" data is *not* modified. // Controls, kickstartaccel and "current profile" data is *not* modified.
void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum); 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) // PR_ApplyProfilePretend(UINT8 profilenum, UINT8 playernum)
// ONLY modifies "current profile" data. // ONLY modifies "current profile" data.
// Exists because any other option inteferes with rapid testing. // Exists because any other option inteferes with rapid testing.

View file

@ -103,16 +103,10 @@ static void M_ProfileEditApply(void)
optionsmenu.profile->fov = cv_dummyprofilefov.value; optionsmenu.profile->fov = cv_dummyprofilefov.value;
// If this profile is in-use by anyone, apply the changes immediately upon exiting. // 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) if (belongsto > -1 && belongsto < MAXSPLITSCREENPLAYERS)
{ {
extern consvar_t cv_fov[MAXSPLITSCREENPLAYERS]; PR_ApplyProfileToggles(optionsmenu.profilen, belongsto);
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);
} }
// Reapply player 1's real profile ID. // Reapply player 1's real profile ID.