Merge pull request #18 from petr666/feature/turning-as-mappable-command

WIP: Turning as mappable command
This commit is contained in:
Simon 2022-03-15 22:35:17 +00:00 committed by GitHub
commit 2566b8ecac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 226 additions and 154 deletions

View file

@ -155,8 +155,8 @@ static void Controls3_MenuEvent( void* ptr, int notification ) {
switch (s_controls3.controlschema.curvalue)
{
case 0: // Default schema
trap_Cvar_Set("vr_button_map_RTHUMBLEFT", ""); // empty ~ turn left
trap_Cvar_Set("vr_button_map_RTHUMBRIGHT", ""); // empty ~ turn right
trap_Cvar_Set("vr_button_map_RTHUMBLEFT", "turnleft"); // turn left
trap_Cvar_Set("vr_button_map_RTHUMBRIGHT", "turnright"); // turn right
trap_Cvar_Set("vr_button_map_RTHUMBFORWARD", "weapnext"); // next weapon
if (s_controls3.uturn.curvalue) {
trap_Cvar_Set("vr_button_map_RTHUMBBACK", "uturn"); // u-turn
@ -190,18 +190,18 @@ static void Controls3_MenuEvent( void* ptr, int notification ) {
trap_Cvar_Set("vr_button_map_RTHUMBFORWARDLEFT", "+weapon_select");
trap_Cvar_Set("vr_button_map_PRIMARYTHUMBSTICK", "+weapon_select");
trap_Cvar_Set("vr_button_map_PRIMARYGRIP", "+alt"); // switch to alt layout
trap_Cvar_Set("vr_button_map_RTHUMBLEFT_ALT", ""); // empty ~ turn left
trap_Cvar_Set("vr_button_map_RTHUMBRIGHT_ALT", ""); // empty ~ turn right
trap_Cvar_Set("vr_button_map_RTHUMBLEFT_ALT", "turnleft"); // turn left
trap_Cvar_Set("vr_button_map_RTHUMBRIGHT_ALT", "turnright"); // turn right
trap_Cvar_Set("vr_button_map_RTHUMBFORWARD_ALT", "weapnext");
if (s_controls3.uturn.curvalue) {
trap_Cvar_Set("vr_button_map_RTHUMBBACK_ALT", "uturn");
} else {
trap_Cvar_Set("vr_button_map_RTHUMBBACK_ALT", "weapprev");
}
trap_Cvar_Set("vr_button_map_RTHUMBFORWARDRIGHT_ALT", ""); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBBACKRIGHT_ALT", ""); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBBACKLEFT_ALT", ""); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBFORWARDLEFT_ALT", ""); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBFORWARDRIGHT_ALT", "blank"); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBBACKRIGHT_ALT", "blank"); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBBACKLEFT_ALT", "blank"); // unmapped
trap_Cvar_Set("vr_button_map_RTHUMBFORWARDLEFT_ALT", "blank"); // unmapped
break;
}
}

View file

