diff --git a/src/main/java/org/terasology/polyworld/IslandWorldGenerator.java b/src/main/java/org/terasology/polyworld/IslandWorldGenerator.java index 438872d..51456e5 100644 --- a/src/main/java/org/terasology/polyworld/IslandWorldGenerator.java +++ b/src/main/java/org/terasology/polyworld/IslandWorldGenerator.java @@ -98,7 +98,7 @@ public Vector3fc getSpawnPosition(EntityRef entity) { int searchRadius = 16; Vector3i ext = new Vector3i(searchRadius, 1, searchRadius); - Vector3i desiredPos = new Vector3i(new Vector3f(pos.x(), 1, pos.z()), RoundingMode.FLOOR); + Vector3i desiredPos = new Vector3i(new Vector3f(pos.x(), 1, pos.z()), RoundingMode.HALF_UP); // try and find somewhere in this region a spot to land BlockRegion spawnArea = new BlockRegion(desiredPos).expand(ext); @@ -121,12 +121,12 @@ public Vector3fc getSpawnPosition(EntityRef entity) { Vector2i target; if (picker.getClosest() != null) { Vector2fc hit = picker.getClosest().getCenter(); - target = new Vector2i(new Vector2f(hit.x(), hit.y()), RoundingMode.FLOOR); + target = new Vector2i(new Vector2f(hit.x(), hit.y()), RoundingMode.HALF_UP); } else { target = new Vector2i(desiredPos.x(), desiredPos.z()); } - FixedSpawner spawner = new FixedSpawner(target.x(), target.y(), RoundingMode.FLOOR); + FixedSpawner spawner = new FixedSpawner(target.x(), target.y()); return spawner.getSpawnPosition(getWorld(), entity); } } diff --git a/src/main/java/org/terasology/polyworld/distribution/AmitBlobDistribution.java b/src/main/java/org/terasology/polyworld/distribution/AmitBlobDistribution.java index 8e723e1..12e7721 100644 --- a/src/main/java/org/terasology/polyworld/distribution/AmitBlobDistribution.java +++ b/src/main/java/org/terasology/polyworld/distribution/AmitBlobDistribution.java @@ -16,6 +16,7 @@ package org.terasology.polyworld.distribution; +import org.joml.Vector2fc; import org.terasology.math.geom.Vector2f; /** @@ -24,8 +25,8 @@ public class AmitBlobDistribution implements Distribution { @Override - public boolean isInside(Vector2f p2) { - Vector2f p = new Vector2f(2 * (p2.getX() - 0.5f), 2 * (p2.getY() - 0.5f)); + public boolean isInside(Vector2fc p2) { + Vector2f p = new Vector2f(2 * (p2.x() - 0.5f), 2 * (p2.y() - 0.5f)); boolean eye1 = new Vector2f(p.getX() - 0.2f, p.getY() / 2 + 0.2f).length() < 0.05f; boolean eye2 = new Vector2f(p.getX() + 0.2f, p.getY() / 2 + 0.2f).length() < 0.05f; diff --git a/src/main/java/org/terasology/polyworld/distribution/Distribution.java b/src/main/java/org/terasology/polyworld/distribution/Distribution.java index 3c27a1e..603e37b 100644 --- a/src/main/java/org/terasology/polyworld/distribution/Distribution.java +++ b/src/main/java/org/terasology/polyworld/distribution/Distribution.java @@ -16,7 +16,7 @@ package org.terasology.polyworld.distribution; -import org.terasology.math.geom.Vector2f; +import org.joml.Vector2fc; /** * TODO Type description @@ -27,6 +27,6 @@ public interface Distribution { * @param point in normalized coordinates [0..1][0..1] * @return true if inside */ - boolean isInside(Vector2f point); + boolean isInside(Vector2fc point); } diff --git a/src/main/java/org/terasology/polyworld/distribution/PerlinDistribution.java b/src/main/java/org/terasology/polyworld/distribution/PerlinDistribution.java index ab004ae..ac5a62e 100644 --- a/src/main/java/org/terasology/polyworld/distribution/PerlinDistribution.java +++ b/src/main/java/org/terasology/polyworld/distribution/PerlinDistribution.java @@ -16,6 +16,7 @@ package org.terasology.polyworld.distribution; +import org.joml.Vector2fc; import org.terasology.math.geom.Vector2f; import org.terasology.utilities.procedural.BrownianNoise; import org.terasology.utilities.procedural.PerlinNoise; @@ -35,11 +36,11 @@ public PerlinDistribution(long seed) { } @Override - public boolean isInside(Vector2f p2) { - Vector2f p = new Vector2f(2 * (p2.getX() - 0.5f), 2 * (p2.getY() - 0.5f)); + public boolean isInside(Vector2fc p2) { + Vector2f p = new Vector2f(2 * (p2.x() - 0.5f), 2 * (p2.y() - 0.5f)); - float x = (p.getX() + 1) * 128; - float y = (p.getY() + 1) * 128; + float x = (p.x() + 1) * 128; + float y = (p.y() + 1) * 128; float val = (noise.noise(x, y, 0) + 1) * 2f; return val < 1.3 + .7 * p.length(); } diff --git a/src/main/java/org/terasology/polyworld/distribution/RadialDistribution.java b/src/main/java/org/terasology/polyworld/distribution/RadialDistribution.java index 2a6d23d..dfb4c4e 100644 --- a/src/main/java/org/terasology/polyworld/distribution/RadialDistribution.java +++ b/src/main/java/org/terasology/polyworld/distribution/RadialDistribution.java @@ -16,9 +16,11 @@ package org.terasology.polyworld.distribution; +import org.joml.Vector2f; +import org.joml.Vector2fc; + import java.util.Random; -import org.terasology.math.geom.Vector2f; /** * TODO Type description @@ -45,11 +47,11 @@ public RadialDistribution(long seed) { } @Override - public boolean isInside(Vector2f p2) { - Vector2f p = new Vector2f(2 * (p2.getX() - 0.5f), 2 * (p2.getY() - 0.5f)); + public boolean isInside(Vector2fc p2) { + Vector2f p = new Vector2f(2 * (p2.x() - 0.5f), 2 * (p2.y() - 0.5f)); - float angle = (float) Math.atan2(p.getY(), p.getX()); - float length = 0.5f * (Math.max(Math.abs(p.getX()), Math.abs(p.getY())) + p.length()); + float angle = (float) Math.atan2(p.y(), p.x()); + float length = 0.5f * (Math.max(Math.abs(p.x()), Math.abs(p.y())) + p.length()); float r1 = 0.5f + 0.40f * (float) Math.sin(startAngle + bumps * angle + Math.cos((bumps + 3) * angle)); float r2 = 0.7f - 0.20f * (float) Math.sin(startAngle + bumps * angle - Math.sin((bumps + 2) * angle)); diff --git a/src/main/java/org/terasology/polyworld/graph/GraphEditor.java b/src/main/java/org/terasology/polyworld/graph/GraphEditor.java index d9c83b1..6937c8a 100644 --- a/src/main/java/org/terasology/polyworld/graph/GraphEditor.java +++ b/src/main/java/org/terasology/polyworld/graph/GraphEditor.java @@ -35,9 +35,9 @@ private GraphEditor() { } /** - * Moving corners by averaging the nearby centers produces more uniform edge lengths, - * although it occasionally worsens the polygon sizes. However, moving corners will - * lose the Voronoi diagram properties. + * Moving corners by averaging the nearby centers produces more uniform edge lengths, although it occasionally + * worsens the polygon sizes. However, moving corners will lose the Voronoi diagram properties. + * * @param corners the collection of corners */ public static void improveCorners(Collection corners) { @@ -66,6 +66,7 @@ public static void improveCorners(Collection corners) { /** * Moves all corners to a random position within a circle with r=maxDist around it + * * @param corners the set of corners * @param random the random number gen * @param maxDist the maximum moving distance @@ -82,13 +83,13 @@ public static void jitterCorners(Collection corners, Random random, floa float len = random.nextFloat(0, maxDist); float rx = (float) (Math.cos(ang) * len); float ry = (float) (Math.sin(ang) * len); - c.setLocation(loc.add(rx, ry, new Vector2f())); + c.setLocation(loc.add(rx, ry, new Vector2f())); } } /** - * Perform Lloyd's algorithm to achieve well-shaped - * and uniformly sized convex cells. + * Perform Lloyd's algorithm to achieve well-shaped and uniformly sized convex cells. + * * @param v the Voronoi diagram to relax * @return a new Voronoi diagram */ @@ -105,7 +106,7 @@ public static Voronoi lloydRelaxation(Voronoi v) { } x /= region.size(); y /= region.size(); - result.add(new Vector2f(x,y)); + result.add(new Vector2f(x, y)); } return new Voronoi(result, v.getPlotBounds()); } diff --git a/src/main/java/org/terasology/polyworld/graph/GraphFacet.java b/src/main/java/org/terasology/polyworld/graph/GraphFacet.java index d30624a..99627e0 100644 --- a/src/main/java/org/terasology/polyworld/graph/GraphFacet.java +++ b/src/main/java/org/terasology/polyworld/graph/GraphFacet.java @@ -16,12 +16,11 @@ package org.terasology.polyworld.graph; -import java.util.Collection; - import org.terasology.math.geom.Vector2i; import org.terasology.polyworld.rp.WorldRegion; import org.terasology.world.generation.WorldFacet2D; -import org.terasology.world.generation.WorldFacet3D; + +import java.util.Collection; /** * TODO Type description diff --git a/src/main/java/org/terasology/polyworld/graph/GridGraph.java b/src/main/java/org/terasology/polyworld/graph/GridGraph.java index 1c379ba..a3f79fa 100644 --- a/src/main/java/org/terasology/polyworld/graph/GridGraph.java +++ b/src/main/java/org/terasology/polyworld/graph/GridGraph.java @@ -48,8 +48,8 @@ public GridGraph(BlockAreac bounds, int rows, int cols) { this.cols = cols; this.bounds.set(bounds); - float dx = (float) (bounds.maxX() - bounds.minX()) / cols; - float dy = (float) (bounds.maxY() - bounds.minY()) / rows; + float dx = (float) bounds.getSizeX() / cols; + float dy = (float) bounds.getSizeY() / rows; for (int r = 0; r <= rows; r++) { for (int c = 0; c <= cols; c++) { diff --git a/src/main/java/org/terasology/polyworld/raster/RiverRasterizer.java b/src/main/java/org/terasology/polyworld/raster/RiverRasterizer.java index 41f9c19..abbc5eb 100644 --- a/src/main/java/org/terasology/polyworld/raster/RiverRasterizer.java +++ b/src/main/java/org/terasology/polyworld/raster/RiverRasterizer.java @@ -31,6 +31,7 @@ import org.terasology.world.block.BlockManager; import org.terasology.world.block.BlockRegion; import org.terasology.world.chunks.ChunkConstants; +import org.terasology.world.chunks.Chunks; import org.terasology.world.chunks.CoreChunk; import org.terasology.world.generation.Region; import org.terasology.world.generation.WorldRasterizer; @@ -89,8 +90,8 @@ public void generateChunk(CoreChunk chunk, Region chunkRegion) { for (Vector2i p : line) { if (p.getX() >= region.minX() && p.getX() <= region.maxX() && p.getY() >= region.minZ() && p.getY() <= region.maxZ()) { - int x = ChunkMath.calcRelativeBlockPos(p.getX(), ChunkConstants.INNER_CHUNK_POS_FILTER.x()); - int z = ChunkMath.calcRelativeBlockPos(p.getY(), ChunkConstants.INNER_CHUNK_POS_FILTER.z()); + int x = ChunkMath.calcRelativeBlockPos(p.getX(), Chunks.INNER_CHUNK_POS_FILTER.x()); + int z = ChunkMath.calcRelativeBlockPos(p.getY(), Chunks.INNER_CHUNK_POS_FILTER.z()); int y = TeraMath.floorToInt(elevationFacet.get(x, z)); Vector3i worldPos = new Vector3i(p.getX(), y, p.getY()); diff --git a/src/main/java/org/terasology/polyworld/rp/WorldRegionFacetProvider.java b/src/main/java/org/terasology/polyworld/rp/WorldRegionFacetProvider.java index d671f62..aa0855f 100644 --- a/src/main/java/org/terasology/polyworld/rp/WorldRegionFacetProvider.java +++ b/src/main/java/org/terasology/polyworld/rp/WorldRegionFacetProvider.java @@ -112,8 +112,8 @@ public void process(GeneratingRegion region) { Vector3i max = worldRegion.getMax(new Vector3i()); BlockAreac secArea = new BlockArea( - Chunks.toChunkPos(min.x, SECTOR_POWER), Chunks.toChunkPos(min.y, SECTOR_POWER), - Chunks.toChunkPos(max.x, SECTOR_POWER), Chunks.toChunkPos(max.y, SECTOR_POWER)); + Chunks.toChunkPos(min.x, SECTOR_POWER), Chunks.toChunkPos(min.z, SECTOR_POWER), + Chunks.toChunkPos(max.x, SECTOR_POWER), Chunks.toChunkPos(max.z, SECTOR_POWER)); BlockAreac target = new BlockArea(min.x, min.z, max.x, max.z); diff --git a/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java b/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java index 1f87bdb..f722e6c 100644 --- a/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java +++ b/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java @@ -37,7 +37,7 @@ public class PoissonDiscSampling implements PointSampling { protected Vector2i getGridDimensions(Rectanglef bounds, int numSites) { - float ratio = (bounds.maxX - bounds.minX) / (bounds.maxY - bounds.minY); + float ratio = bounds.getSizeX() / bounds.getSizeY(); double perRow = Math.sqrt(numSites / ratio); int rows = DoubleMath.roundToInt(perRow, RoundingMode.FLOOR); diff --git a/src/main/java/org/terasology/polyworld/water/DefaultWaterModel.java b/src/main/java/org/terasology/polyworld/water/DefaultWaterModel.java index 1789806..084f8f0 100644 --- a/src/main/java/org/terasology/polyworld/water/DefaultWaterModel.java +++ b/src/main/java/org/terasology/polyworld/water/DefaultWaterModel.java @@ -16,23 +16,20 @@ package org.terasology.polyworld.water; -import java.util.Collection; -import java.util.Deque; -import java.util.LinkedList; -import java.util.Map; - +import com.google.common.collect.Maps; +import org.joml.Vector2f; import org.joml.Vector2fc; -import org.terasology.math.geom.Rect2i; -import org.terasology.math.geom.BaseVector2f; -import org.terasology.math.geom.Vector2f; import org.terasology.polyworld.distribution.Distribution; import org.terasology.polyworld.graph.Corner; import org.terasology.polyworld.graph.Graph; import org.terasology.polyworld.graph.GraphRegion; - -import com.google.common.collect.Maps; import org.terasology.world.block.BlockAreac; +import java.util.Collection; +import java.util.Deque; +import java.util.LinkedList; +import java.util.Map; + /** * Uses a {@link Distribution} to define how water is distributed in the graph. * The result is normalized.