Skip to content

Commit

Permalink
Tidy the code, Fix some issues
Browse files Browse the repository at this point in the history
After this commit, I will playtest extensively and fix any issues I introduced
Then I will release these changes in the final pre-release version (v0.5.3)
This is all in preparation for the rewrite, which comes next (v1.0.0-alpha.1)
After that, any bugfix releases will be next. (v1.0.0-alpha.x, v1.0.0-beta.x)
Then, full release (v1.0.0) and a new showcase trailer.

This commit will likely be ammended multiple times as I find things that can be improved.
  • Loading branch information
thedocruby committed Jan 17, 2022
1 parent a9e9203 commit f618ef5
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 120 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.18.1
yarn_mappings=1.18.1+build.2
loader_version=0.12.12
# Mod Properties
mod_version=0.5.2
mod_version=0.5.3
maven_group=com.soniether
archives_base_name=soundphysics
# Dependencies
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/sonicether/soundphysics/ALstuff/SPEfx.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sonicether.soundphysics.ALstuff;

import com.sonicether.soundphysics.SPMath;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.ALC10;
import org.lwjgl.openal.EXTEfx;
Expand Down Expand Up @@ -91,7 +91,7 @@ public static void setEnvironment(
AL10.alSourcei(sourceID, EXTEfx.AL_DIRECT_FILTER, directFilter0);
checkErrorLog("Set Environment directFilter0:");

AL10.alSourcef(sourceID, EXTEfx.AL_AIR_ABSORPTION_FACTOR, SPMath.clamp(pC.airAbsorption, 10.0f, 0.0f));
AL10.alSourcef(sourceID, EXTEfx.AL_AIR_ABSORPTION_FACTOR, MathHelper.clamp(pC.airAbsorption, 0.0f, 10.0f));
checkErrorLog("Set Environment airAbsorption:");
}

Expand All @@ -104,7 +104,7 @@ public static float getAbsorptionHF() {
double biomeTemp = mc.world.getBiome(mc.player.getBlockPos()).getTemperature();
double freq = 10000.0d;

double relhum = 100.0d * SPMath.lerp(Math.max(biomeHumidity, 0.2d), 1.0d, Math.max(rain, rainS)); // convert biomeHumidity and rain gradients into a dynamic relative humidity value
double relhum = 100.0d * MathHelper.lerp(Math.max(rain, rainS), Math.max(biomeHumidity, 0.2d), 1.0d); // convert biomeHumidity and rain gradients into a dynamic relative humidity value
double tempK = 25.0d * biomeTemp + 273.15d; // Convert biomeTemp to degrees kelvin

double hum = relhum*Math.pow(10.0d,4.6151d-6.8346d*Math.pow((273.15d/tempK),1.261d));
Expand Down Expand Up @@ -154,6 +154,6 @@ public static void updateSmoothedRain() {
float smoothingFactor = (float) (1.0f - Math.exp(-1*rainDecayConstant*tickDelta));

// sₜ = αxₜ + (1 - α)sₜ₋₁
rainAccumulator = SPMath.lerp(rainAccumulator, newValue, smoothingFactor);
rainAccumulator = MathHelper.lerp(smoothingFactor, rainAccumulator, newValue);
}
}
13 changes: 0 additions & 13 deletions src/main/java/com/sonicether/soundphysics/SPMath.java

This file was deleted.

