diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 21:50:44 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 21:50:44 +0800 |
| commit | 5fa4418adb5076d9bd4f923817a36a8d78dffb5f (patch) | |
| tree | 37d98f2a921c7383f6e8bbd8f64b00a5c16b4570 /Minecraft.Client/Minecraft.cpp | |
| parent | 71daf43d998ba998e66740c3266184a853eb2856 (diff) | |
feat: implement per-frame mouse look for reduced input latency on Windows
Diffstat (limited to 'Minecraft.Client/Minecraft.cpp')
| -rw-r--r-- | Minecraft.Client/Minecraft.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 5e1a2119..ff8346be 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -1223,6 +1223,53 @@ void Minecraft::createPrimaryLocalPlayer(int iPad) } } +#ifdef _WINDOWS64 +void Minecraft::applyFrameMouseLook() +{ + // Per-frame mouse look: consume mouse deltas every frame instead of waiting + // for the 20Hz game tick. Apply the same delta to both xRot/yRot AND xRotO/yRotO + // so the render interpolation instantly reflects the change without waiting for a tick. + if (level == NULL) return; + + for (int i = 0; i < XUSER_MAX_COUNT; i++) + { + if (localplayers[i] == NULL) continue; + int iPad = localplayers[i]->GetXboxPad(); + if (iPad != 0) continue; // Mouse only applies to pad 0 + + if (!KMInput.IsCaptured()) continue; + if (localgameModes[iPad] == NULL) continue; + + float rawDx, rawDy; + KMInput.ConsumeMouseDelta(rawDx, rawDy); + if (rawDx == 0.0f && rawDy == 0.0f) continue; + + float mouseSensitivity = 0.5f; + float mdx = rawDx * mouseSensitivity; + float mdy = -rawDy * mouseSensitivity; + if (app.GetGameSettings(iPad, eGameSetting_ControlInvertLook)) + mdy = -mdy; + + // Apply 0.15f scaling (same as Entity::interpolateTurn / Entity::turn) + float dyaw = mdx * 0.15f; + float dpitch = -mdy * 0.15f; + + // Apply to both current and old rotation so render interpolation + // reflects the change immediately (no 50ms tick delay) + localplayers[i]->yRot += dyaw; + localplayers[i]->yRotO += dyaw; + localplayers[i]->xRot += dpitch; + localplayers[i]->xRotO += dpitch; + + // Clamp pitch + if (localplayers[i]->xRot < -90.0f) localplayers[i]->xRot = -90.0f; + if (localplayers[i]->xRot > 90.0f) localplayers[i]->xRot = 90.0f; + if (localplayers[i]->xRotO < -90.0f) localplayers[i]->xRotO = -90.0f; + if (localplayers[i]->xRotO > 90.0f) localplayers[i]->xRotO = 90.0f; + } +} +#endif + void Minecraft::run_middle() { static __int64 lastTime = 0; |
