Biome Rarity

This commit is contained in:
Daniel Mills 2020-07-29 23:18:37 -04:00
parent 36e5fec284
commit 773dd2fd1a
4 changed files with 81 additions and 20 deletions

View File

@ -2,8 +2,8 @@ package com.volmit.iris.layer;
import com.volmit.iris.object.InferredType; import com.volmit.iris.object.InferredType;
import com.volmit.iris.object.IrisRegion; import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.BiomeRarityCellGenerator;
import com.volmit.iris.util.BiomeResult; import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.CellGenerator;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
import lombok.Data; import lombok.Data;
@ -12,14 +12,14 @@ import lombok.Data;
public class BiomeDataProvider public class BiomeDataProvider
{ {
private InferredType type; private InferredType type;
private CellGenerator generator; private BiomeRarityCellGenerator generator;
private GenLayerBiome layer; private GenLayerBiome layer;
public BiomeDataProvider(GenLayerBiome layer, InferredType type, RNG rng) public BiomeDataProvider(GenLayerBiome layer, InferredType type, RNG rng)
{ {
this.type = type; this.type = type;
this.layer = layer; this.layer = layer;
generator = new CellGenerator(rng.nextParallelRNG(4645079 + (type.ordinal() * 23845))); generator = new BiomeRarityCellGenerator(rng.nextParallelRNG(4645079 + (type.ordinal() * 23845)));
} }
public BiomeResult generatePureData(double bx, double bz, int rawX, int rawZ, IrisRegion regionData) public BiomeResult generatePureData(double bx, double bz, int rawX, int rawZ, IrisRegion regionData)

View File

@ -7,6 +7,7 @@ import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisRegion; import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.object.IrisRegionRidge; import com.volmit.iris.object.IrisRegionRidge;
import com.volmit.iris.object.IrisRegionSpot; import com.volmit.iris.object.IrisRegionSpot;
import com.volmit.iris.util.BiomeRarityCellGenerator;
import com.volmit.iris.util.BiomeResult; import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.CellGenerator; import com.volmit.iris.util.CellGenerator;
import com.volmit.iris.util.GenLayer; import com.volmit.iris.util.GenLayer;
@ -119,7 +120,7 @@ public class GenLayerBiome extends GenLayer
return bridgeGenerator.getIndex(x, z, 5) == 1 ? InferredType.SEA : InferredType.LAND; return bridgeGenerator.getIndex(x, z, 5) == 1 ? InferredType.SEA : InferredType.LAND;
} }
public BiomeResult generateBiomeData(double bx, double bz, IrisRegion regionData, CellGenerator cell, KList<IrisBiome> biomes, InferredType inferredType) public BiomeResult generateBiomeData(double bx, double bz, IrisRegion regionData, BiomeRarityCellGenerator cell, KList<IrisBiome> biomes, InferredType inferredType)
{ {
if(biomes.isEmpty()) if(biomes.isEmpty())
{ {
@ -128,7 +129,7 @@ public class GenLayerBiome extends GenLayer
double x = bx / iris.getDimension().getBiomeZoom(); double x = bx / iris.getDimension().getBiomeZoom();
double z = bz / iris.getDimension().getBiomeZoom(); double z = bz / iris.getDimension().getBiomeZoom();
IrisBiome biome = biomes.get(cell.getIndex(x, z, biomes.size())); IrisBiome biome = cell.get(x, z, biomes);
biome.setInferredType(inferredType); biome.setInferredType(inferredType);
return implode(bx, bz, regionData, cell, new BiomeResult(biome, cell.getDistance(x, z))); return implode(bx, bz, regionData, cell, new BiomeResult(biome, cell.getDistance(x, z)));
@ -155,12 +156,12 @@ public class GenLayerBiome extends GenLayer
return pureResult; return pureResult;
} }
public BiomeResult implode(double bx, double bz, IrisRegion regionData, CellGenerator parentCell, BiomeResult parent) public BiomeResult implode(double bx, double bz, IrisRegion regionData, BiomeRarityCellGenerator parentCell, BiomeResult parent)
{ {
return implode(bx, bz, regionData, parentCell, parent, 1); return implode(bx, bz, regionData, parentCell, parent, 1);
} }
public BiomeResult implode(double bx, double bz, IrisRegion regionData, CellGenerator parentCell, BiomeResult parent, int hits) public BiomeResult implode(double bx, double bz, IrisRegion regionData, BiomeRarityCellGenerator parentCell, BiomeResult parent, int hits)
{ {
if(hits > 9) if(hits > 9)
{ {
@ -174,15 +175,10 @@ public class GenLayerBiome extends GenLayer
{ {
if(!parent.getBiome().getRealChildren().isEmpty()) if(!parent.getBiome().getRealChildren().isEmpty())
{ {
CellGenerator childCell = parent.getBiome().getChildrenGenerator(rng, 123, parentCell.getCellScale() * parent.getBiome().getChildShrinkFactor()); BiomeRarityCellGenerator childCell = parent.getBiome().getChildrenGenerator(rng, 123, parentCell.getCellScale() * parent.getBiome().getChildShrinkFactor());
int r = childCell.getIndex(x, z, parent.getBiome().getRealChildren().size() + 1); KList<IrisBiome> chx = parent.getBiome().getRealChildren().copy();
chx.add(parent.getBiome());
if(r == parent.getBiome().getRealChildren().size()) IrisBiome biome = childCell.get(x, z, chx);
{
return new BiomeResult(parent.getBiome(), childCell.getDistance(x, z));
}
IrisBiome biome = parent.getBiome().getRealChildren().get(r);
biome.setInferredType(parent.getBiome().getInferredType()); biome.setInferredType(parent.getBiome().getInferredType());
return implode(bx, bz, regionData, childCell, new BiomeResult(biome, childCell.getDistance(x, z)), hits + 1); return implode(bx, bz, regionData, childCell, new BiomeResult(biome, childCell.getDistance(x, z)), hits + 1);

View File

@ -6,8 +6,8 @@ import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.util.BiomeRarityCellGenerator;
import com.volmit.iris.util.CNG; import com.volmit.iris.util.CNG;
import com.volmit.iris.util.CellGenerator;
import com.volmit.iris.util.Desc; import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate; import com.volmit.iris.util.DontObfuscate;
import com.volmit.iris.util.KList; import com.volmit.iris.util.KList;
@ -96,7 +96,7 @@ public class IrisBiome extends IrisRegistrant
private KList<IrisDepositGenerator> deposits = new KList<>(); private KList<IrisDepositGenerator> deposits = new KList<>();
private transient ReentrantLock lock = new ReentrantLock(); private transient ReentrantLock lock = new ReentrantLock();
private transient CellGenerator childrenCell; private transient BiomeRarityCellGenerator childrenCell;
private transient InferredType inferredType; private transient InferredType inferredType;
private transient CNG biomeGenerator; private transient CNG biomeGenerator;
private transient int maxHeight = Integer.MIN_VALUE; private transient int maxHeight = Integer.MIN_VALUE;
@ -134,11 +134,11 @@ public class IrisBiome extends IrisRegistrant
return biomeGenerator; return biomeGenerator;
} }
public CellGenerator getChildrenGenerator(RNG random, int sig, double scale) public BiomeRarityCellGenerator getChildrenGenerator(RNG random, int sig, double scale)
{ {
if(childrenCell == null) if(childrenCell == null)
{ {
childrenCell = new CellGenerator(random.nextParallelRNG(sig * 213)); childrenCell = new BiomeRarityCellGenerator(random.nextParallelRNG(sig * 2137));
childrenCell.setCellScale(scale); childrenCell.setCellScale(scale);
} }

View File

@ -0,0 +1,65 @@
package com.volmit.iris.util;
import com.volmit.iris.object.IrisBiome;
public class BiomeRarityCellGenerator extends CellGenerator
{
public BiomeRarityCellGenerator(RNG rng)
{
super(rng);
}
public IrisBiome get(double x, double z, KList<IrisBiome> b)
{
if(b.size() == 0)
{
return null;
}
if(b.size() == 1)
{
return b.get(0);
}
KList<IrisBiome> rarityMapped = new KList<>();
boolean o = false;
int max = 1;
for(IrisBiome i : b)
{
if(i.getRarity() > max)
{
max = i.getRarity();
}
}
max++;
for(IrisBiome i : b)
{
for(int j = 0; j < max - i.getRarity(); j++)
{
if(o = !o)
{
rarityMapped.add(i);
}
else
{
rarityMapped.add(0, i);
}
}
}
if(rarityMapped.size() == 1)
{
return rarityMapped.get(0);
}
if(rarityMapped.isEmpty())
{
throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly "));
}
return rarityMapped.get(getIndex(x, z, rarityMapped.size()));
}
}