From 28f5d98d5ca7fbe354d874748cb94f13e845a6da Mon Sep 17 00:00:00 2001 From: z3nth10n Date: Tue, 7 Apr 2020 03:10:38 +0200 Subject: [PATCH] Caching heightmaps in order to use for another generators --- .../terra121/EarthTerrainProcessor.java | 12 +++++-- .../terra121/dataset/HeightmapModel.java | 35 +++++++++++++++++++ .../terra121/populator/RoadGenerator.java | 5 +-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/main/java/io/github/terra121/dataset/HeightmapModel.java diff --git a/src/main/java/io/github/terra121/EarthTerrainProcessor.java b/src/main/java/io/github/terra121/EarthTerrainProcessor.java index 0f3d4ce..a841a29 100644 --- a/src/main/java/io/github/terra121/EarthTerrainProcessor.java +++ b/src/main/java/io/github/terra121/EarthTerrainProcessor.java @@ -17,6 +17,7 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.IBiomeBlockReplacerProvider; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.structure.CubicCaveGenerator; +import io.github.terra121.dataset.HeightmapModel; import io.github.terra121.dataset.Heights; import io.github.terra121.dataset.OpenStreetMaps; import io.github.terra121.populator.CliffReplacer; @@ -54,6 +55,8 @@ public class EarthTerrainProcessor extends BasicCubeGenerator { private boolean doRoads; private boolean doBuildings; + public static final int spawnSize = 5; + public EarthTerrainProcessor(World world) { super(world); @@ -75,7 +78,7 @@ public EarthTerrainProcessor(World world) { unnaturals.add(Blocks.CONCRETE); unnaturals.add(Blocks.BRICK_BLOCK); - surfacePopulators = new TreeSet(); + surfacePopulators = new TreeSet<>(); if(doRoads || cfg.settings.osmwater)surfacePopulators.add(new RoadGenerator(osm, heights, projection)); surfacePopulators.add(new EarthTreePopulator(projection)); snow = new SnowPopulator(); //this will go after the rest @@ -118,7 +121,7 @@ public CubePrimer generateCube(int cubeX, int cubeY, int cubeZ) { boolean surface = false; //null island - if(-5 < cubeX && cubeX < 5 && -5 < cubeZ && cubeZ < 5) { + if(-spawnSize < cubeX && cubeX < spawnSize && -spawnSize < cubeZ && cubeZ < spawnSize) { for(int x=0; x<16; x++) for(int z=0; z<16; z++) heightarr[x][z] = 1; @@ -139,6 +142,11 @@ public CubePrimer generateCube(int cubeX, int cubeY, int cubeZ) { } } + CubePos pos = new CubePos(cubeX, cubeY, cubeZ); + HeightmapModel model = new HeightmapModel(surface, heightarr); + + HeightmapModel.add(pos, model); + //fill in the world for(int x=0; x<16; x++) { for(int z=0; z<16; z++) { diff --git a/src/main/java/io/github/terra121/dataset/HeightmapModel.java b/src/main/java/io/github/terra121/dataset/HeightmapModel.java new file mode 100644 index 0000000..befd46e --- /dev/null +++ b/src/main/java/io/github/terra121/dataset/HeightmapModel.java @@ -0,0 +1,35 @@ +package io.github.terra121.dataset; + +import io.github.opencubicchunks.cubicchunks.api.util.CubePos; + +import java.util.HashMap; +import java.util.Map; + +public class HeightmapModel { + public boolean surface; + public double[][] heightmap; + + private HeightmapModel() {} + + public HeightmapModel(boolean surface, double[][] heightmap) { + this.heightmap = heightmap; + this.surface = surface; + } + + private static Map cachedHeightmaps = new HashMap<>(); + + public static HeightmapModel getModel(int chunkX, int chunkY, int chunkZ) { + return getModel(new CubePos(chunkX, chunkY, chunkZ)); + } + + public static HeightmapModel getModel(CubePos pos) { + if(!cachedHeightmaps.containsKey(pos)) + return null; + + return cachedHeightmaps.get(pos); + } + + public static void add(CubePos pos, HeightmapModel model) { + cachedHeightmaps.put(pos, model); + } +} diff --git a/src/main/java/io/github/terra121/populator/RoadGenerator.java b/src/main/java/io/github/terra121/populator/RoadGenerator.java index 6bed472..3250586 100644 --- a/src/main/java/io/github/terra121/populator/RoadGenerator.java +++ b/src/main/java/io/github/terra121/populator/RoadGenerator.java @@ -1,5 +1,6 @@ package io.github.terra121.populator; +import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.function.BiFunction; @@ -22,7 +23,7 @@ public class RoadGenerator implements ICubicPopulator, Comparable { - private static HashSet roadChunks = new HashSet<>(); + private static Set roadChunks = new HashSet<>(); private static final IBlockState ASPHALT = Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, EnumDyeColor.GRAY); private static final IBlockState WATER_SOURCE = Blocks.WATER.getDefaultState(); @@ -222,7 +223,7 @@ private static double bound(double x, double slope, double j, double k, double r public static boolean isRoad(int cubeX, int cubeY, int cubeZ) { CubePos pos = new CubePos(cubeX, cubeY, cubeZ); boolean isRoad = roadChunks.contains(pos); - roadChunks.remove(pos); + // roadChunks.remove(pos); return isRoad; }