Skip to content

Commit

Permalink
improv: optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jun 21, 2024
1 parent 234e75d commit 60a40ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.debug=false

mod_version=1.0.79
mod_version=1.0.80

# Mod
mod_id=zenith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.zepalesque.zenith.mixin.mixins.common.accessor.PerlinNoiseAccessor;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.UnaryOperator;

Expand All @@ -28,6 +30,7 @@ public class PerlinNoiseFunction implements DensityFunction {

@Nullable
public PerlinNoise noise = null;
private static final Map<Long, PerlinNoiseVisitor> VISITORS = new HashMap<>();
// This is used before the seed is initialized, for methods such as DensityFunction#maxValue
private final PerlinNoise fakeNoise;
public final NormalNoise.NoiseParameters params;
Expand Down Expand Up @@ -82,14 +85,14 @@ public PerlinNoiseFunction initialize(Function<Long, RandomSource> rand) {
return this;
}

public static PerlinNoiseVisitor createVisitor(WorldGenLevel level) {
return new PerlinNoiseVisitor(noise -> {
public static PerlinNoiseVisitor createOrGetVisitor(long seed) {
return VISITORS.computeIfAbsent(seed, l -> new PerlinNoiseVisitor(noise -> {
if (noise.initialized()) {
return noise;
} else {
return noise.initialize(offset -> new XoroshiroRandomSource(level.getSeed() + offset));
return noise.initialize(offset -> new XoroshiroRandomSource(l + offset));
}
});
}));
}

public boolean initialized() {
Expand Down

0 comments on commit 60a40ea

Please sign in to comment.