Merge pull request #632 from lazd/joy_expo

Add UI to configure joystick sensitivity, support joystick expo
This commit is contained in:
Yamagi 2020-12-12 14:09:29 +01:00 committed by GitHub
commit 20ec2ba96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 205 additions and 25 deletions

View file

@ -295,6 +295,12 @@ extern cvar_t *cl_showmiss;
extern cvar_t *cl_showclamp;
extern cvar_t *lookstrafe;
extern cvar_t *sensitivity;
extern cvar_t *joy_expo;
extern cvar_t *joy_yawsensitivity;
extern cvar_t *joy_pitchsensitivity;
extern cvar_t *joy_forwardsensitivity;
extern cvar_t *joy_sidesensitivity;
extern cvar_t *joy_upsensitivity;
extern cvar_t *m_pitch;
extern cvar_t *m_yaw;
extern cvar_t *m_forward;

View file

@ -123,11 +123,12 @@ static int last_haptic_efffect_pos = 0;
static struct hapric_effects_cache last_haptic_efffect[HAPTIC_EFFECT_LAST];
// Joystick sensitivity
static cvar_t *joy_yawsensitivity;
static cvar_t *joy_pitchsensitivity;
static cvar_t *joy_forwardsensitivity;
static cvar_t *joy_sidesensitivity;
static cvar_t *joy_upsensitivity;
cvar_t *joy_yawsensitivity;
cvar_t *joy_pitchsensitivity;
cvar_t *joy_forwardsensitivity;
cvar_t *joy_sidesensitivity;
cvar_t *joy_upsensitivity;
cvar_t *joy_expo;
// Joystick direction settings
static cvar_t *joy_axis_leftx;
@ -681,6 +682,9 @@ IN_Update(void)
fix_value = 0.0f;
}
// Apply expo
fix_value = pow(fix_value, joy_expo->value);
axis_value = (int) (32767 * ((axis_value < 0) ? -fix_value : fix_value));
if (cls.key_dest == key_game && (int) cl_paused->value == 0)
@ -1348,6 +1352,7 @@ IN_Init(void)
joy_forwardsensitivity = Cvar_Get("joy_forwardsensitivity", "1.0", CVAR_ARCHIVE);
joy_sidesensitivity = Cvar_Get("joy_sidesensitivity", "1.0", CVAR_ARCHIVE);
joy_upsensitivity = Cvar_Get("joy_upsensitivity", "1.0", CVAR_ARCHIVE);
joy_expo = Cvar_Get("joy_expo", "2.0", CVAR_ARCHIVE);
joy_axis_leftx = Cvar_Get("joy_axis_leftx", "sidemove", CVAR_ARCHIVE);
joy_axis_lefty = Cvar_Get("joy_axis_lefty", "forwardmove", CVAR_ARCHIVE);

View file

