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 {
private SimplexOctaveGenerator noiseGenerator;
private final int noiseOctaves = 8;
private final float islandGenerationPercent = 30;
private final float exaggerationFactor = 1.5f;
private final double noiseFrequency = 0.5D;
private final double noiseAmplitude = 0.5D;
private final float shoreFactor = 0.065f;
private final float shallowPortion = 0.06f;
private final int noiseOctaves = 3;
private final float islandBlockGenerationPercent = 15f;
private final float exaggerationFactor = 0.15f;
private final double noiseFrequency = 0.6D;
private final double noiseAmplitude = 0.4D;
private final float shoreFactor = 0.035f;
private final float shallowPortion = 0.01f;
private final DepthFirstSearch dfs;
public IslandWorldMapper(Random random) {
@ -30,7 +30,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
* @return
*/
public boolean isLand(int worldX, int worldZ) {
if (getIslandValue(worldX, worldZ) >= 0) {
if (getWorldBlockValue(worldX, worldZ) >= 0) {
return true;
}
return false;
@ -60,7 +60,7 @@ public class IslandWorldMapper implements CoordinateValidatable {
*/
public boolean isShore(int worldX, int worldZ) {
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 false;
@ -89,15 +89,15 @@ public class IslandWorldMapper implements CoordinateValidatable {
* @return true if it is considered the shallow portion.
*/
public boolean isShallowPortion(int worldX, int worldZ) {
if (getIslandValue(worldX, worldZ) >= -shallowPortion) {
if (getWorldBlockValue(worldX, worldZ) >= -shallowPortion) {
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.
* Does not factor in a shallow depth.
* 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.
* @return a value representing the island at the given point.
*/
public double getIslandValue(int worldX, int worldZ) {
double normalized = getNoiseValue(worldX, worldZ);
return Math.pow(normalized, exaggerationFactor);
}
public double getNoiseValue(int worldX, int worldZ) {
float portionSea = 1f - (this.islandGenerationPercent / 100f);
float shift = 1f - 2 * portionSea;
double noise = (noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true) + shift);
float maxNeg = -1 + shift;
float maxPos = 1 + shift;
public double getWorldBlockValue(int worldX, int worldZ) {
double portionSea = 1f - (this.islandBlockGenerationPercent / 100f);
double shift = 1f - 2 * portionSea;
double rawNoise = noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true);
double noise = 0;
if (rawNoise < 0) {
noise = - Math.pow(rawNoise, exaggerationFactor) + shift;
} else {
noise = Math.pow(rawNoise, exaggerationFactor) + shift;
}
double maxNeg = -1 + shift;
double maxPos = 1 + shift;
if (noise < 0) {
return noise / maxNeg;
return - noise / maxNeg;
}
return noise / maxPos;
}
@ -143,6 +144,6 @@ public class IslandWorldMapper implements CoordinateValidatable {
@Override
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) {
double islandValue = islandLocator.getIslandValue(worldX, worldZ);
double islandValue = islandLocator.getWorldBlockValue(worldX, worldZ);
if (islandValue >= 0) {
return seaLevel;
}