Fixed logical fallacies for world mapper.

Method name changed (refactor) as well.
This commit is contained in:
Harrison Deng 2020-04-23 00:01:35 -05:00
parent b1699f8f69
commit e936dff934
2 changed files with 27 additions and 26 deletions

View File

@ -9,13 +9,13 @@ import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch;
public class IslandWorldMapper implements CoordinateValidatable { public class IslandWorldMapper implements CoordinateValidatable {
private SimplexOctaveGenerator noiseGenerator; private SimplexOctaveGenerator noiseGenerator;
private final int noiseOctaves = 8; private final int noiseOctaves = 3;
private final float islandGenerationPercent = 30; private final float islandBlockGenerationPercent = 15f;
private final float exaggerationFactor = 1.5f; private final float exaggerationFactor = 0.15f;
private final double noiseFrequency = 0.5D; private final double noiseFrequency = 0.6D;
private final double noiseAmplitude = 0.5D; private final double noiseAmplitude = 0.4D;
private final float shoreFactor = 0.065f; private final float shoreFactor = 0.035f;
private final float shallowPortion = 0.06f; private final float shallowPortion = 0.01f;
private final DepthFirstSearch dfs; private final DepthFirstSearch dfs;
public IslandWorldMapper(Random random) { public IslandWorldMapper(Random random) {
@ -30,7 +30,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
* @return * @return
*/ */
public boolean isLand(int worldX, int worldZ) { public boolean isLand(int worldX, int worldZ) {
if (getIslandValue(worldX, worldZ) >= 0) { if (getWorldBlockValue(worldX, worldZ) >= 0) {
return true; return true;
} }
return false; return false;
@ -60,7 +60,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
*/ */
public boolean isShore(int worldX, int worldZ) { public boolean isShore(int worldX, int worldZ) {
if (!isIsland(worldX, worldZ)) return false; if (!isIsland(worldX, worldZ)) return false;
if (isLand(worldX, worldZ) && getIslandValue(worldX, worldZ) <= shoreFactor) { if (isLand(worldX, worldZ) && getWorldBlockValue(worldX, worldZ) <= shoreFactor) {
return true; return true;
} }
return false; return false;
@ -89,15 +89,15 @@ public class IslandWorldMapper implements CoordinateValidatable {
* @return true if it is considered the shallow portion. * @return true if it is considered the shallow portion.
*/ */
public boolean isShallowPortion(int worldX, int worldZ) { public boolean isShallowPortion(int worldX, int worldZ) {
if (getIslandValue(worldX, worldZ) >= -shallowPortion) { if (getWorldBlockValue(worldX, worldZ) >= -shallowPortion) {
return true; return true;
} }
return true; return false;
} }
/** /**
* Island value will be 0 or positive if it is a part of an island. * World block value will be 0 or positive if it is a part of an island.
* If less than, it is considered under the sea. * If less than, it is considered under the sea.
* Does not factor in a shallow depth. * Does not factor in a shallow depth.
* The value is normalized to [0, 1]. * The value is normalized to [0, 1].
@ -105,19 +105,20 @@ public class IslandWorldMapper implements CoordinateValidatable {
* @param worldZ the z world coordinate to obtain this value for. * @param worldZ the z world coordinate to obtain this value for.
* @return a value representing the island at the given point. * @return a value representing the island at the given point.
*/ */
public double getIslandValue(int worldX, int worldZ) { public double getWorldBlockValue(int worldX, int worldZ) {
double normalized = getNoiseValue(worldX, worldZ); double portionSea = 1f - (this.islandBlockGenerationPercent / 100f);
return Math.pow(normalized, exaggerationFactor); double shift = 1f - 2 * portionSea;
} double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true);
double noise = 0;
public double getNoiseValue(int worldX, int worldZ) { if (rawNoise < 0) {
float portionSea = 1f - (this.islandGenerationPercent / 100f); noise = - Math.pow(rawNoise, exaggerationFactor) + shift;
float shift = 1f - 2 * portionSea; } else {
double noise = (noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true) + shift); noise = Math.pow(rawNoise, exaggerationFactor) + shift;
float maxNeg = -1 + shift; }
float maxPos = 1 + shift; double maxNeg = -1 + shift;
double maxPos = 1 + shift;
if (noise < 0) { if (noise < 0) {
return noise / maxNeg; return - noise / maxNeg;
} }
return noise / maxPos; return noise / maxPos;
} }
@ -143,6 +144,6 @@ public class IslandWorldMapper implements CoordinateValidatable {
@Override @Override
public boolean validate(int x, int y) { public boolean validate(int x, int y) {
return isIsland(x, x); return isIsland(x, y);
} }
} }

View File

@ -55,7 +55,7 @@ public class WorldHeightShader {
} }
private int calculateTerrainHeight(int worldX, int worldZ) { private int calculateTerrainHeight(int worldX, int worldZ) {
double islandValue = islandLocator.getIslandValue(worldX, worldZ); double islandValue = islandLocator.getWorldBlockValue(worldX, worldZ);
if (islandValue >= 0) { if (islandValue >= 0) {
return seaLevel; return seaLevel;
} }