Skip to content

Commit

Permalink
Vita: -improved analog deadzone (radial, scaled)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Feb 9, 2017
1 parent 36d6748 commit 44dc42c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 54 deletions.
4 changes: 4 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Square = Backspace
Triangle = Toggle Shift

CHANGELOG:
1.49

-improved analog mouse deadzone (radial and scaled)

1.48

- cleaned up display menu
Expand Down
113 changes: 59 additions & 54 deletions src/od-joy.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
/*
* UAE - The Un*x Amiga Emulator
*
*
* Joystick emulation for Linux and BSD. They share too much code to
* split this file.
*
*
* Copyright 1997 Bernd Schmidt
* Copyright 1998 Krister Walfridsson
*/
Expand All @@ -20,6 +20,7 @@
#include "SDL.h"
#include "menu.h"
#include "menu_config.h"
#include "math.h"

#ifdef USE_UAE4ALL_VKBD
#include "vkbd.h"
Expand Down Expand Up @@ -84,7 +85,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)

// are we trying to figure out the regular GP2X controls for the primary (or both) joysticks?
int usingRegularControls = (!mainMenu_customControls) && ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1));

SDL_JoystickUpdate ();
/* Temporary disabled
#ifdef ANDROIDSDL
Expand Down Expand Up @@ -122,7 +123,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
if (((mainMenu_customControls && mainMenu_custom_dpad==2) || gp2xMouseEmuOn || (triggerL[0] && !triggerR[0] && !gp2xButtonRemappingOn)))
#endif
#endif
#endif
#endif
{
if (buttonY[0])
mouseScale = mainMenu_mouseMultiplier * 16;
Expand Down Expand Up @@ -155,7 +156,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
newmousecounters=1;
}
if (dpadUp[0])
{
{
lastmy -= mouseScale;
newmousecounters=1;
}
Expand All @@ -168,7 +169,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
else if (!triggerR[0] /*R+dpad = arrow keys*/ && !(mainMenu_customControls && mainMenu_custom_dpad==0) && usingRegularControls)
{
//regular direction controls for main Joystick (or both if "both" is set.)
#if !defined(AROS) && !defined(__PSP2__)
#if !defined(AROS) && !defined(__PSP2__)
if (dpadRight || SDL_JoystickGetAxis(joy, 0) > 0) right=1;
if (dpadLeft || SDL_JoystickGetAxis(joy, 0) < 0) left=1;
if (dpadUp || SDL_JoystickGetAxis(joy, 1) < 0) top=1;
Expand All @@ -190,25 +191,25 @@ void read_joystick(int nr, unsigned int *dir, int *button)
top = 1;
}
}
// regular button controls without custom remapping

// regular button controls without custom remapping
#ifdef USE_UAE4ALL_VKBD
if (usingRegularControls && !(gp2xMouseEmuOn) && !(gp2xButtonRemappingOn) && !vkbd_mode)
#else
if (usingRegularControls && !(gp2xMouseEmuOn) && !(gp2xButtonRemappingOn))
#endif
{
if (
(mainMenu_autofire & switch_autofire & delay>mainMenu_autofireRate)
||
(mainMenu_autofire & switch_autofire & delay>mainMenu_autofireRate)
||
(
(
(mainMenu_autofireButton1==GP2X_BUTTON_B && buttonA[0])
||
(mainMenu_autofireButton1==GP2X_BUTTON_X && buttonX[0])
||
(mainMenu_autofireButton1==GP2X_BUTTON_B && buttonA[0])
||
(mainMenu_autofireButton1==GP2X_BUTTON_X && buttonX[0])
||
(mainMenu_autofireButton1==GP2X_BUTTON_Y && buttonY[0])
)
)
& delay>mainMenu_autofireRate
)
)
Expand Down Expand Up @@ -240,10 +241,10 @@ void read_joystick(int nr, unsigned int *dir, int *button)
#endif
#endif //__PSP2__
}
}
}


