-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
409 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
platforms/common/src/main/java/dynamic_fps/impl/mixin/ScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package dynamic_fps.impl.mixin; | ||
|
||
import dynamic_fps.impl.service.ModCompat; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import dynamic_fps.impl.util.duck.DuckScreen; | ||
import net.minecraft.client.gui.screens.Screen; | ||
|
||
@Mixin(Screen.class) | ||
public class ScreenMixin implements DuckScreen { | ||
@Unique | ||
private boolean dynamic_fps$canOptimize = false; | ||
|
||
@Unique | ||
private boolean dynamic_fps$hasOptedOut = false; | ||
|
||
@Override | ||
public boolean dynamic_fps$rendersBackground() { | ||
return dynamic_fps$canOptimize; | ||
} | ||
|
||
@Override | ||
public void dynamic_fps$setRendersBackground() { | ||
this.dynamic_fps$canOptimize = true; | ||
} | ||
|
||
@Inject(method = "init", at = @At("HEAD")) | ||
private void onInit(CallbackInfo callbackInfo) { | ||
String name = this.getClass().getName(); | ||
|
||
this.dynamic_fps$hasOptedOut = ModCompat.getInstance().isScreenOptedOut(name); | ||
|
||
// Allow other mods to opt out on behalf of vanilla screens | ||
// That Dynamic FPS forced to opt in via its own mod metadata. | ||
if (!this.dynamic_fps$hasOptedOut) { | ||
this.dynamic_fps$canOptimize = ModCompat.getInstance().isScreenOptedIn(name); | ||
} | ||
} | ||
|
||
@Inject(method = "renderDirtBackground", at = @At("HEAD")) | ||
private void onRenderDirtBackground(CallbackInfo callbackInfo) { | ||
if (!this.dynamic_fps$hasOptedOut) { | ||
this.dynamic_fps$canOptimize = true; // Signal to apply optimizations on next frame | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
platforms/common/src/main/java/dynamic_fps/impl/mixin/StatsScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dynamic_fps.impl.mixin; | ||
|
||
import dynamic_fps.impl.util.duck.DuckScreen; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.client.gui.screens.achievement.StatsScreen; | ||
|
||
@Mixin(StatsScreen.class) | ||
public class StatsScreenMixin { | ||
@Inject(method = "onStatsUpdated", at = @At("HEAD")) | ||
private void onStatsUpdated(CallbackInfo callbackInfo) { | ||
((DuckScreen) this).dynamic_fps$setRendersBackground(); | ||
} | ||
} |
14 changes: 9 additions & 5 deletions
14
platforms/common/src/main/java/dynamic_fps/impl/mixin/ToastComponentMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
package dynamic_fps.impl.mixin; | ||
|
||
import java.util.Deque; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import dynamic_fps.impl.DynamicFPSMod; | ||
import net.minecraft.client.gui.components.toasts.Toast; | ||
import net.minecraft.client.gui.components.toasts.ToastComponent; | ||
|
||
@Mixin(ToastComponent.class) | ||
public class ToastComponentMixin { | ||
@Inject(method = "freeSlots", at = @At("HEAD"), cancellable = true) | ||
private void hasFreeSlots(CallbackInfoReturnable<Integer> callbackInfo) { | ||
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Ljava/util/Deque;isEmpty()Z")) | ||
private boolean onQueueIsEmpty(Deque<Toast> queued) { | ||
if (!DynamicFPSMod.shouldShowToasts()) { | ||
callbackInfo.setReturnValue(0); | ||
return true; | ||
} else { | ||
return queued.isEmpty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
platforms/common/src/main/java/dynamic_fps/impl/util/ModCompatHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dynamic_fps.impl.util; | ||
|
||
import dynamic_fps.impl.service.ModCompat; | ||
import dynamic_fps.impl.service.Platform; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
public class ModCompatHelper { | ||
public static void init() { | ||
fixFastloadSoftLock(); | ||
} | ||
|
||
/** | ||
* Fix softlock in combination with Fastload <=3.4.0 due to our screen / loading overlay optimization. | ||
* | ||
* See the <a href="https://github.com/juliand665/Dynamic-FPS/issues/129">issue report</a> for more info. | ||
*/ | ||
private static void fixFastloadSoftLock() { | ||
Optional<String> optional = Platform.getInstance().getModVersion("fastload"); | ||
|
||
if (optional.isEmpty()) { | ||
return; | ||
} | ||
|
||
String[] parts = optional.get().split("\\."); | ||
int[] version = Arrays.stream(parts).mapToInt(Integer::parseInt).toArray(); | ||
|
||
if (version.length < 3) { | ||
Logging.getLogger().warn("Unable to parse Fastload version: {}!", optional.get()); | ||
return; | ||
} | ||
|
||
// If a version below 3.4.0 is present opt their custom world loading screen out of our optimization | ||
if (!(version[0] > 3 || version[0] == 3 && (version[1] > 4 || version[1] == 4 && version[2] > 0))) { | ||
ModCompat.getInstance().getOptedOutScreens().add( | ||
"io.github.bumblesoftware.fastload.client.BuildingTerrainScreen" | ||
); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
platforms/common/src/main/java/dynamic_fps/impl/util/duck/DuckScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dynamic_fps.impl.util.duck; | ||
|
||
public interface DuckScreen { | ||
public default boolean dynamic_fps$rendersBackground() { | ||
throw new RuntimeException("No implementation for dynamic_fps$rendersBackground was found."); | ||
} | ||
|
||
public default void dynamic_fps$setRendersBackground() { | ||
throw new RuntimeException("No implementation for dynamic_fps$rendersBackground was found."); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
platforms/common/src/main/resources/dynamic_fps-common.mixins.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.