Skip to content

Commit 4a5eda0

Browse files
committed
zoom: fps independent interpolation and disable duration setting
1 parent 2edde7f commit 4a5eda0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/main/java/com/lambda/mixin/render/GameRendererMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ private void injectShowFloatingItem(ItemStack floatingItem, CallbackInfo ci) {
7878

7979
@ModifyReturnValue(method = "getFov", at = @At("RETURN"))
8080
private float modifyGetFov(float original) {
81-
return original / Zoom.getCurrentZoom();
81+
return original / Zoom.getLerpedZoom();
8282
}
8383
}

src/main/kotlin/com/lambda/module/modules/render/Zoom.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ object Zoom : Module(
3232
) {
3333
private var zoom by setting("Zoom", 2f, 1f..10f, 0.1f)
3434
private val style by setting("Style", ZoomStyle.EaseOut)
35-
private val animationDuration by setting("Animation Duration", 1f, 0.1f..10f, 0.1f) { style != ZoomStyle.Instant }
35+
private val animationDuration by setting("Animation Duration", 200, 40..1500, 20, unit = "ms") { style != ZoomStyle.Instant }
36+
private val disableDuration by setting("Disable Duration", 100, 0..1500, 20, unit = "ms") { style != ZoomStyle.Instant }
3637
private val scroll by setting("Scroll", true)
3738
private val persistentScroll by setting("Persistent Scroll", false) { scroll }
3839
private val sensitivity by setting("Sensitivity", 0.2f, 0.1f..1f, 0.1f) { scroll }
@@ -44,11 +45,11 @@ object Zoom : Module(
4445
}
4546
@JvmStatic val targetZoom: Float
4647
get() = zoom + extraZoom
47-
48-
@JvmStatic var currentZoom = 1f; private set
48+
private var currentZoom = 1f
49+
@JvmStatic var lerpedZoom = 1f; private set
4950
private var lastZoomTime = 1L
5051
private val zoomProgress
51-
get() = clamp((System.currentTimeMillis() - lastZoomTime) / (animationDuration * 1000).toDouble(), 0.0, 1.0).toFloat()
52+
get() = clamp((System.currentTimeMillis() - lastZoomTime) / (if (isEnabled) animationDuration else disableDuration).toDouble(), 0.0, 1.0).toFloat()
5253

5354
init {
5455
listen<MouseEvent.Scroll> { event ->
@@ -75,21 +76,23 @@ object Zoom : Module(
7576
}
7677

7778
private fun updateZoomTime() {
79+
currentZoom = lerpedZoom
7880
lastZoomTime = System.currentTimeMillis()
7981
}
8082

8183
@JvmStatic
8284
fun updateCurrentZoom() {
8385
val target = if (isEnabled) targetZoom else 1f
84-
currentZoom = style.apply(currentZoom, target, zoomProgress)
86+
lerpedZoom = style.apply(currentZoom, target, zoomProgress)
87+
if (lerpedZoom == targetZoom) lerpedZoom = targetZoom
8588
}
8689

8790
private enum class ZoomStyle(
8891
override val displayName: String,
8992
val apply: (Float, Float, Float) -> Float,
9093
) : NamedEnum {
9194
Instant("Instant", { _, v, _ -> v }),
92-
EaseOut("Ease Out", { start, end, progress -> start + ((end - start) * (1f - ((1f - progress) * (1f - progress)))) }),
93-
EaseIn("Ease In", { start, end, progress -> start + ((end - start) * (progress * progress)) })
95+
EaseOut("Ease Out", { start, end, progress -> start + ((end - start) * (1f - ((1f - progress) * (1f - progress) * (1f - progress)))) }),
96+
EaseIn("Ease In", { start, end, progress -> start + ((end - start) * (progress * progress * progress)) })
9497
}
9598
}

0 commit comments

Comments
 (0)