@ -101,8 +101,8 @@ void VR_InitCvars( void )
qboolean uturnEnabled = Cvar_VariableValue( "vr_uturn" ) != 0;
int controlSchema = (int)Cvar_VariableValue( "vr_controlSchema" ) % 2;
if (controlSchema == 0) {
Cvar_Get ("vr_button_map_RTHUMBLEFT", "", CVAR_ARCHIVE); // empty ~ turn left
Cvar_Get ("vr_button_map_RTHUMBRIGHT", "", CVAR_ARCHIVE); // empty ~ turn right
Cvar_Get ("vr_button_map_RTHUMBLEFT", "turnleft", CVAR_ARCHIVE); // turn left
Cvar_Get ("vr_button_map_RTHUMBRIGHT", "turnright", CVAR_ARCHIVE); // turn right
Cvar_Get ("vr_button_map_RTHUMBFORWARD", "weapnext", CVAR_ARCHIVE); // next weapon
if (uturnEnabled) {
Cvar_Get ("vr_button_map_RTHUMBBACK", "uturn", CVAR_ARCHIVE); // u-turn
@ -135,18 +135,18 @@ void VR_InitCvars( void )
Cvar_Get ("vr_button_map_RTHUMBFORWARDLEFT", "+weapon_select", CVAR_ARCHIVE);
Cvar_Get ("vr_button_map_PRIMARYTHUMBSTICK", "+weapon_select", CVAR_ARCHIVE);
Cvar_Get ("vr_button_map_PRIMARYGRIP", "+alt", CVAR_ARCHIVE); // switch to alt layout
Cvar_Get ("vr_button_map_RTHUMBLEFT_ALT", "", CVAR_ARCHIVE); // empty ~ turn left
Cvar_Get ("vr_button_map_RTHUMBRIGHT_ALT", "", CVAR_ARCHIVE); // empty ~ turn right
Cvar_Get ("vr_button_map_RTHUMBLEFT_ALT", "turnleft", CVAR_ARCHIVE); // turn left
Cvar_Get ("vr_button_map_RTHUMBRIGHT_ALT", "turnright", CVAR_ARCHIVE); // turn right
Cvar_Get ("vr_button_map_RTHUMBFORWARD_ALT", "weapnext", CVAR_ARCHIVE);
if (uturnEnabled) {
Cvar_Get ("vr_button_map_RTHUMBBACK_ALT", "uturn", CVAR_ARCHIVE);
} else {
Cvar_Get ("vr_button_map_RTHUMBBACK_ALT", "weapprev", CVAR_ARCHIVE);
}
Cvar_Get ("vr_button_map_RTHUMBFORWARDRIGHT_ALT", "", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBBACKRIGHT_ALT", "", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBBACKLEFT_ALT", "", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBFORWARDLEFT_ALT", "", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBFORWARDRIGHT_ALT", "blank", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBBACKRIGHT_ALT", "blank", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBBACKLEFT_ALT", "blank", CVAR_ARCHIVE); // unmapped
Cvar_Get ("vr_button_map_RTHUMBFORWARDLEFT_ALT", "blank", CVAR_ARCHIVE); // unmapped
}
//Remaining button mapping (buttons not affected by schemas)

View file

@ -243,12 +243,16 @@ static void VR_processHaptics() {
}
}
static void IN_SendButtonAction(const char* action, qboolean pressed, qboolean isThumbstickAxis)
// Returns true in case button press should be auto-repeated when holding (now only applicable for smooth-turn)
static qboolean IN_SendButtonAction(const char* action, qboolean pressed, qboolean isThumbstickAxis, float axisValue)
{
if (action)
{
//handle our special actions first
if (strcmp(action, "+alt") == 0)
if (strcmp(action, "blank") == 0) {
// empty function to block alt fallback on unmapped alt buttons
}
else if (strcmp(action, "+alt") == 0)
{
alt_key_mode_active = pressed;
}
@ -279,7 +283,41 @@ static void IN_SendButtonAction(const char* action, qboolean pressed, qboolean i
}
else if (pressed)
{
if (strcmp(action, "uturn") == 0) {
if (strcmp(action, "turnleft") == 0) {
if (vr_snapturn->integer > 0) { // snap turn
int snap = 45;
if (vr_snapturn->integer > 1) {
snap = vr_snapturn->integer;
}
CL_SnapTurn(-snap);
} else { // yaw (smooth turn)
// TODO How to disable this once enabled?
// (In this method i do not know to which button it is assigned and
// since i need to invoke the button repeatedly, i will not receive
// the "pressed=false" event)
// vr.smooth_turning = true;
float value = (isThumbstickAxis ? axisValue : 1.0f) * cl_sensitivity->value * m_yaw->value;
Com_QueueEvent(in_vrEventTime, SE_MOUSE, -value, 0, 0, NULL);
return qtrue;
}
} else if (strcmp(action, "turnright") == 0) {
if (vr_snapturn->integer > 0) { // snap turn
int snap = 45;
if (vr_snapturn->integer > 1) {
snap = vr_snapturn->integer;
}
CL_SnapTurn(snap);
} else { // yaw (smooth turn)
// TODO How to disable this once enabled?
// (In this method i do not know to which button it is assigned and
// since i need to invoke the button repeatedly, i will not receive
// the "pressed=false" event)
// vr.smooth_turning = true;
float value = (isThumbstickAxis ? axisValue : 1.0f) * cl_sensitivity->value * m_yaw->value;
Com_QueueEvent(in_vrEventTime, SE_MOUSE, value, 0, 0, NULL);
return qtrue;
}
} else if (strcmp(action, "uturn") == 0) {
CL_SnapTurn(180);
} else {
char command[256];
@ -288,6 +326,7 @@ static void IN_SendButtonAction(const char* action, qboolean pressed, qboolean i
}
}
}
return qfalse;
}
void VR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight )
@ -351,25 +390,21 @@ void VR_HapticEvent(const char* event, int position, int flags, int intensity, f
static qboolean IN_GetButtonAction(const char* button, char* action)
{
char cvarname[256];
if (alt_key_mode_active) {
Com_sprintf(cvarname, 256, "vr_button_map_%s_ALT", button);
} else {
Com_sprintf(cvarname, 256, "vr_button_map_%s", button);
}
Com_sprintf(cvarname, 256, "vr_button_map_%s%s", button, alt_key_mode_active ? "_ALT" : "");
char * val = Cvar_VariableString(cvarname);
if (val && strlen(val) > 0)
{
Com_sprintf(action, 256, "%s", val);
return qtrue;
}
else if (alt_key_mode_active)
//If we didn't find something for this button and the alt key is active, then see if the un-alt key has a function
if (alt_key_mode_active)
{
// No action found for buttom ALT mapping. Check if we are not
// holding ALT key itself (there is no ALT function for ALT)
Com_sprintf(cvarname, 256, "vr_button_map_%s", button);
char * val = Cvar_VariableString(cvarname);
if (val && strcmp(val, "+alt") == 0) {
if (val && strlen(val) > 0)
{
Com_sprintf(action, 256, "%s", val);
return qtrue;
}
@ -524,18 +559,18 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
}
else if (!vr.weapon_select) //right controller
{
float absoluteAxisValue = sqrt(joystickY*joystickY + joystickX*joystickX);
// up, up-left, up-right (use release threshold to be more sensitive)
if (joystickY > releasedThreshold) {
// stop left & right
vr.smooth_turning = false;
if ((controller->axisButtons & VR_TOUCH_AXIS_LEFT) && IN_GetButtonAction("RTHUMBLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_LEFT;
if ((controller->axisButtons & VR_TOUCH_AXIS_RIGHT) && IN_GetButtonAction("RTHUMBRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_RIGHT;
@ -543,19 +578,22 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
if (joystickX < -releasedThreshold) {
// stop up
if ((controller->axisButtons & VR_TOUCH_AXIS_UP) && IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UP;
// stop up-right
if ((controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT) && IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPRIGHT;
// start up-left
if (!(controller->axisButtons & VR_TOUCH_AXIS_UPLEFT)) {
controller->axisButtons |= VR_TOUCH_AXIS_UPLEFT;
if (IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qtrue, qtrue);
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_UPLEFT;
};
} else {
controller->axisButtons |= VR_TOUCH_AXIS_UPLEFT;
}
}
@ -563,19 +601,22 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else if (joystickX > releasedThreshold) {
// stop up
if ((controller->axisButtons & VR_TOUCH_AXIS_UP) && IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UP;
// stop up-left
if ((controller->axisButtons & VR_TOUCH_AXIS_UPLEFT) && IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPLEFT;
// start up-right
if (!(controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT)) {
controller->axisButtons |= VR_TOUCH_AXIS_UPRIGHT;
if (IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qtrue, qtrue);
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_UPRIGHT;
}
} else {
controller->axisButtons |= VR_TOUCH_AXIS_UPRIGHT;
}
}
@ -583,19 +624,22 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else {
// stop up-left
if ((controller->axisButtons & VR_TOUCH_AXIS_UPLEFT) && IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPLEFT;
// stop up-right
if ((controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT) && IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPRIGHT;
// start up
if (!(controller->axisButtons & VR_TOUCH_AXIS_UP) && joystickY > pressedThreshold) {
controller->axisButtons |= VR_TOUCH_AXIS_UP;
if (IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qtrue, qtrue);
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_UP;
}
} else {
controller->axisButtons |= VR_TOUCH_AXIS_UP;
}
}
}
@ -604,13 +648,12 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else if (joystickY < -releasedThreshold) {
// stop left & right
vr.smooth_turning = false;
if ((controller->axisButtons & VR_TOUCH_AXIS_LEFT) && IN_GetButtonAction("RTHUMBLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_LEFT;
if ((controller->axisButtons & VR_TOUCH_AXIS_RIGHT) && IN_GetButtonAction("RTHUMBRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_RIGHT;
@ -618,19 +661,22 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
if (joystickX < -releasedThreshold) {
// stop down
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWN) && IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWN;
// stop down-right
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT) && IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNRIGHT;
// start down-left
if (!(controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNLEFT;
if (IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qtrue, qtrue);
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNLEFT;
}
} else {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNLEFT;
}
}
@ -638,19 +684,22 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else if (joystickX > releasedThreshold) {
// stop down
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWN) && IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWN;
// stop down-left
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT) && IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNLEFT;
// start down-right
if (!(controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNRIGHT;
if (IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qtrue, qtrue);
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNRIGHT;
}
} else {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNRIGHT;
}
}
@ -658,19 +707,22 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else {
// stop down-left
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT) && IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNLEFT;
// stop down-right
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT) && IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNRIGHT;
// start down
if (!(controller->axisButtons & VR_TOUCH_AXIS_DOWN) && joystickY < -pressedThreshold) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWN;
if (IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qtrue, qtrue);
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWN;
}
} else {
controller->axisButtons |= VR_TOUCH_AXIS_DOWN;
}
}
}
@ -680,113 +732,67 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
// stop up-left
if ((controller->axisButtons & VR_TOUCH_AXIS_UPLEFT) && IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPLEFT;
// stop up
if ((controller->axisButtons & VR_TOUCH_AXIS_UP) && IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UP;
// stop up-right
if ((controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT) && IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPRIGHT;
// stop down-left
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT) && IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNLEFT;
// stop down
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWN) && IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWN;
// stop down-right
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT) && IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNRIGHT;
// left
if (joystickX < -pressedThreshold) {
// left action
if (!(controller->axisButtons & VR_TOUCH_AXIS_LEFT)) {
if (IN_GetButtonAction("RTHUMBLEFT", action)) {
vr.smooth_turning = false;
if (!(controller->axisButtons & VR_TOUCH_AXIS_LEFT)) {
IN_SendButtonAction(action, qtrue, qtrue);
}
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_LEFT;
// yaw (snap turn)
} else if (vr_snapturn->integer > 0) {
vr.smooth_turning = false;
int snap = 45;
if (vr_snapturn->integer > 1) {
snap = vr_snapturn->integer;
}
if (!(controller->axisButtons & VR_TOUCH_AXIS_LEFT)) {
CL_SnapTurn(-snap);
}
// yaw (smooth turn)
} else {
vr.smooth_turning = true;
const float x = joystickX * cl_sensitivity->value * m_yaw->value;
Com_QueueEvent(in_vrEventTime, SE_MOUSE, x, 0, 0, NULL);
}
controller->axisButtons |= VR_TOUCH_AXIS_LEFT;
} else if (joystickX > -releasedThreshold) {
if (joystickX < releasedThreshold) {
vr.smooth_turning = false;
}
}
} else if (joystickX > -releasedThreshold) {
if ((controller->axisButtons & VR_TOUCH_AXIS_LEFT) && IN_GetButtonAction("RTHUMBLEFT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_LEFT;
}
// right
if (joystickX > pressedThreshold) {
// right action
if (!(controller->axisButtons & VR_TOUCH_AXIS_RIGHT)) {
if (IN_GetButtonAction("RTHUMBRIGHT", action)) {
vr.smooth_turning = false;
if (!(controller->axisButtons & VR_TOUCH_AXIS_RIGHT)) {
IN_SendButtonAction(action, qtrue, qtrue);
}
if (!IN_SendButtonAction(action, qtrue, qtrue, absoluteAxisValue)) {
controller->axisButtons |= VR_TOUCH_AXIS_RIGHT;
// yaw (snap turn)
} else if (vr_snapturn->integer > 0) {
vr.smooth_turning = false;
int snap = 45;
if (vr_snapturn->integer > 1) {
snap = vr_snapturn->integer;
}
if (!(controller->axisButtons & VR_TOUCH_AXIS_RIGHT)) {
CL_SnapTurn(snap);
}
// yaw (smooth turn)
} else {
vr.smooth_turning = true;
const float x = joystickX * cl_sensitivity->value * m_yaw->value;
Com_QueueEvent(in_vrEventTime, SE_MOUSE, x, 0, 0, NULL);
}
controller->axisButtons |= VR_TOUCH_AXIS_RIGHT;
} else if (joystickX < releasedThreshold) {
if (joystickX > -releasedThreshold) {
vr.smooth_turning = false;
}
}
} else if (joystickX < releasedThreshold) {
if ((controller->axisButtons & VR_TOUCH_AXIS_RIGHT) && IN_GetButtonAction("RTHUMBRIGHT", action)) {
IN_SendButtonAction(action, qfalse, qtrue);
IN_SendButtonAction(action, qfalse, qtrue, absoluteAxisValue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_RIGHT;
}
@ -830,10 +836,15 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
if (!(controller->axisButtons & VR_TOUCH_AXIS_TRIGGER_INDEX) &&
index > pressedThreshold)
{
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("PRIMARYTRIGGER", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
}
}
else
{
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
}
}
else if ((controller->axisButtons & VR_TOUCH_AXIS_TRIGGER_INDEX) &&
@ -842,7 +853,7 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
controller->axisButtons &= ~VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("PRIMARYTRIGGER", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
}
@ -853,10 +864,15 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
if (!(controller->axisButtons & VR_TOUCH_AXIS_TRIGGER_INDEX) &&
index > pressedThreshold)
{
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("SECONDARYTRIGGER", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
}
}
else
{
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
}
}
else if ((controller->axisButtons & VR_TOUCH_AXIS_TRIGGER_INDEX) &&
@ -865,14 +881,14 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
controller->axisButtons &= ~VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("SECONDARYTRIGGER", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
}
}
}
static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
static void IN_VRButtons( qboolean isRightController, uint32_t buttons )
{
char action[256];
@ -880,8 +896,10 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if ((buttons & ovrButton_Enter) && !(controller->buttons & ovrButton_Enter)) {
controller->buttons |= ovrButton_Enter;
Com_QueueEvent(in_vrEventTime, SE_KEY, K_ESCAPE, qtrue, 0, NULL);
} else if (!(buttons & ovrButton_Enter) && (controller->buttons & ovrButton_Enter)) {
controller->buttons &= ~ovrButton_Enter;
Com_QueueEvent(in_vrEventTime, SE_KEY, K_ESCAPE, qfalse, 0, NULL);
}
}
@ -892,15 +910,22 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("SECONDARYGRIP", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_GripTrigger;
}
}
else
{
controller->buttons |= ovrButton_GripTrigger;
}
}
else if (!(buttons & ovrButton_GripTrigger) &&
(controller->buttons & ovrButton_GripTrigger))
{
controller->buttons &= ~ovrButton_GripTrigger;
if (IN_GetButtonAction("SECONDARYGRIP", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
}
@ -910,15 +935,22 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("PRIMARYGRIP", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_GripTrigger;
}
}
else
{
controller->buttons |= ovrButton_GripTrigger;
}
}
else if (!(buttons & ovrButton_GripTrigger) &&
(controller->buttons & ovrButton_GripTrigger))
{
controller->buttons &= ~ovrButton_GripTrigger;
if (IN_GetButtonAction("PRIMARYGRIP", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
}
@ -929,14 +961,21 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_LThumb) && !(controller->buttons & ovrButton_LThumb)) {
if (IN_GetButtonAction("SECONDARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_LThumb;
}
}
else
{
controller->buttons |= ovrButton_LThumb;
}
vr.realign = 3;
} else if (!(buttons & ovrButton_LThumb) && (controller->buttons & ovrButton_LThumb)) {
controller->buttons &= ~ovrButton_LThumb;
if (IN_GetButtonAction("SECONDARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
}
@ -945,12 +984,19 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_RThumb) && !(controller->buttons & ovrButton_RThumb)) {
if (IN_GetButtonAction("PRIMARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_RThumb;
}
}
else
{
controller->buttons |= ovrButton_RThumb;
}
} else if (!(buttons & ovrButton_RThumb) && (controller->buttons & ovrButton_RThumb)) {
controller->buttons &= ~ovrButton_RThumb;
if (IN_GetButtonAction("PRIMARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
}
@ -960,21 +1006,29 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (cl.snap.ps.pm_flags & PMF_FOLLOW)
{
controller->buttons |= ovrButton_A;
Cbuf_AddText("cmd team spectator\n");
}
else
{
if (IN_GetButtonAction("A", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_A;
}
}
else
{
controller->buttons |= ovrButton_A;
}
}
}
else if (!(buttons & ovrButton_A) && (controller->buttons & ovrButton_A))
{
controller->buttons &= ~ovrButton_A;
if (IN_GetButtonAction("A", action) && !(cl.snap.ps.pm_flags & PMF_FOLLOW))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
@ -982,12 +1036,19 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_B) && !(controller->buttons & ovrButton_B)) {
if (IN_GetButtonAction("B", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_B;
}
}
else
{
controller->buttons |= ovrButton_B;
}
} else if (!(buttons & ovrButton_B) && (controller->buttons & ovrButton_B)) {
controller->buttons &= ~ovrButton_B;
if (IN_GetButtonAction("B", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
@ -1003,15 +1064,22 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("X", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_X;
}
}
else
{
controller->buttons |= ovrButton_X;
}
}
}
else if (!(buttons & ovrButton_X) && (controller->buttons & ovrButton_X))
{
controller->buttons &= ~ovrButton_X;
if (IN_GetButtonAction("X", action) && !(cl.snap.ps.pm_flags & PMF_FOLLOW))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
@ -1019,12 +1087,19 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_Y) && !(controller->buttons & ovrButton_Y)) {
if (IN_GetButtonAction("Y", action))
{
IN_SendButtonAction(action, qtrue, qfalse);
if (!IN_SendButtonAction(action, qtrue, qfalse, 0)) {
controller->buttons |= ovrButton_Y;
}
}
else
{
controller->buttons |= ovrButton_Y;
}
} else if (!(buttons & ovrButton_Y) && (controller->buttons & ovrButton_Y)) {
controller->buttons &= ~ovrButton_Y;
if (IN_GetButtonAction("Y", action))
{
IN_SendButtonAction(action, qfalse, qfalse);
IN_SendButtonAction(action, qfalse, qfalse, 0);
}
}
@ -1139,10 +1214,7 @@ void IN_VRInputFrame( void )
continue;
}
if (controller->buttons ^ state.Buttons) {
IN_VRButtonsChanged(isRight, state.Buttons);
}
IN_VRButtons(isRight, state.Buttons);
IN_VRController(isRight, remoteTracking);
IN_VRJoystick(isRight, state.Joystick.x, state.Joystick.y);
IN_VRTriggers(isRight, state.IndexTrigger);