input_patches: fix touchpad flag magnetism

This commit is contained in:
Hyper 2025-01-25 18:35:18 +00:00
parent fbc07d9579
commit 6a0062a3cc
2 changed files with 27 additions and 18 deletions

View file

@ -165,10 +165,15 @@ static bool IsLeftStickThreshold(const SWA::SPadState* pPadState, double deadzon
(pPadState->LeftStickVertical * pPadState->LeftStickVertical)) > deadzone; (pPadState->LeftStickVertical * pPadState->LeftStickVertical)) > deadzone;
} }
static bool IsTouchThreshold(double deadzone = 0) static bool IsTouchThreshold(double deadzone = 0, bool isBelowThreshold = false)
{ {
return sqrtl((g_worldMapTouchVelocityX * g_worldMapTouchVelocityX) + auto sqrt = sqrtl((g_worldMapTouchVelocityX * g_worldMapTouchVelocityX) +
(g_worldMapTouchVelocityY * g_worldMapTouchVelocityY)) > deadzone; (g_worldMapTouchVelocityY * g_worldMapTouchVelocityY));
if (isBelowThreshold)
return sqrt < deadzone;
return sqrt >= deadzone;
} }
static void SetDPadAnalogDirectionX(PPCRegister& pPadState, PPCRegister& x, bool invert, float max = 1.0f) static void SetDPadAnalogDirectionX(PPCRegister& pPadState, PPCRegister& x, bool invert, float max = 1.0f)
@ -254,13 +259,10 @@ bool WorldMapDeadzoneMidAsmHook(PPCRegister& pPadState)
{ {
SDLEventListenerForInputPatches::Update(App::s_deltaTime); SDLEventListenerForInputPatches::Update(App::s_deltaTime);
auto vxAbs = fabs(g_worldMapTouchVelocityX);
auto vyAbs = fabs(g_worldMapTouchVelocityY);
/* Reduce touch noise if the player has their finger /* Reduce touch noise if the player has their finger
resting on the touchpad, but allow much precise values resting on the touchpad, but allow much precise values
without touch for proper interpolation to zero. */ without touch for proper interpolation to zero. */
if (IsTouchThreshold(0.05)) if (IsTouchThreshold(0.05, true))
return !g_isTouchActive; return !g_isTouchActive;
return IsTouchThreshold(); return IsTouchThreshold();
@ -269,9 +271,17 @@ bool WorldMapDeadzoneMidAsmHook(PPCRegister& pPadState)
return IsDPadThreshold(pGuestPadState) || IsLeftStickThreshold(pGuestPadState, WORLD_MAP_ROTATE_DEADZONE); return IsDPadThreshold(pGuestPadState) || IsLeftStickThreshold(pGuestPadState, WORLD_MAP_ROTATE_DEADZONE);
} }
bool WorldMapTouchMagnetismSupportMidAsmHook(PPCRegister& f0) bool WorldMapMagnetismMidAsmHook(PPCRegister& f0)
{ {
return fabs(g_worldMapTouchVelocityX) > f0.f64 || fabs(g_worldMapTouchVelocityY) > f0.f64; if (IsTouchThreshold(f0.f64, true))
{
g_worldMapTouchVelocityX = 0;
g_worldMapTouchVelocityY = 0;
return true;
}
return false;
} }
void TouchAndDPadSupportWorldMapXMidAsmHook(PPCRegister& pPadState, PPCRegister& x) void TouchAndDPadSupportWorldMapXMidAsmHook(PPCRegister& pPadState, PPCRegister& x)
@ -282,10 +292,9 @@ void TouchAndDPadSupportWorldMapXMidAsmHook(PPCRegister& pPadState, PPCRegister&
{ {
SetDPadAnalogDirectionX(pPadState, x, false); SetDPadAnalogDirectionX(pPadState, x, false);
} }
else else if (fabs(g_worldMapTouchVelocityX) > 0)
{ {
if (fabs(g_worldMapTouchVelocityX) > 0) x.f64 = -g_worldMapTouchVelocityX;
x.f64 = -g_worldMapTouchVelocityX;
} }
} }
@ -297,10 +306,9 @@ void TouchAndDPadSupportWorldMapYMidAsmHook(PPCRegister& pPadState, PPCRegister&
{ {
SetDPadAnalogDirectionY(pPadState, y, false); SetDPadAnalogDirectionY(pPadState, y, false);
} }
else else if (fabs(g_worldMapTouchVelocityY) > 0)
{ {
if (fabs(g_worldMapTouchVelocityY) > 0) y.f64 = g_worldMapTouchVelocityY;
y.f64 = g_worldMapTouchVelocityY;
} }
} }
@ -348,7 +356,7 @@ PPC_FUNC(sub_8256C938)
if (rPadState.IsDown(SWA::eKeyState_DpadRight)) if (rPadState.IsDown(SWA::eKeyState_DpadRight))
pWorldMapCursor->m_LeftStickHorizontal = 1.0f; pWorldMapCursor->m_LeftStickHorizontal = 1.0f;
if (sqrtf((pWorldMapCursor->m_LeftStickHorizontal * pWorldMapCursor->m_LeftStickHorizontal) + if (sqrtl((pWorldMapCursor->m_LeftStickHorizontal * pWorldMapCursor->m_LeftStickHorizontal) +
(pWorldMapCursor->m_LeftStickVertical * pWorldMapCursor->m_LeftStickVertical)) > WORLD_MAP_ROTATE_DEADZONE) (pWorldMapCursor->m_LeftStickVertical * pWorldMapCursor->m_LeftStickVertical)) > WORLD_MAP_ROTATE_DEADZONE)
{ {
pWorldMapCursor->m_IsCursorMoving = true; pWorldMapCursor->m_IsCursorMoving = true;

View file

@ -654,10 +654,11 @@ jump_address_on_true = 0x824862F0
# SWA::CWorldMapCamera - disable flag magnetism for touch # SWA::CWorldMapCamera - disable flag magnetism for touch
[[midasm_hook]] [[midasm_hook]]
name = "WorldMapTouchMagnetismSupportMidAsmHook" name = "WorldMapMagnetismMidAsmHook"
address = 0x824866D4 address = 0x824866D4
registers = ["f0"] registers = ["f0"]
jump_address_on_true = 0x82486838 jump_address_on_true = 0x824866D8
jump_address_on_false = 0x82486838
# SWA::CWorldMapCamera - touch and D-Pad support for camera adjustment threshold on the X axis # SWA::CWorldMapCamera - touch and D-Pad support for camera adjustment threshold on the X axis
[[midasm_hook]] [[midasm_hook]]