Skip to content

Commit

Permalink
Revert "Update NoiseGeneratorOctavesMultithread.java"
Browse files Browse the repository at this point in the history
This reverts commit e6e484b.
  • Loading branch information
quentin452 committed Jan 22, 2024
1 parent 4bcb054 commit 83186ed
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;

import net.minecraft.util.MathHelper;
import net.minecraft.world.gen.NoiseGenerator;
Expand All @@ -16,6 +15,7 @@ public class NoiseGeneratorOctavesMultithread extends NoiseGenerator {
/** Collection of noise generation functions. Output is combined to produce different octaves of noise. */
private final NoiseGeneratorImprovedMultithread[] generatorCollection;
private final int octaves;
private final ExecutorService executor;

public NoiseGeneratorOctavesMultithread(Random p_i2111_1_, int p_i2111_2_) {
this.octaves = p_i2111_2_;
Expand All @@ -24,15 +24,19 @@ public NoiseGeneratorOctavesMultithread(Random p_i2111_1_, int p_i2111_2_) {
for (int j = 0; j < p_i2111_2_; ++j) {
this.generatorCollection[j] = new NoiseGeneratorImprovedMultithread(p_i2111_1_);
}

// Create an executor with a fixed number of threads (you can adjust the number as needed)
this.executor = Executors.newFixedThreadPool(
Runtime.getRuntime()
.availableProcessors());
}

/**
* pars:(par2,3,4=noiseOffset ; so that adjacent noise segments connect) (pars5,6,7=x,y,zArraySize),(pars8,10,12 =
* x,y,z noiseScale)
*/
public double[] generateNoiseOctaves(double[] p_76304_1_, int p_76304_2_, int p_76304_3_, int p_76304_4_,
int p_76304_5_, int p_76304_6_, int p_76304_7_,
double p_76304_8_, double p_76304_10_, double p_76304_12_) {
int p_76304_5_, int p_76304_6_, int p_76304_7_, double p_76304_8_, double p_76304_10_, double p_76304_12_) {
if (p_76304_1_ == null) {
p_76304_1_ = new double[p_76304_5_ * p_76304_6_ * p_76304_7_];
} else {
Expand All @@ -43,8 +47,6 @@ public double[] generateNoiseOctaves(double[] p_76304_1_, int p_76304_2_, int p_

CompletableFuture[] futures = new CompletableFuture[octaves];

ForkJoinPool executor = ForkJoinPool.commonPool();

for (int l1 = 0; l1 < this.octaves; ++l1) {
final int octave = l1;
double d3 = p_76304_2_ * d6 * p_76304_8_;
Expand All @@ -63,18 +65,20 @@ public double[] generateNoiseOctaves(double[] p_76304_1_, int p_76304_2_, int p_
double finalD = d3;
double finalD1 = d5;
double finalD2 = d6;
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> this.generatorCollection[octave].populateNoiseArray(
finalP_76304_1_,
finalD,
d4,
finalD1,
p_76304_5_,
p_76304_6_,
p_76304_7_,
p_76304_8_ * finalD2,
p_76304_10_ * finalD2,
p_76304_12_ * finalD2,
finalD2), executor);
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
this.generatorCollection[octave].populateNoiseArray(
finalP_76304_1_,
finalD,
d4,
finalD1,
p_76304_5_,
p_76304_6_,
p_76304_7_,
p_76304_8_ * finalD2,
p_76304_10_ * finalD2,
p_76304_12_ * finalD2,
finalD2);
}, executor);

futures[l1] = future;
d6 /= 2.0D;
Expand Down

0 comments on commit 83186ed

Please sign in to comment.