Fix Vsync

This commit is contained in:
GabsPuNs
2026-05-20 16:40:07 -04:00
parent bbba35362d
commit 3d802ef86b
7 changed files with 212 additions and 257 deletions

View File

@@ -30,6 +30,7 @@ IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu()
m_pointerPos.y = 0.0f;
m_bPointerDrivenByMouse = false;
m_iLastMouseTickTimeNs = -1;
}
IUIScene_AbstractContainerMenu::~IUIScene_AbstractContainerMenu()
@@ -267,6 +268,20 @@ void IUIScene_AbstractContainerMenu::UpdateTooltips()
void IUIScene_AbstractContainerMenu::onMouseTick()
{
// Frame-rate independent cursor input, normalized to a 60Hz reference frame.
constexpr int64_t kMinDeltaNs = 1000000LL; // 1 ms
constexpr int64_t kMaxDeltaNs = 100000000LL; // 100 ms
int64_t iNowNs = System::nanoTime();
float fFrameScale = 1.0f;
if ( m_iLastMouseTickTimeNs > 0 )
{
int64_t iDeltaNs = std::clamp(iNowNs - m_iLastMouseTickTimeNs, kMinDeltaNs, kMaxDeltaNs);
fFrameScale = static_cast<float>(iDeltaNs) * 60.0f / 1000000000.0f;
}
m_iLastMouseTickTimeNs = iNowNs;
Minecraft *pMinecraft = Minecraft::GetInstance();
if( pMinecraft->localgameModes[getPad()] != nullptr)
{
@@ -423,8 +438,8 @@ void IUIScene_AbstractContainerMenu::onMouseTick()
// The SD/splitscreen scenes are approximately 0.6 times the size of the fullscreen on
if(!RenderManager.IsHiDef() || app.GetLocalPlayerCount() > 1) fInputScale *= 0.6f;
fInputX *= fInputScale;
fInputY *= fInputScale;
fInputX *= fInputScale * fFrameScale;
fInputY *= fInputScale * fFrameScale;
#ifdef USE_POINTER_ACCEL
m_fPointerAccelX += fInputX / 50.0f;
@@ -1269,7 +1284,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick()
// Offset back to image top left.
vPointerPos.x -= m_fPointerImageOffsetX;
vPointerPos.y -= m_fPointerImageOffsetY;
/*
// Update pointer position.
// 4J-PB - do not allow sub pixel positions or we get broken lines in box edges
@@ -1300,6 +1315,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick()
vPointerPos.x = static_cast<float>(floor(vPointerPos.x + 0.5f));
vPointerPos.y = static_cast<float>(floor(vPointerPos.y + 0.5f));
*/
m_pointerPos = vPointerPos;
adjustPointerForSafeZone();