From f618ef57b9502a777c3dbb94b4c20952627d5407 Mon Sep 17 00:00:00 2001
From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com>
Date: Sat, 15 Jan 2022 16:43:16 -0500
Subject: [PATCH] Tidy the code, Fix some issues
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.
---
gradle.properties | 2 +-
.../soundphysics/ALstuff/SPEfx.java | 8 +-
.../com/sonicether/soundphysics/SPMath.java | 13 --
.../sonicether/soundphysics/SoundPhysics.java | 154 ++++++++----------
.../config/BlueTapePack/ConfigManager.java | 30 ++--
.../config/SoundPhysicsConfig.java | 3 +-
.../config/presets/ConfigChanger.java | 1 +
.../soundphysics/mixin/SourceMixin.java | 4 +-
8 files changed, 95 insertions(+), 120 deletions(-)
delete mode 100644 src/main/java/com/sonicether/soundphysics/SPMath.java
diff --git a/gradle.properties b/gradle.properties
index 979b4904..e50bf980 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -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
diff --git a/src/main/java/com/sonicether/soundphysics/ALstuff/SPEfx.java b/src/main/java/com/sonicether/soundphysics/ALstuff/SPEfx.java
index a8ae4038..46a9be85 100644
--- a/src/main/java/com/sonicether/soundphysics/ALstuff/SPEfx.java
+++ b/src/main/java/com/sonicether/soundphysics/ALstuff/SPEfx.java
@@ -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;
@@ -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:");
}
@@ -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));
@@ -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);
}
}
diff --git a/src/main/java/com/sonicether/soundphysics/SPMath.java b/src/main/java/com/sonicether/soundphysics/SPMath.java
deleted file mode 100644
index 617de23a..00000000
--- a/src/main/java/com/sonicether/soundphysics/SPMath.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.sonicether.soundphysics;
-
-public class SPMath {
- //
- public static int clamp(int a, int max, int min) {return Math.min(max, Math.max(min, a)); }
- public static float clamp(float a, float max, float min) {return Math.min(max, Math.max(min, a)); }
- public static double clamp(double a, double max, double min) {return Math.min(max, Math.max(min, a)); }
- //
- //
- public static float lerp(float a, float b, float f) {return a + clamp(f, 1.0f, 0.0f) * (b - a);}
- public static double lerp(double a, double b, double f) {return a + clamp(f, 1.0d, 0.0d) * (b - a);}
- //
-}
diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java
index e2ccdd6c..18e1b8d6 100644
--- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java
+++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java
@@ -1,6 +1,5 @@
package com.sonicether.soundphysics;
-import com.sonicether.soundphysics.config.PrecomputedConfig;
import com.sonicether.soundphysics.performance.RaycastFix;
import com.sonicether.soundphysics.performance.SPHitResult;
import net.fabricmc.api.EnvType;
@@ -22,13 +21,13 @@
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import static com.sonicether.soundphysics.ALstuff.SPEfx.*;
import static com.sonicether.soundphysics.SPLog.*;
import static com.sonicether.soundphysics.performance.RaycastFix.fixedRaycast;
+import static com.sonicether.soundphysics.config.PrecomputedConfig.pC;
@SuppressWarnings({"NonAsciiCharacters", "CommentedOutCode"})
@Environment(EnvType.CLIENT) //IDK why
@@ -66,24 +65,25 @@ public static void init()
public static void setLastSoundCategoryAndName(SoundCategory sc, String name) { lastSoundCategory = sc; lastSoundName = name; }
+ @SuppressWarnings("unused") @Deprecated
public static void onPlaySound(double posX, double posY, double posZ, int sourceID){onPlaySoundReverb(posX, posY, posZ, sourceID, false);}
- @SuppressWarnings("unused")
+ @SuppressWarnings("unused") @Deprecated
public static void onPlayReverb(double posX, double posY, double posZ, int sourceID){onPlaySoundReverb(posX, posY, posZ, sourceID, true);}
public static void onPlaySoundReverb(double posX, double posY, double posZ, int sourceID, boolean auxOnly)
{
- if (PrecomputedConfig.pC.dLog) logGeneral("On play sound... Source ID: " + sourceID + " " + posX + ", " + posY + ", " + posZ + " Sound category: " + lastSoundCategory.toString() + " Sound name: " + lastSoundName);
+ if (pC.dLog) logGeneral("On play sound... Source ID: " + sourceID + " " + posX + ", " + posY + ", " + posZ + " Sound category: " + lastSoundCategory.toString() + " Sound name: " + lastSoundName);
long startTime = 0;
long endTime;
- if (PrecomputedConfig.pC.pLog) startTime = System.nanoTime();
+ if (pC.pLog) startTime = System.nanoTime();
//t1();// rm
evaluateEnvironment(sourceID, posX, posY, posZ, auxOnly); // time = 0.5? OωO
//t2();
//tavg();tres();//tout();// ψ time ψ
- if (PrecomputedConfig.pC.pLog) { endTime = System.nanoTime();
+ if (pC.pLog) { endTime = System.nanoTime();
log("Total calculation time for sound " + lastSoundName + ": " + (double)(endTime - startTime)/(double)1000000 + " milliseconds"); }
}
@@ -92,20 +92,20 @@ private static double getBlockReflectivity(final BlockState blockState)
{
BlockSoundGroup soundType = blockState.getSoundGroup();
String blockName = blockState.getBlock().getTranslationKey();
- if (PrecomputedConfig.pC.blockWhiteSet.contains(blockName)) return PrecomputedConfig.pC.blockWhiteMap.get(blockName).reflectivity;
+ if (pC.blockWhiteSet.contains(blockName)) return pC.blockWhiteMap.get(blockName).reflectivity;
- double r = PrecomputedConfig.pC.reflectivityMap.getOrDefault(soundType, Double.NaN);
- return Double.isNaN(r) ? PrecomputedConfig.pC.defaultReflectivity : r;
+ double r = pC.reflectivityMap.getOrDefault(soundType, Double.NaN);
+ return Double.isNaN(r) ? pC.defaultReflectivity : r;
}
private static double getBlockOcclusionD(final BlockState blockState)
{
BlockSoundGroup soundType = blockState.getSoundGroup();
String blockName = blockState.getBlock().getTranslationKey();
- if (PrecomputedConfig.pC.blockWhiteSet.contains(blockName)) return PrecomputedConfig.pC.blockWhiteMap.get(blockName).absorption;
+ if (pC.blockWhiteSet.contains(blockName)) return pC.blockWhiteMap.get(blockName).absorption;
- double r = PrecomputedConfig.pC.absorptionMap.getOrDefault(soundType, Double.NaN);
- return Double.isNaN(r) ? PrecomputedConfig.pC.defaultAbsorption : r;
+ double r = pC.absorptionMap.getOrDefault(soundType, Double.NaN);
+ return Double.isNaN(r) ? pC.defaultAbsorption : r;
}
private static Vec3d pseudoReflect(Vec3d dir, Vec3i normal)
@@ -114,9 +114,9 @@ private static Vec3d pseudoReflect(Vec3d dir, Vec3i normal)
@SuppressWarnings("ConstantConditions")
private static void evaluateEnvironment(final int sourceID, double posX, double posY, double posZ, boolean auxOnly)
{
- if (PrecomputedConfig.pC.off) return;
+ if (pC.off) return;
- if (mc.player == null || mc.world == null || posY <= mc.world.getBottomY() || (PrecomputedConfig.pC.recordsDisable && lastSoundCategory == SoundCategory.RECORDS) || uiPattern.matcher(lastSoundName).matches() || (posX == 0.0 && posY == 0.0 && posZ == 0.0))
+ if (mc.player == null || mc.world == null || posY <= mc.world.getBottomY() || (pC.recordsDisable && lastSoundCategory == SoundCategory.RECORDS) || uiPattern.matcher(lastSoundName).matches() || (posX == 0.0 && posY == 0.0 && posZ == 0.0))
{
//logDetailed("Menu sound!");
setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, auxOnly ? 0.0f : 1.0f);
@@ -128,7 +128,7 @@ private static void evaluateEnvironment(final int sourceID, double posX, double
boolean block = blockPattern.matcher(lastSoundName).matches() && !stepPattern.matcher(lastSoundName).matches();
if (lastSoundCategory == SoundCategory.RECORDS){posX+=0.5;posY+=0.5;posZ+=0.5;block = true;}
- if (PrecomputedConfig.pC.skipRainOcclusionTracing && isRain)
+ if (pC.skipRainOcclusionTracing && isRain)
{
setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, auxOnly ? 0.0f : 1.0f);
return;
@@ -157,21 +157,21 @@ private static void evaluateEnvironment(final int sourceID, double posX, double
final WorldChunk soundChunk = mc.world.getChunk(((int)Math.floor(posX))>>4,((int)Math.floor(posZ))>>4);
- //Direct sound occlusion // time = 0.1
+ //Direct sound occlusion // time = 0.1 // TODO: This can be done better
final Vec3d soundPos = new Vec3d(posX, posY, posZ);
Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize();
final BlockPos soundBlockPos = new BlockPos(soundPos.x, soundPos.y,soundPos.z);
- if (PrecomputedConfig.pC.dLog) logGeneral("Player pos: " + playerPos.x + ", " + playerPos.y + ", " + playerPos.z + " Sound Pos: " + soundPos.x + ", " + soundPos.y + ", " + soundPos.z + " To player vector: " + normalToPlayer.x + ", " + normalToPlayer.y + ", " + normalToPlayer.z);
+ if (pC.dLog) logGeneral("Player pos: " + playerPos.x + ", " + playerPos.y + ", " + playerPos.z + " Sound Pos: " + soundPos.x + ", " + soundPos.y + ", " + soundPos.z + " To player vector: " + normalToPlayer.x + ", " + normalToPlayer.y + ", " + normalToPlayer.z);
double occlusionAccumulation = 0;
final List> directions = new Vector<>(10, 10);
//Cast a ray from the source towards the player
Vec3d rayOrigin = soundPos;
//System.out.println(rayOrigin.toString());
BlockPos lastBlockPos = soundBlockPos;
- final boolean _9ray = PrecomputedConfig.pC._9Ray && (lastSoundCategory == SoundCategory.BLOCKS || block);
+ final boolean _9ray = pC._9Ray && (lastSoundCategory == SoundCategory.BLOCKS || block);
final int nOccRays = _9ray ? 9 : 1;
double occlusionAccMin = Double.MAX_VALUE;
for (int j = 0; j < nOccRays; j++) {
@@ -190,12 +190,12 @@ private static void evaluateEnvironment(final int sourceID, double posX, double
lastBlockPos = rayHit.getBlockPos();
//If we hit a block
- if (PrecomputedConfig.pC.dRays) RaycastRenderer.addOcclusionRay(rayOrigin, rayHit.getPos(), Color.getHSBColor((float) (1F / 3F * (1F - Math.min(1F, occlusionAccumulation / 12F))), 1F, 1F).getRGB());
+ if (pC.dRays) RaycastRenderer.addOcclusionRay(rayOrigin, rayHit.getPos(), Color.getHSBColor((float) (1F / 3F * (1F - Math.min(1F, occlusionAccumulation / 12F))), 1F, 1F).getRGB());
if (rayHit.isMissed()) {
- if (PrecomputedConfig.pC.soundDirectionEvaluation) directions.add(Map.entry(rayOrigin.subtract(playerPos),
- (_9ray?9:1) * Math.pow(soundPos.distanceTo(playerPos), 2.0)* PrecomputedConfig.pC.rcpTotRays
+ if (pC.soundDirectionEvaluation) directions.add(Map.entry(rayOrigin.subtract(playerPos),
+ (_9ray?9:1) * Math.pow(soundPos.distanceTo(playerPos), 2.0)* pC.rcpTotRays
/
- (Math.exp(-occlusionAccumulation * PrecomputedConfig.pC.globalBlockAbsorption)* PrecomputedConfig.pC.directRaysDirEvalMultiplier)
+ (Math.exp(-occlusionAccumulation * pC.globalBlockAbsorption)* pC.directRaysDirEvalMultiplier)
));
oAValid = true;
break;
@@ -207,7 +207,7 @@ private static void evaluateEnvironment(final int sourceID, double posX, double
// Regardless to whether we hit from inside or outside
- if (PrecomputedConfig.pC.oLog) logOcclusion(blockHit.getBlock().getTranslationKey() + " " + rayHitPos.x + ", " + rayHitPos.y + ", " + rayHitPos.z);
+ if (pC.oLog) logOcclusion(blockHit.getBlock().getTranslationKey() + " " + rayHitPos.x + ", " + rayHitPos.y + ", " + rayHitPos.z);
rayOrigin = rayHitPos; //new Vec3d(rayHit.getPos().x + normalToPlayer.x * 0.1, rayHit.getPos().y + normalToPlayer.y * 0.1, rayHit.getPos().z + normalToPlayer.z * 0.1);
@@ -218,70 +218,49 @@ private static void evaluateEnvironment(final int sourceID, double posX, double
if (rayBack.getBlockPos().equals(lastBlockPos)) {
//Accumulate density
occlusionAccumulation += blockOcclusion * (rayOrigin.distanceTo(rayBack.getPos()));
- if (occlusionAccumulation > PrecomputedConfig.pC.maxDirectOcclusionFromBlocks) break;
+ if (occlusionAccumulation > pC.maxDirectOcclusionFromBlocks) break;
}
- if (PrecomputedConfig.pC.oLog) logOcclusion("New trace position: " + rayOrigin.x + ", " + rayOrigin.y + ", " + rayOrigin.z);
+ if (pC.oLog) logOcclusion("New trace position: " + rayOrigin.x + ", " + rayOrigin.y + ", " + rayOrigin.z);
}
if (oAValid) occlusionAccMin = Math.min(occlusionAccMin, occlusionAccumulation);
}
- occlusionAccumulation = Math.min(occlusionAccMin, PrecomputedConfig.pC.maxDirectOcclusionFromBlocks);
- double directCutoff = Math.exp(-occlusionAccumulation * PrecomputedConfig.pC.globalBlockAbsorption);
+ occlusionAccumulation = Math.min(occlusionAccMin, pC.maxDirectOcclusionFromBlocks);
+ double directCutoff = Math.exp(-occlusionAccumulation * pC.globalBlockAbsorption);
double directGain = auxOnly ? 0 : Math.pow(directCutoff, 0.01);
- if (PrecomputedConfig.pC.oLog) logOcclusion("direct cutoff: " + directCutoff + " direct gain:" + directGain);
+ if (pC.oLog) logOcclusion("direct cutoff: " + directCutoff + " direct gain:" + directGain);
final double[] δsendGain = {0d,0d,0d,0d};
- if (isRain) {finalizeEnvironment(true, sourceID, directCutoff, 0, occlusionAccumulation, directGain, auxOnly, null, δsendGain); return;}
+ if (isRain) {finalizeEnvironment(true, sourceID, directCutoff, 0, directGain, auxOnly, null, δsendGain); return;}
// Shoot rays around sound
- final double maxDistance = 256 * PrecomputedConfig.pC.nRayBounces;
+ final double maxDistance = 256 * pC.nRayBounces;
- boolean doDirEval = PrecomputedConfig.pC.soundDirectionEvaluation && (occlusionAccumulation > 0 || PrecomputedConfig.pC.notOccludedRedirect);
+ boolean doDirEval = pC.soundDirectionEvaluation && (occlusionAccumulation > 0 || pC.notOccludedRedirect);
- final double[] bounceReflectivityRatio = new double[PrecomputedConfig.pC.nRayBounces];
+ final double[] bounceReflectivityRatio = new double[pC.nRayBounces];
- AtomicReference sharedAirspace = new AtomicReference<>(0d);
+ final double[] sharedAirspace = new double[1];
final double gRatio = 1.618033988;
final double epsilon;
- if (PrecomputedConfig.pC.nRays >= 600000)
- {
- epsilon = 214d;
- }
- else if (PrecomputedConfig.pC.nRays >= 400000)
- {
- epsilon = 75d;
- }
- else if (PrecomputedConfig.pC.nRays >= 11000)
- {
- epsilon = 27d;
- }
- else if (PrecomputedConfig.pC.nRays >= 890)
- {
- epsilon = 10d;
- }
- else if (PrecomputedConfig.pC.nRays >= 177)
- {
- epsilon = 3.33d;
- }
- else if (PrecomputedConfig.pC.nRays >= 24)
- {
- epsilon = 1.33d;
- }
- else
- {
- epsilon = 0.33d;
- }
+ if (pC.nRays >= 600000) { epsilon = 214d; }
+ else if (pC.nRays >= 400000) { epsilon = 75d; }
+ else if (pC.nRays >= 11000) { epsilon = 27d; }
+ else if (pC.nRays >= 890) { epsilon = 10d; }
+ else if (pC.nRays >= 177) { epsilon = 3.33d; }
+ else if (pC.nRays >= 24) { epsilon = 1.33d; }
+ else { epsilon = 0.33d; }
//for (int i = 0; i < pC.nRays; i++)
- IntStream stream = IntStream.range(0, PrecomputedConfig.pC.nRays);
- (PrecomputedConfig.pC.multiThreading ? stream.parallel() : stream).forEach((i) -> { // time = 3
- final double x = (i + epsilon) / (PrecomputedConfig.pC.nRays - 1d + 2d*epsilon);
+ IntStream stream = IntStream.range(0, pC.nRays);
+ (pC.multiThreading ? stream.parallel() : stream).forEach((i) -> { // time = 3
+ final double x = (i + epsilon) / (pC.nRays - 1d + 2d*epsilon);
final double y = (double) i / gRatio;
final double theta = 2d * Math.PI * y;
final double phi = Math.acos(1d - 2d*x);
@@ -294,8 +273,9 @@ else if (PrecomputedConfig.pC.nRays >= 24)
SPHitResult rayHit = fixedRaycast(soundPos, rayEnd, mc.world, soundBlockPos, soundChunk);
- if (PrecomputedConfig.pC.dRays) RaycastRenderer.addSoundBounceRay(soundPos, rayHit.getPos(), Formatting.GREEN.getColorValue());
+ if (pC.dRays) RaycastRenderer.addSoundBounceRay(soundPos, rayHit.getPos(), Formatting.GREEN.getColorValue());
+ // TODO: This can be done better
if (!rayHit.isMissed()) {
// Additional bounces
@@ -311,12 +291,12 @@ else if (PrecomputedConfig.pC.nRays >= 24)
double totalReflectivityCoefficient = Math.min(blockReflectivity, 1);
// Secondary ray bounces
- for (int j = 0; j < PrecomputedConfig.pC.nRayBounces; j++) {
+ for (int j = 0; j < pC.nRayBounces; j++) {
// Cast (one) final ray towards the player. If it's
// unobstructed, then the sound source and the player
// share airspace.
- final double energyTowardsPlayer = Math.pow(blockReflectivity, 1 / PrecomputedConfig.pC.globalBlockReflectance) * 0.1875 + 0.0625;
- if (!PrecomputedConfig.pC.simplerSharedAirspaceSimulation || j == PrecomputedConfig.pC.nRayBounces - 1) {
+ final double energyTowardsPlayer = Math.pow(blockReflectivity, 1 / pC.globalBlockReflectance) * 0.1875 + 0.0625;
+ if (!pC.simplerSharedAirspaceSimulation || j == pC.nRayBounces - 1) {
final Vec3d finalRayStart = new Vec3d(lastHitPos.x + lastHitNormal.getX() * 0.01,
lastHitPos.y + lastHitNormal.getY() * 0.01, lastHitPos.z + lastHitNormal.getZ() * 0.01);
@@ -331,16 +311,16 @@ else if (PrecomputedConfig.pC.nRays >= 24)
if (doDirEval) synchronized (directions) {directions.add(Map.entry(finalRayStart.subtract(playerPos), (totalFinalRayDistance*totalFinalRayDistance)*(totalReflectivityCoefficient == 0d ? 1000000d : 1d/totalReflectivityCoefficient)));}
//log("Secondary ray hit the player!");
- sharedAirspace.updateAndGet(v -> v + 1d);
+ synchronized (sharedAirspace) { sharedAirspace[0] += 1d; }
- final double reflectionDelay = Math.max(totalRayDistance, 0.0) * 0.12 * Math.pow(blockReflectivity, 1 / PrecomputedConfig.pC.globalBlockReflectance);
+ final double reflectionDelay = Math.max(totalRayDistance, 0.0) * 0.12 * Math.pow(blockReflectivity, 1 / pC.globalBlockReflectance);
final double cross0 = 1d - MathHelper.clamp(Math.abs(reflectionDelay - 0d), 0d, 1d);
final double cross1 = 1d - MathHelper.clamp(Math.abs(reflectionDelay - 1d), 0d, 1d);
final double cross2 = 1d - MathHelper.clamp(Math.abs(reflectionDelay - 2d), 0d, 1d);
final double cross3 = MathHelper.clamp(reflectionDelay - 2d, 0d, 1d);
- double factor = energyTowardsPlayer * 12.8 * PrecomputedConfig.pC.rcpTotRays;
+ double factor = energyTowardsPlayer * 12.8 * pC.rcpTotRays;
synchronized (δsendGain) {
δsendGain[0] += cross0 * factor * 0.5;
δsendGain[1] += cross1 * factor;
@@ -349,7 +329,7 @@ else if (PrecomputedConfig.pC.nRays >= 24)
}
}
- if (PrecomputedConfig.pC.dRays) RaycastRenderer.addSoundBounceRay(finalRayStart, finalRayHit.getPos(), color);
+ if (pC.dRays) RaycastRenderer.addSoundBounceRay(finalRayStart, finalRayHit.getPos(), color);
}
final Vec3d newRayDir = pseudoReflect(lastRayDir, lastHitNormal);
@@ -363,16 +343,16 @@ else if (PrecomputedConfig.pC.nRays >= 24)
if (rayHit.isMissed()) {
- if (PrecomputedConfig.pC.dRays) RaycastRenderer.addSoundBounceRay(newRayStart, newRayEnd, Formatting.DARK_RED.getColorValue());
+ if (pC.dRays) RaycastRenderer.addSoundBounceRay(newRayStart, newRayEnd, Formatting.DARK_RED.getColorValue());
break;
} else {
final Vec3d newRayHitPos = rayHit.getPos();
final double newRayLength = lastHitPos.distanceTo(newRayHitPos);
- if (PrecomputedConfig.pC.dRays) RaycastRenderer.addSoundBounceRay(newRayStart, newRayHitPos, Formatting.BLUE.getColorValue());
+ if (pC.dRays) RaycastRenderer.addSoundBounceRay(newRayStart, newRayHitPos, Formatting.BLUE.getColorValue());
- bounceReflectivityRatio[j] += Math.pow(blockReflectivity, 1 / PrecomputedConfig.pC.globalBlockReflectance);
+ synchronized (bounceReflectivityRatio) { bounceReflectivityRatio[j] += Math.pow(blockReflectivity, 1 / pC.globalBlockReflectance); }
totalRayDistance += newRayLength;
@@ -387,16 +367,16 @@ else if (PrecomputedConfig.pC.nRays >= 24)
}
}
});
- for (int i = 0; i < PrecomputedConfig.pC.nRayBounces; i++) {
- bounceReflectivityRatio[i] = bounceReflectivityRatio[i] * PrecomputedConfig.pC.rcpNRays;
+ for (int i = 0; i < pC.nRayBounces; i++) {
+ bounceReflectivityRatio[i] = bounceReflectivityRatio[i] / pC.nRays; // TODO: Why is this here?
}
// Take weighted (on squared distance) average of the directions sound reflection came from
- dirEval: // time = 0.04
+ dirEval: // time = 0.04 // TODO: Make this better
{
if (directions.isEmpty()) break dirEval;
- if (PrecomputedConfig.pC.pLog) log("Evaluating direction from "+sharedAirspace+" entries...");
+ if (pC.pLog) log("Evaluating direction from " + sharedAirspace[0] + " entries...");
Vec3d sum = new Vec3d(0, 0, 0);
double weight = 0;
@@ -416,10 +396,10 @@ else if (PrecomputedConfig.pC.nRays >= 24)
}
- finalizeEnvironment(false, sourceID, directCutoff, sharedAirspace.get(), occlusionAccumulation, directGain, auxOnly, bounceReflectivityRatio, δsendGain);
+ finalizeEnvironment(false, sourceID, directCutoff, sharedAirspace[0], directGain, auxOnly, bounceReflectivityRatio, δsendGain);
}
- private static void finalizeEnvironment(boolean isRain, int sourceID, double directCutoff, double sharedAirspace, double occlusionAccumulation, double directGain, boolean auxOnly, double[] bounceReflectivityRatio, double @NotNull [] δsendGain) {
+ private static void finalizeEnvironment(boolean isRain, int sourceID, double directCutoff, double sharedAirspace, double directGain, boolean auxOnly, double[] bounceReflectivityRatio, double @NotNull [] δsendGain) { // TODO: Fix questionable math
// Calculate reverb parameters for this sound
double sendGain0 = 0d + δsendGain[0];
double sendGain1 = 0d + δsendGain[1];
@@ -435,7 +415,7 @@ private static void finalizeEnvironment(boolean isRain, int sourceID, double dir
assert mc.player != null;
if (mc.player.isSubmergedInWater())
{
- directCutoff *= PrecomputedConfig.pC.underwaterFilter;
+ directCutoff *= pC.underwaterFilter;
}
if (isRain)
@@ -446,10 +426,10 @@ private static void finalizeEnvironment(boolean isRain, int sourceID, double dir
sharedAirspace *= 64d;
- if (PrecomputedConfig.pC.simplerSharedAirspaceSimulation)
- sharedAirspace *= PrecomputedConfig.pC.rcpNRays;
+ if (pC.simplerSharedAirspaceSimulation)
+ sharedAirspace /= pC.nRays;
else
- sharedAirspace *= PrecomputedConfig.pC.rcpTotRays;
+ sharedAirspace /= pC.nRays * pC.nRayBounces;
final double sharedAirspaceWeight0 = MathHelper.clamp(sharedAirspace * 0.05, 0d, 1d);
final double sharedAirspaceWeight1 = MathHelper.clamp(sharedAirspace * 0.06666666666666667, 0d, 1d);
@@ -469,7 +449,7 @@ private static void finalizeEnvironment(boolean isRain, int sourceID, double dir
//logDetailed("HitRatio0: " + hitRatioBounce1 + " HitRatio1: " + hitRatioBounce2 + " HitRatio2: " + hitRatioBounce3 + " HitRatio3: " + hitRatioBounce4);
- if (PrecomputedConfig.pC.eLog) logEnvironment("Bounce reflectivity 0: " + bounceReflectivityRatio[0] + " bounce reflectivity 1: " + bounceReflectivityRatio[1] + " bounce reflectivity 2: " + bounceReflectivityRatio[2] + " bounce reflectivity 3: " + bounceReflectivityRatio[3]);
+ if (pC.eLog) logEnvironment("Bounce reflectivity 0: " + bounceReflectivityRatio[0] + " bounce reflectivity 1: " + bounceReflectivityRatio[1] + " bounce reflectivity 2: " + bounceReflectivityRatio[2] + " bounce reflectivity 3: " + bounceReflectivityRatio[3]);
sendGain1 *= bounceReflectivityRatio[1];
@@ -486,7 +466,7 @@ private static void finalizeEnvironment(boolean isRain, int sourceID, double dir
sendGain2 *= Math.pow(sendCutoff2, 0.1);
sendGain3 *= Math.pow(sendCutoff3, 0.1);
- if (PrecomputedConfig.pC.eLog) logEnvironment("Final environment settings: " + sendGain0 + ", " + sendGain1 + ", " + sendGain2 + ", " + sendGain3);
+ if (pC.eLog) logEnvironment("Final environment settings: " + sendGain0 + ", " + sendGain1 + ", " + sendGain2 + ", " + sendGain3);
assert mc.player != null;
if (mc.player.isSubmergedInWater())
diff --git a/src/main/java/com/sonicether/soundphysics/config/BlueTapePack/ConfigManager.java b/src/main/java/com/sonicether/soundphysics/config/BlueTapePack/ConfigManager.java
index a2bba788..ecf03e0f 100644
--- a/src/main/java/com/sonicether/soundphysics/config/BlueTapePack/ConfigManager.java
+++ b/src/main/java/com/sonicether/soundphysics/config/BlueTapePack/ConfigManager.java
@@ -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 {
@@ -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() {
@@ -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;
}
diff --git a/src/main/java/com/sonicether/soundphysics/config/SoundPhysicsConfig.java b/src/main/java/com/sonicether/soundphysics/config/SoundPhysicsConfig.java
index 439617d4..4197f3b8 100644
--- a/src/main/java/com/sonicether/soundphysics/config/SoundPhysicsConfig.java
+++ b/src/main/java/com/sonicether/soundphysics/config/SoundPhysicsConfig.java
@@ -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;
}
diff --git a/src/main/java/com/sonicether/soundphysics/config/presets/ConfigChanger.java b/src/main/java/com/sonicether/soundphysics/config/presets/ConfigChanger.java
index 43e69faf..8631e6c6 100644
--- a/src/main/java/com/sonicether/soundphysics/config/presets/ConfigChanger.java
+++ b/src/main/java/com/sonicether/soundphysics/config/presets/ConfigChanger.java
@@ -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;
diff --git a/src/main/java/com/sonicether/soundphysics/mixin/SourceMixin.java b/src/main/java/com/sonicether/soundphysics/mixin/SourceMixin.java
index 8ddcf119..f232f1db 100644
--- a/src/main/java/com/sonicether/soundphysics/mixin/SourceMixin.java
+++ b/src/main/java/com/sonicether/soundphysics/mixin/SourceMixin.java
@@ -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");
}
@@ -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");
}
}