@ -59,6 +59,7 @@ static void M_Menu_DMOptions_f(void);
static void M_Menu_Video_f(void);
static void M_Menu_Options_f(void);
static void M_Menu_Keys_f(void);
static void M_Menu_Joy_f(void);
static void M_Menu_Quit_f(void);
void M_Menu_Credits(void);
@ -801,6 +802,7 @@ int keys_cursor;
static int bind_grab;
static menuframework_s s_keys_menu;
static menuframework_s s_joy_menu;
static menuaction_s s_keys_actions[NUM_BINDNAMES];
static void
@ -1011,6 +1013,178 @@ M_Menu_Keys_f(void)
M_PushMenu(Keys_MenuDraw, Keys_MenuKey);
}
/*
* JOY MENU
*/
static menuslider_s s_joy_expo_slider;
static menuslider_s s_joy_yawsensitivity_slider;
static menuslider_s s_joy_pitchsensitivity_slider;
static menuslider_s s_joy_forwardsensitivity_slider;
static menuslider_s s_joy_sidesensitivity_slider;
static menuslider_s s_joy_upsensitivity_slider;
static menuslider_s s_joy_haptic_slider;
static void
HapticMagnitudeFunc(void *unused)
{
Cvar_SetValue("joy_haptic_magnitude", s_joy_haptic_slider.curvalue / 10.0F);
}
static void
JoyExpoFunc(void *unused)
{
Cvar_SetValue("joy_expo", s_joy_expo_slider.curvalue / 10.0F);
}
static void
JoyYawSensitivityFunc(void *unused)
{
Cvar_SetValue("joy_yawsensitivity", s_joy_yawsensitivity_slider.curvalue / 10.0F);
}
static void
JoyPitchSensitivityFunc(void *unused)
{
Cvar_SetValue("joy_pitchsensitivity", s_joy_pitchsensitivity_slider.curvalue / 10.0F);
}
static void
JoyForwardSensitivityFunc(void *unused)
{
Cvar_SetValue("joy_forwardsensitivity", s_joy_forwardsensitivity_slider.curvalue / 10.0F);
}
static void
JoySideSensitivityFunc(void *unused)
{
Cvar_SetValue("joy_sidesensitivity", s_joy_sidesensitivity_slider.curvalue / 10.0F);
}
static void
JoyUpSensitivityFunc(void *unused)
{
Cvar_SetValue("joy_upsensitivity", s_joy_upsensitivity_slider.curvalue / 10.0F);
}
static void
Joy_MenuInit(void)
{
extern qboolean show_haptic;
int y = 0;
s_joy_menu.x = (int)(viddef.width * 0.50f);
s_joy_menu.nitems = 0;
s_joy_yawsensitivity_slider.curvalue = joy_yawsensitivity->value * 10;
s_joy_yawsensitivity_slider.generic.type = MTYPE_SLIDER;
s_joy_yawsensitivity_slider.generic.x = 0;
s_joy_yawsensitivity_slider.generic.y = y;
y += 10;
s_joy_yawsensitivity_slider.generic.name = "yaw sensitivity";
s_joy_yawsensitivity_slider.generic.callback = JoyYawSensitivityFunc;
s_joy_yawsensitivity_slider.minvalue = 0;
s_joy_yawsensitivity_slider.maxvalue = 20;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_yawsensitivity_slider);
s_joy_pitchsensitivity_slider.curvalue = joy_pitchsensitivity->value * 10;
s_joy_pitchsensitivity_slider.generic.type = MTYPE_SLIDER;
s_joy_pitchsensitivity_slider.generic.x = 0;
s_joy_pitchsensitivity_slider.generic.y = y;
y += 10;
s_joy_pitchsensitivity_slider.generic.name = "pitch sensitivity";
s_joy_pitchsensitivity_slider.generic.callback = JoyPitchSensitivityFunc;
s_joy_pitchsensitivity_slider.minvalue = 0;
s_joy_pitchsensitivity_slider.maxvalue = 20;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_pitchsensitivity_slider);
y += 10;
s_joy_forwardsensitivity_slider.curvalue = joy_forwardsensitivity->value * 10;
s_joy_forwardsensitivity_slider.generic.type = MTYPE_SLIDER;
s_joy_forwardsensitivity_slider.generic.x = 0;
s_joy_forwardsensitivity_slider.generic.y = y;
y += 10;
s_joy_forwardsensitivity_slider.generic.name = "forward sensitivity";
s_joy_forwardsensitivity_slider.generic.callback = JoyForwardSensitivityFunc;
s_joy_forwardsensitivity_slider.minvalue = 0;
s_joy_forwardsensitivity_slider.maxvalue = 20;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_forwardsensitivity_slider);
s_joy_sidesensitivity_slider.curvalue = joy_sidesensitivity->value * 10;
s_joy_sidesensitivity_slider.generic.type = MTYPE_SLIDER;
s_joy_sidesensitivity_slider.generic.x = 0;
s_joy_sidesensitivity_slider.generic.y = y;
y += 10;
s_joy_sidesensitivity_slider.generic.name = "side sensitivity";
s_joy_sidesensitivity_slider.generic.callback = JoySideSensitivityFunc;
s_joy_sidesensitivity_slider.minvalue = 0;
s_joy_sidesensitivity_slider.maxvalue = 20;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_sidesensitivity_slider);
y += 10;
s_joy_upsensitivity_slider.curvalue = joy_upsensitivity->value * 10;
s_joy_upsensitivity_slider.generic.type = MTYPE_SLIDER;
s_joy_upsensitivity_slider.generic.x = 0;
s_joy_upsensitivity_slider.generic.y = y;
y += 10;
s_joy_upsensitivity_slider.generic.name = "up sensitivity";
s_joy_upsensitivity_slider.generic.callback = JoyUpSensitivityFunc;
s_joy_upsensitivity_slider.minvalue = 0;
s_joy_upsensitivity_slider.maxvalue = 20;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_upsensitivity_slider);
y += 10;
s_joy_expo_slider.curvalue = joy_expo->value * 10;
s_joy_expo_slider.generic.type = MTYPE_SLIDER;
s_joy_expo_slider.generic.x = 0;
s_joy_expo_slider.generic.y = y;
y += 10;
s_joy_expo_slider.generic.name = "expo";
s_joy_expo_slider.generic.callback = JoyExpoFunc;
s_joy_expo_slider.minvalue = 10;
s_joy_expo_slider.maxvalue = 50;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_expo_slider);
if (show_haptic) {
y += 10;
s_joy_haptic_slider.curvalue = Cvar_VariableValue("joy_haptic_magnitude") * 10.0F;
s_joy_haptic_slider.generic.type = MTYPE_SLIDER;
s_joy_haptic_slider.generic.x = 0;
s_joy_haptic_slider.generic.y = y;
y += 10;
s_joy_haptic_slider.generic.name = "haptic magnitude";
s_joy_haptic_slider.generic.callback = HapticMagnitudeFunc;
s_joy_haptic_slider.minvalue = 0;
s_joy_haptic_slider.maxvalue = 22;
Menu_AddItem(&s_joy_menu, (void *)&s_joy_haptic_slider);
}
Menu_Center(&s_joy_menu);
}
static void
Joy_MenuDraw(void)
{
Menu_AdjustCursor(&s_joy_menu, 1);
Menu_Draw(&s_joy_menu);
}
static const char *
Joy_MenuKey(int key)
{
return Default_MenuKey(&s_joy_menu, key);
}
static void
M_Menu_Joy_f(void)
{
Joy_MenuInit();
M_PushMenu(Joy_MenuDraw, Joy_MenuKey);
}
/*
* CONTROLS MENU
*/
@ -1018,6 +1192,7 @@ M_Menu_Keys_f(void)
static menuframework_s s_options_menu;
static menuaction_s s_options_defaults_action;
static menuaction_s s_options_customize_options_action;
static menuaction_s s_options_customize_joy_action;
static menuslider_s s_options_sensitivity_slider;
static menulist_s s_options_freelook_box;
static menulist_s s_options_alwaysrun_box;
@ -1025,7 +1200,6 @@ static menulist_s s_options_invertmouse_box;
static menulist_s s_options_lookstrafe_box;
static menulist_s s_options_crosshair_box;
static menuslider_s s_options_sfxvolume_slider;
static menuslider_s s_options_haptic_slider;
static menulist_s s_options_oggshuffle_box;
static menuslider_s s_options_oggvolume_slider;
static menulist_s s_options_oggenable_box;
@ -1038,18 +1212,18 @@ CrosshairFunc(void *unused)
Cvar_SetValue("crosshair", (float)s_options_crosshair_box.curvalue);
}
static void
HapticMagnitudeFunc(void *unused)
{
Cvar_SetValue("joy_haptic_magnitude", s_options_haptic_slider.curvalue / 10.0F);
}
static void
CustomizeControlsFunc(void *unused)
{
M_Menu_Keys_f();
}
static void
CustomizeJoyFunc(void *unused)
{
M_Menu_Joy_f();
}
static void
AlwaysRunFunc(void *unused)
{
@ -1098,7 +1272,6 @@ ControlsSetMenuItemValues(void)
s_options_lookstrafe_box.curvalue = (lookstrafe->value != 0);
s_options_freelook_box.curvalue = (freelook->value != 0);
s_options_crosshair_box.curvalue = ClampCvar(0, 3, crosshair->value);
s_options_haptic_slider.curvalue = Cvar_VariableValue("joy_haptic_magnitude") * 10.0F;
}
static void
@ -1269,7 +1442,6 @@ Options_MenuInit(void)
};
float scale = SCR_GetMenuScale();
extern qboolean show_haptic;
/* configure controls menu and menu items */
s_options_menu.x = viddef.width / 2;
@ -1318,7 +1490,7 @@ Options_MenuInit(void)
s_options_sensitivity_slider.generic.y = 60;
s_options_sensitivity_slider.generic.name = "mouse speed";
s_options_sensitivity_slider.generic.callback = MouseSpeedFunc;
s_options_sensitivity_slider.minvalue = 2;
s_options_sensitivity_slider.minvalue = 0;
s_options_sensitivity_slider.maxvalue = 22;
s_options_alwaysrun_box.generic.type = MTYPE_SPINCONTROL;
@ -1356,13 +1528,11 @@ Options_MenuInit(void)
s_options_crosshair_box.generic.callback = CrosshairFunc;
s_options_crosshair_box.itemnames = crosshair_names;
s_options_haptic_slider.generic.type = MTYPE_SLIDER;
s_options_haptic_slider.generic.x = 0;
s_options_haptic_slider.generic.y = 120;
s_options_haptic_slider.generic.name = "haptic magnitude";
s_options_haptic_slider.generic.callback = HapticMagnitudeFunc;
s_options_haptic_slider.minvalue = 0;
s_options_haptic_slider.maxvalue = 22;
s_options_customize_joy_action.generic.type = MTYPE_ACTION;
s_options_customize_joy_action.generic.x = 0;
s_options_customize_joy_action.generic.y = 130;
s_options_customize_joy_action.generic.name = "customize joystick";
s_options_customize_joy_action.generic.callback = CustomizeJoyFunc;
s_options_customize_options_action.generic.type = MTYPE_ACTION;
s_options_customize_options_action.generic.x = 0;
@ -1397,9 +1567,7 @@ Options_MenuInit(void)
Menu_AddItem(&s_options_menu, (void *)&s_options_freelook_box);
Menu_AddItem(&s_options_menu, (void *)&s_options_crosshair_box);
if (show_haptic)
Menu_AddItem(&s_options_menu, (void *)&s_options_haptic_slider);
Menu_AddItem(&s_options_menu, (void *)&s_options_customize_joy_action);
Menu_AddItem(&s_options_menu, (void *)&s_options_customize_options_action);
Menu_AddItem(&s_options_menu, (void *)&s_options_defaults_action);
Menu_AddItem(&s_options_menu, (void *)&s_options_console_action);
@ -4755,6 +4923,7 @@ M_Init(void)
Cmd_AddCommand("menu_video", M_Menu_Video_f);
Cmd_AddCommand("menu_options", M_Menu_Options_f);
Cmd_AddCommand("menu_keys", M_Menu_Keys_f);
Cmd_AddCommand("menu_joy", M_Menu_Joy_f);
Cmd_AddCommand("menu_quit", M_Menu_Quit_f);
/* initialize the server address book cvars (adr0, adr1, ...)