154 changes: 67 additions & 87 deletions src/main/java/com/sonicether/soundphysics/SoundPhysics.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.minecraft.util.ActionResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class ConfigManager {
Expand All @@ -34,9 +36,8 @@ public static void registerAutoConfig() {
try {GuiRegistryinit.register();} catch (@SuppressWarnings("CatchMayIgnoreException") Exception ignored){ignored.printStackTrace();}

holder.registerSaveListener((holder, config) -> onSave(config));
holder.load();
onSave(holder.getConfig());
save();
holder.registerLoadListener((holder, config) -> onSave(config));
reload(true);
}

public static SoundPhysicsConfig getConfig() {
Expand All @@ -54,23 +55,28 @@ public static void reload(boolean load) {
holder.save();
}

public static void save() { if (holder == null) {registerAutoConfig();} holder.save(); }
public static void save() { if (holder == null) {registerAutoConfig();} else {holder.save();} }

public static void handleBrokenMaterials( SoundPhysicsConfig c ){
SPLog.logError("Critical materialProperties error. Resetting materialProperties");
SoundPhysicsConfig fallback = DEFAULT;
ConfigPresets.THEDOCRUBY.configChanger.accept(fallback);
c.Materials.materialProperties = fallback.Materials.materialProperties;
if (c.Materials.materialProperties == null) c.Materials.materialProperties = new HashMap<>();
c.Materials.blockWhiteList = List.of("block.minecraft.water");
ConfigPresets.RESET_MATERIALS.configChanger.accept(c);
}

public static void handleUnstableConfig( SoundPhysicsConfig c ){
SPLog.logError("Error: Config file is not from a compatible version! Resetting the config...");
ConfigPresets.DEFAULT_PERFORMANCE.configChanger.accept(c);
ConfigPresets.RESET_MATERIALS.configChanger.accept(c);
c.version = "0.5.3";
}

public static ActionResult onSave(SoundPhysicsConfig c) {
if (c.Materials.materialProperties == null || c.Materials.materialProperties.get("DEFAULT") == null)
handleBrokenMaterials(c);
if (c.preset != ConfigPresets.LOAD_SUCCESS) {c.preset.configChanger.accept(c);}
if (c.Materials.materialProperties == null || c.Materials.materialProperties.get("DEFAULT") == null) handleBrokenMaterials(c);
if (c.preset != ConfigPresets.LOAD_SUCCESS) c.preset.configChanger.accept(c);
if (c.version == null || !Objects.equals(c.version, "0.5.3")) handleUnstableConfig(c);
if(PrecomputedConfig.pC != null) PrecomputedConfig.pC.deactivate();
try {
PrecomputedConfig.pC = new PrecomputedConfig(c);} catch (CloneNotSupportedException e) {e.printStackTrace(); return ActionResult.FAIL;}
try {PrecomputedConfig.pC = new PrecomputedConfig(c);} catch (CloneNotSupportedException e) {e.printStackTrace(); return ActionResult.FAIL;}
SPEfx.syncReverbParams();
return ActionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ public static class Misc {

@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
@Comment("Soft presets. Some of these can be applied one after another to stack effects onto a base profile.")
public ConfigPresets preset = ConfigPresets.THEDOCRUBY;
public ConfigPresets preset = ConfigPresets.DEFAULT_PERFORMANCE;
public String version;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sonicether.soundphysics.config.SoundPhysicsConfig;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

import static com.sonicether.soundphysics.SoundPhysicsMod.groupMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SourceMixin implements SourceAccessor {

@Inject(method = "play", at = @At("HEAD"))
private void OnPlaySoundInjector(CallbackInfo ci) {
SoundPhysics.onPlaySound(pos.x, pos.y, pos.z, pointer);
SoundPhysics.onPlaySoundReverb(pos.x, pos.y, pos.z, pointer, false);
SPLog.checkErrorLog("onplayinjector");
}

Expand All @@ -43,7 +43,7 @@ private float AttenuationHijack(int pointer2, int param_id, float attenuation) {

public void calculateReverb(SoundCategory category, String name) {
SoundPhysics.setLastSoundCategoryAndName(category, name);
SoundPhysics.onPlaySound(pos.x, pos.y, pos.z, pointer);
SoundPhysics.onPlaySoundReverb(pos.x, pos.y, pos.z, pointer, false);
SPLog.checkErrorLog("onRecalculate");
}
}

0 comments on commit f618ef5

Please sign in to comment.