modernize input

This commit is contained in:
univ committed 2026-08-26 19:03:52 -05:00
1 parent d3bfe54f73
commit 802b0ebfdf
2 files changed
+67 -38

No files matched your search

+66 -37
View File
@@ -7,6 +7,9 @@
#include "Input.h" #include "Input.h"
#include "..\Minecraft.Client\LocalPlayer.h" #include "..\Minecraft.Client\LocalPlayer.h"
#include "Options.h" #include "Options.h"
#ifdef _WINDOWS64
#include "Windows64/KBMInput.h"
#endif
Input::Input() Input::Input()
{ {
@@ -15,10 +18,10 @@ Input::Input()
wasJumping = false; wasJumping = false;
jumping = false; jumping = false;
sneaking = false; sneaking = false;
sprinting = false;
lReset = false; lReset = false;
rReset = false; rReset = false;
m_gamepadSneaking = false;
} }
void Input::tick(LocalPlayer *player) void Input::tick(LocalPlayer *player)
@@ -43,20 +46,12 @@ void Input::tick(LocalPlayer *player)
#ifdef _WINDOWS64 #ifdef _WINDOWS64
// WASD movement (combine with gamepad) if (iPad == 0 && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive())
if (iPad == 0)
{ {
float kbX = 0.0f, kbY = 0.0f; if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT) )
if (g_KBMInput.IsKeyDown('W')) kbY += 1.0f; kbXA = g_KBMInput.GetMoveX();
if (g_KBMInput.IsKeyDown('S')) kbY -= 1.0f; if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD) )
if (g_KBMInput.IsKeyDown('A')) kbX += 1.0f; // inverted like gamepad kbYA = g_KBMInput.GetMoveY();
if (g_KBMInput.IsKeyDown('D')) kbX -= 1.0f;
// Normalize diagonal
if (kbX != 0.0f && kbY != 0.0f) { kbX *= 0.707f; kbY *= 0.707f; }
if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT))
xa = max(min(xa + kbX, 1.0f), -1.0f);
if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD))
ya = max(min(ya + kbY, 1.0f), -1.0f);
} }
#endif #endif
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
@@ -81,16 +76,42 @@ void Input::tick(LocalPlayer *player)
{ {
if((player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_SNEAK_TOGGLE)) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE)) if((player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_SNEAK_TOGGLE)) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE))
{ {
m_gamepadSneaking=!m_gamepadSneaking; sneaking=!sneaking;
} }
} }
sneaking = m_gamepadSneaking;
#ifdef _WINDOWS64 #ifdef _WINDOWS64
// Keyboard hold-to-sneak (overrides gamepad toggle) if (iPad == 0 && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive())
if (iPad == 0 && g_KBMInput.IsKeyDown(VK_SHIFT) && !player->abilities.flying) {
sneaking = true; // Left Shift = sneak (hold to crouch)
#endif if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE))
{
if (!player->abilities.flying)
{
sneaking = g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_SNEAK);
}
}
// Ctrl + forward = sprint (hold to sprint, including while flying)
{
bool ctrlHeld = g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_SPRINT);
bool movingForward = (kbYA > 0.0f);
if (ctrlHeld && movingForward)
{
sprinting = true;
}
else
{
sprinting = false;
}
}
}
else if (iPad == 0)
{
sprinting = false;
}
#endif
if(sneaking) if(sneaking)
{ {
@@ -125,39 +146,47 @@ void Input::tick(LocalPlayer *player)
} }
tx = ty = 0.0f; tx = ty = 0.0f;
} }
player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed);
#ifdef _WINDOWS64 #ifdef _WINDOWS64
// Mouse look (added after stick-based turn) if (iPad == 0 && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive())
if (iPad == 0 && g_KBMInput.IsCaptured())
{ {
float mouseSensitivity = 1.25f; float mouseSensitivity = static_cast<float>(app.GetGameSettings(iPad, eGameSetting_Sensitivity_InGame)) / 100.0f;
float mdx = g_KBMInput.GetMouseDeltaX() * mouseSensitivity; float mouseLookScale = 5.0f;
float mdy = -g_KBMInput.GetMouseDeltaY() * mouseSensitivity; float mx = g_KBMInput.GetLookX(mouseSensitivity * mouseLookScale);
if (app.GetGameSettings(iPad, eGameSetting_ControlInvertLook)) float my = g_KBMInput.GetLookY(mouseSensitivity * mouseLookScale);
mdy = -mdy;
player->interpolateTurn(mdx, mdy); if ( app.GetGameSettings(iPad,eGameSetting_ControlInvertLook) )
{
my = -my;
}
turnX += mx;
turnY += my;
} }
#endif #endif
player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed);
//jumping = controller.isButtonPressed(0); //jumping = controller.isButtonPressed(0);
unsigned int jump = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP); unsigned int jump = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP);
if( jump > 0 && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) ) bool kbJump = false;
jumping = true;
else
jumping = false;
#ifdef _WINDOWS64 #ifdef _WINDOWS64
// Keyboard jump (Space) kbJump = (iPad == 0) && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive() && g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_JUMP);
if (iPad == 0 && g_KBMInput.IsKeyDown(VK_SPACE) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP))
jumping = true;
#endif #endif
if( (jump > 0 || kbJump) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) )
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
if (app.GetFreezePlayers()) jumping = false; if (app.GetFreezePlayers()) jumping = false;
#endif #endif
#ifdef _WINDOWS64
if (iPad == 0 && g_KBMInput.IsKeyPressed(VK_ESCAPE) && g_KBMInput.IsMouseGrabbed())
{
g_KBMInput.SetMouseGrabbed(false);
}
#endif
//OutputDebugString("INPUT: End input tick\n"); //OutputDebugString("INPUT: End input tick\n");
} }
+1 -1
View File
@@ -10,6 +10,7 @@ public:
bool wasJumping; bool wasJumping;
bool jumping; bool jumping;
bool sneaking; bool sneaking;
bool sprinting;
Input(); // 4J - added Input(); // 4J - added
@@ -19,5 +20,4 @@ private:
bool lReset; bool lReset;
bool rReset; bool rReset;
bool m_gamepadSneaking;
}; };