//Analog Mouse
//Analog Mouse
#ifdef USE_UAE4ALL_VKBD
if (!vkbd_mode) {
#endif
Expand All @@ -253,33 +254,37 @@ void read_joystick(int nr, unsigned int *dir, int *button)
//This can be disabled in the menu because it interferes with Joystick Port 0
if (mainMenu_mouseEmulation)
{
int analogX=0;
int analogY=0;

float analogX=0.0f;
float analogY=0.0f;
float deadZone=(float) mainMenu_deadZone;
float scalingFactor=1.0f;
float magnitude=0.0f;

if (mainMenu_leftStickMouse)
{
analogX=lAnalogX;
analogY=lAnalogY;
analogX=(float) lAnalogX;
analogY=(float) lAnalogY;
}
else
else
{
analogX=rAnalogX;
analogY=rAnalogY;
analogX=(float) rAnalogX;
analogY=(float) rAnalogY;
}
//Deadzone
//radial and scaled deadzone
//http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html
//max movement is mouseScale.
//that way, when in one of the other mouse modes,
//that way, when in one of the other mouse modes,
//the Y button to change scale still works
if (!(analogX<mainMenu_deadZone && analogX>-mainMenu_deadZone))
{
lastmx += (int) (analogX/32769.0f * mouseScale);
newmousecounters=1;
}
if (!(analogY<mainMenu_deadZone && analogY>-mainMenu_deadZone))
{
lastmy += (int) (analogY/32769.0f * mouseScale);
newmousecounters=1;
}
magnitude=sqrt(analogX*analogX+analogY*analogY);
if (magnitude >= deadZone)
{
scalingFactor=(magnitude-deadZone)/(32769.0f-deadZone);
analogX = analogX * scalingFactor;
analogY = analogY * scalingFactor;
lastmx += (int) (analogX/32769.0f * mouseScale);
lastmy += (int) (analogY/32769.0f * mouseScale);
newmousecounters=1;
}
}
else
{
Expand All @@ -295,11 +300,11 @@ void read_joystick(int nr, unsigned int *dir, int *button)
#else
if(mainMenu_customControls)
#endif
{
{
for (int i=0; i<nr_joysticks; i++)
{
// The main Joystick mapping directions
if ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1))
if ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1))
{
if((mainMenu_custom_A[i]==-5 && buttonA[i]) || (mainMenu_custom_B[i]==-5 && buttonB[i]) || (mainMenu_custom_X[i]==-5 && buttonX[i]) || (mainMenu_custom_Y[i]==-5 && buttonY[i]) || (mainMenu_custom_L[i]==-5 && triggerL[i]) || (mainMenu_custom_R[i]==-5 && triggerR[i]))
top = 1;
Expand Down Expand Up @@ -382,7 +387,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
for (int i=0; i<nr_joysticks; i++)
{
//The main joystick mapping buttons
if ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1))
if ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1))
{
if((mainMenu_custom_A[i]==-3 && buttonA[i]) || (mainMenu_custom_B[i]==-3 && buttonB[i]) || (mainMenu_custom_X[i]==-3 && buttonX[i]) || (mainMenu_custom_Y[i]==-3 && buttonY[i]) || (mainMenu_custom_L[i]==-3 && triggerL[i]) || (mainMenu_custom_R[i]==-3 && triggerR[i]))
*button = 1;
Expand All @@ -409,7 +414,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
if((mainMenu_custom_up[i]==-1 && dpadUp[i]) || (mainMenu_custom_down[i]==-1 && dpadDown[i]) || (mainMenu_custom_left[i]==-1 && dpadLeft[i]) || (mainMenu_custom_right[i]==-1 && dpadRight[i]))
*button = 1;
}

if((mainMenu_custom_A[i]==-2 && buttonA[i]) || (mainMenu_custom_B[i]==-2 && buttonB[i]) || (mainMenu_custom_X[i]==-2 && buttonX[i]) || (mainMenu_custom_Y[i]==-2 && buttonY[i]) || (mainMenu_custom_L[i]==-2 && triggerL[i]) || (mainMenu_custom_R[i]==-2 && triggerR[i]))
*button |= 1 << 1;
else if(mainMenu_custom_dpad == 0)
Expand All @@ -422,12 +427,12 @@ void read_joystick(int nr, unsigned int *dir, int *button)
}
}
}

#ifdef USE_UAE4ALL_VKBD
if (vkbd_mode && nr)
{
// move around the virtual keyboard instead

// if Start+Dpad is used (or right analog stick on Vita)
// move the keyboard itself and/or change transparency
#ifdef __PSP2__
Expand All @@ -446,7 +451,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
{
vkbd_displace_down();
}
#ifdef __PSP2__
#ifdef __PSP2__
else if (rAnalogX < -1024*10)
#else
else if (buttonStart[0] && (dpadLeft[0] || left))
Expand All @@ -470,7 +475,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
can_change_vkbd_transparency=0;
}
}
else
else
{
can_change_vkbd_transparency=1;
if (left || dpadLeft[0])
Expand Down Expand Up @@ -521,7 +526,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
}
#endif
else //button release, make shift toggle possible again.
{
{
vkbd_can_switch_shift=1;
}
// TODO: add vkbd_button2 mapped to button2
Expand All @@ -537,7 +542,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
{
if (dpadRight[1])
right = 1;
else if (dpadLeft[1])
else if (dpadLeft[1])
left = 1;
if (dpadUp[1])
top = 1;
Expand All @@ -547,33 +552,33 @@ void read_joystick(int nr, unsigned int *dir, int *button)
*button |= 0x01;
if (buttonB[1])
*button |= (0x01 << 1);
}
}
#endif //__PSP2__
// normal joystick movement
// make sure it is impossible to press left + right etc
if (left)
top = !top;
if (right)
if (right)
bot = !bot;
*dir = bot | (right << 1) | (top << 8) | (left << 9);
}

#ifndef __PSP2__
#ifndef __PSP2__
//If not on Vita, zero the "other" joystick
if (!mainMenu_customControls)
{
if(mainMenu_joyPort != 0)
{
// Only one joystick active
// Only one joystick active
if((nr == 0 && mainMenu_joyPort == 2) || (nr == 1 && mainMenu_joyPort == 1))
{
*dir = 0;
*button = 0;
}
}
}


#endif //__PSP2__
#endif // MAXAUTOEVENTS
}
Expand Down

0 comments on commit 44dc42c

Please sign in to comment.