Add joy_haptic_distance cvar.

Haptic maximum effect distance value, By default this cvar is `100.0`.
Any positive value is valid. E.g. effect of shot near barrel to barrel
has 58 points.
This commit is contained in:
Denis Pauk 2022-12-14 23:39:12 +02:00
parent e1aed62201
commit 4e36b66654
4 changed files with 22 additions and 8 deletions

View file

@ -547,7 +547,11 @@ Set `0` by default.
'calibrate' in the 'gamepad' -> 'gyro' menu to set them.
* **joy_haptic_magnitude**: Haptic magnitude value, By default this cvar
is `0.0` or disabled. Valid values are 0..1.0;
is `0.0` or disabled. Valid values are 0..1.0.
* **joy_haptic_distance**: Haptic maximum effect distance value, By default
this cvar is `100.0`. Any positive value is valid. E.g. effect of shot
near barrel to barrel has 58 points.
* **s_feedback_kind**: Select kind of controller feedback to use. By default
this cvar is `0`. Possible values:

View file

@ -289,7 +289,7 @@ void Controller_Rumble(const char *name, vec3_t source, qboolean from_player,
unsigned int duration, unsigned short int volume);
void Haptic_Feedback(const char *name, int effect_volume, int effect_duration,
int effect_delay, int effect_attack, int effect_fade,
int effect_x, int effect_y, int effect_z);
int effect_x, int effect_y, int effect_z, float effect_distance);
int Key_GetMenuKey(int key);
#endif

View file

@ -152,6 +152,7 @@ static cvar_t *joy_flick_smoothed;
// Joystick haptic
static cvar_t *joy_haptic_magnitude;
static cvar_t *joy_haptic_distance;
// Gyro mode (0=off, 3=on, 1-2=uses button to enable/disable)
cvar_t *gyro_mode;
@ -1702,27 +1703,35 @@ Haptic_Feedback_Filtered(const char *name, const char *filter)
* effect_volume=0..SHRT_MAX
* effect{x,y,z} - effect direction
* effect{delay,attack,fade} - effect durations
* effect_distance - distance to sound source
* name - sound file name
*/
void
Haptic_Feedback(const char *name, int effect_volume, int effect_duration,
int effect_delay, int effect_attack, int effect_fade,
int effect_x, int effect_y, int effect_z)
int effect_x, int effect_y, int effect_z, float effect_distance)
{
float max_distance = joy_haptic_distance->value;
if (!joystick_haptic || joy_haptic_magnitude->value <= 0 ||
max_distance <= 0 || /* skip haptic if distance is negative */
effect_distance > max_distance ||
effect_volume <= 0 || effect_duration <= 0 ||
last_haptic_effect_size <= 0) /* haptic but without slots? */
{
return;
}
if (last_haptic_volume != (int)(joy_haptic_magnitude->value * 255))
/* combine distance and volume */
effect_volume *= (max_distance - effect_distance) / max_distance;
if (last_haptic_volume != (int)(joy_haptic_magnitude->value * 16))
{
IN_Haptic_Effects_Shutdown();
IN_Haptic_Effects_Init();
}
last_haptic_volume = joy_haptic_magnitude->value * 255;
last_haptic_volume = joy_haptic_magnitude->value * 16;
if (Haptic_Feedback_Filtered(name, haptic_feedback_filter->string))
{
@ -2154,6 +2163,7 @@ IN_Init(void)
sensitivity = Cvar_Get("sensitivity", "3", CVAR_ARCHIVE);
joy_haptic_magnitude = Cvar_Get("joy_haptic_magnitude", "0.0", CVAR_ARCHIVE);
joy_haptic_distance = Cvar_Get("joy_haptic_distance", "100.0", CVAR_ARCHIVE);
haptic_feedback_filter = Cvar_Get("joy_haptic_filter", default_haptic_filter, CVAR_ARCHIVE);
joy_yawsensitivity = Cvar_Get("joy_yawsensitivity", "1.0", CVAR_ARCHIVE);

View file

@ -1149,16 +1149,16 @@ S_StartSound(vec3_t origin, int entnum, int entchannel, sfx_t *sfx,
}
/* sound near player has 16 points */
effect_volume = sfx->cache->volume / 16;
effect_volume = sfx->cache->volume;
/* remove silence duration in the end of sound effect */
effect_duration -= sfx->cache->end;
Haptic_Feedback(
sfx->name, (16 - distance_direction / 32) * effect_volume,
sfx->name, effect_volume,
effect_duration,
sfx->cache->begin, sfx->cache->attack, sfx->cache->fade,
dir_x, dir_y, dir_z);
dir_x, dir_y, dir_z, distance_direction);
}
}
else if (sfx->name[0] && s_feedback_kind->value == 0)