Fix Vsync

This commit is contained in:
GabsPuNs
2026-05-20 16:40:07 -04:00
parent 76489fd42c
commit 4216b72ae2
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();

View File

@@ -153,6 +153,8 @@ protected:
int m_iConsectiveInputTicks;
int64_t m_iLastMouseTickTimeNs;
// Used for detecting quick "taps" in a direction, should jump cursor to next slot.
enum ETapState
{

View File

@@ -102,7 +102,26 @@ void UIControl_PlayerSkinPreview::tick()
}
}
}
if( m_currentAnimation == e_SkinPreviewAnimation_Attacking )
{
m_swingTime += 2;
if (m_swingTime >= (Player::SWING_DURATION * 3) )
m_swingTime = 0;
}
}
#ifdef SKIN_PREVIEW_BOB_ANIM
m_bobTick += 2;
if(m_bobTick >= 360*2)
m_bobTick = 0;
#endif
#ifdef SKIN_PREVIEW_WALKING_ANIM
m_walkAnimSpeedO = m_walkAnimSpeed;
m_walkAnimSpeed += (0.1f - m_walkAnimSpeed) * 0.4f * 2.0f;
m_walkAnimPos += m_walkAnimSpeed * 2.0f;
#endif
}
void UIControl_PlayerSkinPreview::SetTexture(const wstring &url, TEXTURE_NAME backupTexture)
@@ -259,11 +278,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
HumanoidModel *model = static_cast<HumanoidModel *>(renderer->getModel());
//getAttackAnim(mob, a);
//if (armor != nullptr) armor->attackTime = model->attackTime;
//model->riding = mob->isRiding();
//if (armor != nullptr) armor->riding = model->riding;
// 4J Stu - Remember to reset these values once the rendering is done if you add another one
model->attackTime = 0;
model->sneaking = false;
@@ -287,11 +301,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
break;
case e_SkinPreviewAnimation_Attacking:
model->holdingRightHand = true;
m_swingTime++;
if (m_swingTime >= (Player::SWING_DURATION * 3) )
{
m_swingTime = 0;
}
model->attackTime = m_swingTime / static_cast<float>(Player::SWING_DURATION * 3);
break;
default:
@@ -299,10 +308,9 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
};
}
float bodyRot = m_yRot; //(mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a);
float headRot = m_yRot; //(mob->yRotO + (mob->yRot - mob->yRotO) * a);
float headRotx = 0; //(mob->xRotO + (mob->xRot - mob->xRotO) * a);
float bodyRot = m_yRot;
float headRot = m_yRot;
float headRotx = 0;
//setupPosition(mob, x, y, z);
// is equivalent to
@@ -311,9 +319,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
//float bob = getBob(mob, a);
#ifdef SKIN_PREVIEW_BOB_ANIM
float bob = (m_bobTick + a)/2;
++m_bobTick;
if(m_bobTick>=360*2) m_bobTick = 0;
#else
float bob = 0.0f;
#endif
@@ -339,9 +344,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
#endif
#ifdef SKIN_PREVIEW_WALKING_ANIM
m_walkAnimSpeedO = m_walkAnimSpeed;
m_walkAnimSpeed += (0.1f - m_walkAnimSpeed) * 0.4f;
m_walkAnimPos += m_walkAnimSpeed;
float ws = m_walkAnimSpeedO + (m_walkAnimSpeed - m_walkAnimSpeedO) * a;
float wp = m_walkAnimPos - m_walkAnimSpeed * (1 - a);
#else
@@ -349,114 +351,35 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
float wp = 0;
#endif
if (ws > 1) ws = 1;
if (ws > 1)
ws = 1;
MemSect(31);
bindTexture(m_customTextureUrl, m_backupTexture);
MemSect(0);
glEnable(GL_ALPHA_TEST);
//model->prepareMobModel(mob, wp, ws, a);
model->render(nullptr, wp, ws, bob, headRot - bodyRot, headRotx, _scale, true);
/*for (int i = 0; i < MAX_ARMOR_LAYERS; i++)
{
if (prepareArmor(mob, i, a))
{
armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, true);
glDisable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
}
}*/
//additionalRendering(mob, a);
if (bindTexture(m_capeTextureUrl, L"" ))
{
glPushMatrix();
glTranslatef(0, 0, 2 / 16.0f);
double xd = 0;//(mob->xCloakO + (mob->xCloak - mob->xCloakO) * a) - (mob->xo + (mob->x - mob->xo) * a);
double yd = 0;//(mob->yCloakO + (mob->yCloak - mob->yCloakO) * a) - (mob->yo + (mob->y - mob->yo) * a);
double zd = 0;//(mob->zCloakO + (mob->zCloak - mob->zCloakO) * a) - (mob->zo + (mob->z - mob->zo) * a);
float flap = 0.0f;
float yr = 1;//mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a;
double xa = sin(yr * PI / 180);
double za = -cos(yr * PI / 180);
float flap = static_cast<float>(yd) * 10;
if (flap < -6) flap = -6;
if (flap > 32) flap = 32;
float lean = static_cast<float>(xd * xa + zd * za) * 100;
float lean2 = static_cast<float>(xd * za - zd * xa) * 100;
if (lean < 0) lean = 0;
//float pow = 1;//mob->oBob + (bob - mob->oBob) * a;
flap += 1;//sin((mob->walkDistO + (mob->walkDist - mob->walkDistO) * a) * 6) * 32 * pow;
flap += 1.0f;
if (model->sneaking)
{
flap += 25;
}
flap += 25.0f;
glRotatef(6.0f + lean / 2 + flap, 1, 0, 0);
glRotatef(lean2 / 2, 0, 0, 1);
glRotatef(-lean2 / 2, 0, 1, 0);
glRotatef(180, 0, 1, 0);
glRotatef(6.0f + flap, 1, 0, 0);
glRotatef(0, 0, 0, 1);
glRotatef(0, 0, 1, 0);
glRotatef(180.0f, 0, 1, 0);
model->renderCloak(1 / 16.0f,true);
glPopMatrix();
}
/*
float br = mob->getBrightness(a);
int overlayColor = getOverlayColor(mob, br, a);
if (((overlayColor >> 24) & 0xff) > 0 || mob->hurtTime > 0 || mob->deathTime > 0)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthFunc(GL_EQUAL);
// 4J - changed these renders to not use the compiled version of their models, because otherwise the render states set
// about (in particular the depth & alpha test) don't work with our command buffer versions
if (mob->hurtTime > 0 || mob->deathTime > 0)
{
glColor4f(br, 0, 0, 0.4f);
model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
for (int i = 0; i < MAX_ARMOR_LAYERS; i++)
{
if (prepareArmorOverlay(mob, i, a))
{
glColor4f(br, 0, 0, 0.4f);
armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
}
}
}
if (((overlayColor >> 24) & 0xff) > 0)
{
float r = ((overlayColor >> 16) & 0xff) / 255.0f;
float g = ((overlayColor >> 8) & 0xff) / 255.0f;
float b = ((overlayColor) & 0xff) / 255.0f;
float aa = ((overlayColor >> 24) & 0xff) / 255.0f;
glColor4f(r, g, b, aa);
model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
for (int i = 0; i < MAX_ARMOR_LAYERS; i++)
{
if (prepareArmorOverlay(mob, i, a))
{
glColor4f(r, g, b, aa);
armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
}
}
}
glDepthFunc(GL_LEQUAL);
glDisable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);
}
*/
glDisable(GL_RESCALE_NORMAL);
glEnable(GL_CULL_FACE);
@@ -464,7 +387,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou
glPopMatrix();
MemSect(31);
//renderName(mob, x, y, z);
MemSect(0);
// Reset the model values to stop the changes we made here affecting anything in game (like the player hand render)