input_patches: fix cursor threshold and SFX during tutorial

This commit is contained in:
Hyper 2025-01-25 17:58:28 +00:00
parent 470d8f797b
commit fbc07d9579
2 changed files with 44 additions and 34 deletions

View file

@ -4,10 +4,12 @@
#include <app.h> #include <app.h>
#include <exports.h> #include <exports.h>
constexpr double WORLD_MAP_ROTATE_DEADZONE = 0.69999999;
constexpr double WORLD_MAP_CURSOR_DEADZONE = 0.30000001;
class WorldMapTouchParams class WorldMapTouchParams
{ {
public: public:
float CancelDeadzone{ 0.31f };
float Damping{ 0.99f }; float Damping{ 0.99f };
float FlickAccelX{ 0.25f }; float FlickAccelX{ 0.25f };
float FlickAccelY{ 0.1f }; float FlickAccelY{ 0.1f };
@ -149,7 +151,7 @@ g_sdlEventListenerForInputPatches;
// -------------- COMMON --------------- // // -------------- COMMON --------------- //
static bool IsDPadActive(SWA::SPadState* pPadState) static bool IsDPadThreshold(const SWA::SPadState* pPadState)
{ {
return pPadState->IsDown(SWA::eKeyState_DpadUp) || return pPadState->IsDown(SWA::eKeyState_DpadUp) ||
pPadState->IsDown(SWA::eKeyState_DpadDown) || pPadState->IsDown(SWA::eKeyState_DpadDown) ||
@ -157,6 +159,18 @@ static bool IsDPadActive(SWA::SPadState* pPadState)
pPadState->IsDown(SWA::eKeyState_DpadRight); pPadState->IsDown(SWA::eKeyState_DpadRight);
} }
static bool IsLeftStickThreshold(const SWA::SPadState* pPadState, double deadzone = 0)
{
return sqrtl((pPadState->LeftStickHorizontal * pPadState->LeftStickHorizontal) +
(pPadState->LeftStickVertical * pPadState->LeftStickVertical)) > deadzone;
}
static bool IsTouchThreshold(double deadzone = 0)
{
return sqrtl((g_worldMapTouchVelocityX * g_worldMapTouchVelocityX) +
(g_worldMapTouchVelocityY * g_worldMapTouchVelocityY)) > 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)
{ {
auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32); auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32);
@ -227,21 +241,32 @@ void PostureSpaceHurrierDPadSupportYMidAsmHook(PPCRegister& pPadState, PPCVRegis
// ------------- WORLD MAP ------------- // // ------------- WORLD MAP ------------- //
bool WorldMapTouchSupportMidAsmHook() bool WorldMapDeadzoneMidAsmHook(PPCRegister& pPadState)
{
auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32);
if (IsLeftStickThreshold(pGuestPadState))
{
g_worldMapTouchVelocityX = 0;
g_worldMapTouchVelocityY = 0;
}
else
{ {
SDLEventListenerForInputPatches::Update(App::s_deltaTime); SDLEventListenerForInputPatches::Update(App::s_deltaTime);
auto vxAbs = fabs(g_worldMapTouchVelocityX); auto vxAbs = fabs(g_worldMapTouchVelocityX);
auto vyAbs = fabs(g_worldMapTouchVelocityY); auto vyAbs = fabs(g_worldMapTouchVelocityY);
/* Reduce touch noise if the player has /* Reduce touch noise if the player has their finger
their finger resting on the touchpad, resting on the touchpad, but allow much precise values
but allow much precise values without without touch for proper interpolation to zero. */
touch for proper interpolation to zero. */ if (IsTouchThreshold(0.05))
if (vxAbs < 0.05f || vyAbs < 0.05f)
return !g_isTouchActive; return !g_isTouchActive;
return vxAbs > 0 || vyAbs > 0; return IsTouchThreshold();
}
return IsDPadThreshold(pGuestPadState) || IsLeftStickThreshold(pGuestPadState, WORLD_MAP_ROTATE_DEADZONE);
} }
bool WorldMapTouchMagnetismSupportMidAsmHook(PPCRegister& f0) bool WorldMapTouchMagnetismSupportMidAsmHook(PPCRegister& f0)
@ -253,16 +278,8 @@ void TouchAndDPadSupportWorldMapXMidAsmHook(PPCRegister& pPadState, PPCRegister&
{ {
auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32); auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32);
if (fabs(pGuestPadState->LeftStickHorizontal) > g_worldMapTouchParams.CancelDeadzone || if (IsDPadThreshold(pGuestPadState))
fabs(pGuestPadState->LeftStickVertical) > g_worldMapTouchParams.CancelDeadzone)
{ {
g_worldMapTouchVelocityX = 0;
}
if (IsDPadActive(pGuestPadState))
{
g_worldMapTouchVelocityX = 0;
SetDPadAnalogDirectionX(pPadState, x, false); SetDPadAnalogDirectionX(pPadState, x, false);
} }
else else
@ -276,16 +293,8 @@ void TouchAndDPadSupportWorldMapYMidAsmHook(PPCRegister& pPadState, PPCRegister&
{ {
auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32); auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32);
if (fabs(pGuestPadState->LeftStickHorizontal) > g_worldMapTouchParams.CancelDeadzone || if (IsDPadThreshold(pGuestPadState))
fabs(pGuestPadState->LeftStickVertical) > g_worldMapTouchParams.CancelDeadzone)
{ {
g_worldMapTouchVelocityY = 0;
}
if (IsDPadActive(pGuestPadState))
{
g_worldMapTouchVelocityY = 0;
SetDPadAnalogDirectionY(pPadState, y, false); SetDPadAnalogDirectionY(pPadState, y, false);
} }
else else
@ -313,7 +322,7 @@ PPC_FUNC(sub_8256C938)
{ {
auto pWorldMapCursor = (SWA::CWorldMapCursor*)g_memory.Translate(ctx.r3.u32); auto pWorldMapCursor = (SWA::CWorldMapCursor*)g_memory.Translate(ctx.r3.u32);
pWorldMapCursor->m_IsCursorMoving = g_isTouchActive; pWorldMapCursor->m_IsCursorMoving = g_isTouchActive && IsTouchThreshold(1.0);
if (ctx.r4.u8) if (ctx.r4.u8)
{ {
@ -340,7 +349,7 @@ PPC_FUNC(sub_8256C938)
pWorldMapCursor->m_LeftStickHorizontal = 1.0f; pWorldMapCursor->m_LeftStickHorizontal = 1.0f;
if (sqrtf((pWorldMapCursor->m_LeftStickHorizontal * pWorldMapCursor->m_LeftStickHorizontal) + if (sqrtf((pWorldMapCursor->m_LeftStickHorizontal * pWorldMapCursor->m_LeftStickHorizontal) +
(pWorldMapCursor->m_LeftStickVertical * pWorldMapCursor->m_LeftStickVertical)) > 0.7f) (pWorldMapCursor->m_LeftStickVertical * pWorldMapCursor->m_LeftStickVertical)) > WORLD_MAP_ROTATE_DEADZONE)
{ {
pWorldMapCursor->m_IsCursorMoving = true; pWorldMapCursor->m_IsCursorMoving = true;
} }

View file

@ -647,8 +647,9 @@ after_instruction = true
# SWA::CWorldMapCamera - disable rotation deadzone for touch # SWA::CWorldMapCamera - disable rotation deadzone for touch
[[midasm_hook]] [[midasm_hook]]
name = "WorldMapTouchSupportMidAsmHook" name = "WorldMapDeadzoneMidAsmHook"
address = 0x824862EC address = 0x824862EC
registers = ["r30"]
jump_address_on_true = 0x824862F0 jump_address_on_true = 0x824862F0
# SWA::CWorldMapCamera - disable flag magnetism for touch # SWA::CWorldMapCamera - disable flag magnetism for touch