Skip to content

Commit

Permalink
FF7: Add support for walk/run based on the left analogue position
Browse files Browse the repository at this point in the history
Fixes #523
  • Loading branch information
julianxhokaxhiu committed Feb 5, 2023
1 parent ef34288 commit e7474c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/ff7/field/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,20 @@ namespace ff7::field

void ff7_field_update_models_position(int key_input_status)
{
if (gamepad_analogue_intent == INTENT_RUN)
{
key_input_status |= 0x40;
ff7_externals.modules_global_object->current_key_input_status |= 0x40;
}

((void(*)(int))ff7_externals.field_update_models_positions)(key_input_status);

if (gamepad_analogue_intent == INTENT_RUN)
{
key_input_status &= ~0x40;
ff7_externals.modules_global_object->current_key_input_status &= ~0x40;
}

for(int model_idx = 0; model_idx < (int)(*ff7_externals.field_n_models); model_idx++)
{
// Reset movement frame index for all models if they are not walking/running
Expand Down
36 changes: 27 additions & 9 deletions src/ff7/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
{
// Reset
ZeroMemory(ff7_externals.gamepad_status, sizeof(ff7_gamepad_status));
gamepad_analogue_intent = INTENT_NONE;

if (simulate_OK_button)
{
Expand All @@ -278,10 +279,10 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
{
ff7_externals.gamepad_status->pos_x = gamepad.leftStickX;
ff7_externals.gamepad_status->pos_y = gamepad.leftStickY;
ff7_externals.gamepad_status->dpad_up = (gamepad.leftStickY > 0.5f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_UP); // UP
ff7_externals.gamepad_status->dpad_down = (gamepad.leftStickY < -0.5f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_DOWN); // DOWN
ff7_externals.gamepad_status->dpad_left = (gamepad.leftStickX < -0.5f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_LEFT); // LEFT
ff7_externals.gamepad_status->dpad_right = (gamepad.leftStickX > 0.5f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_RIGHT); // RIGHT
ff7_externals.gamepad_status->dpad_up = (gamepad.leftStickY > 0.25f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_UP); // UP
ff7_externals.gamepad_status->dpad_down = (gamepad.leftStickY < -0.25f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_DOWN); // DOWN
ff7_externals.gamepad_status->dpad_left = (gamepad.leftStickX < -0.25f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_LEFT); // LEFT
ff7_externals.gamepad_status->dpad_right = (gamepad.leftStickX > 0.25f) || gamepad.IsPressed(XINPUT_GAMEPAD_DPAD_RIGHT); // RIGHT
ff7_externals.gamepad_status->button1 = gamepad.IsPressed(XINPUT_GAMEPAD_X); // Square
ff7_externals.gamepad_status->button2 = gamepad.IsPressed(XINPUT_GAMEPAD_A); // Cross
ff7_externals.gamepad_status->button3 = gamepad.IsPressed(XINPUT_GAMEPAD_B); // Circle
Expand All @@ -300,7 +301,9 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
ff7_externals.gamepad_status->button12 = gamepad.IsPressed(XINPUT_GAMEPAD_RIGHT_THUMB); // R3
ff7_externals.gamepad_status->button13 = gamepad.IsPressed(0x400); // PS Button


// Update the player intent based on the analogue movement
if (abs(gamepad.leftStickX) > 0.75f || abs(gamepad.leftStickY) > 0.75f) gamepad_analogue_intent = INTENT_RUN;
else if(abs(gamepad.leftStickX) > 0.25f || abs(gamepad.leftStickY) > 0.25f) gamepad_analogue_intent = INTENT_WALK;
}
}
else if (gamehacks.canInputBeProcessed())
Expand All @@ -309,10 +312,10 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
{
ff7_externals.gamepad_status->pos_x = joystick.GetState()->lX;
ff7_externals.gamepad_status->pos_y = joystick.GetState()->lY;
ff7_externals.gamepad_status->dpad_up = (joystick.GetState()->lY < joystick.GetDeadZone(-0.5f)) || joystick.GetState()->rgdwPOV[0] == 0; // UP
ff7_externals.gamepad_status->dpad_down = (joystick.GetState()->lY > joystick.GetDeadZone(0.5f)) || joystick.GetState()->rgdwPOV[0] == 18000; // DOWN
ff7_externals.gamepad_status->dpad_left = (joystick.GetState()->lX < joystick.GetDeadZone(-0.5f)) || joystick.GetState()->rgdwPOV[0] == 27000; // LEFT
ff7_externals.gamepad_status->dpad_right = (joystick.GetState()->lX > joystick.GetDeadZone(0.5f)) || joystick.GetState()->rgdwPOV[0] == 9000; // RIGHT
ff7_externals.gamepad_status->dpad_up = (joystick.GetState()->lY < joystick.GetDeadZone(-0.25f)) || joystick.GetState()->rgdwPOV[0] == 0; // UP
ff7_externals.gamepad_status->dpad_down = (joystick.GetState()->lY > joystick.GetDeadZone(0.25f)) || joystick.GetState()->rgdwPOV[0] == 18000; // DOWN
ff7_externals.gamepad_status->dpad_left = (joystick.GetState()->lX < joystick.GetDeadZone(-0.25f)) || joystick.GetState()->rgdwPOV[0] == 27000; // LEFT
ff7_externals.gamepad_status->dpad_right = (joystick.GetState()->lX > joystick.GetDeadZone(0.25f)) || joystick.GetState()->rgdwPOV[0] == 9000; // RIGHT
ff7_externals.gamepad_status->button1 = joystick.GetState()->rgbButtons[0] & 0x80; // Square
ff7_externals.gamepad_status->button2 = joystick.GetState()->rgbButtons[1] & 0x80; // Cross
ff7_externals.gamepad_status->button3 = joystick.GetState()->rgbButtons[2] & 0x80; // Circle
Expand All @@ -330,6 +333,21 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
ff7_externals.gamepad_status->button11 = joystick.GetState()->rgbButtons[10] & 0x80; // L3
ff7_externals.gamepad_status->button12 = joystick.GetState()->rgbButtons[11] & 0x80; // R3
ff7_externals.gamepad_status->button13 = joystick.GetState()->rgbButtons[12] & 0x80; // PS Button

// Update the player intent based on the analogue movement
if (
(joystick.GetState()->lY < joystick.GetDeadZone(-0.75f)) ||
(joystick.GetState()->lY > joystick.GetDeadZone(0.75f)) ||
(joystick.GetState()->lX < joystick.GetDeadZone(-0.75f)) ||
(joystick.GetState()->lX > joystick.GetDeadZone(0.75f))
)
gamepad_analogue_intent = INTENT_RUN;
else if (
(joystick.GetState()->lY < joystick.GetDeadZone(-0.25f)) ||
(joystick.GetState()->lY > joystick.GetDeadZone(0.25f)) ||
(joystick.GetState()->lX < joystick.GetDeadZone(-0.25f)) ||
(joystick.GetState()->lX > joystick.GetDeadZone(0.25f))
) gamepad_analogue_intent = INTENT_WALK;
}
}

Expand Down

0 comments on commit e7474c8

Please sign in to comment.