Skip to content

Commit

Permalink
Fix fade flickering (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Nov 4, 2024
1 parent 80c21a1 commit 140889c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class LinearTransitionMode implements TransitionMode {
private boolean active;
private final double minimumLinearStep;
private final double maximumLinearStep;
private float fovMultiplier;
private float internalMultiplier;
private float lastInternalMultiplier;
private float internalFade;
Expand All @@ -25,13 +24,12 @@ public LinearTransitionMode(double minimumLinearStep, double maximumLinearStep)

@Override
public boolean getActive() {
return this.active;
return this.active || this.internalMultiplier != 1.0F || this.internalFade != 1.0F;
}

@Override
public float applyZoom(float fov, float tickDelta) {
fovMultiplier = Mth.lerp(tickDelta, this.lastInternalMultiplier, this.internalMultiplier);
return fov * fovMultiplier;
return fov * Mth.lerp(tickDelta, this.lastInternalMultiplier, this.internalMultiplier);
}

@Override
Expand All @@ -51,9 +49,7 @@ public void tick(boolean active, double divisor) {
this.internalMultiplier = Mth.approach(this.internalMultiplier, (float) zoomMultiplier, (float) linearStep);
this.internalFade = Mth.approach(this.internalFade, (float) fadeMultiplier, (float) linearStep);

if (active || fovMultiplier == this.internalMultiplier) {
this.active = active;
}
this.active = active;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
public class SmoothTransitionMode implements TransitionMode {
private boolean active;
private final float smoothMultiplier;
private float fovMultiplier;
private float internalMultiplier;
private float lastInternalMultiplier;
private float internalFade;
Expand All @@ -26,13 +25,12 @@ public SmoothTransitionMode() {

@Override
public boolean getActive() {
return this.active;
return this.active || this.internalMultiplier != 1.0F || this.internalFade != 1.0F;
}

@Override
public float applyZoom(float fov, float tickDelta) {
fovMultiplier = Mth.lerp(tickDelta, this.lastInternalMultiplier, this.internalMultiplier);
return fov * fovMultiplier;
return fov * Mth.lerp(tickDelta, this.lastInternalMultiplier, this.internalMultiplier);
}

@Override
Expand All @@ -42,18 +40,16 @@ public float getFade(float tickDelta) {

@Override
public void tick(boolean active, double divisor) {
double zoomMultiplier = 1.0 / divisor;
double fadeMultiplier = active ? 1.0 : 0.0;
float zoomMultiplier = (float) (1.0 / divisor);
float fadeMultiplier = active ? 1.0F : 0.0F;

this.lastInternalMultiplier = this.internalMultiplier;
this.lastInternalFade = this.internalFade;

this.internalMultiplier += (float) ((zoomMultiplier - this.internalMultiplier) * this.smoothMultiplier);
this.internalFade += (float) ((fadeMultiplier - this.internalFade) * this.smoothMultiplier);
this.internalMultiplier += (zoomMultiplier - this.internalMultiplier) * this.smoothMultiplier;
this.internalFade += (fadeMultiplier - this.internalFade) * this.smoothMultiplier;

if (active || fovMultiplier == this.internalMultiplier) {
this.active = active;
}
this.active = active;
}

@Override
Expand Down

0 comments on commit 140889c

Please sign in to comment.