Chunk generation now generates sea and island.

Adjusted values for the island mapper.
Island world mapper now takes a seed instead of a random object.
Refactoring of method names.

Reduced cache sizes used by terrain generation.

Reworked height shader to not use it's own noise generator.

Updated tests implementing changes respectively.
This commit is contained in:
2020-04-30 21:42:03 -05:00
parent d0701ce63d
commit e4597538b2
5 changed files with 173 additions and 84 deletions

View File

@@ -19,14 +19,14 @@ public class IslandWorldMapperTest {
public final Cache<Point2, Double> blockValCache = new Cache<>(2048);
public final int SEED = 102385923;
public Random random = new Random(SEED);
public IslandWorldMapper mapper = new IslandWorldMapper(random, blockValCache);
public IslandWorldMapper mapper = new IslandWorldMapper(SEED, blockValCache);
public final double[][] answers = new double[2048][2048];
@BeforeAll
public void setUp() {
for (int x = 0; x < answers.length; x++) {
for (int y = 0; y < answers[x].length; y++) {
answers[x][y] = mapper.getWorldBlockValue(x, y);
answers[x][y] = mapper.getWorldValue(x, y);
}
}
blockValCache.clearCache();
@@ -40,14 +40,14 @@ public class IslandWorldMapperTest {
@BeforeEach
public void individualSetUp() {
random = new Random(SEED);
mapper = new IslandWorldMapper(random, blockValCache);
mapper = new IslandWorldMapper(SEED, blockValCache);
}
@Test
public void testBlockValueConsistency() {
for (int x = 0; x < answers.length; x++) {
for (int y = 0; y < answers[x].length; y++) {
assertEquals(answers[x][y], mapper.getWorldBlockValue(x, y), String.format("Occurred at (%d, %d)", x, y));
assertEquals(answers[x][y], mapper.getWorldValue(x, y), String.format("Occurred at (%d, %d)", x, y));
}
}
}
@@ -57,7 +57,7 @@ public class IslandWorldMapperTest {
for (int amount = 0; amount < 1024; amount++) {
int x = random.nextInt(answers.length);
int y = random.nextInt(answers[x].length);
assertEquals(answers[x][y], mapper.getWorldBlockValue(x, y), String.format("Occurred at (%d, %d)", x, y));
assertEquals(answers[x][y], mapper.getWorldValue(x, y), String.format("Occurred at (%d, %d)", x, y));
}
}
}

View File

@@ -3,7 +3,6 @@ package ca.recrown.islandsurvivalcraft.world.generation;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.LinkedList;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -12,6 +11,7 @@ import java.util.concurrent.TimeUnit;
import org.bukkit.block.Biome;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;
@@ -27,9 +27,9 @@ import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper;
public class UniBiomeIslandGeneratorTest {
private final int SEED = 249398015;
private final DummyWorld dummyWorld = new DummyWorld();
private final Cache<Point2, Double> blockValueCache = new Cache<>(524288);
private final Cache<Point2, Biome[]> biomeCache = new Cache<>(524288);
private final Cache<Point2, Boolean> chunkExistenceCache = new Cache<>(16384);
private volatile Cache<Point2, Double> blockValueCache;
private volatile Cache<Point2, Biome[]> biomeCache;
private volatile Cache<Point2, Boolean> chunkExistenceCache;
private class BiomeGenTask implements Runnable {
private final int amount;
@@ -49,8 +49,7 @@ public class UniBiomeIslandGeneratorTest {
}
public void generateBiome(int chunkX, int chunkZ) {
Random rand = new Random(SEED);
IslandWorldMapper mapper = new IslandWorldMapper(rand, blockValueCache);
IslandWorldMapper mapper = new IslandWorldMapper(SEED, blockValueCache);
TemperatureMapGenerator temperatureMapGenerator = new TemperatureMapGenerator(SEED);
BiomeSelector biomeSelector = new BiomeSelector();
biomeSelector.initialize();
@@ -70,6 +69,13 @@ public class UniBiomeIslandGeneratorTest {
}
}
@BeforeEach
public void individualSetup() {
blockValueCache = new Cache<>(524288);
biomeCache = new Cache<>(524288);
chunkExistenceCache = new Cache<>(16384);
}
@AfterEach
public void individualCleanup() {
blockValueCache.clearCache();
@@ -107,6 +113,40 @@ public class UniBiomeIslandGeneratorTest {
}
}
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationMultithread1608ChunksSmallCache() {
this.blockValueCache = new Cache<>(1024);
this.biomeCache = new Cache<>(1024);
this.chunkExistenceCache = new Cache<>(1024);
int chunksToDoEach = 268;
Runnable g1 = new BiomeGenTask(chunksToDoEach, 0);
Runnable g2 = new BiomeGenTask(chunksToDoEach, 1);
Runnable g3 = new BiomeGenTask(chunksToDoEach, 2);
Runnable g4 = new BiomeGenTask(chunksToDoEach, 3);
Runnable g5 = new BiomeGenTask(chunksToDoEach, 4);
Runnable g6 = new BiomeGenTask(chunksToDoEach, 5);
ExecutorService ex = Executors.newFixedThreadPool(6);
LinkedList<Future<?>> tasks = new LinkedList<>();
tasks.add(ex.submit(g1));
tasks.add(ex.submit(g2));
tasks.add(ex.submit(g3));
tasks.add(ex.submit(g4));
tasks.add(ex.submit(g5));
tasks.add(ex.submit(g6));
while (!tasks.isEmpty()) {
try {
tasks.pop().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
assertFalse(false, e.getCause().getMessage());
}
}
}
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationSingleThread1608Chunks() {
@@ -146,8 +186,11 @@ public class UniBiomeIslandGeneratorTest {
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationMultithread6000ChunksScatteredColumns() {
int chunksToDoEach = 1000;
public void testBiomeGenerationMultithread1608ChunksScatteredColumnsSmallCache() {
this.blockValueCache = new Cache<>(1024);
this.biomeCache = new Cache<>(1024);
this.chunkExistenceCache = new Cache<>(1024);
int chunksToDoEach = 268;
Runnable g1 = new BiomeGenTask(chunksToDoEach, 0);
Runnable g2 = new BiomeGenTask(chunksToDoEach, 2);
Runnable g3 = new BiomeGenTask(chunksToDoEach, 4);
@@ -173,4 +216,68 @@ public class UniBiomeIslandGeneratorTest {
}
}
}
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationMultithread6000ChunksScatteredColumns() {
int chunksToDoEach = 1000;
Runnable g1 = new BiomeGenTask(chunksToDoEach, 0);
Runnable g2 = new BiomeGenTask(chunksToDoEach, 3);
Runnable g3 = new BiomeGenTask(chunksToDoEach, 6);
Runnable g4 = new BiomeGenTask(chunksToDoEach, 9);
Runnable g5 = new BiomeGenTask(chunksToDoEach, 12);
Runnable g6 = new BiomeGenTask(chunksToDoEach, 15);
ExecutorService ex = Executors.newFixedThreadPool(6);
LinkedList<Future<?>> tasks = new LinkedList<>();
tasks.add(ex.submit(g1));
tasks.add(ex.submit(g2));
tasks.add(ex.submit(g3));
tasks.add(ex.submit(g4));
tasks.add(ex.submit(g5));
tasks.add(ex.submit(g6));
while (!tasks.isEmpty()) {
try {
tasks.pop().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
assertFalse(false, e.getCause().getMessage());
}
}
}
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationMultithread6000ChunksScatteredColumnsSmallCache() {
this.blockValueCache = new Cache<>(1024);
this.biomeCache = new Cache<>(1024);
this.chunkExistenceCache = new Cache<>(1024);
int chunksToDoEach = 1000;
Runnable g1 = new BiomeGenTask(chunksToDoEach, 0);
Runnable g2 = new BiomeGenTask(chunksToDoEach, 3);
Runnable g3 = new BiomeGenTask(chunksToDoEach, 6);
Runnable g4 = new BiomeGenTask(chunksToDoEach, 9);
Runnable g5 = new BiomeGenTask(chunksToDoEach, 12);
Runnable g6 = new BiomeGenTask(chunksToDoEach, 15);
ExecutorService ex = Executors.newFixedThreadPool(6);
LinkedList<Future<?>> tasks = new LinkedList<>();
tasks.add(ex.submit(g1));
tasks.add(ex.submit(g2));
tasks.add(ex.submit(g3));
tasks.add(ex.submit(g4));
tasks.add(ex.submit(g5));
tasks.add(ex.submit(g6));
while (!tasks.isEmpty()) {
try {
tasks.pop().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
assertFalse(false, e.getCause().getMessage());
}
}
}
}