Skip to content

Commit

Permalink
Merge branch 'main' into 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Dec 16, 2023
2 parents b6e2393 + fcdee8e commit fa0c7a7
Show file tree
Hide file tree
Showing 49 changed files with 769 additions and 249 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
matrix:
java: [
17,
20,
21,
]
os: [
ubuntu-22.04,
Expand All @@ -34,7 +34,7 @@ jobs:
arguments: build --warning-mode=all
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '20' }} # Upload artifacts from one job, ignore the rest
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Upload artifacts from one job, ignore the rest
uses: actions/upload-artifact@v3
with:
name: dynamic-fps-artifacts
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'maven-publish'
id "maven-publish"
alias libs.plugins.fabric.loom
}

Expand All @@ -19,13 +19,17 @@ dependencies {
minecraft libs.minecraft
mappings loom.officialMojangMappings()

modImplementation libs.fabric.api
modImplementation libs.fabric.loader
modImplementation libs.bundles.fabric.api

modApi libs.modmenu
modApi libs.cloth.config
}

loom {
accessWidenerPath = file("src/main/resources/dynamic_fps.accesswidener")
}

processResources {
inputs.property "version", generateVersion()

Expand All @@ -42,7 +46,7 @@ java {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release.set(17)
it.options.encoding = "UTF-8"

it.options.compilerArgs += ["-Xlint:deprecation"]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ org.gradle.parallel = true
org.gradle.jvmargs = -Xmx1G

# Mod Properties
mod_version = 3.2.1
mod_version = 3.3.0
maven_group = juliand665
archives_base_name = dynamic-fps
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fabric_api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fab
cloth_config = { module = "me.shedaniel.cloth:cloth-config-fabric", version.ref = "cloth_config" }

[bundles]
fabric_api = ["fabric_api"]

[plugins]
fabric_loom = { id = "fabric-loom", version = "1.3.8" }
fabric_loom = { id = "fabric-loom", version = "1.4.5" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 2 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
4 changes: 0 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ pluginManagement {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
name = 'Quilt'
url = 'https://maven.quiltmc.org/repository/release'
}
gradlePluginPortal()
}
}
Expand Down
100 changes: 63 additions & 37 deletions src/main/java/dynamic_fps/impl/DynamicFPSMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import dynamic_fps.impl.util.Logging;
import dynamic_fps.impl.util.ModCompatibility;
import dynamic_fps.impl.util.OptionsHolder;
import dynamic_fps.impl.util.WindowObserver;
import dynamic_fps.impl.util.event.InputObserver;
import dynamic_fps.impl.util.event.WindowObserver;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.LoadingOverlay;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.sounds.SoundSource;

import static dynamic_fps.impl.util.Localization.translationKey;
Expand All @@ -33,10 +34,15 @@ public class DynamicFPSMod implements ClientModInitializer {
private static boolean isForcingLowFPS = false;

private static Minecraft minecraft;

private static WindowObserver window;
private static InputObserver devices;

private static long lastRender;

private static boolean wasIdle = false;
private static boolean tickEventRegistered = false;

// we always render one last frame before actually reducing FPS, so the hud text
// shows up instantly when forcing low fps.
// additionally, this would enable mods which render differently while mc is
Expand All @@ -63,11 +69,10 @@ public class DynamicFPSMod implements ClientModInitializer {

@Override
public void onInitializeClient() {
modConfig.save(); // Force create file on disk

toggleForcedKeyBinding.register();
toggleDisabledKeyBinding.register();

registerTickEvent();
HudRenderCallback.EVENT.register(new HudInfoRenderer());
}

Expand All @@ -81,6 +86,11 @@ public static void onStatusChanged() {
checkForStateChanges();
}

public static void onConfigChanged() {
modConfig.save();
registerTickEvent();
}

public static PowerState powerState() {
return state;
}
Expand All @@ -91,6 +101,7 @@ public static boolean isForcingLowFPS() {

public static void setWindow(long address) {
window = new WindowObserver(address);
devices = new InputObserver(address);
}

public static boolean checkForRender() {
Expand All @@ -109,8 +120,8 @@ public static int targetFrameRate() {
return config.frameRateTarget();
}

public static float volumeMultiplier() {
return config.volumeMultiplier();
public static float volumeMultiplier(SoundSource source) {
return config.volumeMultiplier(source);
}

public static boolean shouldShowToasts() {
Expand All @@ -127,18 +138,45 @@ private static boolean isDisabledInternal() {
return isDisabled || FREX.isFlawlessFramesActive();
}

private static boolean isPauseScreenOpened() {
return minecraft.screen instanceof PauseScreen;
}

private static boolean isLevelCoveredByScreen() {
return minecraft.screen != null && minecraft.screen.dynamic_fps$rendersBackground();
}

private static boolean isIdle() {
var idleTime = modConfig.idleTime();

if (idleTime == 0) {
return false;
}

return (Util.getEpochMillis() - devices.lastActionTime()) >= idleTime * 1000;
}

private static boolean isLevelCoveredByOverlay() {
return OVERLAY_OPTIMIZATION_ACTIVE && minecraft.getOverlay() instanceof LoadingOverlay loadingOverlay && loadingOverlay.dynamic_fps$isReloadComplete();
}

private static void registerTickEvent() {
if (tickEventRegistered) {
return;
}

if (modConfig.idleTime() == -1) {
return;
}

tickEventRegistered = true;

ClientTickEvents.START_CLIENT_TICK.register((minecraft) -> {
var idle = isIdle();

if (idle != wasIdle) {
wasIdle = idle;
onStatusChanged();
}
});
}

@SuppressWarnings("squid:S1215") // Garbage collector call
public static void handleStateChange(PowerState previous, PowerState current) {
if (DEBUG) {
Expand All @@ -154,8 +192,10 @@ public static void handleStateChange(PowerState previous, PowerState current) {
System.gc();
}

if (before.volumeMultiplier() != config.volumeMultiplier()) {
setVolumeMultiplier(config.volumeMultiplier());
for (var source : SoundSource.values()) {
if (before.volumeMultiplier(source) != config.volumeMultiplier(source)) {
minecraft.getSoundManager().soundEngine.dynamic_fps$updateVolume(source);
}
}

if (before.graphicsState() != config.graphicsState()) {
Expand All @@ -176,17 +216,26 @@ private static void checkForStateChanges() {
minecraft = Minecraft.getInstance();
}

if (minecraft.isSameThread()) {
checkForStateChanges0();
} else {
// Schedule check for the beginning of the next frame
minecraft.tell(DynamicFPSMod::checkForStateChanges0);
}
}

private static void checkForStateChanges0() {
PowerState current;

if (isDisabledInternal()) {
current = PowerState.FOCUSED;
} else if (isForcingLowFPS) {
current = PowerState.UNFOCUSED;
} else if (window.isFocused()) {
if (!isPauseScreenOpened()) {
if (!isIdle()) {
current = PowerState.FOCUSED;
} else {
current = PowerState.SUSPENDED;
current = PowerState.ABANDONED;
}
} else if (window.isHovered()) {
current = PowerState.HOVERED;
Expand All @@ -204,29 +253,6 @@ private static void checkForStateChanges() {
}
}

private static void setVolumeMultiplier(float multiplier) {
// Set the sound engine to a new volume multiplier,
// Or instead pause it when the multiplier is zero.

// We can not set the sound engine to a zero volume
// Because it stops all actively playing sounds and
// Makes for a rather jarring experience when music
// Is stopped. Also fixes now-playing compatibility

var manager = minecraft.getSoundManager();

if (multiplier == 0) {
manager.pause();
} else {
manager.resume();

manager.updateSourceVolume(
SoundSource.MASTER,
minecraft.options.getSoundSourceVolume(SoundSource.MASTER) * multiplier
);
}
}

private static boolean checkForRender(long timeSinceLastRender) {
int frameRateTarget = config.frameRateTarget();

Expand Down
25 changes: 0 additions & 25 deletions src/main/java/dynamic_fps/impl/GraphicsState.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package dynamic_fps.impl;

import java.util.Locale;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.PrimitiveCodec;

/*
* Graphics settings to apply within a given power state.
*/
Expand All @@ -25,22 +18,4 @@ public enum GraphicsState {
* Reduce graphics settings to minimal values, this will reload the world!
*/
MINIMAL;

public static final Codec<GraphicsState> CODEC = new PrimitiveCodec<GraphicsState>() {
@Override
public <T> T write(DynamicOps<T> ops, GraphicsState value) {
return ops.createString(value.toString().toLowerCase(Locale.ROOT));
}

@Override
public <T> DataResult<GraphicsState> read(DynamicOps<T> ops, T input) {
var value = ops.getStringValue(input).get().left();

if (value.isEmpty()) {
return DataResult.error("Graphics state must not be empty!");
} else {
return DataResult.success(GraphicsState.valueOf(value.get().toUpperCase(Locale.ROOT)));
}
}
};
}
Loading

0 comments on commit fa0c7a7

Please sign in to comment.