From 89fc9a618e2baea3205f6a0fea704d59927407c3 Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 2 Apr 2023 23:16:58 +0100 Subject: [PATCH] Rumble toggle attached to profile - Will silently merge conflict with !1093, make sure to adjust PROFILEVER handling - (profile_t *)->rumble - cv_rumble[MAXSPLITSCREENPLAYERS] - cv_dummyprofilerumble - Disables all current rumbles when toggling off - Prevents new rumbles from being set while turned off --- src/d_netcmd.c | 1 + src/g_game.c | 36 ++++++++++++++++++++++ src/g_input.c | 25 +++++++++++++++ src/g_input.h | 3 ++ src/k_menu.h | 1 + src/k_menufunc.c | 1 + src/k_profiles.c | 10 ++++++ src/k_profiles.h | 3 +- src/menus/options-profiles-1.c | 3 ++ src/menus/options-profiles-edit-controls.c | 6 ++++ 10 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 1c99d00cd..a7060a31d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1024,6 +1024,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_kickstartaccel[i]); CV_RegisterVar(&cv_shrinkme[i]); CV_RegisterVar(&cv_deadzone[i]); + CV_RegisterVar(&cv_rumble[i]); } // filesrch.c diff --git a/src/g_game.c b/src/g_game.c index 64d36527a..0adcbe98f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -353,6 +353,11 @@ static void weaponPrefChange2(void); static void weaponPrefChange3(void); static void weaponPrefChange4(void); +static void rumble_off_handle(void); +static void rumble_off_handle2(void); +static void rumble_off_handle3(void); +static void rumble_off_handle4(void); + // don't mind me putting these here, I was lazy to figure out where else I could put those without blowing up the compiler. // chat timer thingy @@ -445,6 +450,13 @@ consvar_t cv_deadzone[MAXSPLITSCREENPLAYERS] = { CVAR_INIT ("deadzone4", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL) }; +consvar_t cv_rumble[MAXSPLITSCREENPLAYERS] = { + CVAR_INIT ("rumble", "On", CV_SAVE|CV_CALL, CV_OnOff, rumble_off_handle), + CVAR_INIT ("rumble", "On", CV_SAVE|CV_CALL, CV_OnOff, rumble_off_handle2), + CVAR_INIT ("rumble", "On", CV_SAVE|CV_CALL, CV_OnOff, rumble_off_handle3), + CVAR_INIT ("rumble", "On", CV_SAVE|CV_CALL, CV_OnOff, rumble_off_handle4) +}; + // now automatically allocated in D_RegisterClientCommands // so that it doesn't have to be updated depending on the value of MAXPLAYERS char player_names[MAXPLAYERS][MAXPLAYERNAME+1]; @@ -1474,6 +1486,30 @@ static void weaponPrefChange4(void) WeaponPref_Send(3); } +static void rumble_off_handle(void) +{ + if (cv_rumble[0].value == 0) + G_ResetPlayerDeviceRumble(0); +} + +static void rumble_off_handle2(void) +{ + if (cv_rumble[1].value == 0) + G_ResetPlayerDeviceRumble(1); +} + +static void rumble_off_handle3(void) +{ + if (cv_rumble[2].value == 0) + G_ResetPlayerDeviceRumble(2); +} + +static void rumble_off_handle4(void) +{ + if (cv_rumble[3].value == 0) + G_ResetPlayerDeviceRumble(3); +} + // // G_DoLoadLevelEx // diff --git a/src/g_input.c b/src/g_input.c index ac6724087..5883cc36d 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -324,6 +324,11 @@ void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strengt { INT32 device_id; + if (cv_rumble[player].value == 0) + { + return; + } + device_id = G_GetDeviceForPlayer(player); if (device_id < 1) @@ -338,6 +343,11 @@ void G_PlayerDeviceRumbleTriggers(INT32 player, UINT16 left_strength, UINT16 rig { INT32 device_id; + if (cv_rumble[player].value == 0) + { + return; + } + device_id = G_GetDeviceForPlayer(player); if (device_id < 1) @@ -348,6 +358,21 @@ void G_PlayerDeviceRumbleTriggers(INT32 player, UINT16 left_strength, UINT16 rig I_GamepadRumbleTriggers(device_id, left_strength, right_strength); } +void G_ResetPlayerDeviceRumble(INT32 player) +{ + INT32 device_id; + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) + { + return; + } + + I_GamepadRumble(device_id, 0, 0); + I_GamepadRumbleTriggers(device_id, 0, 0); +} + void G_ResetAllDeviceRumbles(void) { int i; diff --git a/src/g_input.h b/src/g_input.h index 64f55653b..bd52d6ca4 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -157,8 +157,11 @@ void G_SetDeviceForPlayer(INT32 player, INT32 device); void G_SetPlayerGamepadIndicatorToPlayerColor(INT32 player); +extern consvar_t cv_rumble[MAXSPLITSCREENPLAYERS]; + void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength); void G_PlayerDeviceRumbleTriggers(INT32 player, UINT16 left_strength, UINT16 right_strength); +void G_ResetPlayerDeviceRumble(INT32 player); void G_ResetAllDeviceRumbles(void); /// Get the gamekeydown array (NUMINPUTS values) for the given device, or NULL if the device id is invalid. diff --git a/src/k_menu.h b/src/k_menu.h index cd7bbbe68..e1e4af6ce 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -945,6 +945,7 @@ extern INT16 controlleroffsets[][2]; extern consvar_t cv_dummyprofilename; extern consvar_t cv_dummyprofileplayername; extern consvar_t cv_dummyprofilekickstart; +extern consvar_t cv_dummyprofilerumble; void M_ResetOptions(void); void M_InitOptions(INT32 choice); // necessary for multiplayer since there's some options we won't want to access diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 4727f2fbe..fc16f606d 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -1171,6 +1171,7 @@ void M_Init(void) CV_RegisterVar(&cv_dummyprofilename); CV_RegisterVar(&cv_dummyprofileplayername); CV_RegisterVar(&cv_dummyprofilekickstart); + CV_RegisterVar(&cv_dummyprofilerumble); CV_RegisterVar(&cv_dummygpdifficulty); CV_RegisterVar(&cv_dummykartspeed); diff --git a/src/k_profiles.c b/src/k_profiles.c index aad3fd221..d43253dfa 100644 --- a/src/k_profiles.c +++ b/src/k_profiles.c @@ -88,6 +88,7 @@ profile_t* PR_MakeProfileFromPlayer(const char *prname, const char *pname, const // Player bound cvars: new->kickstartaccel = cv_kickstartaccel[pnum].value; + new->rumble = cv_rumble[pnum].value; return new; } @@ -277,6 +278,7 @@ void PR_SaveProfiles(void) // Consvars. WRITEUINT8(save.p, profilesList[i]->kickstartaccel); + WRITEUINT8(save.p, profilesList[i]->rumble); // Controls. for (j = 0; j < num_gamecontrols; j++) @@ -409,6 +411,14 @@ void PR_LoadProfiles(void) // Consvars. profilesList[i]->kickstartaccel = (boolean)READUINT8(save.p); + if (version < 4) + { + profilesList[i]->rumble = true; + } + else + { + profilesList[i]->rumble = (boolean)READUINT8(save.p); + } // Controls. for (j = 0; j < num_gamecontrols; j++) diff --git a/src/k_profiles.h b/src/k_profiles.h index c5e49bab9..06b880c42 100644 --- a/src/k_profiles.h +++ b/src/k_profiles.h @@ -31,7 +31,7 @@ extern "C" { #define SKINNAMESIZE 16 #define PROFILENAMELEN 6 -#define PROFILEVER 3 +#define PROFILEVER 4 #define MAXPROFILES 16 #define PROFILESFILE "ringprofiles.prf" #define PROFILE_GUEST 0 @@ -74,6 +74,7 @@ struct profile_t // Player-specific consvars. // @TODO: List all of those boolean kickstartaccel; // cv_kickstartaccel + boolean rumble; // cv_rumble // Finally, control data itself INT32 controls[num_gamecontrols][MAXINPUTMAPPING]; // Lists of all the controls, defined the same way as default inputs in g_input.c diff --git a/src/menus/options-profiles-1.c b/src/menus/options-profiles-1.c index 17d4c241b..311788bb1 100644 --- a/src/menus/options-profiles-1.c +++ b/src/menus/options-profiles-1.c @@ -30,6 +30,7 @@ menu_t OPTIONS_ProfilesDef = { consvar_t cv_dummyprofilename = CVAR_INIT ("dummyprofilename", "", CV_HIDDEN, NULL, NULL); consvar_t cv_dummyprofileplayername = CVAR_INIT ("dummyprofileplayername", "", CV_HIDDEN, NULL, NULL); consvar_t cv_dummyprofilekickstart = CVAR_INIT ("dummyprofilekickstart", "Off", CV_HIDDEN, CV_OnOff, NULL); +consvar_t cv_dummyprofilerumble = CVAR_INIT ("dummyprofilerumble", "On", CV_HIDDEN, CV_OnOff, NULL); void M_ProfileSelectInit(INT32 choice) { @@ -92,12 +93,14 @@ static void M_StartEditProfile(INT32 c) CV_StealthSet(&cv_dummyprofilename, optionsmenu.profile->profilename); CV_StealthSet(&cv_dummyprofileplayername, optionsmenu.profile->playername); CV_StealthSetValue(&cv_dummyprofilekickstart, optionsmenu.profile->kickstartaccel); + CV_StealthSetValue(&cv_dummyprofilerumble, optionsmenu.profile->rumble); } else { CV_StealthSet(&cv_dummyprofilename, ""); CV_StealthSet(&cv_dummyprofileplayername, ""); CV_StealthSetValue(&cv_dummyprofilekickstart, 0); // off + CV_StealthSetValue(&cv_dummyprofilerumble, 1); // on } // Setup greyout and stuff. diff --git a/src/menus/options-profiles-edit-controls.c b/src/menus/options-profiles-edit-controls.c index 779fc625c..f3dd23871 100644 --- a/src/menus/options-profiles-edit-controls.c +++ b/src/menus/options-profiles-edit-controls.c @@ -83,6 +83,9 @@ menuitem_t OPTIONS_ProfileControls[] = { {IT_HEADER, "TOGGLES", "For per-player commands", NULL, {NULL}, 0, 0}, + {IT_CONTROL | IT_CVAR, "RUMBLE", "For gamepad users - should your device rumble?", + NULL, {.cvar = &cv_dummyprofilerumble}, 0, 0}, + {IT_CONTROL | IT_CVAR, "KICKSTART ACCEL", "Hold A to auto-accel. Tap it to cancel.", NULL, {.cvar = &cv_dummyprofilekickstart}, 0, 0}, @@ -182,6 +185,7 @@ static void M_ProfileControlSaveResponse(INT32 choice) SINT8 belongsto = PR_ProfileUsedBy(optionsmenu.profile); // Save the profile optionsmenu.profile->kickstartaccel = cv_dummyprofilekickstart.value; + optionsmenu.profile->rumble = cv_dummyprofilerumble.value; memcpy(&optionsmenu.profile->controls, optionsmenu.tempcontrols, sizeof(gamecontroldefault)); // If this profile is in-use by anyone, apply the changes immediately upon exiting. @@ -190,6 +194,7 @@ static void M_ProfileControlSaveResponse(INT32 choice) { memcpy(&gamecontrol[belongsto], optionsmenu.tempcontrols, sizeof(gamecontroldefault)); CV_SetValue(&cv_kickstartaccel[belongsto], cv_dummyprofilekickstart.value); + CV_SetValue(&cv_rumble[belongsto], cv_dummyprofilerumble.value); } M_GoBack(0); @@ -206,6 +211,7 @@ void M_ProfileControlsConfirm(INT32 choice) M_ProfileControlSaveResponse(MA_YES); optionsmenu.profile->kickstartaccel = cv_dummyprofilekickstart.value; // Make sure to save kickstart accel. + optionsmenu.profile->rumble = cv_dummyprofilerumble.value; // And rumble too! // Reapply player 1's real profile. if (cv_currprofile.value > -1)