正确命名和处理lastTimeRenderWeaponIndex

This commit is contained in:
Light_Quanta 2025-03-11 05:33:47 +08:00
parent 45570b7aa3
commit e58c8292df
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -69,7 +69,7 @@ public class VehicleHudOverlay {
private static final long[] weaponSlotUpdateTime = new long[9]; private static final long[] weaponSlotUpdateTime = new long[9];
private static boolean lastTimeRenderingWeapons = false; private static boolean lastTimeRenderingWeapons = false;
private static int lastTimeWeaponIndex = -1; private static int lastTimeWeaponIndex = -1;
private static int renderLastTimeWeaponIndex = -1; private static int lastTimeRenderWeaponIndex = -1;
private static long weaponIndexUpdateTime = 0; private static long weaponIndexUpdateTime = 0;
public static final int ANIMATION_TIME = 300; public static final int ANIMATION_TIME = 300;
@ -472,6 +472,7 @@ public class VehicleHudOverlay {
// 若上一帧未在渲染武器信息则初始化动画相关变量 // 若上一帧未在渲染武器信息则初始化动画相关变量
if (!lastTimeRenderingWeapons) { if (!lastTimeRenderingWeapons) {
lastTimeWeaponIndex = weaponIndex; lastTimeWeaponIndex = weaponIndex;
lastTimeRenderWeaponIndex = weaponIndex;
weaponSlotUpdateTime[weaponIndex] = currentTime; weaponSlotUpdateTime[weaponIndex] = currentTime;
weaponIndexUpdateTime = currentTime; weaponIndexUpdateTime = currentTime;
@ -482,7 +483,7 @@ public class VehicleHudOverlay {
weaponSlotUpdateTime[weaponIndex] = currentTime; weaponSlotUpdateTime[weaponIndex] = currentTime;
weaponSlotUpdateTime[lastTimeWeaponIndex] = currentTime; weaponSlotUpdateTime[lastTimeWeaponIndex] = currentTime;
renderLastTimeWeaponIndex = lastTimeWeaponIndex; lastTimeRenderWeaponIndex = lastTimeWeaponIndex;
lastTimeWeaponIndex = weaponIndex; lastTimeWeaponIndex = weaponIndex;
weaponIndexUpdateTime = currentTime; weaponIndexUpdateTime = currentTime;
} }
@ -526,7 +527,7 @@ public class VehicleHudOverlay {
startXDiff = Mth.lerp(progress, xDiff, 0); startXDiff = Mth.lerp(progress, xDiff, 0);
var startY = Mth.lerp(progress, var startY = Mth.lerp(progress,
h - (weapons.size() - 1 - renderLastTimeWeaponIndex) * 18 - 16, h - (weapons.size() - 1 - lastTimeRenderWeaponIndex) * 18 - 16,
h - (weapons.size() - 1 - weaponIndex) * 18 - 16 h - (weapons.size() - 1 - weaponIndex) * 18 - 16
); );
@ -551,8 +552,8 @@ public class VehicleHudOverlay {
pose.popPose(); pose.popPose();
// 切换武器光标动画播放结束后更新上次选择槽位 // 切换武器光标动画播放结束后更新上次选择槽位
if (lastTimeWeaponIndex != renderLastTimeWeaponIndex && currentTime - weaponIndexUpdateTime > ANIMATION_TIME) { if (lastTimeWeaponIndex != lastTimeRenderWeaponIndex && currentTime - weaponIndexUpdateTime > ANIMATION_TIME) {
renderLastTimeWeaponIndex = lastTimeWeaponIndex; lastTimeRenderWeaponIndex = lastTimeWeaponIndex;
} }
lastTimeRenderingWeapons = true; lastTimeRenderingWeapons = true;
} }