Skip to content

Commit

Permalink
Merge branch 'main' into 1.16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Jan 14, 2024
2 parents 56a95d3 + fad5a97 commit 0138d35
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 46 deletions.
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.3.2
mod_version = 3.3.3
maven_group = juliand665
archives_base_name = dynamic-fps
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ cloth_config = { module = "me.shedaniel.cloth:cloth-config-fabric", version.ref
[bundles]

[plugins]
fabric_loom = { id = "fabric-loom", version = "1.4.5" }
fabric_loom = { id = "fabric-loom", version = "1.5.5" }
32 changes: 17 additions & 15 deletions src/main/java/dynamic_fps/impl/DynamicFPSMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import static dynamic_fps.impl.util.Localization.translationKey;

import org.jetbrains.annotations.Nullable;

public class DynamicFPSMod implements ClientModInitializer {
public static final String MOD_ID = "dynamic_fps";
public static final boolean DEBUG = FabricLoader.getInstance().isDevelopmentEnvironment();
Expand All @@ -34,15 +36,15 @@ public class DynamicFPSMod implements ClientModInitializer {
private static boolean isDisabled = false;
private static boolean isForcingLowFPS = false;

private static Minecraft minecraft;
private static final Minecraft minecraft = Minecraft.getInstance();

private static WindowObserver window;
private static InputObserver devices;
private static @Nullable WindowObserver window;
private static @Nullable InputObserver devices;

private static long lastRender;

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

// we always render one last frame before actually reducing FPS, so the hud text
// shows up instantly when forcing low fps.
Expand Down Expand Up @@ -73,7 +75,7 @@ public void onInitializeClient() {
toggleForcedKeyBinding.register();
toggleDisabledKeyBinding.register();

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

Expand All @@ -89,7 +91,7 @@ public static void onStatusChanged() {

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

public static PowerState powerState() {
Expand All @@ -102,7 +104,7 @@ public static boolean isForcingLowFPS() {

public static void setWindow(long address) {
window = new WindowObserver(address);
devices = new InputObserver(address);
initializeIdleCheck(); // Register input observer if wanted
}

public static boolean checkForRender() {
Expand Down Expand Up @@ -157,16 +159,20 @@ private static boolean isLevelCoveredByOverlay() {
return OVERLAY_OPTIMIZATION_ACTIVE && minecraft.getOverlay() instanceof LoadingOverlay && ((DuckSplashOverlay)minecraft.getOverlay()).dynamic_fps$isReloadComplete();
}

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

if (modConfig.idleTime() == -1) {
if (modConfig.idleTime() == 0 || window == null) {
return;
}

tickEventRegistered = true;
idleCheckRegistered = true;

// We only register the input observer and tick handler
// When it's used to run less unused code at all times.
devices = new InputObserver(window.address());

ClientTickEvents.START_CLIENT_TICK.register((minecraft) -> {
boolean idle = isIdle();
Expand Down Expand Up @@ -227,10 +233,6 @@ private static void checkForStateChanges() {
return;
}

if (minecraft == null) {
minecraft = Minecraft.getInstance();
}

if (minecraft.isSameThread()) {
checkForStateChanges0();
} else {
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public class SoundEngineMixin implements DuckSoundEngine {
@Final
private Map<SoundInstance, ChannelAccess.ChannelHandle> instanceToChannel;

@Shadow
private float getVolume(@Nullable SoundSource source) {
throw new RuntimeException("Failed to find SoundEngine#getVolume.");
}

@Shadow
private float calculateVolume(SoundInstance instance) {
throw new RuntimeException("Failed to find SoundEngine#calculateVolume.");
Expand All @@ -55,7 +50,8 @@ private float calculateVolume(SoundInstance instance) {
}

if (source.equals(SoundSource.MASTER)) {
this.listener.setGain(this.getVolume(source));
var volume = this.options.getSoundSourceVolume(source);
this.listener.setGain(this.adjustVolume(volume, source));
return;
}

Expand All @@ -65,7 +61,7 @@ private float calculateVolume(SoundInstance instance) {
boolean isMusic = source.equals(SoundSource.MUSIC) || source.equals(SoundSource.RECORDS);

this.instanceToChannel.forEach((instance, handle) -> {
float volume = this.calculateVolume((SoundInstance) instance);
float volume = this.calculateVolume(instance);

if (instance.getSource().equals(source)) {
handle.execute(channel -> {
Expand Down Expand Up @@ -105,12 +101,14 @@ private void play(SoundInstance instance, CallbackInfo callbackInfo) {
*/
@ModifyReturnValue(method = "getVolume", at = @At("RETURN"))
private float getVolume(float original, @Local @Nullable SoundSource source) {
// Note: The original doesn't consider the user's setting when the source is MASTER
// In vanilla this doesn't matter because it's never called, but we use it when setting the gain
if (SoundSource.MASTER.equals(source)) {
original = this.options.getSoundSourceVolume(source);
return this.adjustVolume(original, source);
}

private float adjustVolume(float value, @Nullable SoundSource source) {
if (source == null) {
source = SoundSource.MASTER;
}

return original * DynamicFPSMod.volumeMultiplier(source);
return value * DynamicFPSMod.volumeMultiplier(source);
}
}
16 changes: 10 additions & 6 deletions src/main/java/dynamic_fps/impl/util/event/WindowObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dynamic_fps.impl.DynamicFPSMod;

public class WindowObserver {
private final long window;
private final long address;

private boolean isFocused = true;
private final GLFWWindowFocusCallback previousFocusCallback;
Expand All @@ -20,17 +20,21 @@ public class WindowObserver {
private final GLFWWindowIconifyCallback previousIconifyCallback;

public WindowObserver(long address) {
this.window = address;
this.address = address;

this.previousFocusCallback = GLFW.glfwSetWindowFocusCallback(this.window, this::onFocusChanged);
this.previousMouseCallback = GLFW.glfwSetCursorEnterCallback(this.window, this::onMouseChanged);
this.previousFocusCallback = GLFW.glfwSetWindowFocusCallback(this.address, this::onFocusChanged);
this.previousMouseCallback = GLFW.glfwSetCursorEnterCallback(this.address, this::onMouseChanged);

// Vanilla doesn't use this (currently), other mods might register this callback though ...
this.previousIconifyCallback = GLFW.glfwSetWindowIconifyCallback(this.window, this::onIconifyChanged);
this.previousIconifyCallback = GLFW.glfwSetWindowIconifyCallback(this.address, this::onIconifyChanged);
}

private boolean isCurrentWindow(long address) {
return address == this.window;
return address == this.address;
}

public long address() {
return this.address;
}

public boolean isFocused() {
Expand Down
36 changes: 25 additions & 11 deletions src/main/resources/assets/dynamic_fps/lang/it_it.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
{
"config.dynamic_fps.title": "Configura Dynamic FPS",

"config.dynamic_fps.category.general": "Generale",
"config.dynamic_fps.category.hovered": "Sopra il cursore",
"config.dynamic_fps.category.hovered": "Cursore sopra",
"config.dynamic_fps.category.unfocused": "Non in primo piano",
"config.dynamic_fps.category.abandoned": "Inattivo",
"config.dynamic_fps.category.invisible": "Invisibile",

"config.dynamic_fps.frame_rate_target": "Obiettivo di frame rate",
"config.dynamic_fps.frame_rate_target_description": "Imposta l'obiettivo di frame rate a -1 per disabilitare la riduzione del FPS.",
"config.dynamic_fps.volume_multiplier": "Moltiplicatore volume",
"config.dynamic_fps.graphics_state": "Opzioni grafiche",
"config.dynamic_fps.show_toasts": "Mostra i toasts",
"config.dynamic_fps.disabled": "Disattivato",
"config.dynamic_fps.minutes": "%d minuto(i)",

"config.dynamic_fps.idle_time": "Tempo di Inattività",
"config.dynamic_fps.idle_time_tooltip": "Minuti senza input prima che Dynamic FPS attivi lo stato di Inattività quando il gioco è in primo piano.",

"config.dynamic_fps.frame_rate_target": "Obiettivo di Frame Rate",
"config.dynamic_fps.volume_multiplier": "Moltiplicatore del Volume",

"config.dynamic_fps.graphics_state": "Opzioni Grafiche",
"config.dynamic_fps.graphics_state_default": "Predefinito",
"config.dynamic_fps.graphics_state_reduced": "Ridotto",
"config.dynamic_fps.graphics_state_minimal": "Minimale",
"config.dynamic_fps.graphics_state_minimal_tooltip": "Le grafiche minime causano il ricaricamento del mondo!",

"config.dynamic_fps.show_toasts": "Mostra Toast",
"config.dynamic_fps.show_toasts_tooltip": "Se visualizzare o ritardare le notifiche toast",

"config.dynamic_fps.run_garbage_collector": "Esegui Garbage Collector",
"config.dynamic_fps.run_garbage_collector_tooltip": "Libera la memoria non utilizzata quando si passa a questo stato",

"key.dynamic_fps.toggle_forced": "Forza la modalità non in primo piano (Attiva/Disattiva)",
"key.dynamic_fps.toggle_forced": "Forza Modalità Non in Primo Piano (Attiva/Disattiva)",
"key.dynamic_fps.toggle_disabled": "Disabilita Dynamic FPS (Attiva/Disattiva)",
"gui.dynamic_fps.hud.reducing": "Dynamic FPS: Riduzione forzata del FPS",
"gui.dynamic_fps.hud.disabled": "Dynamic FPS disabilitato",
"gui.dynamic_fps.hud.reducing": "Dynamic FPS: Riduzione Forzata FPS",
"gui.dynamic_fps.hud.disabled": "Dynamic FPS Disattivato",

"modmenu.descriptionTranslation.dynamic_fps": "Regola dinamicamente il FPS in modo che Minecraft non consumi risorse in background."
"modmenu.descriptionTranslation.dynamic_fps": "Regola dinamicamente gli FPS in modo che Minecraft non utilizzi troppe risorse in background."
}
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"=1.18.1",
"=1.18.2"
],
"mixinextras": ">=0.3.2",
"fabricloader": ">=0.15.0",
"fabric-resource-loader-v0": "*",
"fabric-rendering-v1": "*",
Expand Down

0 comments on commit 0138d35

Please sign in to comment.