mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 14:50:30 +00:00
Performance improvements
This commit is contained in:
57
src/main/java/com/dfsek/terra/procgen/GridSpawn.java
Normal file
57
src/main/java/com/dfsek/terra/procgen/GridSpawn.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.dfsek.terra.procgen;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class GridSpawn {
|
||||
private final int separation;
|
||||
private final int width;
|
||||
public GridSpawn(int width, int separation) {
|
||||
this.separation = separation;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nearest spawnpoint
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @param seed Seed for RNG
|
||||
* @return Vector representing nearest spawnpoint
|
||||
*/
|
||||
public Vector getNearestSpawn(int x, int z, long seed) {
|
||||
int structureChunkX = x / (width + 2*separation);
|
||||
int structureChunkZ = z / (width + 2*separation);
|
||||
List<Vector> zones = new ArrayList<>();
|
||||
for(int xi = structureChunkX-1; xi <= structureChunkX+1; xi++) {
|
||||
for(int zi = structureChunkZ-1; zi <= structureChunkZ+1; zi++) {
|
||||
zones.add(getChunkSpawn(xi, zi, seed));
|
||||
}
|
||||
}
|
||||
Vector shortest = zones.get(0);
|
||||
Vector compare = new Vector(x, 0, z);
|
||||
for(Vector v : zones) {
|
||||
if(compare.distanceSquared(shortest) > compare.distanceSquared(v)) shortest = v.clone();
|
||||
}
|
||||
return shortest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X/Z coordinates of the spawnpoint in the nearest Chunk (not Minecraft chunk)
|
||||
* @param structureChunkX Chunk X coordinate
|
||||
* @param structureChunkZ Chunk Z coordinate
|
||||
* @param seed Seed for RNG
|
||||
* @return Vector representing spawnpoint
|
||||
*/
|
||||
private Vector getChunkSpawn(int structureChunkX, int structureChunkZ, long seed) {
|
||||
Random r = new Random(MathUtil.getCarverChunkSeed(structureChunkX, structureChunkZ, seed));
|
||||
int offsetX = r.nextInt(width);
|
||||
int offsetZ = r.nextInt(width);
|
||||
int sx = structureChunkX * (width + 2*separation) + offsetX;
|
||||
int sz = structureChunkZ * (width + 2*separation) + offsetZ;
|
||||
return new Vector(sx, 0, sz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dfsek.terra.procgen.voxel;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.FastNoise;
|
||||
|
||||
public class DeformedSphere extends VoxelGeometry {
|
||||
public DeformedSphere(Vector start, int rad, double deform, FastNoise noise) {
|
||||
for(int x = -rad; x <= rad; x++) {
|
||||
for(int y = -rad; y <= rad; y++) {
|
||||
for(int z = -rad; z <= rad; z++) {
|
||||
Vector c = new Vector(x, y, z);
|
||||
if(c.length() < (rad + 0.5) * ((noise.getNoise(x, y, z)+1)*deform)) {
|
||||
addVector(c.add(start));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/main/java/com/dfsek/terra/procgen/voxel/Sphere.java
Normal file
19
src/main/java/com/dfsek/terra/procgen/voxel/Sphere.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.procgen.voxel;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.FastNoise;
|
||||
|
||||
public class Sphere extends VoxelGeometry {
|
||||
public Sphere(Vector start, int rad) {
|
||||
for(int x = -rad; x <= rad; x++) {
|
||||
for(int y = -rad; y <= rad; y++) {
|
||||
for(int z = -rad; z <= rad; z++) {
|
||||
Vector c = new Vector(x, y, z);
|
||||
if(c.length() < rad + 0.5) {
|
||||
addVector(c.add(start));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/main/java/com/dfsek/terra/procgen/voxel/Tube.java
Normal file
15
src/main/java/com/dfsek/terra/procgen/voxel/Tube.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.dfsek.terra.procgen.voxel;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Tube extends VoxelGeometry {
|
||||
public Tube(Vector start, Vector end, int radius) {
|
||||
Vector step = start.clone().subtract(end).normalize();
|
||||
Vector run = start.clone();
|
||||
int steps = (int) start.distance(end);
|
||||
for(int i = 0; i < steps; i++) {
|
||||
merge(new Sphere(run, radius));
|
||||
run.add(step);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.procgen.voxel;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class VoxelGeometry {
|
||||
public List<Vector> geometry = new ArrayList<>();
|
||||
|
||||
public List<Vector> getGeometry() {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
protected void addVector(Vector v) {
|
||||
geometry.add(v);
|
||||
}
|
||||
|
||||
public void merge(VoxelGeometry other) {
|
||||
geometry.addAll(other.getGeometry());
|
||||
}
|
||||
public static VoxelGeometry getBlank() {
|
||||
return new Blank();
|
||||
}
|
||||
private static class Blank extends VoxelGeometry {}
|
||||
}
|
||||
Reference in New Issue
Block a user