mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-10-25 20:22:22 +00:00
feat: add smooth zoom option (#1890)
This commit is contained in:
1 parent
f4f9b56b17
commit
9acb0e67a7
6 files changed
+61
-5
No files matched your search
@@ -4,6 +4,8 @@ import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import jss.notfine.core.Settings;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
@@ -19,6 +21,13 @@ public class Zoom {
|
||||
|
||||
@Getter
|
||||
private static float zoom = ZOOM_DEFAULT;
|
||||
|
||||
public static final float ZOOM_SMOOTH_SNAP_EPSILON = 0.001F;
|
||||
|
||||
@Getter
|
||||
private static float currentZoom = 1.0F;
|
||||
private static long zoomLerpLastNano = 0L;
|
||||
|
||||
@Getter
|
||||
private static final KeyBinding zoomKey = new KeyBinding("Zoom", 0, "key.categories.misc");
|
||||
|
||||
@@ -38,6 +47,29 @@ public class Zoom {
|
||||
zoom = MathHelper.clamp_float((float) (zoom * Math.pow(ZOOM_STEP, Integer.signum(eventDWheel))), ZOOM_MIN, ZOOM_MAX);
|
||||
}
|
||||
|
||||
public static void updateZoomLerp() {
|
||||
final long now = System.nanoTime();
|
||||
float dt = zoomLerpLastNano == 0L ? 0.0F : (now - zoomLerpLastNano) / 1.0e9F;
|
||||
zoomLerpLastNano = now;
|
||||
|
||||
final float target = zoomEnabled ? zoom : 1.0F;
|
||||
|
||||
if (dt <= 0.0F || !(boolean) Settings.ZOOM_SMOOTH.option.getStore()) {
|
||||
currentZoom = target;
|
||||
return;
|
||||
}
|
||||
|
||||
// Clamp dt so a long frame (alt-tab, GC pause) does not snap the zoom.
|
||||
dt = Math.min(dt, 0.1F);
|
||||
|
||||
final int rate = (int) Settings.ZOOM_SMOOTH_SPEED.option.getStore();
|
||||
currentZoom += (target - currentZoom) * (1.0F - (float) Math.exp(-dt * rate));
|
||||
|
||||
if (Math.abs(target - currentZoom) < ZOOM_SMOOTH_SNAP_EPSILON) {
|
||||
currentZoom = target;
|
||||
}
|
||||
}
|
||||
|
||||
private static void resetMouseFilters(Minecraft mc) {
|
||||
if (mc.entityRenderer != null) {
|
||||
((IMouseFilterExt) mc.entityRenderer.mouseFilterXAxis).angelica$reset();
|
||||
@@ -79,4 +111,10 @@ public class Zoom {
|
||||
handleKeyEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderTick(TickEvent.RenderTickEvent e) {
|
||||
if (e.phase != TickEvent.Phase.START) return;
|
||||
updateZoomLerp();
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,9 @@ public enum Settings {
|
||||
RenderStars.reloadStarRenderList(Minecraft.getMinecraft().renderGlobal);
|
||||
}
|
||||
},
|
||||
VOID_FOG(new NotFineOptionTickBox(false, OptionImpact.LOW));
|
||||
VOID_FOG(new NotFineOptionTickBox(false, OptionImpact.LOW)),
|
||||
ZOOM_SMOOTH(new NotFineOptionTickBox(true, OptionImpact.LOW)),
|
||||
ZOOM_SMOOTH_SPEED(new NotFineOptionSlider(14, 1, 30, 1, OptionImpact.LOW));
|
||||
|
||||
public final NotFineOption<?> option;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package jss.notfine.gui;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import jss.notfine.config.NotFineConfig;
|
||||
import jss.notfine.core.Settings;
|
||||
@@ -169,6 +170,12 @@ public class NotFineGameOptionPages {
|
||||
.build());
|
||||
}
|
||||
|
||||
if (AngelicaConfig.enableZoom) {
|
||||
groups.add(OptionGroup.createBuilder()
|
||||
.add(Settings.ZOOM_SMOOTH.option)
|
||||
.add(Settings.ZOOM_SMOOTH_SPEED.option)
|
||||
.build());
|
||||
}
|
||||
|
||||
return new OptionPage(I18n.format("options.video"), ImmutableList.copyOf(groups));
|
||||
}
|
||||
|
||||
@@ -532,6 +532,13 @@ public class SodiumGameOptionPages {
|
||||
.build())
|
||||
.build());
|
||||
|
||||
if (AngelicaConfig.enableZoom) {
|
||||
groups.add(OptionGroup.createBuilder()
|
||||
.add(Settings.ZOOM_SMOOTH.option)
|
||||
.add(Settings.ZOOM_SMOOTH_SPEED.option)
|
||||
.build());
|
||||
}
|
||||
|
||||
return new OptionPage(I18n.format("sodium.options.pages.appearance"), ImmutableList.copyOf(groups));
|
||||
}
|
||||
|
||||
|
||||
@@ -78,3 +78,7 @@ options.void_fog=Void Fog
|
||||
options.void_fog.tooltip=Void Fog
|
||||
options.hurt_shake=Hurt Screen Shake
|
||||
options.background.random=Random
|
||||
options.zoom_smooth=Smooth Zoom
|
||||
options.zoom_smooth.tooltip=Smoothly interpolates the camera toward the zoom level instead of snapping instantly.
|
||||
options.zoom_smooth_speed=Smooth Zoom Speed
|
||||
options.zoom_smooth_speed.tooltip=How fast smooth zoom converges to the target zoom. Higher is snappier, lower is floatier. No effect when Smooth Zoom is off.
|
||||
+2
-4
@@ -16,10 +16,8 @@ public class MixinEntityRenderer_Zoom {
|
||||
|
||||
@ModifyReturnValue(method = "getFOVModifier", at = @At("RETURN"))
|
||||
private float angelica$modifyFOV(float original) {
|
||||
if (Zoom.getZoomKey().getIsKeyPressed()) {
|
||||
return original / Zoom.getZoom();
|
||||
}
|
||||
return original;
|
||||
final float current = Zoom.getCurrentZoom();
|
||||
return current > 1.0001F ? original / current : original;
|
||||
}
|
||||
|
||||
@ModifyConstant(method = "updateCameraAndRender", constant = @Constant(floatValue = 8.0F))
|
||||
|
||||
Reference in new issue
Block a user