Skip to content

Commit

Permalink
Merge branch '1.19.x/stable' of https://github.com/FlashyReese/sodium…
Browse files Browse the repository at this point in the history
…-extra-fabric into 1.19.x/stable
  • Loading branch information
dima_dencep committed Aug 30, 2022
2 parents 52dae6e + 72ac082 commit 974df4a
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 280 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ forge_version = 43.1.1
loom.platform = forge

# Mod Properties
mod_version = 0.4.7
mod_version = 0.4.9
maven_group = ml.dima_dencep
archives_base_name = RubidiumExtra

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,34 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;

import java.util.Comparator;
import java.util.Queue;

public class ClientTickHandler {
private final Queue<Integer> averageFps = new EvictingQueue<>(200);
private int averageFps, lowestFps, highestFps;
private final Queue<Integer> fpsQueue = new EvictingQueue<>(200);

public void onClientInitialize() {
MinecraftForge.EVENT_BUS.addListener(this::onTick);
}

public void onTick(TickEvent.ClientTickEvent event) {
int currentFPS = MinecraftClientAccessor.getCurrentFPS();
this.averageFps.add(currentFPS);
this.fpsQueue.add(currentFPS);
this.averageFps = (int) this.fpsQueue.stream().mapToInt(Integer::intValue).average().orElse(0);
this.lowestFps = this.fpsQueue.stream().min(Comparator.comparingInt(e -> e)).orElse(0);
this.highestFps = this.fpsQueue.stream().max(Comparator.comparingInt(e -> e)).orElse(0);
}

public int getAverageFps() {
int actualAverageFPS = 0;
for (int fps : this.averageFps) {
actualAverageFPS += fps;
}
return actualAverageFPS / this.averageFps.size();
return this.averageFps;
}

public int getLowestFps() {
int temp = -1;
for (int fps : this.averageFps) {
if (temp == -1 || fps < temp) {
temp = fps;
}
}
return temp;
return this.lowestFps;
}

public int getHighestFps() {
int temp = -1;
for (int fps : this.averageFps) {
if (temp == -1 || fps > temp) {
temp = fps;
}
}
return temp;
return this.highestFps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.io.File;

@Mod("sodiumextra")
@OnlyIn(Dist.CLIENT)
public class SodiumExtraClientMod {
Expand Down Expand Up @@ -38,7 +37,7 @@ public static ClientTickHandler getClientTickHandler() {
}

private static SodiumExtraGameOptions loadConfig() {
return SodiumExtraGameOptions.load(new File("config/sodium-extra-options.json"));
return SodiumExtraGameOptions.load(FMLPaths.CONFIGDIR.get().resolve("sodium-extra-options.json").toFile());
}

public SodiumExtraClientMod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import it.unimi.dsi.fastutil.objects.Object2BooleanArrayMap;
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import me.jellysquid.mods.sodium.client.gui.options.TextProvider;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -41,7 +42,8 @@ public static SodiumExtraGameOptions load(File file) {
try (FileReader reader = new FileReader(file)) {
config = gson.fromJson(reader, SodiumExtraGameOptions.class);
} catch (IOException e) {
throw new RuntimeException("Could not parse config", e);
SodiumExtraClientMod.logger().error("Could not parse config, falling back to defaults!", e);
config = new SodiumExtraGameOptions();
}
} else {
config = new SodiumExtraGameOptions();
Expand Down Expand Up @@ -230,7 +232,6 @@ public static class ExtraSettings {
public boolean showFPSExtended;
public boolean showCoords;
public boolean reduceResolutionOnMac;
public boolean useAdaptiveSync;
public int cloudHeight;
public boolean toasts;
public boolean instantSneak;
Expand All @@ -243,7 +244,6 @@ public ExtraSettings() {
this.showFPSExtended = true;
this.showCoords = false;
this.reduceResolutionOnMac = true;
this.useAdaptiveSync = false;
this.cloudHeight = 192;
this.toasts = true;
this.instantSneak = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class SodiumExtraMixinConfigPlugin extends AbstractCaffeineConfigMixinPlu
@Override
protected CaffeineConfig createConfig() {
return CaffeineConfig.builder("Sodium Extra").withSettingsKey("sodium-extra:options")
.addMixinOption("adaptive_sync", true)
.addMixinOption("animation", true)
.addMixinOption("biome_colors", true)
.addMixinOption("cloud", true)
Expand All @@ -31,10 +30,9 @@ protected CaffeineConfig createConfig() {
.addMixinOption("sky_colors", true)
.addMixinOption("sodium", true)
.addMixinOption("sodium.accessibility", true)
.addMixinOption("sodium.gui_scale", true)
.addMixinOption("sodium.resolution", true)
.addMixinOption("sodium.scrollable_page", true)
.addMixinOption("sodium.vsync", true)
.addMixinOption("sodium.vsync", false)
.addMixinOption("stars", true)
.addMixinOption("sun_moon", true)
.addMixinOption("toasts", true)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.flashyreese.mods.sodiumextra.mixin.sodium.vsync;

import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptionPages;
import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptions;
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages;
import me.jellysquid.mods.sodium.client.gui.options.Option;
Expand All @@ -9,6 +8,7 @@
import me.jellysquid.mods.sodium.client.gui.options.OptionImpl;
import me.jellysquid.mods.sodium.client.gui.options.control.CyclingControl;
import me.jellysquid.mods.sodium.client.gui.options.storage.MinecraftOptionsStorage;
import me.jellysquid.mods.sodium.client.gui.options.storage.SodiumOptionsStorage;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -22,36 +22,40 @@ public class MixinSodiumGameOptionsPages {
@Final
private static MinecraftOptionsStorage vanillaOpts;

@Shadow
@Final
private static SodiumOptionsStorage sodiumOpts;

@Redirect(method = "general", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder;add(Lme/jellysquid/mods/sodium/client/gui/options/Option;)Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder;", ordinal = 5), remap = false)
private static OptionGroup.Builder redirectVsyncToggle(OptionGroup.Builder instance, Option<?> option) {
if (!option.getTooltip().getString().equals(Text.translatable("sodium.options.v_sync.tooltip").getString())) {
return instance.add(option);
}
return instance.add(OptionImpl.createBuilder(SodiumExtraGameOptions.VerticalSyncOption.class, SodiumExtraGameOptionPages.sodiumExtraOpts)
return instance.add(OptionImpl.createBuilder(SodiumExtraGameOptions.VerticalSyncOption.class, sodiumOpts)
.setName(Text.translatable("options.vsync"))
.setTooltip(Text.literal(Text.translatable("sodium.options.v_sync.tooltip").getString() + "\n- " + Text.translatable("sodium-extra.option.use_adaptive_sync.name").getString() + ": " + Text.translatable("sodium-extra.option.use_adaptive_sync.tooltip").getString()))
.setTooltip(Text.literal(Text.translatable("sodium.options.v_sync.tooltip").getString() + "\n- " + Text.translatable("sodium-extra.option.use_adaptive_sync.name").getString() + ": " + Text.translatable("sodium.options.use_adaptive_sync.tooltip").getString()))
.setControl((opt) -> new CyclingControl<>(opt, SodiumExtraGameOptions.VerticalSyncOption.class,
SodiumExtraGameOptions.VerticalSyncOption.getAvailableOptions()))
.setBinding((opts, value) -> {
switch (value) {
case OFF -> {
opts.extraSettings.useAdaptiveSync = false;
opts.performance.useAdaptiveSync = false;
vanillaOpts.getData().getEnableVsync().setValue(false);
}
case ON -> {
opts.extraSettings.useAdaptiveSync = false;
opts.performance.useAdaptiveSync = false;
vanillaOpts.getData().getEnableVsync().setValue(true);
}
case ADAPTIVE -> {
opts.extraSettings.useAdaptiveSync = true;
vanillaOpts.getData().getEnableVsync().setValue(false);
opts.performance.useAdaptiveSync = true;
vanillaOpts.getData().getEnableVsync().setValue(true);
}
}
vanillaOpts.save();
}, opts -> {
if (vanillaOpts.getData().getEnableVsync().getValue() && !opts.extraSettings.useAdaptiveSync) {
if (vanillaOpts.getData().getEnableVsync().getValue() && !opts.performance.useAdaptiveSync) {
return SodiumExtraGameOptions.VerticalSyncOption.ON;
} else if (!vanillaOpts.getData().getEnableVsync().getValue() && !opts.extraSettings.useAdaptiveSync) {
} else if (!vanillaOpts.getData().getEnableVsync().getValue() && !opts.performance.useAdaptiveSync) {
return SodiumExtraGameOptions.VerticalSyncOption.OFF;
} else {
return SodiumExtraGameOptions.VerticalSyncOption.ADAPTIVE;
Expand All @@ -60,4 +64,12 @@ private static OptionGroup.Builder redirectVsyncToggle(OptionGroup.Builder insta
.setImpact(OptionImpact.VARIES)
.build());
}

@Redirect(method = "performance", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder;add(Lme/jellysquid/mods/sodium/client/gui/options/Option;)Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder;", ordinal = 7), remap = false)
private static OptionGroup.Builder removeAdaptiveSyncToggle(OptionGroup.Builder instance, Option<?> option) {
if (!option.getTooltip().getString().equals(Text.translatable("sodium.options.use_adaptive_sync.tooltip").getString())) {
return instance.add(option);
}
return instance;
}
}
Loading

0 comments on commit 974df4a

Please sign in to comment.